http://shahrulnizam.com/ct-uno-lesson-coin-acceptor/
/* Project: Coin Acceptor Lesson Programmer: Shahrulnizam Mat Rejab Board: Arduino Uno Last Modified: 27 November 2015 Website: http://shahrulnizam.com */ #define pulseTimeout 200 //How many milliseconds there are from the last impulse to the coin is determined const byte coinValues[3]={10,20,50}; //Coin values goes into this array unsigned long lastPulse=0; //When last pulse was send int pulseCount=0; //How many pulses detect int temp=0; float total; void setup() { Serial.begin(9600); attachInterrupt(0, acceptorPulse, RISING); //Digital interrupt pin 2 Serial.println("Coin Acceptor ready"); } void loop() { if((temp==1)&&(millis()-lastPulse>pulseTimeout)) { if(pulseCount<=3) { total += 0.01*coinValues[pulseCount-1]; Serial.print("Total money: RM"); Serial.println(total); } pulseCount=0; temp=0; } delay(1); } void acceptorPulse() { temp=1; lastPulse = millis(); pulseCount++; }
CT-Uno Lesson: Coin Acceptor
November 28th, 2015 Posted at Lesson Arduino
Coin Acceptor adalah sensor yang boleh
mengenal pasti duit syiling. Output nya adalah keluaran pulse mengikut
sample duit syiling yang telah disetkan. Boleh dapatkan coin acceptor di
cytron.com.my.
Berikut adalah demo menggunakan Coin Acceptor.
Arduino Source Code
/*
Project: Coin Acceptor Lesson
Programmer: Shahrulnizam Mat Rejab
Board: Arduino Uno
Last Modified: 27 November 2015
Website: http://shahrulnizam.com
*/
#define pulseTimeout 200 //How many milliseconds there are from the last impulse to the coin is determined
const byte coinValues[3]={10,20,50}; //Coin values goes into this array
unsigned long lastPulse=0; //When last pulse was send
int pulseCount=0; //How many pulses detect
int temp=0;
float total;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, acceptorPulse, RISING); //Digital interrupt pin 2
Serial.println("Coin Acceptor ready");
}
void loop()
{
if((temp==1)&&(millis()-lastPulse>pulseTimeout))
{
if(pulseCount<=3)
{
total += 0.01*coinValues[pulseCount-1];
Serial.print("Total money: RM");
Serial.println(total);
}
pulseCount=0;
temp=0;
}
delay(1);
}
void acceptorPulse()
{
temp=1;
lastPulse = millis();
pulseCount++;
}
No comments:
Post a Comment