Instructables

Arduino animatronics- make your awesome costumes more awesome!

FeaturedContest WinnerContest Winner

Step 8: Sound effects and bend sensors

Example 4- adding sound and using a bend sensor to make an Iron Man hand repulsor

The bend sensor in this example is used as a trigger- once its output value reaches a certain level it causes the Arduino to run the specified code. You can change the threshold value to alter the point at which the sensor acts as a trigger. If you open the Arduino serial monitor window while the servo board is connected to your computer you can see when the bend sensor triggers. The bend sensor is set up using a voltage divider to provide an analog input value on input pin 1.

This example uses the Adafruit Wave Shield to provide sound effects. The instructions for building and setting up the Wave Shield can be found on the Wave Shield web page at http://www.ladyada.net/make/waveshield/

There are several code examples on the Wave Shield page for playing back audio files. The example I used is the play6_hc.pde example located at http://www.ladyada.net/make/waveshield/libraryhcplay6.html

Just download the sound file to a SD memory card and place it in your Wave Shield and you're good to go.

For the wiring schematic I did it two ways. The first version uses a small surface mount transistor board to activate the LED board and the Wave Shield.  The second version uses two TIP 120 transistors instead- they are functionally identical. The big difference is the TIP 120 transistors can handle much larger current loads than the small surface mount transistors- but the TIP 120s take up a lot more space.

The transistors are needed because the Wave Shield needs a switch to tell it when to play the audio file (the transistor grounds the Wave Shield input pin when activated) and multiple LEDs use far more current than a single Arduino output pin can provide.

When the bend sensor is bent far enough the LEDs will fade, the sound file will play and then a servo will move. The servo would be used to open a forearm missile compartment.


For more Iron Man costuming fun check out the SIWDAT site-
http://www.siwdat.com/index.html

Copy and paste this sketch into your Arduino window-

/*
* Example 4
* Bend Sensor/Wave shield
* This example uses a bend sensor as a trigger to fade a LED with sound effect
* using a Wave shield and then activate a servo
* Honus 2010
* Modified from Knock Sensor code created 25 Mar 2007 by David Cuartielles
* and modified 4 Sep 2010 by Tom Igoe
*/

#include "Servo.h"  // include the servo library

 Servo servo1; // creates an instance of the servo object to control a servo

  
// these constants won't change:
    const int servoPin1 = 9; // control pin for servo
    const int triggerSensor = 1; // the sensor is connected to analog pin 1
    const int threshold = 400;  // threshold value to decide when the sensor input triggers
    const int ledPin = 11;
    int soundPin1 = 10;  // control pin for sound board
  
   // these variables will change:
    int sensorReading = 0;  // variable to store the value read from the sensor pin
    int ledState = LOW;  // variable used to store the last LED status, to toggle the light

  void setup() {
   Serial.begin(9600);       // use the serial port
   servo1.attach(servoPin1);   // attaches the servo on pin 9 to the servo object
   pinMode(soundPin1, OUTPUT);  // sets the sound pin as output
      digitalWrite(soundPin1, LOW);
 
  }
 
   void loop()  {
     servo1.write(20); // move the servo to 20 degree position
    
    // read the sensor and store it in the variable sensorReading:
  sensorReading = analogRead(triggerSensor);   
 
  // if the sensor reading is greater than the threshold:
  if (sensorReading >= threshold) {
   
   digitalWrite(soundPin1, HIGH); // turn the sound on
   delay(10); // wait ten milliseconds
   digitalWrite(soundPin1, LOW); // turn the sound off
  
    // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);        
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);        
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);
    // send the string "trigger!" back to the computer, followed by newline
    Serial.println("trigger!");         
  }
 
  servo1.write(160);  // move the servo to 160 degree position
   delay(3000);   // wait 3 seconds
   servo1.write(20);  // move the servo to 20 degree position
  }
  
  delay (3000);  //  three second delay to avoid overloading the serial port buffer
  }
 
 
 
Remove these adsRemove these ads by Signing Up
the cage3 years ago
Hi Honus.
First of all: Your work is absolutly great!
I'm working on a Iron Man arcreactor + 1 lower arm with hand repulsor, like seen in one scene of the first movie. in the beginnings I experimentated with some low budget solution: Soundmoduls of greetingcards. Perhaps a tip for people with very low budget. But i want to synchron the lighteffects with the sound, so your instructable is perfect for me.
My first question:
Is it right, that you need an Arduino uno under the wave shield? Is there nothing to programm onto this Arduino?
Second question:
Can i put 2 different sounds on the waveshield, wiche are played with different input pins high?
Third question:
Why do you power the two arduinos with two 9V Blocks?
My planed setup: 2 x Arduino uno, 1x wave shield , 2 bend senors, two led circuits (open the hand -> repulsor starts glowing; spread thumb away from forefinger -> second led circuit with blast sound), powered by 9v blocks + step down voltage regulator.
Thanks again for your awsome instructable!
Felix
Honus (author)  the cage3 years ago
Thanks! Yes, the Wave shield fits on top of an Arduino Uno. You program the Uno to play the sound files. There is a link to the code used that will allow you to play six different sound files. The diagram just shows 9V power to both Arduinos- it's doesn't have to be two separate batteries.
the cage Honus3 years ago
Oh sorry, missed that...
I just looked a little bit closer into the programming. With another if condition in the first one, it should be possible to use one bend sensor as tricker with two threshold, right? open hand -> threshold 1 -> glowing repulsor, finger straight -> threshold 2 -> blast effects.
By the way, I changed the power setup: I will use 3V batteries for the LED instead of the step down regulator. If theres no energy for the Arduinos left, there will be still energy for the LED's of the Arcreactor.
Thanks again for your instructable. Without your great instruction, I would never start the project with Arduinos. But the potential of the Arduinos is just huge!
Honus (author)  the cage3 years ago
Yep- you just set individual threshold limits for the two different bend sensors and treat them as two separate inputs. Make sure to post your project when it's done!
the cage Honus3 years ago
Hi Honus,
i have a problem: Have to finish the project today. but I forgot to buy the 1k Ohm resistors infront of the tip120, and i won't get them here. What are they for? Are they just protecting the transistors? Would it work withou them?
Honus (author)  the cage3 years ago
Those resistors protect the Arduino output pins- without them you could fry your Arduino. I wouldn't hook up the transistors without them.
the cage Honus3 years ago
found 2 until now in my dvd player. One to go for the second led ciruit. But to much smd everywhere ;-)
Hi Honus!
Thanks for your fast repley yesterday! Saddly, I didn't made it: Found a third 1k resistor in the dvd player (broken by the way): a 102 SMD. But it was so tiny that it always broke before I was able to coat it with epoxy.... No chance without a board, just soldering the wiring. So I went to bed, had a good sleep and a good idea to optimize your circuit:
I read that the wave shield doesn't use the analog input pins, and that they could be used as output, too. So what i will try next: Just one arduino uno with waveshield, one flexsenor with two triger values (trigerglow & trigerblast) on Analog 0, the blue "Glow" Led circuit ond A1, and the white "Blast" Led Circuit on A2. Should work i gues, and i need just one arduine and, very important, 2 1k resistor on the transistors ;).
Heres a picture of my selfmade repulsor board, I made with my laserjet and "Natriumpersulfat". Quite good for the first try :)
IMG_1304[1].JPG
Having another problem :(. i connected the led with tip120's (everything without the waveshield). but the leds are not nearly as bright as connected directly to the power source. how could that be? I think it's even brighter if i connect them directly to the arduino! Are there different TIP120's or are they all the same?
Honus (author)  the cage3 years ago
The PCB looks great! As far as I know all TIP 120s are the same. What LEDs/resistor values are you using?
the cage Honus3 years ago
The LED's are 3,2V SMD LED's:
http://www.conrad.de/ce/de/product/180958/LED-SMD-PLCC2-BLAU-DDB-UJS-RS1-1/SHOP_AREA_17320
and
http://www.conrad.de/ce/de/product/180966/LED-SMD-PLCC2-WEISS-DDW-PJG-WX1-1/SHOP_AREA_17320
with 100 Ohm resistors.
If i measure the voltage between Emittor and Collector i just get about 0,9 V! That's not okay, isn't it?
Honus (author)  the cage3 years ago
Are you sure you have the transistors wired correctly so that when the Arduino output pin is high the transistor turns on? What is the voltage at the LED when the transistor is on?
the cage Honus3 years ago
Transistor Base with 1k Ohm to the arduino output pin., Collector to the PCB, Emittor to - of the Battery.
If the transistor is on, i just get the 2,1V at the led. I'm loosing the 0,9V somewhere in the transistor?!?
and emittor to the ground....
Honus (author)  the cage3 years ago
Are all grounds connected together and the LED has it's own power supply?
the cage Honus3 years ago
All grounds are connected and the led has a own 3 V power supply. If the transistor is on i have 2,1V at the LED and 0,9 V at the transistor between E and C. If i bridge E & C at the transistor, I have 3 V at the LED, but logically the transitor is out of function... this thing is killing me!
Honus (author)  the cage3 years ago
Here's what's going on- TIP 120s will have a voltage drop and that is what is affecting the brightness. The LEDs I used were rated at around 4V and I used a single cell LiPo battery, which is rated at 3.7V but actually measures just over 4V on a full charge. That's why I never had any brightness issues. Try using 3 AA rechargeable batteries that are rated at 1.2V each and see what that does to your output voltage at the LEDs.
the cage Honus3 years ago
Thanks, that's what I thought, too. The Datasheet of the TIP 120s says something about 60V. A drop of 0,something V wouldn't count there, but at 3V...! I just tried the complete setup as planed, but without the transistors: getting the led power from the arduino. I don't know why, but with the waveshield on A2 and A3 i get enough power for the full brightness. Wasn't the case at my first try with the naked arduino. But looks quit cool now, hehe. I didn't want to use another powersupply, because i have allready the 3 V for the arcreactor, and the 9 V for the arduino in my pocket. Another advantage is, that I don't have to wire the Arcreactor with the repulsor arm, so I'm quite happy with it.
Now I'm in the programming stuff. With some testsounds its working fine:
1. Open hand-> trigger 1 -> blue led circuit high and start up sound
2. hand still opend -> blue led circuit high and a electronic waving loop sound
3. complet open hand -> blue and white led circuit high and a looping blast sound
4. closing hand a bit -> white led circuit of and Modus 3
5.closing hand completly -> everything off.

Now i will ad some dimming effects. That for, I have to look over the playing procedure, because I took the playcomplete, which causes, that the arduino will do nothing until the sound is completly played. But not a big problem i think.
the glove is waiting for the electronic components to be glued together and the arm waits for its production. Looks quite good at the moment. I will post some images when its done.
Big thanks for your help!
Regards, Felix
Honus (author)  the cage3 years ago
Felix,

Cool- glad everything worked out. Make sure to post a video!
Wait, at the transistor shouldn't be any V... measuring my board, theres just 2,1 from the 3 v battery.