Make Money With Arduino


164,523

309

52

Curiosity is the key. The "How"'s & "Why"'s always lead me to pull stuff apart. The "Can I build...

**** ENTERED IN THE HURRICANE LASERS CONTEST****
What would I do with a Laser Cutter? Build Simple Robotic Kits to teach people a Hobby that I Love.

Ever wanted to make some money from your projects?
This Instrutable will show you how to Simply interface a coin selector with your Adruino.
And also how to then connect that to your Visual C# Project.
Then it's all up to you and that great idea you have, if it's electronic or a program/game,
The Buck Starts Here.


You will need:
A Coin Selector: There are many different type's, the CH-926 accepts the most amount of coins so thats what I'll be using.
UK Stock, US Stock

Any 12v Power Supply, Batteries or Wall Wart.

An Arduino UNO

Microsoft Visual Express 2010 C#: Free Download, Scroll down until you see the correct option.
Note: Only needed for a coin operated Program, Not electronics Projects.

Let's get Started!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Coin Sampling

For your Coin Selector to know what type of coins it accepts, you have to set it up and then feed it samples of those coins.
It is recommend to sample at least 15 coins of the same type, up to a maximum of 30. Don't feed the same coin through 30 times, it's make the selector to fussy about what it accepts.

A Coin Selector works by comparing the material, weight and size of coins past through it to the samples you provide. If a coin is not reconised it drops out the return slot, if it is reconised the Unit sends out pulse's on the "COIN" line.
So to make it easier for the programming side we use a "greatest common factor" rule.
eg. We'll use the following coins (UK) 5p, 10p, 20p, 50p,& £1, (US) 5c, 10c, 25c, 50c & $1.
All the the coins can be made up with multiple 5p or 5c coins, so we make 1 pulse equal to 5p or 5c.
5p/c = 1 pulse, 10p/c = 2 pulses, 20p = 4 pulses, 25c = 5 pulses, 50p/c = 10 pulses, £/$1 = 20 pulses.

Now, TheSetup:

First the switches...
select "NC" by sliding the top switch to the bottom position.
select "FAST" by sliding the bottom switch to the top position.

Power Up the unit with a 12v supply.

1. Hold the "ADD" and "MINUS" buttons down at the same time for about 3 seconds, release and then the letter "A" will appear on the LED display.
2. Press the "SETUP" button once, and the letter "E" will appear. Then use the "ADD" and "MINUS" buttons to choose how many kinds of coins your going to use. Press the "SETUP" button again to finish.
3. The letter "H" will appear. Use the "ADD" and "MINUS"buttons to choose how many sample coins your going to feed it later. Press the"SETUP" button again to finish.
4.  The letter "P" will appear. Again use the "ADD" and "MINUS" buttons to choose the amount of output pulses you want. Press the "SETUP" button to finish. Refer to the above example to determine number of pulses.
5.  The letter "F" will appear. Using the "ADD" and "MINUS" buttons, choose the accuracy. The value is from 1 to 30, with 1 being the most accurate. I use 10 and it works fine. Again "SETUP" to finish.

You have now setup the first coin, depending on how many coins you selected in step 2, you'll have to repeat Step's 3 to 5 for each one.
The letter "A" will appear when you've setup all the coins. Hold "SETUP" for 3 seconds to finish, the letter "E" will appear.
Finally, switch the unit off and then back on.

Sampling time:

1.  Hold the "SETUP" button down for about 3 seconds, release and then the letters "A1" will appear on the LED display. This is your first coin (5p/c)
2. Feed the Coin Selector your sample coins, the LED display will show the amount of coins you've entered. "A1" will appear again when finished.
3. Hold the "SETUP" button down again for about 3 seconds, release and then"A2" will appear, repeat these steps until all coins are sampled.

If your not using all of the coin types available (eg 5 coins of a 6 type coin selector) the unit will ask for samples of a coin type you haven't setup, just hold the "SETUP" button down for 3 secconds of each of the remaining coins.

The Coin Selector restarts itself and is now ready to connect to the Arduino.

Step 2: Arduino Time

To Wire the Coin Selector to the Arduino is easy.

The white "COIN" Wire from the Selector connects to pin 2 on the Arduino. It has to be pin 2 or 3 as these are Interrupt pins.

Now if your using a different power supply for the Coin Selector to the Arduino, you must connect a common Ground. So the Red wire from the Coin Selector connects to +12V of the supply and the Black wire to ground of the supply AND to ground of the arduino.
Note: USB will NOT power the coin selector.

Step 3: Some Simple Code

Now, Fire up the Arduino IDE and let start coding:
PROGRAM START:

const int coinInt = 0; 
//Attach coinInt to Interrupt Pin 0 (Digital Pin 2). Pin 3 = Interrpt Pin 1.

volatile float coinsValue = 0.00;
//Set the coinsValue to a Volatile float
//Volatile as this variable changes any time the Interrupt is triggered
int coinsChange = 0;                  
//A Coin has been inserted flag

void setup()
{
  Serial.begin(9600);  
               
//Start Serial Communication
  attachInterrupt(coinInt, coinInserted, RISING);   
//If coinInt goes HIGH (a Pulse), call the coinInserted function
//An attachInterrupt will always trigger, even if your using delays
}

void coinInserted()    
//The function that is called every time it recieves a pulse
{
  coinsValue = coinsValue + 0.05;  
//As we set the Pulse to represent 5p or 5c we add this to the coinsValue
  coinsChange = 1;                           
//Flag that there has been a coin inserted
}

void loop()
{
  if(coinsChange == 1)         
 
//Check if a coin has been Inserted
  {
    coinsChange = 0;        
      
//unflag that a coin has been inserted
  
    Serial.print("Credit: £");
    Serial.println(coinsValue);    

//Print the Value of coins inserted
  }
}


PROGRAM END!

This simple program will write the total value of coins inserted to the serial monitor.
If you'd like your project to start automatically after say 50p or 50c has been inserted then replace:

    Serial.print("Credit: £");
    Serial.println(coinsValue);

with:

  if(coinsValue >= 0.50)
  {
          //your code here, eg Big Flashing Lights!!!! and Serial.println("I'M MAKING MONEY!!!!");
  }

CONGRATULATIONS
The Electronics Side is finished, Continue if you want to Interface with a Window Application you've created

Step 4: Basic Windows Form Application

Load up Microsoft Express 2010 and create a new "Windows Form Application".
I'm calling mine Coin Selector.

Now to your form add the following components:
1. A Button, Change the Text to "Connect"
2. A Text Box, Change the Text to "0.00"
3. A Serial Port, Change the PortName to the COM Port your Arduino connects to.

Step 5: Coding Time

Double Click the "Connect" Button and you'll open the Code window, paste the following code in the brackets:

if (button1.Text == "Connect")   //If the button say's connect
            {
                 serialPort1.Open();             //Open Serial Port
                 if (serialPort1.IsOpen)         //If the Port Opens
                 {
                     button1.Text = "Disconnect";    //Change the Button to Disconnect
                     this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
      //Adds an Event when the serial port receives data
                           
            }
            else
            {
                serialPort1.Close();
            //Close the Serial Port
                button1.Text = "Connect";    //Change the Button to Connect
            }


We have to add a few functions, the first will close the port if we close the application. The second tells the program what to do if data is received and the third is what it does. So Just below the final "}" of "button1_Click"
add the following:

//CLOSE PORT ON EXIT
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
            }
        }


//SERIAL DATA RECEIVED EVENT
        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
   //serialPort1 runs in a different thread, to call a function in the main code Invoke must be used
            this.Invoke(new EventHandler(serialReceived));  //Calls the below function
        }
        private void serialReceived(object sender, EventArgs e)
        {
 
                double coinsValue = Convert.ToDouble(textBox1.Text);  //converts the text to a number
                coinsValue = coinsValue + 0.05;          //Add 0.05 to that number
                textBox1.Text = Convert.ToString(coinsValue);     //Converts it back to text and puts it back in the textbox          
        }

Now, Scroll up and you'll see some "using" lines, add "using System.IO.Ports;" as we'll be using Serial port functions.

The Basic Program is finished, On the Arduino side:
replace...
    Serial.print("Credit: £");
    Serial.println(coinsValue);

with...
  Serial.print(0);  //Sends 1 piece of data over the Serial, the windows program add's 0.05 for every piece (println would send 3)

Upload, Run the windows Application, Click "Connect" and your away!


Step 6: CONGRATULATIONS

You can now activate your projects by receiving the right amount of money!

Good Luck & when your a Millionaire please send me some!

Hack It! Contest

Participated in the
Hack It! Contest

Hurricane Lasers Contest

Participated in the
Hurricane Lasers Contest

1 Person Made This Project!

Recommendations

  • Instrument Contest

    Instrument Contest
  • Make it Glow Contest

    Make it Glow Contest
  • STEM Contest

    STEM Contest

52 Discussions

0
None
ptavaressilva

3 months ago

Great code @Skipped, thanks! Love the fact that you commented so well and that it worked practically out of the box.

At first the behaviour was erratic, but once I added:
pinMode(2, INPUT_PULLUP);
to setup(), to turn on the pull-up of D2, it worked perfectly.

When you turn on/off the coin acceptor there is noise on the COIN line, so you may need to wait and reset credit after powering up the Arduino, to avoid generating credit due to race conditions (especially if you use different power supplies for the Arduino and the acceptor).

I'm using it on a vending machine I'm making. Will share on releasetheinnergeek.com when done.

1 reply
0
None
Hodgeypodgeptavaressilva

Reply 2 months ago

See my comment about removing noise, it may help you with the startup noise. I don't have any with the solution.

0
None
Hodgeypodge

Tip 2 months ago

I also had issues with noise, like many others, even while using the internal pull-up.
Static
electricity, touching the cables or tapping the transformer causes
pulses to be read. But the main issue was on average one in every 10
coins would have a pulse too many.

A solution I've found is to modify the ISR coinInserted() slightly by adding an if statement.

void coinInserted() {

if(digitalRead(2)== LOW) {
coinsValue = coinsValue + 0.05;
coinsChange = 1;
}}

This resolves all the false reads that I get, including on startup.

(Note
my coin acceptor (CH926) connects to an internally pulled up pin and
pulses down to ground so I have my attachInterrupt at "Falling" and the
idle state of the COIN cable is set to Normally Open (NO). You need to
adjust the code if your acceptor works differently, and it may be less
effective I haven't tested it.)

Solution stolen from this fantastic guide http://blog.deconinck.info/post/2017/02/25/CH923/CH926/CH928-coin-acceptor-features-and-caveats
0
None
Mistablik

2 years ago

I ran into a pretty big problem with static electricity in my application. Sometimes you could shock the front plate and it would count for a pulse or two, giving you false money. I modified the code slightly. You'll also need to set each coin to pulse one more time than normal. For instance, make nickles pulse 2 times instead of one. Then use this code:

const int coinInt = 0;

//Attach coinInt to Interrupt Pin 0 (Digital Pin 2). Pin 3 = Interrpt Pin 1.

int oldMillis = 0; //set first old time to 0

volatile float coinsValue = 0.00;

//Set the coinsValue to a Volatile float

//Volatile as this variable changes any time the Interrupt is triggered

int coinsChange = 0;

//A Coin has been inserted flag

int currentMillis = 0; //define currentMillis

void setup()

{

Serial.begin(9600);

//Start Serial Communication

attachInterrupt(coinInt, coinInserted, RISING);

//If coinInt goes HIGH (a Pulse), call the coinInserted function

//An attachInterrupt will always trigger, even if your using delays

}

void coinInserted()

//The function that is called every time it recieves a pulse

{

//As we set the Pulse to represent 5p or 5c we add this to the coinsValue

coinsChange = 1;

unsigned long currentMillis = millis(); //check current time

int difference = currentMillis-oldMillis; //find difference between last pulse time //and current pulse time

//Serial.print("Millis: ");

//Serial.println(difference);

oldMillis = currentMillis; //set old pulse time

if(difference < 152 && difference >148){

//unless the pulse time was in between the numbers above, it won't count for //money

coinsValue = coinsValue +0.05;

coinsChange = 1;

}

//Flag that there has been a coin inserted

}

void loop()

{

if (coinsChange == 1){

Serial.print("Money: $");

Serial.println(coinsValue);

coinsChange = 0;

}

}

1 reply
0
None
tanjamayaMistablik

Reply 2 years ago

Ok. now I get it... It works great... Thanks... In arduino code I change

this line

volatile float coinsValue = 0.00

whith line

volatile int coinsValue = 0

also this line

if(difference < 152 && difference >148)

with this

if(difference < 200 && difference >100){

and this line

coinsValue = coinsValue +0.05;

whit this line

coinsValue = coinsValue +10;

In coinAcceptor Settings I chandge the pulses...

before 10denars was 1 pulse, after 10 denars is 2 pulses

also before 50denars was 5 pulses, after 50 denars is 6 pulses

and now it works great.

Thanks a lot you saved me :)

0
None
HifdzulH

2 years ago

Is anyone know the source code of charging mobile with coin sensor?

0
None
JulioS47

3 years ago

I made it. It does not work as published. I feel there may be something blocking the main thread in the application. The arduino monitor reads the bits correctly. If I send 5 pulses it sends five zeros. But my VS application almost never produces the right ammount. I would appreciate any help.
I´m using VS Profesional 2013 and Net Framewrk 4.5

0
None
Robbiezxc

3 years ago

hi thanks for this it just what i was looking for but does any one know now i would go about adding to the code say if i put in £3 it would do something and then it i put in £4 it would do something else

0
None
TuxedoNinja

3 years ago

hey anyone know how to reset the coins value my project is supposed to start after fifty cents so I used that code and it works the first time after I upload the code but after that it breaks any help is great thanks!

0
None
ajrulradhi

3 years ago

Hello, i'm in process to make project similar like vending machine. But, i dont know what to write in code if we press A button, then price should be like 5$ . Can you help me?

0
None
종찬윤

4 years ago on Introduction

How can I use this coin adapter with AVR Program(Atmega128)??

Can you help me?

I don't know how to make the AVR souce....

Please.. help me...

I need just simple souce..

0
None
lezi007

4 years ago on Introduction

How can the arduino (your program) tells the difference if a 10p/c(dime) coin or 25p/c(quarter) coin is inserted from two 5p/c coins (nickel)? The way I understand is that this code:
void coinInserted()
//The function that is called every time it recieves a pulse
{
coinsValue = coinsValue + 0.05;
//As we set the Pulse to represent 5p or 5c we add this to the coinsValue
coinsChange = 1;
//Flag that there has been a coin inserted
}
will only add 0.05 to the value for each pulse.
How can I change the program so that It counts how many nickels (5p/c), dimes (10p/c), quarters (25p/c) etc... were inserted? I want just don't want to know the total value but also the number of coins type inserted.
Thanks

0
None
Sebuk

7 years ago on Introduction

Inspired by this set of instructions I have embarked on a project using the CH-926. After successfully getting everything working - Today, when I turned it on, instead of the usual beeps it is displaying E2 and no combination of button pressing makes a difference. Can the units be reset?

Thanks.

2 replies
0
None
fbccnt3Sebuk

Reply 4 years ago on Introduction

@Sebuk Were you able to solve this E2 problem, by any chance? I encountered the same error today and I'm completely at a loss :(

0
None
frollardSebuk

Reply 7 years ago on Introduction

Looking online the only time you should see 'e' is during training...

0
None
crares

5 years ago on Introduction

Hey, can I program this coin acceptor with an Arduino Leonardo?

0
None
pjac82

6 years ago on Introduction

How can I store the credit to EEPROM???! in case of powering off and on? SO it starts the count from the memory? I am trying but failing.