Step 8Sound effects and bend sensors
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
}
HandRepulsorSound.wav689 KB| « Previous Step | Download PDFView All Steps | Next Step » |

























































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
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!
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?
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 :)
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?
If the transistor is on, i just get the 2,1V at the led. I'm loosing the 0,9V somewhere in the transistor?!?
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
Cool- glad everything worked out. Make sure to post a video!