Introduction: Automatic IoT Hallway Night Light With ESP8266
I started this project inspired by a staircase light from another instructable post. The difference is the brain of the circuit is using ESP8266, which means it will be come an IoT device.
What I have in mind is to have the hallway night light for the kids, when they step out from their room, it light up the path going to the bathroom. For this I am using the ESP8266 to detect the motion from the PIR sensor. I used 2 PIR sensors, one at each end for the return trip. Given that ESP8266 is IoT capable, then I can also use this to detect whether there is any movement on the hallway by posting MQTT message to the Home Assistant.
Step 1: Gather All the Materials Needed
For this project I am using the following materials:
- PIR sensor
- 330 Ohm resistor which act as the current limitter
- 5 V addressable LED Strip (WS2812B)
- Electrical conduit to house the lights
Step 2: Connect the Circuit
We are essentially connecting the LED strip Data line to pin D2 or ESP8266 via 330 Ohm resistor to limit the current. Keep in mind the ESP8266's operating voltage is 3.3V.
The PIR sensors are connected to Pin D5 and D6, one for the left sensor and one for the right. Don't forget to connect the power for PIR and LED strip to 3.3V in this case.
Step 3: Upload the Code
For the code to work you will need the following library:
- "FastLed" library by Daniel Garcia, in this instance I have version 3.3.3 installed
If you don't already have them installed you can install them from "Tools->Manage Library" in the Arduino interface.
In the following section of the code
#define FASTLED_ESP8266_D1_PIN_ORDER<br>#include "FastLED.h" FASTLED_USING_NAMESPACE
#define NUM_LEDS 30 #define LEDS_PER_STAIR 2 // Number of Leds per stair. Not yet currenlty changable - just noteable #define BRIGHTNESS 120 // 0...255 ( used in fade7 ) #define PIN_LED 04 // LED Data pin (GPIO4) D2 #define PIN_PIR_DOWN 14 // PIR Downstairs Pin (GPI14) D5 #define PIN_PIR_UP 12 // PIR Upstairs Pin (GPI12) D6
You can configure the Number of LED in your LED strip, also the connection of the LEDStrip if you decide to connect it to a different pin and also the PIR sensor pin if you decide to connect it to a different pin of the MCU.
The above configuration is located in "ledsettings.h" file.
You can download the full source code from the following link.
Once you are able to compile the code successfully you can upload it to the ESP8266.
Step 4: Test and Test and Troubleshooting
If all goes well, you should have a working Hallway Lights that you can be proud of. When you power up the circuit for the first time, the LED Strip will light up with some rainbow sequence. Then the can the ESP8266 will act as an access point (AP) to allow you to configure the WiFi connection.
If you are using the code that I have you should be able to see "ESP-HallLight" as the access point. For security I have put password protection for the AP. The default password is "arduino" you can change this in the settings.h file, in the following section.
#define CLOCK_NAME "ESP-HallLight" #define WIFI_AP_NAME CLOCK_NAME #define WIFI_APPSK "arduino" // default AP password
Once connected successfully using a mobile phone or laptop via WiFi, you should be able to point your browser to 192.168.4.1, you should see the settings screen as shown in the picture above. You can now enter your WiFi settings and once entered ESP8266 will re-boot and trying to connect to your WiFi. If it is able to connect successfully you will no longer see the "ESP-HallLight" access point.
If you are still connected to Arduino interface you can monitor this through the serial monitor.
Note: You don't have to configure the WiFi for the sensors to work, it should work after a few seconds when the initial lights are off.
To test you can try walking from one side or waving your hand, the light should light up following the direction of travel, if it is doing the opposite, then you need to swap the left and right sensor in the code.
During my first build I accidentally connect the wrong end of the LED strip, which resulting none of the LEDs lighting up.
I hope you enjoy this build, if this is helpful, please vote for the contest. If you have any questions don't hesitate to drop me a note, and I will get to it as soon as I can.
Some after thought would be to add the additional features like :
Participated in the