Party @ Ginger Bread House After hundreds of years of listening to Christmas Jingles while working on Santa s toy sweatshop the Elves decided to break with tradition and throw a techno-rave party. But of course they don t want to end on the unemployment office, thought times to be and Elf, so they decided to put a sensor in the garden to know when Santa is coming For this exercise we will use the Sharp IR sensor and the Wave Shield, and of course a Ginger Bread house. Let s start learning about the Wave Shield Wave Shield Adding quality audio to an electronic project is surprisingly difficult. People tend to end up either using low-quality ISD chips (you might get 8Khz sampling rate for 30seconds out of these, if you're lucky!) or mucking around with trying to control a CD or MP3 player. Volume can be controlled with the onboard thumbwheel potentiometer. Can play any uncompressed 22KHz, 12bit, mono Wave (.wav) files of any size. While it isn t CD quality, it is certainly good enough to play music, have spoken word, or audio effects. Output is mono, into L and R channels, standard 3.5mm headphone jack and a connection for a speaker that is switched on when the headphones are unplugged. Files are read off of FAT16 formatted SD/MMC card. Included library makes playing audio easy. FIRST STEP, FORMATTING THE SD CARD If you bought an SD card, chances are it's already pre-formatted with a FAT file system. However you may have problems with how the factory formats the card, or if it's an old cart it needs to be reformatted. The Arduino SD library we use supports both FAT16 and FAT32 filesystems. If you have a very small SD card, say 8-32 Megabytes you might find it is formatted FAT12 which isn't supported. You'll have to reformat these cards. Either way, it's always a good idea to format the card before using, even if it's new! Note that formatting will erase the card so save anything you want first. Don t worry, I ll provide the card in the right format.
SECOND STEP, CONVERT THE FILES Again, I already put the Sound files in the right format for you, 22KHz, 12bit, mono Wave (.wav) THIRD STEP, DOWNLOAD THE LIBRARY Go to https://code.google.com/p/wavehc/downloads/list and download the latest library (wavehc20110919.zip ) or get it from www.federicomuelas.com/sva/nov_4_class. Install it on your arduino Library folder. FOURTH STEP, TRY THE ARDUINO WAVE Go ahead and open the daphc example from the WaveHC Submenu. Or download the code step_4.ino from Fede s web page. This code should play the two files we have on the card. Now that we know the Wave shield is working let s incorporate the SHARP IR sensor INFRARED PROXIMITY SENSOR - SHARP GP2Y0A21YK The Sharp GP2Y0A21YK is an Infrared proximity Sensor. It shines a beam of IR light from an LED, and measures the intensity of light that is bounced back using an infrared sensor. If you stare at the IR emitter, you can see one of the LEDs glowing slightly red as some of the IR falls into the visiblelight spectrum. Because the GP2Y0A21YK is sensing the intensity of its reflected IR light, the sensor outputs near 0V when nothing is in front of it (approx. > 3ft), and ramps up as an object comes near. At about 4in, the reading from the Arduino is about 630.
FIFTH STEP: FIRST, CONNECTING THE SENSOR (use the Jumpers Attached to the Wave Shield) Red wire: Arduino 5V Black Wire: Arduino Ground Yellow Wire: Analog in A0 Once you connect the sensor to the Arduino read it as any analog sensor with analogread() function. SIXTH STEP: Upload the following code, open the serial monitor and find the range for the Sharp sensor. Write down the range you are getting from the IR sensor. You can download the code step_6.ino from Fede s web page. CODE: int sensorpin = A0; int sensorvalue = 0; void setup() { Serial.begin (9600); void loop() { sensorvalue = analogread(sensorpin); Serial.println (sensorvalue); delay (300); Let s incorporate the RGB LED at this point RGB LEDS RGB LEDs are in essence, three LEDs of different colors in ONE. The idea here is to change individually the brightness of each LED (R G B) so you can achieve any color on the visible color spectrum; therefore you want to use PWM pins. RGB LEDs contain red, green and blue emitters, generally using a four-wire connection with one common lead (anode or cathode). These LEDs can have either common positive or common negative leads. Common cathode Vs. Common Anode The different between common cathode and common anode RGB LEDs is pretty much the direction of the three LEDs.
What means that in order to operate a common cathode RGB LED you have to individually provide power to each LED (by turning the Arduino pins (HIGH). For common cathode RGB LED you need to provide Ground (Arduino Pins LOW) Connect the hardware as follows -Red LED (first lead) to pin 6 (PWM) via the 120 ohms resistor. -Common cathode (second lead) to Arduino Ground. -Green LED (third lead) to pin 9 via the 120 ohms resistor. -Blue LED (Fourth and last lead) to pin 11 via the 120 ohms resistor. EIGHTH STEP: WRITE AND UPLOAD THE RGB LED CODE SEVENTH STEP: CONNECTING THE RGB LED Write the code below and upload the program to your Arduino and try it out. This is the lighting effect for the party!! You can download the code below from Fede s web page. Code for the PARTY MODE: int ledcolor = 0; int a = 50; //this sets how long the stays one color for int red = 6; //this sets the red led pin int green = 9; //this sets the green led pin int blue = 11; //this sets the blue led pin void setup() { //this sets the output pins pinmode(red, OUTPUT); pinmode(green, OUTPUT); pinmode(blue, OUTPUT); void loop() { int ledcolor = random(7); //this randomly selects a number between 0 and 6 switch (ledcolor) { case 0: //if ledcolor equals 0 then the led will turn red analogwrite(red, 204); case 1: //if ledcolor equals 1 then the led will turn green case 2: //if ledcolor equals 2 then the led will turn blue case 3: //if ledcolor equals 3 then the led will turn yellow analogwrite(red, 160);
case 4: //if ledcolor equals 4 then the led will turn cyan analogwrite(red, 168); case 5: //if ledcolor equals 5 then the led will turn magenta case 6: //if ledcolor equals 6 then the led will turn white analogwrite(red, 100); Code for the GOOD ELF MODE: int red = 6; //this sets the red led pin int green = 9; //this sets the green led pin int blue = 11; //this sets the blue led pin void setup() { //this sets the output pins pinmode(red, OUTPUT); pinmode(green, OUTPUT); pinmode(blue, OUTPUT); void loop() { analogwrite(red, 204); analogwrite(blue, 50); analogwrite(green, 50); NINTH AND FINAL STEP; PUTTING ALL TOGETHER At this point we know that the Wave Shield the Sharp IR sensor and the RGB LED are working property, let s go ahead and put everything together so when someone is close to the gingerbread house the party stops and the elves start singing jiggles and turn the strobe light off. Use the codes from steps 4, 6 and 8 (both) as a reference Oh don t forget to build the ginger bread house!!!