Hi I`m making a change machine to change coins into 10 pence coins. So £1 in, 10x10p (pence) out, 50p in 5x10p out.
There are two devices: 1. A coin acceptor - it detects which coin has been inserted and pulses a set number of pulses on a single line to let the ardunio know what can has entered. e.g £1 in = 1 pulse, 2p in = 2pulses, 5p in = 3 pulses. 2. A coin hopper - power it up and it starts ejecting 10pence coins - each coin it ejects it goes Low so the arduinos job to count the coints ejected and turn it off.
So to clarify: arduino sits and waits for a pulse by a coin inserted --> it then waits and sees how many pulses came and identifies what coin it was --> it turns on a relay which turns on the hopper --> it senses a pulse each coin ejected and turns off the hopper when the correct number of coins has been sent out.
Problem: When a coin is inserted, it senses that the correct coin has gone in but then randomly senses that other coins have been inserted! So you put 10p in and it sends out 1 coin but then immediately says £1 was inserted as well and spits 10 more out.
Troubleshooting so far - I
ve commented out lines and it is definitely an issue with the despense() function. Without it, it recognises the coins just fine. Now I cant see a problem with this function since the same function works in similar code I`ve written for the hopper alone.
using a Serial.write I can see that for some reason, during the dispence function coinPulseCount is increasing - as though a coin has been inserted!! I`ve tried code to hold coinPulseCount low when dispensing but still an issue!
Can anyone see a problem with the code? Could this be a hardware issue - I don`t see why coinPulseCount is counting when nothing is coming through on the coin selector line - no coins are inserted but for some reason the "dispence()" function is making it change!!
Any help would be massively appreciated. I`m totally lost as to why this is happening.