A simple project to control an LED strip that reacts to the proximity of objects using an ultrasonic sensor. The LED strip changes colors when an object is detected and smoothly returns to the default color when the object moves away.
Used in and developed for SG Night Fest 2024's Delulu High.
- Proximity Detection: Changes LED color based on object distance.
- Smooth Transitions: LED colors fade smoothly between states.
- Pulsing Brightness: LED brightness gently pulses in a sine wave.
- Microcontroller: NodeMCU ESP8266
- LED Strip: WS2812B (can be changed to any compatible with FastLED)
- Ultrasonic Sensor: HC-SR04
- Power Supply: Adequate power for both the microcontroller and LED strip
-
Pin Configuration:
- LED Strip Data Pin: Connect to D0 (GPIO16)
- Ultrasonic Trigger Pin: Connect to D1 (GPIO5)
- Ultrasonic Echo Pin: Connect to D2 (GPIO4)
-
Power Supply:
- LED Strip: Ensure the LED strip has a stable 5V power supply. The NodeMCU's 3.3V pin is not sufficient for the LEDs.
- Microcontroller: Power the NodeMCU via USB or a 5V source connected to Vin.
- Ultrasonic Sensor: Power the HC-SR04 via a 5V source connected to VCC.
-
Library Installation:
- Install the FastLED library using the Arduino IDE Library Manager.
-
ESP8266 Setup in Arduino IDE:
- In the Arduino IDE, go to
File > Preferences. - Add this URL to the "Additional Board Manager URLs" field:
http://arduino.esp8266.com/stable/package_esp8266com_index.json - Go to
Tools > Board > Boards Manager, search for "ESP8266", and install it. - Select
NodeMCU 1.0 (ESP-12E Module)underTools > Board.
- In the Arduino IDE, go to
-
CH340C Driver Installation:
- If your NodeMCU board uses the CH340C USB-to-serial chip, you may need to install the appropriate driver to ensure your computer can communicate with the board.
- Download Driver:
- For Windows: Download CH340C Driver
- For Mac: Download CH340C Driver
- For Linux: Download CH340C Driver
- Or: Get the latest driver from factory
- Verify Installation:
- After installation, connect your NodeMCU to your computer via USB. The board should now appear under
Tools > Portin the Arduino IDE.
- After installation, connect your NodeMCU to your computer via USB. The board should now appear under
-
Uploading Code:
- Clone or download this repository.
- Open the
LEDProximitySensor.inofile in the Arduino IDE. - Select the correct port under
Tools > Port. - Upload the code to your NodeMCU.
- Wire the components as described in the pin configuration.
- Power on the setup; the LED strip will start pulsing in the default green color.
- The color changes when an object is detected within 10 cm. The LEDs return to green when the object is removed.
- Set default color: Change
DEFAULT_COLORin the code.- CRGB::Black represents a turned off state. A list of colours can be found here.
- Modify detection distance: Change
DETECTION_DISTANCE. - Adjust transition speed: Modify
TRANSITION_DURATION.