Lamp for My Nightstand
Hello!
By all means this instructable is meant as a form of documentation for a school assignment. If things do not seem to be explained clearly or there are things missing, or extra. Note that this is because there was extra context given in previous meetings between my instructors and I, or there is an extra need for context.
This project was originally meant as a book nook with sever puzzle elements build into it. After the initial concept phase I stumbled upon an object in a craft store that seemed a lot more fun to work with. I bought it on an impulse, looked at home what kind of problem I had (and wanted to solve), and made that my project.
On my nightstand I have a lamp that my partner and I lovingly refer to as "The fucking sun" since it is nothing but a 30 cm large glass opaque orb that can't be dimmed. I apparently like a challenge as I chose to make this instead of spending a ridiculous amount of money on a light bulb with controls.
Supplies
Parts used
Electronics:
- Arduino Uno
- RGB Led strip
- Wire
- Heatschrink
- Yellow led
- Breadboard
- Force sensitive resistor
- Rotary potentiometer
- Micro Servo
- USB A to USB B cavel
- 3.3k Ohm resistor
- 220 Ohm Resistor
- 5x 10k Ohm resistor
- 5x mini push button switch
- Strip board
- Optional: A 5V 2A power adapter. This is only necessary if you want to use a longer led strip with a higher power consumption.
Building material:
- Cardboard
- PVC Foam board
- Craft Foam board
- Pre-made wooden book box
- Hot glue
- Super glue
- Mod Podge
Concept
As I said before, I planned out a book nook with sever puzzle elements build into it. A book nook is a miniature diorama that is build into a bookshelf to give the illusion of a miniature world within the bookshelf. In theory this would have been an extremely fun project but the concept did not last.
I lack the skills and materials to pull this project off. And with the limited time available to me I subconsciously started to already look for different options.
Complete Redo
Going through a craft store I found this wooden book box. I immediately bought it on an impulse believing that I had found the perfect project to replace the lamp on my nightstand with.
Without much planning or sketching I started to put together the functionalities that I wanted this lamp to have.
I wanted it to:
- Create a light that I could dim and brighten easily.
- Have it change colour through hidden switches.
- Have a secret button that opened a small compartment for me to store my rings in.
- Have the secret compartment to only be accessible through finding another secret button.
Considering that I am wildly out of my depth here and it being my first time using an Arduino I thought that this would be quite a challenge already. Spoiler. It was.
Rough Planning and Breadboard Build
I have attempted to take multiple pictures of the breadboard situation but there was a dire need of schematics and some context. In step 6 the code will provide additional context.
Two things to note here. There is a button missing that turns the yellow led on and off. And this schematic shows the inclusion of an extra power adapter. The power adapter is advised to build in when you use a led strip that is significantly longer then mine. I ended up using 17 leds total and they are pushing the current setup to it's limit.
There are currently 5 buttons and a potentiometer interacting with the led strip. The potentiomer is used to adjust the brightness of the lights and the buttons to change colour.
The rest of the parts create a circuit that includes a button, led, force sensitive resistor and micro servo. When the button is pressed the led will turn on. When the led is turned on you can move the servo by using the force sensitive resistor. When the led is off they will not work
Placement and Soldering
After having tested everything I attempted to solder everything in as neatly as I could. By placing the Arduino first I measured everything in relative distance. Then I build everything in part by part.
With strands of microfiber made some candles coming from the yellow led. This would be an indicator for when you could open the secret compartment.
Construction
At this point it was time to start building everything into a solid housing. Truthfully speaking this has taken up a significantly larger portion of time then I anticipated.
Not only is it a challenge to do this on its own, but disaster would also strike on several occasions. After I had already closed up the compartment around the Arduino, the cable that grounded everything broke. The button for my puzzle mechanic snapped off. And my first attempt at creating a window pane was extremely lumpy.
Despite this I got everything roughly into place. After I made sure everything still worked correctly I started to close up the housing completely. Apart from the cables that run from one side of the book to the other all electronic components have been covered.
Code
Brief explanation of what the code does and extra context when needed.
The Code has two different parts and this here is the first.
You will need to add the Adafruit NeoPixel package to your library otherwise this project will not work.
Every bit of this code has been removed other then the necessary parts which are needed for the colour change and brightness.
Normally speaking the colour changing part of the code responsible for a new colour to slowly crawl down the led strip. The delay has been reduced to make this change instantaneous. Also a starting colour has been declared in the code so the colour is always orange on starting up. The potentiometer communicates it's position through and is then converted into a value that changes the brightness of the leds.
Now for the second part of the code.
The reason for splitting the code in two was that, if, I wanted to store my rings at night with the lights off, I would not have to blind myself by being forced to turn the light on.
Second part has a led, button, force sensitive resistor and a micro servo. If the button is pressed and the led is turned on the other two are capable of functioning. When you press on the resister the servo will move. The servo has a min and max position. Whenever that position has been reached the servo will be shut off completely. This was mainly done to make the movement of the servo be smooth and without stutter.
//Led code
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define LED_PIN 6
#define LED_COUNT 17
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
//brightness code
int bright_val;
//Led button code
#define button_1 2
#define button_2 4
#define button_3 7
#define button_4 8
#define button_5 12
#define button_6 13
int blue = 0;
int red = 255;
int green = 110;
//puzzle code
#define ledPin 3
#define buttonPin 5
int fsrAnalogPin = 1;
int fsrOutputPin = 9;
int fsrReading;
int fsrOutputValue;
#include <Servo.h>
Servo mimicServo;
byte lastButtonState;
byte ledState = LOW;
unsigned long lastTimeButtonStateChanged = millis ();
unsigned long debounceDuration = 50;
// setup() function - Led
void setup() {
//Led specific support code
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of led specific support code.
//led code
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
//led button code
pinMode(button_1, INPUT_PULLUP);
pinMode(button_2, INPUT_PULLUP);
pinMode(button_3, INPUT_PULLUP);
pinMode(button_4, INPUT_PULLUP);
pinMode(button_5, INPUT_PULLUP);
pinMode(button_6, INPUT_PULLUP);
//puzzle code
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
lastButtonState = digitalRead(buttonPin);
// pinMode(fsrOutputPin, OUTPUT);
mimicServo.attach(fsrOutputPin);
mimicServo.write(180);
mimicServo.detach();
}
void loop() {
// Set BRIGHTNESS to about 1/5 (max = 255)
// brightness code
bright_val = analogRead(0);
bright_val = map(bright_val, 0, 1023, 0, 255);
strip.setBrightness(bright_val);
delay(15);
//led code
// Fill along the length of the strip in various colors...
colorWipe(strip.Color(red, green, blue), 0); // Blue
//led button code
if (digitalRead(button_1) == LOW) {
blue = 255;
red = 30;
green = 5;
}
if (digitalRead(button_2) == LOW) {
blue = 5;
red = 255;
green = 2;
}
if (digitalRead(button_3) == LOW) {
blue = 25;
red = 10;
green = 255;
}
if (digitalRead(button_4) == LOW) {
blue = 255;
red = 185;
green = 0;
}
if (digitalRead(button_5) == LOW) {
blue = 0;
red = 255;
green = 75;
}
if (digitalRead(button_6) == LOW) {
blue = 0;
red = 255;
green = 110;
}
//puzzle code
if (millis() - lastTimeButtonStateChanged >= debounceDuration){
byte buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
lastTimeButtonStateChanged = millis();
lastButtonState = buttonState;
if (buttonState == LOW) {
if (ledState == HIGH) {
ledState = LOW;
}
else {
ledState = HIGH;
}
digitalWrite(ledPin, ledState);
}
}
}
if (ledState == HIGH){
fsrReading = analogRead(fsrAnalogPin);
fsrOutputValue = map(fsrReading, 800, 1023, 180, 0);
if (fsrOutputValue >= 150) {
mimicServo.attach(fsrOutputPin);
mimicServo.write(180);
delay(500);
mimicServo.detach();
}
else {
mimicServo.attach(fsrOutputPin);
mimicServo.write(0);
delay(500);
mimicServo.detach();
}
}
}
// Led functions
// Colour wipe, changing to a different colour that does not wipe
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}
Finished Project and Future Steps
Here is a video of the project working while testing it throughout, and the final version.
Potentially I will still make time to decorate this. Currently there are no plans to do so, as this took up more time then there was planned in for the subject.
Reflection
This project has been chaotic from start to finish. I believe that is also the intend of the assignment.
Despite that I could have had planned a few things better. While in part my lack of better tools is to blame, the circuitry did fail on me multiple times by breaking and it is inefficiently put together. The physical space most components need has also been underestimated and could have been done better. And I would have liked to reach a state where the project would have had more decorations.
That being said there where also parts I greatly enjoyed. While I learned a lot about electronics and the coding needed behind it, it is most definitely not got me. Working with pre functioning tools however, like the led strip, was an immense joy. Planning out details, decorations and thinking of clever ways to incorporate the leds was even more fun.
Thankfully the goals I set out for the projects functionality where reached. Which for me counts as a huge success in assessing my capabilities and time management.
This project single-handedly kick started my current love for tabletop miniatures. While I will not grab an Arduino to make any electronics myself, I will not hesitate to grab something small to elevate them in the future.