Hi everyone! I am currently building one of the tiki birds from Walt Disney’s Enchanted Tiki Room in Disneyland and am want to control the beak movement with audio. At the moment, I have a servo attached to pin 9, 5V and GND, and an audio jack is hooked up to GND and A0. The audio is played through a 3.5mm cord from my iPhone. I’m using the code below, but it is a little shaky, and whenever there isn’t audio playing the servo slowly starts to spin and will spaz out. I’m kind of stuck at this point, and any help would be greatly appreciated. Thanks and have a magical day!
-Matthew
#include <Servo.h>
Servo myservo;
int ServoPin = 9;
int SoundInPin = A0;
void setup() {
myservo.attach(ServoPin);
pinMode(SoundInPin, INPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(SoundInPin);
sensorValue = map(sensorValue,0,512,0,180);
//myservo.write(90);
myservo.write(sensorValue);
}