Hello Everyone, i am currently working on a project where i am trying to make a coin sorting machine.
The principle, is that a coin is falling down into a container, where it flyes by an optocoupler, of this kind LTH 301-32. I have manages to get some code running which works fine as it was supposed to. The next step is to only get readings inside the Serial monitor when a change happens on the pin which the optocoupler is connected to, so my Serial monitor doesn’t get spammed with every single reading from the optocoupler, and i dont know how to make it happen like i want to. :((
You can see my code here:
Okay, so when i run my code, the optocoupler gives me a lot of analog reading in my Serial monitor, and i get to see the total saldo, which is 0.00.
Then when i block off the light from the LED in the optocoupler, it is this one LTH 301-32, i see that the analog readings change to a lower value. Lets say if i hold this item in front of the LED in two seconds i would have a ton of analog reading.
In my code i have an if statement that says, i a value gets below 900, it will add 20 (dollars) to my saldo. But because of the many readings it would have within the two seconds that i block the LED, i would have over 2k dollars. It is this part of the programming where i need help.
I want to just add 20 dollars to the saldo, until the LED gets blocked again, so it is not the time of the blokade that decides how many dollars is added to the saldo, but the amount of times that the LED gets blocked by a coin.
Hopefully this explains my problem better
Optokobler_kode.ino (709 Bytes)