Skip to content

Control an LED strip that reacts to object proximity with smooth color transitions and pulsing effects using a NodeMCU ESP8266 and HC-SR04 ultrasonic sensor.

Notifications You must be signed in to change notification settings

rrvsh/LEDProximitySensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LEDProximitySensor

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.

Features

  • 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.

Hardware Requirements

  • 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

NodeMCU ESP8266 Specific Set-up Instructions

  1. Pin Configuration:

    • LED Strip Data Pin: Connect to D0 (GPIO16)
    • Ultrasonic Trigger Pin: Connect to D1 (GPIO5)
    • Ultrasonic Echo Pin: Connect to D2 (GPIO4)
  2. 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.
  3. Library Installation:

  4. 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) under Tools > Board.
  5. CH340C Driver Installation:

  6. Uploading Code:

    • Clone or download this repository.
    • Open the LEDProximitySensor.ino file in the Arduino IDE.
    • Select the correct port under Tools > Port.
    • Upload the code to your NodeMCU.

Usage

  1. Wire the components as described in the pin configuration.
  2. Power on the setup; the LED strip will start pulsing in the default green color.
  3. The color changes when an object is detected within 10 cm. The LEDs return to green when the object is removed.

Customization

  • Set default color: Change DEFAULT_COLOR in 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.

About

Control an LED strip that reacts to object proximity with smooth color transitions and pulsing effects using a NodeMCU ESP8266 and HC-SR04 ultrasonic sensor.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages