Programme a String of Xmas Lights to Blink Morse Code With Arduino & Snap Circuits
by brianfit in Living > Christmas
5446 Views, 27 Favorites, 0 Comments
Programme a String of Xmas Lights to Blink Morse Code With Arduino & Snap Circuits
This is a project my son Dylan (9) and I put together using an Arduino Circuit board, a Snap Circuit set, and a string of Christmas lights.
What you need:
An Arduino: An Arduino is a computer on a single circuit board that you can programme with a looping routine from a Windows, Mac, or Linux computer connected via USB. The unit can then run independently with a 5-12 volt power source -- USB battery packs work well. It's a great little gizmo for hobbyists and for learning the basics of programming.
Snap Circuits: Your basic electronics learning/experimentation kit, built around components that snap together. Snap Circuits are a super way to learn basic electronics.
Low-voltage Christmas Tree lights: Since you'll need to slice a wire in your string of lights, you need the kind of lights that run on low voltage from a transformer or wall wart. Do NOT mess around with mains power circuits!!!!!!!!!
Optional, but handy: Pin-to-snap wires available from the good folks at Elenco allow you to use any of the components from your Snap Circuits kit as output or input components for the Arduino, and make integrating the board with Snap Circuit projects a (heh, heh) snap.
The task of making an LED light up and go off is a really basic Arduino routine. To make it control a Christmas Tree, we decided to use an electromagnetic relay from our Snap Circuits kit. A relay can isolate two circuits, so the (in our case) 12 volt christmas tree lights wouldn't fry the delicate six volt snap circuit components. I don't know what the limit is on the Q2 transistor included in the kit, but given that it normally only handles loads of up to 6volts from 4 AA batteries, probably better to keep those circuits separate.
We originally planned to fire the Snap Circuit components with the Arduino's five volt output, but I wasn't sure enough of my own electronics knowledge not to make a mistake and send a voltage spike or a reversed polarity current into our favorite kit and toast it: we want to use this puppy for other projects! That's when we hit on the idea of using a photosensor from the Snap Circuits. By placing the LED from the Arduino into the barrel of the photosensor, we could control the relay circuit with light rather than electricity! This meant the Arduino was in a circuit all its own with just an LED, and completely safe.
The process of building this project involves three steps.
Programme the Arduino
/*
Merry Christmas in Morse Code Blink
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
//M in morse code is two dashes. We define the dot and dash subroutines below.
dash();
dash();
space();
//E
dot();
space();
//R
dot();
dash();
dot();
space();
//R
dot();
dash();
dot();
space();
//Y
dash();
dot();
dash();
dash();
space();
//Space
wordspace();
//C
dash();
dot();
dash();
dot();
space();
//H
dot();
dot();
dot();
dot();
space();
//R
dot();
dash();
dot();
space();
//I
dot();
dot();
space();
//S
dot();
dot();
dot();
space();
//T
dash();
space();
//M
dash();
dash();
space();
//A
dot();
dash();
space();
//S
dot();
dot();
dot();
space();
wordspace();
}
void dot() {
digitalWrite(led, LOW); // turn the LED off (LOW is the voltage level)
delay(200); // keep the light off for 200 ms (dot)
digitalWrite(led, HIGH); // turn the LED on by making the voltage HIGH
delay(600); //pause between characters
}
void dash() {
digitalWrite(led, LOW); // turn the LED off
delay(600); // keep the light off for 600 ms
digitalWrite(led, HIGH); // turn the LED on by making the voltage high
delay(600);
}
void space(){
digitalWrite(led, HIGH); //Make sure the LED is on
delay(1000); //For one second to mark space between characters
}
void wordspace(){
digitalWrite(led, HIGH); //make sure the LED is on
delay(3000); //for 3 seconds to mark space between words
}
Set Up the Snap Circuit Board
You put the LED attached to the Arduino into the barrel of the photosensor (fits nicely). When the light fires, the photosensor's resistance drops, putting a current into the base of the NPN transistor. This opens the circuit across the collector and emitter, firing the relay, and turning off the xmas tree lights. When the light goes off, the resistance of the photosensor rises, cutting off the current to the transistor. The relay returns to its normal state, opening the path between the christmas tree lights. The diode you see there (yep, with the positive side hooked up to the negative side of the circuit) is to protect the transistor from stray charges that can build up from the relay firing -- it just shunts them back in a short circuit to the relay coil.
Wire the Christmas Tree Lights In
Again: Our lights are low-voltage (12 volts DC) DON'T DO THIS unless you know you're dealing with a low voltage circuit. Alligator clips to the Snap Circuit Relay poles is an open, uninsulated, bare wire connection which a child or a cat might touch. You may end up doing what my brother calls the Dance of the Sugar Plum Fairy if you mess around with a higher voltage line and create a path to ground with your highly conductive body. And if you mess around with a mains circuit, you could seriously hurt yourself. Be smart. Be safe.