Arduino: bathroom light prototype
This is one of my first “useful” projects i.e. has a practical use. Our bathroom light triggers a fan (we don’t have any windows) when turned on, which is fine until you have to pay a nocturnal visit…
Cue the gentle bathroom night light project!
And before I get the comments, yes yes I know I could prolly buy something off the shelf, but that’s not the point. I CAN HAS COMPONANTZ N I R USE THEM!
The final product will consist of a super bright, but warm LED that triggers (gently fades on) when the bathroom door is open, then fades out after five minutes. The prototype is a proof of concept to test the brightness of LEDs, timing of fader and finally the auto-switch off feature. I need to find a mains power jack so I can connect a battery pack to it, so until I have that I won’t be able to test it fully (it’s tethered and powered by USB at the moment).
I think I’m going to play around with with IR LEDs and photo transistors and see if I can make a rudimentary distance sensor, which could be the door trigger i.e. either the door opening or the person walking towards the sensor would trigger it. If it’s at all possible I’d like to keep this as one package rather than having the light on one board and a transmitter or receiver for the other.
Here’s an incredibly boring video demonstrating the prototype (which you won’t be able to see if you’re reading this post via your news reader)
Here’s a circuit diagram which took forever to create in Fritzing
Finally here’s the source code
// button to activate light
/*
* Purpose: Push button activates an LED that slow fades on and after a fixed paused, fades off.
* Change log:
* 20080202: initial release, calling this the first prototype.
* Code taken from:
* Button by DojoDave - http://www.arduino.cc/en/Tutorial/Button
* Fading LED // by BARRAGAN
*/
// Parameters
#define STEPPER 50 // how slow to fade on and off
// #define PAUSE 300000 // five minutes
#define PAUSE 500 // how long to leave the light on
#define DEBUG 1 // see serial messages
// Vars
int inputPin = 2; // choose the input pin (for a pushbutton)
int switchVal = 0; // variable for reading the pin status
int switchOn = 0; // switch is set to off
int value = 0; // variable to keep the actual value
int ledpin = 9; // light connected to digital pin 9
void setup() {
pinMode(inputPin, INPUT); // declare pushbutton as input
if ( DEBUG )
{
Serial.begin(9600);
}
}
void loop(){
switchVal = digitalRead(inputPin); // read input value
if (switchVal == LOW ) { // check if the input is LOW (pushed in)
switchOn = 1;
if (DEBUG)
{
Serial.print("Turning on switch for ");
Serial.print(PAUSE);
Serial.println(" milliseconds.");
}
lightOn();
delay(PAUSE);
if (DEBUG)
{
Serial.println("Turning off switch");
}
switchOn = 0;
lightOff();
}
}
// supporting functions
void lightOn()
{
for(value = 0 ; value <= 255; value+=1) // fade in (from min to max)
{
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
delay(STEPPER); // waits for STEPPER milli seconds to see the dimming effect
}
}
void lightOff()
{
for(value = 255; value >=0; value-=1) // fade out (from max to min)
{
analogWrite(ledpin, value);
delay(STEPPER);
}
}
About this entry
You’re currently reading “Arduino: bathroom light prototype,” an entry on archived blog – booyaa dot org
- Published:
- 2.3.08 / 12pm
- Category:
- Tags:
- arduino, electronics, geekout

Technorati
Flickr
del.icio.us
Ice Rocket
Wikipedia
Comments are closed
Comments are currently closed on this entry.