In this project for Martí Guixé we built a small autonomous device with Arduino that can detect the presence of people with an ultrasonic sensor. It then proceeds to play an MP3 song with a Yampp Industrial III.
int val = 0;
int ledPin = 13;
int active = 0;
void setup(){
Serial.begin(19200);
pinMode(ledPin, OUTPUT);
}
void loop(){
val = analogRead(0);
if(val>200)
{
if(active==0)
{
Serial.print (1, BYTE);
digitalWrite(ledPin, HIGH);
delay(3000);
}
active = 1;
}else{
active = 0;
digitalWrite(ledPin, LOW);
delay(100);
}
}