(home made vendo machine)

when i insert 1 coin in my ir sensor my servo motor will rotate no problem in that I just want to insert 2 coin (means 1 coin will not trigger my motor but when 2 coin passed my sensor it will now trigger) sorry for my code i just picked them in internet plss help me

and if its ok? can you guys add a push button before my servo motor rotates

sorry for my ugly english :slight_smile:

72470930_993549804339864_8575406920955854848_n.png

#include <Servo.h>
Servo myservo;

int pos=0; // variable to store the servo position
int pd=2; //Photodiode to digital pin 2
int senRead=0; //Readings from sensor to analog pin 0
int limit=200; //Threshold range of an obstacle

void setup()
{
pinMode(pd,OUTPUT);
digitalWrite(pd,HIGH); //supply 5 volts to photodiode
Serial.begin(9600); //setting serial monitor at a default baund rate of 9600
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
int val=analogRead(senRead); //variable to store values from the photodiode
Serial.println(val); // prints the values from the sensor in serial monitor
if(val > limit) //If obstacle is nearer than the Threshold range
{
for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(10); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1)
{ // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(10);

} } }