An Arduino is at the heart of an auto fading LED strip mounted under the kitchen cabinets. When a PIR (Passive InfraRed) sensor detects motion, the Arduino fades the LED strip on via a power FET module. If there is no motion, after x seconds the LEDs fade off again. The brightness can be adjusted via a rotary encoder and the encoder's
switch is used to change states between 'off', 'on/off based on sensor trigger', 'permanent on, sensor inactive'.
Check out this video to see it in action plus an explanation how to build it.
The software
Download link: Fading LED PIR sensor Arduino sketch download link.
The software contains a configuration section at the top where you can change the following parameters and hardware pinning to your preferences:
#define STAY_ON_TIME 20 // [s] fade off after ... seconds
#define SHORT_PRESS_TIME 50 // [ms
#define LONG_PRESS_TIME 1500 // [ms]
#define FADE_INTERVAL 30 // [ms] time between LED fade steps
#define BRIGHTNESS_A 200 // 0-255
#define BRIGHTNESS_B 50 // 0-255
#define ENC_CLK_PIN 2 // rotary encoder CLK or A
#define ENC_DATA_PIN 3 // rotary encoder DATA or B
#define ENC_SW_PIN 4 // rotary encoder SWITCH
#define SENSOR_PIN 6 // HIGH = movement detected
#define PWM_OUTPUT_PIN 5 // only use PWM pins: 3,5,6,9,10,11
#define STAY_ON_TIME 20 // [s] fade off after ... seconds
#define SHORT_PRESS_TIME 50 // [ms
#define LONG_PRESS_TIME 1500 // [ms]
#define FADE_INTERVAL 30 // [ms] time between LED fade steps
#define BRIGHTNESS_A 200 // 0-255
#define BRIGHTNESS_B 50 // 0-255
#define ENC_CLK_PIN 2 // rotary encoder CLK or A
#define ENC_DATA_PIN 3 // rotary encoder DATA or B
#define ENC_SW_PIN 4 // rotary encoder SWITCH
#define SENSOR_PIN 6 // HIGH = movement detected
#define PWM_OUTPUT_PIN 5 // only use PWM pins: 3,5,6,9,10,11
(Click the images to see a larger version)
Parts needed and how to connect it:
Click the links below to see where you can buy:
- LED strip with 12V power adapter
- Arduino Uno or Nano
- PIR sensor
- Rotary encoder with switch
- Power FET module
- 12V jack screw terminal connector (optional)
Brightness can be changed by rotating the encoder. The state the LED lighting is in can be changed by pressing the encoder:
Have fun building and using this.
Rudy.