You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Dasduino and the basic code. Everything else is left to your imagination.


In this tutorial, we will become acquainted with a device which we, not even knowingly, use often. It is about a coin or token accepting device used for various purposes. It appears in coffee, soda or snacks vending machines, parking meters and even gaming machines. This device accepts only a type of coins (tokens) which we program it for, but there are also some devices which accept more types of coins. In the follow-up we will find out more about its operating mode, and how to connect and use it with Dasduino.


A coin accepting device contains microcontroller which processes data from the sensor which is located inside the device. The sensor collects different data on the token (coin) which goes through coin acceptor and using this data, microcontroller knows whether this token needs to be stored in a container or returned depending on which tokens it is programmed for.

The device is easily programmed using a push-button which is located on the top, we press the push-button and hold it for 4 seconds until the LED diode lights up and just then we release it. While the diode is on, we insert the token (coin) we want to program it for (we must use the same type of tokens or coins, e.g. if we want to program it for 1 kuna coins we will insert only 1 kuna coins while we program it). We are supposed to insert the same coin into the device 30 times in order for it to commit the coin to memory. After the programming is over, LED diode will turn off and the device is ready for usage.

The device gives us an impulse on the output for every inserted coin and by counting impulses we know how many coins have been inserted.

It also has three switches which we use in order to select the type of signal we want to get on the output.

The first switch has three positions and with it we select the impulse length (we can choose between 20 ms, 40 ms or 60 ms). With the other switch, we choose if the impulse will be +5 V(NC) or 0 V(NO), i.e. whether we will have +5V on the output while there is no impulse or 0 V, as can be seen in the picture. Using the last switch, we choose the precision of the device and for that we have 3 positions which we adjust depending on the need.



The device is easily connected to Dasdudino since it only uses one wire that we need to connect to Dasduino. COIN output is connected to Dasduino, and we need to connect GND power supply with Dasduino’s GND. The device power supply needs 12V power input that we connect to marked position.

In order for Dasduino to read impulses correctly, we must connect the resistor of 10KΩ between the pin we used to connect COIN with the device and +5V from Dasduino as shown in the scheme.


An example of a code that can be used for various applications that require a coin counter is given. In the counter variable we save the number of inserted coins and we can use it for various purposes, we just need to add our code which does something else and is supposed to reduce counter value (e.g. we can create a charge for entrance to the room so that the door opens when coins are inserted or a game which requires inserting coins in order to play for a certain amount of time).

const int coinpin = 2;//pin to which we connect COIN pin from the coin recognition device 
const int ledpin = 13;//pin used for LED diode
volatile int stanje= 0; //variable in which we save the number of inserted coins
boolean bInserted = false;
void setup() {
  Serial.begin(9600);//we begin with serial communication
  attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING); //coinpin(pin 2)
  //we enter it as interrupt, and the one on the raising edge as coinInterrupt
  pinMode(ledpin, OUTPUT);//ledpin is set as an output
void loop() {
  if( bInserted  ){ // this if loop is executed when the coin is inserted and we can add 
    //our own function there (e.g. starting something if there is enough coins)
     bInserted = false;
     digitalWrite(ledpin, HIGH);//LED diode is turned on on pin 13 when the coin
     //is inserted (this part is an example and can be left out)
     delay(1000); // 1 sec pause
  // Turn off LED
  digitalWrite(ledpin, LOW); //LED diode is shut down 
  } }
void coinInterrupt(){
 //each time we insert the corresponding coin, the state of one condition increases
  bInserted = true;
 Serial.println( pulse );//on Serial monitor we write out how many coins have been inserted