3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

coin slot detector

Step 3Program in Arduino 0012

open up Arduino 0012 on your computer. copy and paste the following code into your program window...then press the Verify button to make sure it works. Finally, click the Upload to Board button, to upload it to the Arduino to run. Once the program is uploaded, click the Serial Monitor button to see the values changing as you cover and uncover the photoresistor. When the values go above 500, the vibrating motor will vibrate!

/*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 StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
5
Followers
1
Author:semiotech(Amy Khoshbin)
Amy Khoshbin is an Iranian-American artist based in Brooklyn. She creates hybrids between performance, video and installation art, music, and interactive media to explore the subjects of perception an...
more »