Laser Pointer Switch
This instructable will detail how to make a switch that uses an arduino to sample light. When the light sample reaches a threshold it will trigger a relay that can be used to turn on/off a small appliance (light, radio, fan, etc...) The parts for this instructable can be ordered as a kit:
Jameco Kit
http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2209967_-1
Review Relay and Prep Wire
unpackage the relay and stretch out the cable. this cable is used to activate the relay but will also be used to power the arduino. cut the wire in about two equal parts. the part with the white clip end will plug into the relay and be soldered into the arduino. the wire with the black clip end will be spliced into the usb cable to supply power to the arduino. this is also a good time to review the relay tutorial for safety information: http://www.dfrobot.com/wiki/index.php?title=Tutorial:_DFR0017_V2_Relay
Modify USB Cable
Identify Arduino
Component Layout
Solder Arduino
Program Arduino
//adjust the lTrigger number for your light values
int lTrigger = 610;
int photoPin = A5; //define a pin for Photo cell
int ledPin=5; //define a pin for relay activator
boolean bLatch = false;
int lLaser = 0;
void setup() {
Serial.begin(9600); //Begin serial communcation
pinMode( photoPin, INPUT );
pinMode( ledPin, OUTPUT );
}
void loop() {
lLaser = analogRead(photoPin);
if (lLaser > lTrigger) {
bLatch = !bLatch;
digitalWrite(ledPin,bLatch);
delay(1000);
}
Serial.println(lLaser); //display photocell value to serial monitor.
delay(10); //short delay for switch bounce
}
test your arduino with the serial monitor open to see the light reading values. adjust the trigger value to a range that works best with your laser pointer
Prepare Power Cord
using the end of the power cord that plugs into the wall, connect the black wire and the short black piece to one leg of the USB block. connect the white wires from both ends of the power cord to the other leg of the USB block. connect the green wires together so they dont touch any part of the USB block. connect the short black wire to the COM header on the relay. connect the black wire from the other power cord end (the end that your appliance will be plugged into) into the NO header on the relay. tape any bare wires and the USB block ends to avoid accidental contact with wires and you.