Guides · 11 min read

Arduino Stair Lighting: Motion-Activated LED Steps with PIR

Build Arduino stair lighting: two PIR sensors detect the direction, steps light up one by one with WS2812B or MOSFET strips, plus LDR night mode and ESP32 code.

Arduino stair lighting needs only an Arduino, two motion sensors and an LED strip: when you step onto the bottom stair, the steps light up one after another from bottom to top, and when you come from above, the wave of light runs the other way. About 15 seconds after the last movement the steps switch off in the same order. The eyes of the system are two PIR motion sensors at the bottom and top of the staircase plus an LDR that keeps the lights off during the day; its brain is a state machine of just a few lines.

In this guide you will see both approaches: a WS2812B addressable strip that controls hundreds of LEDs individually over a single data wire, and the classic method with a separate single-color 12 V strip on each step, faded in and out by a MOSFET. You also get an LED and power table by number of steps, the wiring diagram, Arduino Uno code, a 16-step version with a PCA9685 and an ESP32 version you can adjust from your phone.

WS2812B addressable LED strip
WS2812B strip: every LED has its own driver chip, so each step can be lit individually over one data line.

How does automatic stair lighting work?

The logic has four states: idle, turning on, lit and turning off. While idle, the Arduino watches both PIR sensors and checks the LDR to see whether it is dark. If the bottom sensor fires, the direction is stored as "up"; if the top sensor fires, it is "down", and the steps light up one by one 100–200 ms apart. Once the last step is lit, the system stays in the lit state, and every new trigger restarts the timer. When the set time passes without motion, the lights go out in the same direction, like a wave following the person. This structure is called a state machine, and everything runs without blocking thanks to millis(), so the sensors keep being read even while the lights are animating.

StateWhat happens?Transition to the next state
IdleLEDs off, LDR is readIn the dark, a bottom or top PIR trigger starts turning on
Turning onSteps light up one by one in walking directionWhen the last step is lit, the system goes to lit
LitAll steps on, every movement extends the timeWhen the time (e.g. 15 s) passes without motion, turning off starts
Turning offSteps go out one by one in the same directionNew motion goes back to turning on; when all are off, back to idle

Parts list and two circuit options

  • Arduino Uno or Nano (ESP32 if you want to adjust settings from your phone).
  • 2 × HC-SR501 PIR sensors: one at the bottom step, one at the top step.
  • LDR and 10 kΩ resistor: a voltage divider to detect nighttime.
  • Option A: WS2812B strip (30 or 60 LEDs/m), 5 V power supply, 1000 µF capacitor and 330 Ω resistor.
  • Option B: a single-color 12 V LED strip piece per step, one IRLZ44N MOSFET and 10 kΩ resistor per step, a PCA9685 16-channel PWM module and a 12 V power supply.
  • Wiring and mounting: 0.75–1.5 mm² (18–16 AWG) wire for power, thin stranded wire for signals, aluminum channels with diffusers for the strips.
FeatureOption A: WS2812BOption B: MOSFET + single-color strip
Control lineOne data pin2 I2C pins with PCA9685 (up to 16 steps)
Wiring3-wire chain across all steps (5V, GND, DIN)2 separate wires from each step to the controller
EffectsColors, rainbow, per-LED animationSmooth fade per step, one color
Voltage5 V (12 V with WS2815)12 V or 24 V
Long runsVoltage drop, power injection neededFewer losses thanks to the higher voltage
Standby drawAbout 0.5–1 mA per dark LEDAlmost zero with the MOSFET off

LED and power table by number of steps

On a WS2812B, each LED draws about 60 mA at full white and full brightness (20 mA per color). On a staircase, though, you run the LEDs in warm white at around 30% brightness, which avoids glare and cuts the current to roughly a third. The "full white" column in the table is the worst case: even if your code limits brightness, all LEDs may light up full white during a test. So choose a power supply rated at least 1.5 times the practical current, and size the wires for full white. The last column shows the RAM the code needs to store the LED colors; remember that the Uno has only 2 KB of RAM.

StepsLEDs / stepTotal LEDsFull white (60 mA)30% brightness (~18 mA)Recommended 5 V supplyRAM (3 bytes/LED)
10101006.0 A1.8 A5 V 3 A300 bytes
121518010.8 A3.2 A5 V 5 A540 bytes
141521012.6 A3.8 A5 V 6 A630 bytes
162032019.2 A5.8 A5 V 10 A960 bytes
163048028.8 A8.6 A5 V 15 A or a 12 V strip1440 bytes (too much for the Uno)

Option B is easier to calculate, because single-color 12 V strips are rated in watts per meter. A 2835 strip with 60 LEDs/m draws about 4.8 W/m. With 60 cm of strip on each step you get 2.9 W per step and 46 W for 16 steps, which is 3.8 A at 12 V. With a 20% margin, a 12 V 5 A (60 W) supply is enough. You can convert between current, voltage and power quickly with the Ohm's law calculator.

Wiring diagram and pin table

ConnectionArduino UnoESP32Note
Bottom PIR OUTD2GPIO 27PIR VCC to 5 V, common GND
Top PIR OUTD3GPIO 263-core cable if the top end is far away
LDR divider midpointA0GPIO 34LDR to 5 V (3.3 V on the ESP32), 10 kΩ to GND
WS2812B DIND6 (through 330 Ω)GPIO 4 (through 74AHCT125)Option A
PCA9685 SDA / SCLA4 / A5GPIO 21 / 22Option B
Strip + and -5 V and GND of the supply5 V and GND of the supplyNot from the board's 5V pin
Never power the LED strip from the Arduino's 5V pin: the board's USB or regulator path handles 500 mA to 1 A at most, and after a few dozen LEDs the board resets or gets damaged. Feed the strip straight from the power supply, connect the supply's GND to the Arduino's GND (common ground) and put a 1000 µF / 10 V capacitor at the strip's input. Leave mains-side wiring and in-wall installation to a licensed electrician; a ready-made plug-in power supply is the safe choice.

With the LDR between 5 V and A0 and the 10 kΩ resistor between A0 and GND, the reading goes up as the room gets brighter. The LDR's resistance climbs into the megaohm range in darkness and drops to 1–10 kΩ in daylight; the voltage divider calculator shows which voltage the divider gives at which light level. The HC-SR501 output goes to 3.3 V when triggered; the Uno reads that as HIGH, and it suits the ESP32 directly. Turn the sensor's time potentiometer to minimum (about 3 seconds) and set the jumper to H (repeat trigger); let the code decide how long the lights stay on, not the sensor. More on the sensor in the PIR motion sensor guide.

Step-by-step build

  1. Count your steps and decide how many LEDs go on each one; cut the WS2812B strip only at the copper cut marks.
  2. Chain the strip pieces starting at the bottom step: the DOUT end of each piece goes to the DIN end of the piece on the next step up. That way step 0 in the code is the bottom one.
  3. Every 2–3 steps (about every 100 LEDs), bring 5 V and GND separately from the power supply; this power injection keeps the colors from turning yellow on the upper steps.
  4. Mount the PIR sensors on the wall about 30–50 cm (12–20 in) high, facing the first and last step; a short tube in front of the lens narrows the field of view.
  5. Place the LDR where the stair light does not hit it directly but it still gets light from a window or the hallway lamp.
  6. Test the circuit on your desk with a short strip for 2–3 steps first, then change STEPS and LEDS_PER_STEP in the code to match your staircase.
  7. Give the PIR sensors a 30–60 second warm-up after power-on; random triggers during that time are normal.

Option A: Arduino code with WS2812B

The code uses the Adafruit NeoPixel library, which you can install from the Library Manager. The number of steps, LEDs per step, wave speed, on time and darkness thresholds are set in the constants at the top of the file. You can find the WS2812B basics in the WS2812B NeoPixel LED guide.

C++ (Arduino IDE)
1// Arduino merdiven aydınlatması: 2 PIR + LDR + WS2812B / Arduino stair lighting: 2 PIR + LDR + WS2812B
2#include <Adafruit_NeoPixel.h>
3
4const uint8_t PIN_PIR_BOTTOM = 2;      // alt basamak PIR / bottom step PIR
5const uint8_t PIN_PIR_TOP    = 3;      // üst basamak PIR / top step PIR
6const uint8_t PIN_LDR        = A0;     // LDR bölücü orta noktası / LDR divider midpoint
7const uint8_t PIN_STRIP      = 6;      // WS2812B DIN (330 ohm üzerinden / through 330 ohm)
8
9const uint8_t  STEPS          = 14;     // basamak sayısı / number of steps
10const uint8_t  LEDS_PER_STEP  = 15;     // basamak başına LED / LEDs per step
11const uint16_t STEP_DELAY_MS  = 150;    // basamaklar arası gecikme / delay between steps
12const unsigned long ON_TIME_MS = 15000; // son hareketten sonra açık kalma / on time after last motion
13const int DARK_LEVEL  = 300;            // bunun altı karanlık / below this is dark
14const int LIGHT_LEVEL = 400;            // bunun üstü aydınlık / above this is bright
15
16Adafruit_NeoPixel strip(STEPS * LEDS_PER_STEP, PIN_STRIP, NEO_GRB + NEO_KHZ800);
17const uint32_t WARM_WHITE = Adafruit_NeoPixel::Color(255, 150, 50);   // sıcak beyaz / warm white
18
19enum State { IDLE, TURNING_ON, LIT, TURNING_OFF };
20State state = IDLE;
21int8_t direction = 1;           // 1: aşağıdan yukarı / bottom-up, -1: yukarıdan aşağı / top-down
22uint8_t stepCount = 0;          // dalgada kaçıncı basamak / position in the wave
23unsigned long lastStepTime = 0;
24unsigned long lastMotion = 0;
25bool isDark = true;
26
27// Yöne göre k'inci sıradaki fiziksel basamak (0 = en alt) / physical step at position k (0 = bottom)
28uint8_t stepAt(uint8_t k) {
29  return (direction == 1) ? k : (STEPS - 1 - k);
30}
31
32void setStep(uint8_t step, uint32_t color) {
33  uint16_t first = step * LEDS_PER_STEP;
34  for (uint8_t i = 0; i < LEDS_PER_STEP; i++) strip.setPixelColor(first + i, color);
35  strip.show();
36}
37
38// LDR'yi yalnız ışıklar sönükken oku, iki eşikli / read the LDR only while lights are off, with hysteresis
39void updateDarkness() {
40  int level = analogRead(PIN_LDR);
41  if (isDark && level > LIGHT_LEVEL) isDark = false;
42  else if (!isDark && level < DARK_LEVEL) isDark = true;
43}
44
45void startWave(State next, int8_t dir) {
46  state = next;
47  direction = dir;
48  stepCount = 0;
49  lastStepTime = millis() - STEP_DELAY_MS;   // ilk basamak hemen yansın / first step at once
50}
51
52void setup() {
53  pinMode(PIN_PIR_BOTTOM, INPUT);
54  pinMode(PIN_PIR_TOP, INPUT);
55  strip.begin();
56  strip.setBrightness(80);     // yaklaşık %30 parlaklık / about 30% brightness
57  strip.show();                // hepsi kapalı / all off
58}
59
60void loop() {
61  unsigned long now = millis();
62  bool bottom = digitalRead(PIN_PIR_BOTTOM) == HIGH;
63  bool top = digitalRead(PIN_PIR_TOP) == HIGH;
64
65  if (state == IDLE) updateDarkness();
66
67  if (bottom || top) {
68    if ((state == IDLE && isDark) || state == TURNING_OFF) {
69      startWave(TURNING_ON, bottom ? 1 : -1);   // yön: hangi sensör önce / direction: which sensor first
70    }
71    if (state != IDLE) lastMotion = now;        // her hareket süreyi uzatır / every motion extends the time
72  }
73
74  switch (state) {
75    case TURNING_ON:
76    case TURNING_OFF:
77      if (now - lastStepTime >= STEP_DELAY_MS) {
78        lastStepTime = now;
79        setStep(stepAt(stepCount), state == TURNING_ON ? WARM_WHITE : 0);
80        stepCount++;
81        if (stepCount >= STEPS) state = (state == TURNING_ON) ? LIT : IDLE;
82      }
83      break;
84    case LIT:
85      if (now - lastMotion >= ON_TIME_MS) startWave(TURNING_OFF, direction);   // aynı yönde sön / fade out the same way
86      break;
87    default:
88      break;
89  }
90}
Constant or functionPurpose
STEPS, LEDS_PER_STEPSize of the staircase; the total LED count is their product
STEP_DELAY_MSDelay between steps; 100–200 ms feels like natural walking speed
ON_TIME_MSHow long the lights stay on after the last motion
DARK_LEVEL, LIGHT_LEVELTwo-threshold night detection; prevents toggling at dusk
stepAt(k)Returns the physical step at position k for the current direction
updateDarkness()Reads the LDR only while the lights are off
Reading the LDR only while the lights are off is a small but important detail: if the stair light shines on the LDR, the system may think it is daytime and not switch on at the next trigger. To find the thresholds, note the value at dusk with Serial.println(analogRead(A0)), then set DARK_LEVEL slightly below it and LIGHT_LEVEL slightly above it.

Option B: smooth fading with MOSFETs and a PCA9685

Each single-color strip needs its own channel, but the Uno has only 6 PWM pins. For smooth fades on up to 16 steps, use the PCA9685 module: it connects over I2C and generates 12-bit (0–4095) PWM on each of its 16 channels. Each channel drives the gate of an IRLZ44N logic-level MOSFET, which switches the strip's negative lead to GND. A 10 kΩ resistor between gate and source keeps the strips from flashing randomly while the Arduino boots. The basics are in the Arduino MOSFET guide.

MOSFET pinConnects to
Gate (G)PCA9685 channel output; 10 kΩ to Source
Drain (D)The strip's - lead
Source (S)GND of the 12 V supply (shared with the Arduino's GND)
Strip ++ of the 12 V supply
The common IRF520 MOSFET modules do not fully turn on with a 5 V gate voltage; they heat up at a few amps and the strip never reaches full brightness. Use logic-level MOSFETs such as the IRLZ44N, IRL540N or AOD4184; you can compare suitable parts in the transistor table.
C++ (Arduino IDE)
1// Arduino merdiven aydınlatması: PCA9685 + MOSFET ile yumuşak geçiş / stair lighting: smooth fades with PCA9685 + MOSFETs
2#include <Wire.h>
3#include <Adafruit_PWMServoDriver.h>
4
5Adafruit_PWMServoDriver pwm(0x40);     // PCA9685 varsayılan adres / default address
6
7const uint8_t PIN_PIR_BOTTOM = 2;
8const uint8_t PIN_PIR_TOP    = 3;
9const uint8_t PIN_LDR        = A0;
10
11const uint8_t  STEPS         = 16;      // kanal 0 = en alt basamak / channel 0 = bottom step
12const uint16_t STEP_DELAY_MS = 120;     // dalga hızı / wave speed
13const uint16_t FADE_MS       = 400;     // bir basamağın açılma süresi / fade time of one step
14const uint16_t MAX_PWM       = 3000;    // 4095 = tam parlaklık / full brightness
15const unsigned long ON_TIME_MS = 15000;
16const int DARK_LEVEL = 300, LIGHT_LEVEL = 400;
17
18uint16_t level[STEPS];          // her basamağın parlaklığı / brightness of each step
19bool lightsOn = false;          // hedef: açık mı / target: on?
20bool waveRunning = false;
21int8_t direction = 1;
22unsigned long waveStart = 0, lastMotion = 0;
23bool isDark = true;
24
25void updateDarkness() {
26  int v = analogRead(PIN_LDR);
27  if (isDark && v > LIGHT_LEVEL) isDark = false;
28  else if (!isDark && v < DARK_LEVEL) isDark = true;
29}
30
31void startWave(bool on) {
32  lightsOn = on;
33  waveStart = millis();
34  waveRunning = true;
35}
36
37// Her basamağın parlaklığı = dalga başlangıcından geçen süre - sıra x gecikme
38// Brightness of each step = time since wave start - position x delay
39void updateWave(unsigned long now) {
40  bool finished = true;
41  for (uint8_t k = 0; k < STEPS; k++) {
42    uint8_t step = (direction == 1) ? k : STEPS - 1 - k;
43    long t = (long)(now - waveStart) - (long)k * STEP_DELAY_MS;
44    uint32_t p = constrain(t, 0L, (long)FADE_MS);    // 0..FADE_MS
45    if (p < FADE_MS) finished = false;
46    uint32_t q = lightsOn ? p : FADE_MS - p;
47    uint16_t target = q * q * MAX_PWM / ((uint32_t)FADE_MS * FADE_MS);   // karesel: göze doğal / quadratic: natural to the eye
48    uint16_t next = lightsOn ? max(level[step], target) : min(level[step], target);
49    if (next != level[step]) {
50      level[step] = next;
51      pwm.setPin(step, next);
52    }
53  }
54  if (finished) waveRunning = false;
55}
56
57void setup() {
58  pinMode(PIN_PIR_BOTTOM, INPUT);
59  pinMode(PIN_PIR_TOP, INPUT);
60  pwm.begin();
61  pwm.setPWMFreq(1000);                 // 1 kHz, titremesiz / no visible flicker
62  for (uint8_t i = 0; i < STEPS; i++) {
63    level[i] = 0;
64    pwm.setPin(i, 0);
65  }
66}
67
68void loop() {
69  unsigned long now = millis();
70  bool bottom = digitalRead(PIN_PIR_BOTTOM) == HIGH;
71  bool top = digitalRead(PIN_PIR_TOP) == HIGH;
72
73  if (!lightsOn && !waveRunning) updateDarkness();   // yalnız hepsi sönükken / only while all are off
74
75  if (bottom || top) {
76    if (!lightsOn && (isDark || waveRunning)) {       // karanlıkta ya da sönerken / when dark or while fading out
77      direction = bottom ? 1 : -1;
78      startWave(true);
79    }
80    if (lightsOn) lastMotion = now;
81  }
82  if (lightsOn && now - lastMotion >= ON_TIME_MS) startWave(false);
83  if (waveRunning) updateWave(now);
84}

The heart of the code is the updateWave() function: the brightness of each step is calculated from the time since the wave started and the step's position in the sequence. Brightness rises quadratically rather than linearly, because the eye notices changes at low brightness much more strongly, so the fade looks more natural. If new motion arrives while the lights are fading out, each step rises again from its current brightness, with no hard off-on jump. With the PWM frequency at 1 kHz, you will not see flicker even through a phone camera.

ESP32 version: set brightness and on time from your phone

Move the same logic to an ESP32 and you can adjust the stair lighting over Wi-Fi. The code below joins your home network and serves a small settings page at the ESP32's IP address, where you change the brightness and on time and see the latest LDR reading. If Wi-Fi fails to connect, the system carries on offline after 10 seconds, so the stairs never stay dark. Because the ESP32's ADC is 12-bit, the thresholds range from 0 to 4095, and the LDR divider runs on 3.3 V. For setup, see What is the ESP32?.

C++ (Arduino IDE)
1// ESP32 merdiven aydınlatması + Wi-Fi ayar sayfası / ESP32 stair lighting + Wi-Fi settings page
2#include <WiFi.h>
3#include <WebServer.h>
4#include <Adafruit_NeoPixel.h>
5
6const char* WIFI_SSID = "AgAdi";        // Wi-Fi adın / your Wi-Fi name
7const char* WIFI_PASS = "Sifre123";     // Wi-Fi şifren / your Wi-Fi password
8
9const uint8_t PIN_PIR_BOTTOM = 27;
10const uint8_t PIN_PIR_TOP    = 26;
11const uint8_t PIN_LDR        = 34;      // ADC1, yalnız giriş / input only
12const uint8_t PIN_STRIP      = 4;       // 74AHCT125 üzerinden DIN / to DIN via 74AHCT125
13
14const uint8_t  STEPS         = 14;
15const uint8_t  LEDS_PER_STEP = 15;
16const uint16_t STEP_DELAY_MS = 150;
17const int DARK_LEVEL = 1200, LIGHT_LEVEL = 1600;   // 12 bit ADC: 0-4095
18
19uint8_t brightness = 80;               // web sayfasından değişir / set from the web page
20unsigned long onTimeMs = 15000;
21
22Adafruit_NeoPixel strip(STEPS * LEDS_PER_STEP, PIN_STRIP, NEO_GRB + NEO_KHZ800);
23WebServer server(80);
24
25enum State { IDLE, TURNING_ON, LIT, TURNING_OFF };
26State state = IDLE;
27int8_t direction = 1;
28uint8_t stepCount = 0;
29unsigned long lastStepTime = 0, lastMotion = 0;
30bool isDark = true;
31int lastLdr = 0;
32
33uint32_t warmWhite() {                 // parlaklığı renge uygula / apply brightness to the color
34  return Adafruit_NeoPixel::Color(255 * brightness / 255, 150 * brightness / 255, 50 * brightness / 255);
35}
36
37void setStep(uint8_t step, uint32_t color) {
38  for (uint8_t i = 0; i < LEDS_PER_STEP; i++) strip.setPixelColor(step * LEDS_PER_STEP + i, color);
39  strip.show();
40}
41
42void startWave(State next, int8_t dir) {
43  state = next;
44  direction = dir;
45  stepCount = 0;
46  lastStepTime = millis() - STEP_DELAY_MS;
47}
48
49void handleRoot() {
50  if (server.hasArg("b")) brightness = constrain(server.arg("b").toInt(), 5, 255);
51  if (server.hasArg("t")) onTimeMs = constrain(server.arg("t").toInt(), 5, 300) * 1000UL;
52  String html = "<!DOCTYPE html><html><head><meta name='viewport' content='width=device-width'></head><body>";
53  html += "<h2>Merdiven / Stairs</h2><form>";
54  html += "Parlaklik / Brightness (5-255): <input name='b' type='number' value='" + String(brightness) + "'><br>";
55  html += "Sure / Time (s): <input name='t' type='number' value='" + String(onTimeMs / 1000) + "'><br>";
56  html += "<button>Kaydet / Save</button></form>";
57  html += "<p>LDR: " + String(lastLdr) + (isDark ? " (gece / night)" : " (gunduz / day)") + "</p></body></html>";
58  server.send(200, "text/html", html);
59}
60
61void setup() {
62  Serial.begin(115200);
63  pinMode(PIN_PIR_BOTTOM, INPUT);
64  pinMode(PIN_PIR_TOP, INPUT);
65  strip.begin();
66  strip.show();
67  WiFi.mode(WIFI_STA);
68  WiFi.begin(WIFI_SSID, WIFI_PASS);
69  unsigned long t0 = millis();
70  while (WiFi.status() != WL_CONNECTED && millis() - t0 < 10000) delay(250);   // en çok 10 s / at most 10 s
71  if (WiFi.status() == WL_CONNECTED) Serial.println(WiFi.localIP());
72  else Serial.println("Wi-Fi yok, cevrimdisi calisiyor / no Wi-Fi, running offline");
73  server.on("/", handleRoot);
74  server.begin();
75}
76
77void loop() {
78  server.handleClient();
79  unsigned long now = millis();
80  bool bottom = digitalRead(PIN_PIR_BOTTOM) == HIGH;
81  bool top = digitalRead(PIN_PIR_TOP) == HIGH;
82
83  if (state == IDLE) {                 // LDR yalnız ışıklar sönükken / LDR only while lights are off
84    lastLdr = analogRead(PIN_LDR);
85    if (isDark && lastLdr > LIGHT_LEVEL) isDark = false;
86    else if (!isDark && lastLdr < DARK_LEVEL) isDark = true;
87  }
88
89  if (bottom || top) {
90    if ((state == IDLE && isDark) || state == TURNING_OFF) startWave(TURNING_ON, bottom ? 1 : -1);
91    if (state != IDLE) lastMotion = now;
92  }
93
94  if ((state == TURNING_ON || state == TURNING_OFF) && now - lastStepTime >= STEP_DELAY_MS) {
95    lastStepTime = now;
96    uint8_t step = (direction == 1) ? stepCount : STEPS - 1 - stepCount;
97    setStep(step, state == TURNING_ON ? warmWhite() : 0);
98    if (++stepCount >= STEPS) state = (state == TURNING_ON) ? LIT : IDLE;
99  } else if (state == LIT && now - lastMotion >= onTimeMs) {
100    startWave(TURNING_OFF, direction);
101  }
102}
The ESP32's data output is 3.3 V, while a WS2812B powered at 5 V expects at least about 3.5 V on its data input. With short wires it often works anyway, but if you see random colors or flicker, add a fast level shifter such as the 74AHCT125 to the data line. Simple bidirectional I2C level converters can be too slow for the 800 kHz WS2812B signal; details in the logic level converter guide.

Sensor placement and alternative sensors

A PIR sensor detects changes in heat: it reacts when body heat moves across its field of view. The most common problem on stairs is someone walking along the hallway below, or a radiator, setting off the sensor. Angle the sensor toward the step, tape over part of the Fresnel lens and turn the sensitivity pot to the middle. For more precise detection, put an HC-SR04 or VL53L0X at each end and use it like a light barrier: when the measured distance suddenly drops, someone has stepped onto the stair. The RCWL-0516 radar sensor, on the other hand, sees through walls and gets triggered from the next room, so it is not recommended here.

SensorProsConsFit for stairs
HC-SR501 PIRCheap, 5–7 m range, adjustableFalse triggers from heat sources, 2–3 s blind timeVery good
AM312 mini PIRSmall, runs on 3.3 V, fits inside a stepNo adjustment, 3–5 m rangeGood
HC-SR04 or VL53L0XReliably detects a foot on the stepNeeds code for continuous measuringGood (like a light barrier)
RCWL-0516 radarCan hide behind a coverPasses through walls, triggers from the next roomNot recommended

Common mistakes and fixes

  • Colors turn yellow on the upper steps: voltage drop on the 5 V line; inject power every 2–3 steps and use thick supply wires.
  • First LED is right, the rest show random colors: no common ground or the data line is too long; join the GNDs, put the 330 Ω resistor close to the strip and keep the data wire under a few meters.
  • The lights run the wrong way: the strip chain starts at the top step; either start the chain at the bottom or invert the direction logic in the code.
  • It turns on during the day or never at night: the LDR thresholds are wrong or the LDR sees the stair light; measure the value in the Serial Monitor and move the LDR.
  • The lights never turn off: the PIR time pot is set too long or the sensor faces a heat source; turn the pot to minimum and re-aim the sensor.
  • The Arduino resets randomly: the power supply sags when the LEDs come on, or the strip is fed from the board's 5V pin; use a bigger supply and power the strip separately.
  • The MOSFET gets hot: you are using a non-logic-level MOSFET; switch to a part like the IRLZ44N and keep the gate resistor between 100 and 220 Ω.
Full brightness is blinding for someone walking downstairs in the middle of the night. Extend the code to drop the brightness to 10% between 11 p.m. and 6 a.m.; to get the time from the internet on the ESP32, use the method from the ESP32 NTP time guide.

Ideas to upgrade your stair lighting

  • Night light mode: with no motion, keep only the first and last step at 5% to show where the stairs are.
  • Color wave: with WS2812B, light each step in a different rainbow shade and change the colors for the holidays.
  • Hallway extension: use the same logic to light a long hallway with a PIR at each end.
  • Home automation: connect the ESP32 to Home Assistant via MQTT and control the stairs together with your other lights.
  • Ready-made firmware: if you want effects without writing code, install WLED and connect the PIR sensors to it.

Stair lighting combines sensor reading, timing, power calculation and LED driving in one project, so it adds lasting value to your home and teaches you a lot along the way. Try it on your desk with a short two-step strip first, then move it to your staircase. In the BlueGrays app, the Smart Stair and Hallway Lighting project walks you through the wiring diagram and code step by step, and the WS2812B and PIR projects help you get to know each part on its own.

Frequently asked questions

How many LEDs do I need per stair step?

It depends on the step width and the strip density. A 30 LEDs/m strip gives 27 LEDs on a 90 cm (36 in) step; on most staircases 10–20 LEDs per step give even light. Putting the strip in an aluminum channel with a diffuser hides the individual LED dots.

What size power supply do I need for LED stair lights?

For WS2812B, multiply the total LED count by 18 mA (about 30% brightness) and add 50% headroom; for 210 LEDs, for example, a 5 V 6 A supply is a good fit. For a single-color 12 V strip, multiply the watts per meter by the total length, divide by 12 and add a 20% margin.

WS2812B or single-color LED strip for stairs?

If you want colors and animations, WS2812B is more flexible and needs only one data wire. If you just want warm white light over long runs, a single-color 12 V or 24 V strip with MOSFETs is more efficient, has less voltage drop and almost no standby draw.

Why does my PIR sensor turn the stair lights on by itself?

A PIR sensor reacts to heat changes, so radiators, sunlight through a window, warm drafts or pets can trigger it. Triggers in the first 30–60 seconds after power-on are also normal. Aim the sensor at the step, mask part of the lens and lower the sensitivity.

How do I stop stair lights from turning on during the day?

Add an LDR and accept PIR triggers only when the light reading is below a threshold. Using two thresholds instead of one (hysteresis) prevents switching on and off at dusk. Place the LDR where the stair lights do not hit it and read it only while the lights are off.

How many WS2812B LEDs can an Arduino Uno drive?

Each LED uses 3 bytes of RAM; with the Uno's 2 KB and your other variables, the practical limit is about 400–500 LEDs. For longer staircases use an Arduino Mega or ESP32, or fewer LEDs per step. The power supply provides the current, so the limit is memory, not power.

See all projects
Smart Stair and Corridor Lighting
AR-82Intermediate
Premium

Smart Stair and Corridor Lighting

Step onto the stairs or into the hallway and the lights come on one step at a time in the direction you are walking.

5.0(36)
52
Night Light with Ldr
AR-12Beginner

Night Light with Ldr

A little night light that turns on by itself when it gets dark and goes off when morning comes.

4.7(105)
225
Using a WS2812B LED Strip
AR-69Intermediate
Premium

Using a WS2812B LED Strip

Meet a smart LED strip where you can colour every single light on its own. The Arduino first lights the first five LEDs red, a second later turns the other five blue, then switches them all off and…

4.8(54)
70
WS2812B LED Chaser (Fill Effect)
AR-72Intermediate
Premium

WS2812B LED Chaser (Fill Effect)

A light strip that fills up and empties like a glass of water. The Arduino lights ten color LEDs one by one in orange and keeps them on; once the strip is full, it switches them off one by one in the…

4.7(50)
65
Motion Detector with Motion Sensor
AR-24Beginner
Premium

Motion Detector with Motion Sensor

A simple guard that tells you when someone walks into the room. The motion sensor picks up the warmth given off by the human body, and the Arduino keeps the LED on as long as there is movement and…

4.6(47)
67
Automatic Lighting with the ESP32 PIR Motion Sensor
ES-19Intermediate
Premium

Automatic Lighting with the ESP32 PIR Motion Sensor

In this project an HC-SR501 PIR motion sensor detects someone entering the room and turns on an LED automatically. millis() tracks how long the LED stays on: each HIGH reading refreshes the last-motion time, and the LED turns off at least 10 seconds after the last HIGH. The code also waits 50 ms with delay(50) in every loop, so the loop is not fully non-blocking. Great for stairs, hallways, bathrooms or closet lighting.

4.4(24)
38
ESP32 Smart Lighting (PIR + LDR + Relay + OLED)
ES-37Advanced
Premium

ESP32 Smart Lighting (PIR + LDR + Relay + OLED)

With an ESP32, a PIR motion sensor, an LDR light sensor and a relay module, we turn your hallway, bathroom or pantry into smart lighting. If the room is already bright, the light stays off even when there is motion, so it never wastes energy during the day. The light stays on for 30 seconds, and the time extends automatically while motion continues.

4.3(6)
11
ESP32 WS2812B NeoPixel Strip Control
ES-24Intermediate
Premium

ESP32 WS2812B NeoPixel Strip Control

WS2812B (NeoPixel) addressable LEDs are smart RGB LEDs that can be chained and controlled from a single data pin. In this project we drive an 8-LED WS2812B strip with the Adafruit_NeoPixel library and create a smooth rainbow animation. The ESP32's 3.3V logic works with most WS2812B batches; if it gets unstable, we show the fix with a 470Ω series resistor and a 1000µF capacitor. The animation shifts the hue in HSV color space.

4.9(19)
30