DIY Hidden Night Light(s) Using Arduino, LED Strips, Potentiometers

by RonnyFalconeri in Circuits > Arduino

185 Views, 4 Favorites, 0 Comments

DIY Hidden Night Light(s) Using Arduino, LED Strips, Potentiometers

title.jpg
nightstand.jpg
corner.jpg
case4.jpg
case1.jpg
case3.jpg

A DIY night light for my bedroom using an Arduino as the processing unit, 2 LED strips for illumination which are individually controlled by one potentiometer each.

Two LED strips are used to separate them into a left and right side so that me and my wife have our own separate light source which won't affect the other as much. They are hidden behind the corners of our beds backboard and are only visible when turned on. By turning the potentiometer, which are integrated in the nightstand, the user can adjust the brightness.

This project on GitHub (more details on code and wiring): https://github.com/RonnyFalconeri/night-light-uino


Lightstrips

I'm using SK6812 LEDs because they can provide a quality warm white light effect. Each strip is 1 meter long and is encased in its own diffuser channel. With the diffuser, the LEDs are blended into one continuous light bar instead of seeing them individually, which gives them a more pleasing look. To further avoid seeing individual LEDs, I choose a LED density of 144 LEDs / meter. To make the strips go around the corner of the backboard, the diffuser channels are bended into an "L" shape.


Potentiometers

Special 5 pin potentiometers are used which have an integrated "twist switch" causing it to "click" when the user starts turning, giving the user a more haptic feedback. I choose an aluminium knob for the premium feel. To make everything even more elegant and minimalistic, I integrated the potentiometers into the surface of the nightstand using a square aluminium plate as the surface mount.


TRRS Connections

An important requirement of this project was to make everything modular in order to attach / detach every component to or from the Arduino without soldering. This allows me to:

  • disconnect the potentiometers so I can move the nightstand while cleaning
  • disconnect the LEDs for maintainance or replacement
  • disconnect the Arduino for reprogramming or debugging

To implement this requirement I choose TRRS cables and connectors because they had the right amount of pins and are easy to solder. Such TRRS are also convinient because they can cover longer distances than usual jumper cables and are more protected.

IMPORTANT: You can of course just solder everything directly together if this requirement is not important to you. In such case you can ignore everything regarding the TRRS connections.


Micro Controller

As the micro controller I choose an Arduino Nano Every because it should be small enough to fit in the case. Since it has no header pins soldered to it, it also has a smaller footprint on the PCB.

The Arduino and the lightstrips are powered by a single 5V/10A power supply. To easily disconnect it from the power source, a female VCC jack is soldered on. The original male VCC plug was not fitting tight (2.5mm instead of 2.1mm) so I had to resolder a smaller male plug to it.


Supplies

potentiometer.jpg
led-strip.jpg

Shopping List

  • Arduino -> Arduino Nano Every
  • Strips -> SK6812, 144/m, IP30, 1m, white pcb
  • Diffuser -> Paulmann 78902 Profile Base with White Diffuser 1m LED Channels Black Strips Aluminium Plastic Stripe
  • Potentiometer -> Taiss 10K ohm potentiometer single line cone dimmer with switch
  • Knob -> HiFi Lab Pot Knob Aluminium 38 x 22 mm Solid Silver 6 mm
  • Potentiometer Plate -> 60 x 60 mm Aluminium Blech AlMg3 (5754 - Foliert)
  • Connectors -> InduSKY 3.5mm Mini Stereo Jack Plug with Nuts 4 Pin Fully Gold Plated
  • Cables -> Goobay 63828 AUX cable, 3.5mm jack plug (4-pin, stereo), 1.5m
  • Power Supply -> LEICKE Ull Universal Power Supply, 5V/ 10A 50W, 5.5 x 2.5 mm Plug
  • Female VCC Jack -> DC Power Jack Socket 55 x 21 mm
  • Case -> Plastic Junction Box for Electronics, Black, 100 x 60 x 25 mm
  • I/O-Switch -> Rocker Switch Button, Round, Black


Tools

  • Soldering Iron
  • Jumper cables
  • THT soldering board
  • Everything from Shopping List

Wiring

wiring-overview.png
pcb-layout.png
connectors-wiring.png
trrs-male.jpg
trrs.jpg

The two LED Strips and two potentiometers must be soldered to the Arduino pins. You can find the details for the wiring layout and specific Arduino pins on these 3 images.

Keep in mind that the LED strips and potentiometers are not directly soldered to the Arduino. They are decoupled by using TRRS connectors.

I stuffed everything inside a plastic electrical box.


Flashing the Code

In the Arduino IDE, flash this code to your Arduino:


#include <Adafruit_NeoPixel.h>

#define NUMPIXELS 144

#define LED_DATA_PIN_LEFT 5
#define POT_DATA_PIN_LEFT A0
#define POT_SWITCH_PIN_LEFT 7

#define LED_DATA_PIN_RIGHT 6
#define POT_DATA_PIN_RIGHT A1
#define POT_SWITCH_PIN_RIGHT 8

#define LOW_BRIGHTNESS 5
#define DELAYVAL 10

Adafruit_NeoPixel STRIP_LEFT(NUMPIXELS, LED_DATA_PIN_LEFT, NEO_RGBW + NEO_KHZ800);
Adafruit_NeoPixel STRIP_RIGHT(NUMPIXELS, LED_DATA_PIN_RIGHT, NEO_RGBW + NEO_KHZ800);

bool isLeftSwitchedOff = true;
bool isRightSwitchedOff = true;

void setup() {
Serial.begin(9600);

pinMode(POT_SWITCH_PIN_LEFT, INPUT_PULLUP);
pinMode(POT_SWITCH_PIN_RIGHT, INPUT_PULLUP);

STRIP_LEFT.begin();
STRIP_RIGHT.begin();

startUpAnimation();
}

void loop() {

if(isLeftSwitchedOn()) {

turnOnLeftIfNeeded();

processCurrentInputLeft();

} else {
turnOffLeftIfNeeded();
}

if(isRightSwitchedOn()) {

turnOnRightIfNeeded();

processCurrentInputRight();

} else {
turnOffRightIfNeeded();
}

delay(DELAYVAL);
}


bool isLeftSwitchedOn() {
// because of INPUT_PULLUP, the values LOW and HIGH are switched
return digitalRead(POT_SWITCH_PIN_LEFT) == LOW;
}

bool isRightSwitchedOn() {
// because of INPUT_PULLUP, the values LOW and HIGH are switched
return digitalRead(POT_SWITCH_PIN_RIGHT) == LOW;
}

void turnOnLeftIfNeeded() {
if(isLeftSwitchedOff) {
turnLeftOn();
isLeftSwitchedOff = false;
}
}

void turnLeftOn() {
Serial.println("turning on.");
for(int i=0; i < NUMPIXELS; i++) {
STRIP_LEFT.setPixelColor(i, getColor(LOW_BRIGHTNESS));
}
STRIP_LEFT.show();
}

void turnOnRightIfNeeded() {
if(isRightSwitchedOff) {
turnRightOn();
isRightSwitchedOff = false;
}
}

void turnRightOn() {
Serial.println("turning on.");
for(int i=0; i < NUMPIXELS; i++) {
STRIP_RIGHT.setPixelColor(i, getColor(LOW_BRIGHTNESS));
}
STRIP_RIGHT.show();
}

void processCurrentInputLeft() {
int pivot = map(analogRead(POT_DATA_PIN_LEFT), 0, 1023, 0, NUMPIXELS);
int dynamicBrightness = map(analogRead(POT_DATA_PIN_LEFT), 0, 1023, LOW_BRIGHTNESS, 255);

for(int i=0; i < pivot; i++) {
STRIP_LEFT.setPixelColor(i, getColor(dynamicBrightness));
}

for(int i=pivot; i < NUMPIXELS; i++) {
STRIP_LEFT.setPixelColor(i, getColor(LOW_BRIGHTNESS));
}

STRIP_LEFT.show();
}

void processCurrentInputRight() {
int pivot = map(analogRead(POT_DATA_PIN_RIGHT), 0, 1023, 0, NUMPIXELS);
int dynamicBrightness = map(analogRead(POT_DATA_PIN_RIGHT), 0, 1023, LOW_BRIGHTNESS, 255);

for(int i=0; i < pivot; i++) {
STRIP_RIGHT.setPixelColor(i, getColor(dynamicBrightness));
}

for(int i=pivot; i < NUMPIXELS; i++) {
STRIP_RIGHT.setPixelColor(i, getColor(LOW_BRIGHTNESS));
}

STRIP_RIGHT.show();
}

void turnOffLeftIfNeeded() {
if(!isLeftSwitchedOff) {
turnOffLeft();
isLeftSwitchedOff = true;
}
}

void turnOffRightIfNeeded() {
if(!isRightSwitchedOff) {
turnOffRight();
isRightSwitchedOff = true;
}
}

void turnOffLeft() {
Serial.println("turning off.");
for(int i=NUMPIXELS-1; i >= 0; i--) {
STRIP_LEFT.setPixelColor(i, getColor(0));
STRIP_LEFT.show();
}
}

void turnOffRight() {
Serial.println("turning off.");
for(int i=NUMPIXELS-1; i >= 0; i--) {
STRIP_RIGHT.setPixelColor(i, getColor(0));
STRIP_RIGHT.show();
}
}

void startUpAnimation() {
Serial.println("starting up.");
for(int j=0; j < 3; j++) {
for(int i=0; i < NUMPIXELS; i++) {
STRIP_LEFT.setPixelColor(i, getColor(255));
STRIP_RIGHT.setPixelColor(i, getColor(255));
}
STRIP_LEFT.show();
STRIP_RIGHT.show();
delay(200);

for(int i=0; i < NUMPIXELS; i++) {
STRIP_LEFT.setPixelColor(i, getColor(0));
STRIP_RIGHT.setPixelColor(i, getColor(0));
}
STRIP_LEFT.show();
STRIP_RIGHT.show();
delay(200);
}
}

uint32_t getColor(int brightness) {
return STRIP_LEFT.Color(0, 0, 0, brightness);
}


Mounting

overview.png
nightstand-bottom.jpg

I cut and bended the diffusers to an L shape and screw them behind the backboard of my bed. I attached the Arduino in the center using velcro tape.

To integrate the potentiometers in the nightstand, I cut a hole in it and glued the square aluminium potentiometer surface plate on top of it using double sided tape. The potentiometer and knob were already attached to the aluminium plate.

And that's it! Have fun with it.