2017年8月30日 星期三

Sintron arduino working with CH-926 coin acceptor to make money

with this arduino example ,you will learn how to read signals from CH-926 coin acceptor ,and then use LED to response .so alternatively .you can use coin acceptor to control any other device to charge fee for your service .


Wirings :


1. supply 12V power supply for both “coin acceptor” and “arduino uno”.


2. coin acceptor output pin ( white wire ) -- arduino pin D2 .
3. LED control pin :  pin D8 ( add 220 ohm resistance between D8 & LED )

code :


int Ledpin = 8;
int Coinpin = 2 ;


void setup( )
{
  pinMode(Ledpin,OUTPUT);
  pinMode( Coinpin,INPUT);
}
 void loop ( )

 {
   if (digitalRead( Coinpin) == HIGH)
   {
     digitalWrite(Ledpin,HIGH);
 
   }
   else if  (digitalRead( Coinpin) == LOW)
   {
     digitalWrite(Ledpin,LOW);
   
   }
 }






code 2: updated on 2019 june, using interrupt method:

// by Sintron ccfeng june 2019
const byte builtinLED = 13;
const byte ledPin = 8;
const byte coin_input = 2;
volatile byte state = LOW;
boolean coin_flag = false ;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(coin_input, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(coin_input), CH926, FALLING);
}

void loop() {

  if (coin_flag == true )
  {
    delay (15);
    state = !state;
    digitalWrite(ledPin, state);    // you can also use this for a relay
    digitalWrite(builtinLED, state);   // check if the bulit in LED changes

    coin_flag = false ;     // remove the flag
    Serial.println("got a coin in");  // you can also check in serial monitor

  }

 
}

void CH926() {
  coin_flag = true;

}











Material list :

1. Sintron arduino-compatible board
2. Sintron CH-926 coin acceptor
3. LED
4. 220 ohm resistor *1
5. 12V power supply *1


Share:

Sintron

Search This Blog

技術提供:Blogger.

Blog Archive

Arduino Super Mario tone with Buzzer