A video showing the SH-400 coin dispenser and interfaced with Arduino.
Please ask any questions in the comments.
#define sensorPin 3
#define motorPin 2
byte amountToDispense = 0;
volatile byte amountDispensed = 0;
void setup() {
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(sensorPin), coinPulse, FALLING);
pinMode(sensorPin, INPUT_PULLUP);
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, HIGH);
}
void loop() {
if (Serial.available())
{
amountToDispense = Serial.read() - 48;
digitalWrite(motorPin, LOW);
}
}
void coinPulse()
{
++amountDispensed;
if (amountDispensed == amountToDispense)
{
Serial.print("Completed");
digitalWrite(motorPin, HIGH);
amountDispensed = 0;
}
}
Негізгі бет Controlling a Coin Hopper with Arduino + Code
Пікірлер: 79