Build a Motion-Activated Desk Light
SensorsAutomationDisplays
Use a motion sensor and controller to switch a low-voltage light automatically, introducing digital inputs, timing and simple automation logic.
7 real parts included
Total for this kit: 1,640.00 ฿
Doesn't include any order discount you may get at checkout.
What you'll need
ESP32-C3 SuperMini Development Board — Wi-Fi & Bluetooth, USB-C
670.00 ฿
PIR Motion Sensor Module — Adjustable Sensitivity & Delay
85.00 ฿
WS2812B Addressable LED Strip — 5V, 30 LEDs/m
265.00 ฿
LM2596 Adjustable Buck Converter Module
95.00 ฿
830-Point Solderless Breadboard
125.00 ฿
Jumper Wire Kit — Male-Male, Male-Female, Female-Female
220.00 ฿
USB-C Data & Charging Cable — 1m
180.00 ฿
Wiring Diagram
Starter Code
#include <Adafruit_NeoPixel.h>
#define PIR_PIN 4
#define LED_DATA_PIN 5
#define NUM_LEDS 30
// How long to keep the light on after the last motion pulse
const unsigned long HOLD_TIME_MS = 30000;
Adafruit_NeoPixel strip(NUM_LEDS, LED_DATA_PIN, NEO_GRB + NEO_KHZ800);
bool lightsOn = false;
unsigned long lastMotionTime = 0;
void setLights(bool on) {
uint32_t color = on ? strip.Color(255, 214, 170) : strip.Color(0, 0, 0); // warm white / off
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, color);
}
strip.show();
lightsOn = on;
}
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
strip.begin();
strip.setBrightness(180);
setLights(false);
// Many PIR modules need 30-60s to calibrate ambient IR after power-up
Serial.println("Warming up PIR...");
delay(30000);
Serial.println("Ready.");
}
void loop() {
if (digitalRead(PIR_PIN) == HIGH) {
lastMotionTime = millis();
if (!lightsOn) {
Serial.println("Motion detected — lights on");
setLights(true);
}
}
if (lightsOn && (millis() - lastMotionTime > HOLD_TIME_MS)) {
Serial.println("Timeout — lights off");
setLights(false);
}
}Not sure about a step? Ask us