Projects / ESP32-C3 hallway night glow

ESP32-C3 hallway night glow

Beginner1.8 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32motion

    Wire the PIR

    VCC to 5V, GND to GND, OUT to GPIO4.

  2. ESP328.9 mA

    Wire the ring

    5V to 5V, GND to GND, DIN to GPIO5 through 330 ohms.

  3. ESP32motion

    Set the PIR dials

    Time dial fully anticlockwise, jumper on repeat.

  4. ESP32

    Install the library

    Adafruit NeoPixel.

  5. ESP32

    Upload the sketch

    One dim blue pixel for 30 seconds.

  6. ESP329.0 mA

    Wave your hand

    The ring glows warm.

  7. ESP32

    Stand still

    It fades out after about a minute.

In short

How do you build an ESP32-C3 hallway night glow?

An ESP32-C3 SuperMini lights a 16-LED ring in a dim warm colour when a PIR sensor sees movement, and fades it out after a minute. You need ESP32-C3 SuperMini, PIR Motion Sensor HC-SR501, WS2812B ring 16 LEDs and Breadboard 830 Tie Points. It takes 7 steps and about 110 minutes.

Level
Beginner
Time
About 110 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
PIR VCCESP32-C3 SuperMini 5V5 V from the USB pin
PIR GNDESP32-C3 SuperMini GNDCommon ground
PIR OUTESP32-C3 SuperMini GPIO4High when it sees movement (3.3 V signal)
Ring 5VESP32-C3 SuperMini 5VPower (low brightness only)
Ring GNDESP32-C3 SuperMini GNDCommon ground
Ring DINESP32-C3 SuperMini GPIO5 through a 330 ohm resistorData

Code

A passive infrared sensor, or PIR, senses the change in heat radiation when a warm body moves across its view, and sets its output pin high. The module needs about 30 seconds after power-up to learn the background, so the program waits and shows one dim blue pixel during that time. After movement the program keeps the ring lit for a minute, then fades it out slowly so the change does not startle you. Each LED in the ring is a tiny RGB light with its own controller, and it receives colour values on one data wire. Full white on 16 LEDs could draw nearly an ampere, which is too much for a USB port, so the program keeps the level low at 40 out of 255, which also gives a restful glow. The PIR module has two small dials: set the time dial to the shortest, and the jumper to repeat mode, so the program sets the timing instead.

Runs on a virtual ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Adafruit_NeoPixel.h>

const int PIR = 4, RING_PIN = 5, N = 16;
Adafruit_NeoPixel ring(N, RING_PIN, NEO_GRB + NEO_KHZ800);

const uint8_t MAX_LEVEL = 40;                      // keep the brightness low to limit current
const unsigned long WARM_UP = 30000;               // the PIR needs about 30 seconds to settle
const unsigned long HOLD = 60000;                  // stay lit this long after the last movement
const unsigned long FADE = 3000;                   // then fade out over this long

unsigned long lastMotion = 0;
bool lit = false;

void setLevel(uint8_t level) {
  ring.fill(ring.Color(level, (level * 4) / 10, level / 12));   // a warm orange white
  ring.show();
}

void setup() {
  pinMode(PIR, INPUT);
  ring.begin();
  ring.clear();
  ring.setPixelColor(0, ring.Color(0, 0, 6));      // one dim blue pixel during warm-up
  ring.show();
}

void loop() {
  unsigned long now = millis();
  if (now < WARM_UP) { delay(100); return; }
  if (!lit && now - WARM_UP < 200) { ring.clear(); ring.show(); }

  if (digitalRead(PIR) == HIGH) { lastMotion = now; lit = true; }

  if (lit) {
    unsigned long idle = now - lastMotion;
    if (idle < HOLD) {
      setLevel(MAX_LEVEL);
    } else if (idle < HOLD + FADE) {
      setLevel(MAX_LEVEL * (HOLD + FADE - idle) / FADE);
    } else {
      setLevel(0);
      lit = false;
    }
  }
  delay(20);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
During warm-upOne dim blue pixel
After warm-up, wave a handThe ring lights warm and dim
Keep movingThe ring stays lit
Stand still for a minuteIt fades out over three seconds
BrightnessSoft, comfortable in the dark

If it does not work

Ring lights on its own

Wait the full 30 seconds, and keep the PIR away from heaters and sunlight.

Ring flickers or wrong colours

Keep the data wire short and add a 1000 microfarad capacitor across the ring supply.

Never lights

Check PIR OUT is on GPIO4 and the PIR has 5 V.

Board resets

The USB supply cannot give enough current, lower MAX_LEVEL or use a stronger adapter.

Stays lit all the time

Turn the PIR sensitivity dial down and aim it away from moving curtains.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the ESP32-C3 hallway night glow?

ESP32-C3 SuperMini, PIR Motion Sensor HC-SR501, WS2812B ring 16 LEDs and Breadboard 830 Tie Points.

How long does the ESP32-C3 hallway night glow take to build?

About 110 minutes for a beginner maker, in 7 steps.

How do I know the ESP32-C3 hallway night glow works?

During warm-up: One dim blue pixel. After warm-up, wave a hand: The ring lights warm and dim. Keep moving: The ring stays lit.

Ring lights on its own: what should I check?

Wait the full 30 seconds, and keep the PIR away from heaters and sunlight.

Ring flickers or wrong colours: what should I check?

Keep the data wire short and add a 1000 microfarad capacitor across the ring supply.

Never lights: what should I check?

Check PIR OUT is on GPIO4 and the PIR has 5 V.

Board resets: what should I check?

The USB supply cannot give enough current, lower MAX_LEVEL or use a stronger adapter.