Step 3Program in Arduino 0012
/*Coin Slot Detector
by Amy Khoshbin
2008*/
int photoPin = 0; // Analog input pin that the photo resistor is attached to
int photoValue = 0; // value read from the photoresistor
int vibPin = 9;
boolean isVibrating = false;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(vibPin, OUTPUT);
}
void loop() {
photoValue = analogRead(photoPin); // read the pot value
Serial.println(photoValue); // print the pot value back to the debugger pane
vibrate();
delay(10); // wait 10 milliseconds before the next loop
}
void vibrate(){
//change the values greater than and less than to fit the sensitivity of the photoresistors you use
if(photoValue > 500 && isVibrating == false){
digitalWrite(vibPin, HIGH);
isVibrating = true;
}
if(photoValue < 500 && isVibrating == true) {
digitalWrite(vibPin, LOW);
isVibrating = false;
}
}
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|





























































