Introduction: Automatic Entrance Lighting

About: Maker, Tangible or Intangible Stuff

I want to install automatic lighting in the entrance inside the house. In most cases, a PIR (Passive Infrared Sensor) motion sensing switch and a lamp will do but I drop this idea, as a sensor attached outside seems clumsy.

My goal in this project:

  1. The outlook of the lighting should look simple and low profile.
  2. It is also my interest to try new stuff and verify new ideas in the project:
  • Use 3D Printing for complex geometry.
  • Circuit Design, PCB (Printed Circuit Board) Layout and Prototyping for the electronics.
  • I have use the WiFi-MCU (Microcontroller) ESP32 before. Since we can interact with the MCU via the http-server, isn't it convenient if we have a web-based interface to read sensors signal and set the lighting parameters?

Based on these ideas I made a Mockup and verify it works; I design and make the lighting system.

Note:

  • The physical dimensions stated in this project is for illuminating an area of 1m x 1.5m. You can use it as a reference to scale your design.
  • Some works in this project may be dangerous, take necessary precautions before testing and installation.
  • I don’t have all the equipment and tools to make components. As a result, I outsource 3D printing and PCB manufacturing jobs to professional studios. CAD such as Fusion 360 and EAGLE helps a lot in this scenario. I will talk more in the later sections.

Step 1: Design Overview, Layout and Model

My idea is to make a lighting system “hide” inside the wooden compartment, but allow illumination via an opening.


I use Fusion360 to model the whole scene first. You can visit the Tutorial on how to use it. CAD helps a lot for better visualization in design phase.

For example, we use infrared sensors to track for any people approaching and switch on the light. Therefore, sensors have to position accurately. We can just draw the Infrared ray path in the model. Rotate and move the sensors in any way we want with no complicated calculation beforehand.

Finally, I made it in this way:

  • Create an Opening and install an LED assembly above it.
  • APhotoresistor to check if the room is dark enough to light up.
  • I use 2 Long-range Infrared Sensors to detect if any person approaching the entrance, switching on the light if he is close enough.
  • Another Short-range Infrared Sensor to check if the door opens.
  • The opening is narrow and thus we need to put the sensors in precise positions. We also need a reflector to direct the LED light go through the opening. We can 3D-Print a single part (The Sensors Holder) to fulfill these 2 purposes.
  • System monitoring and parameters adjustment via WiFi: What are the sensor readings now? How close to switching on the light? How dark should the light turn on? How long should the lamp remain ON? We can control the lighting via a web browser by using a WiFi MCU like ESP32.

Step 2: Making the Opening

Tools:

  • Square Ruler
  • Saw- handsaw or electric powered.
  • Drill - hand drill or any electrical driver capable of drilling in wood and plastic.
  • File
  • Trowel, Sandpaper and Paintbrush - for restoring the surface to its original condition and color.

Materials:

  • Acrylic strips - Scraped material is fine provided it is thick enough (~5mm)
  • Plaster
  • Interior Paint

Procedures:

  1. Make An acrylic template to define the dimension of the opening. I stack 4 acrylic strips and glue them together. Use a square ruler to make sure they are 90 Deg to each other. The size of the opening is 365mm X 42mm.
  2. Make 4 mounting holes on the template, then fix it to the compartment using screws.
  3. Drill holes along the edges and saw off the unwanted area.
  4. Use a file to remove excess material and make the edges straight along the template.
  5. Remove the template. Apply plaster on the mounting holes and wooden surface.
  6. Sand the surface and apply plaster. Repeat these steps until the surface is smooth.
  7. Paint the surface.

Step 3: Making the LED Assembly

Tools:

  • Saw - handsaw or electric powered.
  • Drill - hand drill or any electrical driver capable of drilling in wood and plastic.
  • Wire Stripper
  • Soldering iron

Materials:

  • Ø20mm PVC tubing and holders.
  • 5W G4 LED light bulb and socket x5
  • Electrical cables
  • Solder wire
  • Hear shrinkage tube

Procedures:

  1. Cut a PVC tubing length 355mm as the lamp body.
  2. Install Two tube holders at both ends as stands.
  3. Drill Five Ø17mm holes on the PVC tubing for the LED sockets.
  4. Insert the LED sockets and make sure the cables are long enough to come out from the tube, extend the cable in case they are too short. As we will use 5W G4 LED lamps as light sources, the current will be ~ 23mA for a 220VAC source. I use AWG#24 ribbon wires to solder the original cable. Use shrinkage tube to protect the jointed area.
  5. Install the LED bulbs to the LED sockets.
  6. Connect the LED lamps in parallel.

Step 4: Making the Sensor Holder

I use Fusion360 to model the sensor holder first. To simplify installation and manufacturing, the sensor holder also serves as the light reflector and they are a single part. The sensor holder should have mounting cavities match the shapes of the IR Range sensors. This can be done easily when using Fusion360:

  1. Import and position the sensors and sensor holder to their desired positions [as shown in step2]
  2. Use the interference command to check for overlapped volume between the holder and the sensors.
  3. Keep the sensors and remove the overlapped volume in the holder.
  4. Save the model as a new part. The mounting cavities now have the shape of the sensors!
  5. We should also account for the manufacturing tolerance: The sensor dimension tolerance is ±0.3mm and the manufacturing tolerance of 3D printing is ±0.1mm. I made a 0.2mm outward offset on all contact surfaces of the cavities to ensure a clearance fit.

The model is sent to a studio for 3D printing. To lower the manufacturing cost, I use a small thickness of 2mm and create empty patterns to save material.

Turnaround time of the 3D printing is around 48 hours and cost ~US$32. The finished part had already sanded when I receive, but it is too coarse. I therefore refine the surfaces with 400 grit wet sandpaper, followed by spraying the interior with white paint.

Step 5: Circuit Design

Goals and considerations

  • I don't have a solder reflow oven, so only parts in DIP Package is considered.
  • Single board design: The PCB contained all components including the AC-DC power supply unit.
  • Energy saving: Turn on sensors and LED lamp only when the entrance is dark enough.
  • Remote configuration: set the MCU parameters via WiFi.


How the circuit work

  • AC power input through the Terminal Box (TB1), with Fuse protection (XF1).
  • A miniature AC-DC Power supply(PS1) is used to supply 5VDC power to the ESP32 MCU (JP1&2) board and the sensors.
  • The WiFi MCU ESP32 (NodeMCU-32S) read voltage signal from the Photoresistor (PR) using an ADC channel (ADC1_CHANNEL_7). Turn on MOSFET (Q1) via GPIO pin22 to power up all 3 infra-red sensors if the signal is lower than the threshold.
  • Another 3 ADC Channels (ADC1_CHANNEL_0, ADC1_CHANNEL_3, ADC1_CHANNEL_6) for the 3 infra-red sensors signal output (IR_Long_1, IR_Long_2, IR_Short). If signal is higher than the threshold, turn onMOSFET (Q2) via GPIO pin 21, which turn on the SSR (K1) and light up the LED Lamps connected at TB1.
  • The MCU check if the WiFi Toggle (S1) is switched ON via (ADC1_CHANNEL_4), running the WiFi Task to allow parameters set in the MCU.


Part List

  1. NodeMCU-32S x1
  2. Mean Well IRM-10-5 Power Supply x1
  3. Omron G3MC-202P-DC5 Solid State Relay x1
  4. STP16NF06L N-Channel MOSFET x2
  5. Sharp GP2Y0A710K0F Distance Measuring Sensor x2
  6. Sharp GP2Y0A02YK0F Distance Measuring Sensor x1
  7. Female Header 2.54mm -19 pins x2 (or any combinations of headers to make it 19pins)
  8. HB-9500 9.mm spacing Terminal Block 4-pin2 (HP-4P) x1
  9. KF301 5.08mm spacing Terminal Block Connector 2-pins x1
  10. KF301 5.08mm spacing Terminal Block Connector 3-pins x3
  11. SS-12D00 1P2T Toggle Switch x1
  12. BLX-A Fuse holder x1
  13. 500mA Fuse
  14. PhotoResistor x1
  15. 1k Ohm Resistors x3
  16. 0.1uF Capacitors x3
  17. 10uF Capacitor x1
  18. M3X6mm Nylon screws x6
  19. M3X6mm Nylon countersunk screws x4
  20. M3X8mm Nylon spacer x4
  21. M3 Nylon nuts x2
  22. Plastic enclosure (size larger than 86mm x 84mm)
  23. 2W 33k Ohm Resistor x1 (Optional)

Note that low power LED may still glow even the Solid State Relay is OFF, this is because of the snubber inside the solid-state relay. You may need a resistor and capacitor connect in parallel with the LED Lamp to solve this problem.

Step 6: PCB Layout and Assembly

We can use prototype universal PCB to make the circuit. But I try to use EAGLE CAD to design the schematic and layout. The board images (Gerber file) are sent to PCB Prototyping Studio for fabrication.

A 2-layers FR4 board with 1oz copper is used. Features such as Mounting holes, Plated Through Holes, Hot Air Solder Leveling, Solder mask layer, Silkscreen text (well.. now they use ink-jet printing) are included. The cost for making 10pcs(MOQ) PCB is ~US$4.2 - a reasonable price at such quality of work.

There are good tutorials on using EAGLE for PCB design.

From Sparkfun:

A good Youtube tutorial by Ilya Mikhelson:

Insert the components to the PCB and soldering at the back. Reinforce the Solid State Relay, fuse box and capacitors with hot glue.
Drill holes at the bottom of plastic enclosure and install the nylon spacers. Make openings at the side walls to allow cable connections. Mount the PCB Assembly on top of the spacers.

Step 7: Extend the Sensor Cables

The original sensor cables are too short and need extension. I use shielded 22AWG signal cable to reduce noise from interfering with signal voltage. Connected the shielding to the sensor Ground, while Vcc and Vo to other wires. Protect the joint with shrinkage tube.

Extend the photoresistor in the same way.

Step 8: Assembly

    1. Install the LED assembly, apply silicone or hot glue to the stand and fix it on the compartment.
    2. Install the sensor holder to cover the LED assembly. Mount the 3 infra-red sensors to the sensor holders.
    3. Drill a Ø6.5mm hole in the compartment near the corner. Insert the photoresistor, fix it and the cable by using hot heat glue.
    4. Mount the enclosure containing the control circuit to the wall.
    5. Make the following wire connections:
    • AC Power Source to "AC IN" of the circuit.
    • The LED lamp power to the "AC OUT" of the circuit.
    • Infrared sensors: Vcc to "5V", GND to "GND", Vo to "Vout" in the circuit
    • Photoresistor to "PR" in the circuit.

    Step 9: The Firmware and Setup

    The Firmware source code can be download in this GitHub Link.

    Switch on the WiFi Toggle button and Power up the device. The MCU will enter the SoftAP mode by default and you can connect to the Access Point "ESP32_Entrance_Lighting" via WiFi.

    Go to 192.168.10.1 in the browser and access the following functions:

    1. OTA Firmware Update via browser upload.
    2. Parameters Setting :

    • PhotoResistor- Photoresistor Trigger Level below which sensors will power up (12bit ADC range 0-4095)
    • IR_Long1 - Distance below which Long Range Infrared Sensor 1 will switch on the lamp (12bit ADC range 0-4095)
    • IR_Long2 - Distance below which Long Range Infrared Sensor 2 will switch on the lamp (12bit ADC range 0-4095)
    • IR_Short - Distance below which Short Range Infrared Sensor will switch on the lamp (12bit ADC range 0-4095)
    • Light On Time - The duration which the lamp stay on (milliseconds)

    Click "Update" will set the trigger levels to the values in the text boxes.

    Click "Sensor polling" the present sensor readings will be update every second, provided that the light level is lower than trigger level of photoresistor.

    Step 10: Finish !

    Some thoughts on further improvement:

    • MCU deep sleep mode/Ultra Low Power coprocessor to reduce the energy consumption.
    • Using websocket/secure websocket instead of traditional HTTP message for a faster response.
    • Use of lower cost components like laser range sensors.

    The material cost for this project is around US$91 - a little expensive but I think it is worthy to try new stuff and explore technology.

    Project completed and it works. Hope you enjoy this Instructable.