Sunday, December 20, 2009

piezo triggers servo movement 004

//servo attached to pin 2 + piezo on analog pin 0 [needs amplifier, check here]
//load servo library!

Servo myServo;
const int threshold=200;//how hard do you need to knock?
int piezoRead;

void setup(){
myServo.attach(2);
}

void loop(){

piezoRead=analogRead(0);

if (piezoRead>threshold){//if the signal from piezo is strong enough, then...

for (int i=0; i<180;i+=1){ //turn the servo
myServo.write(i);
delay(10);
}

myServo.write(0);//and go back
delay(500);

}
}

No comments:

Post a Comment