
A coin counter on ESP 8266
Now this code will work on a diy coin sorter that looks something like this
I still didn't build a case yet as the biggest challenge seems to be not code but mechanical! (getting the right coin to fall through the right slot

Schematics: LCD 1602 to be connected to pins 4,5 (i.e D1 and D2)
Other pins to be connected to ground, with the falling coin through the slit closing the circuit (I've pulled all pins high)
Customised for Australian coins, but you can change to your own
d3 = 5¢
d4 = 10¢
d5 = 20¢
d6 = 50¢
d7 = $1
tx = $2
rx = Reset button to zero all values and restart count a new
Code: [Local Link Removed for Guests]
'Initialise LCD
I2C.SETUP 4,5
LCD.INIT 39, 16,2
LCD.CLS
'Message
lcd.print 1,1, "Coin counter "
lcd.print 1,2, "@2024 Basicboy"
pause 3000
'Initialise Counter pins
D0=16:D1=5:D2=4:D3=0:D4=2:D5=14:D6=12:D7=13:D8=15:D9=3:Tx=1:rx=3
dim coin(6) =d3,d4, d5,d6,d7,tx,rx
dim lcoin(6) = 1,1,1,1,1,1,1
dim vcoin(5) = 0,0,0,0,0,0
for y = 0 to 6
PIN.MODE coin(y), INPUT, PULLUP
next y
'Initialise lcd update timer and Input timer
timer0 500, Update_lcd
timer1 10, scan_input
wait
update_lcd:
a$ = "5¢ = " + str$(vcoin(0))+ ", 10¢ = " + str$(vcoin(1))+ ", 20¢ = " + str$(vcoin(2))+ ", 50¢ = " + str$(vcoin(3))+ ", $1 = " + str$(vcoin(4))+ ", $2 = " + str$(vcoin(5) )
a$ = " "+a$+" "
z =z +1
if z=(len(a$) -16) then z = 1
LCD.PRINT 1, 1, mid$(a$,z,16)
total = (0.05* vcoin(0))+(0.1*vcoin(1))+(0.2*vcoin(2)) + (0.5*vcoin(3))+vcoin(4)+(2*vcoin(5))
lcd.print 1,2, " "
lcd.prinT 1,2, "Total = " + str$(total)
return
scan_input:
'scans for coins
for y = 0 to 5
if pin(coin(y)) = 0 and lcoin(y) = 1 then lcoin(y) = 0: vcoin(y) = vcoin(y)+1
lcoin(y) = pin(coin(y))
next y
'scans for reset button
if pin(coin(6)) = 0 and lcoin(6) = 1 then lcoin(6) = 0: gosub clear_all
return
clear_all:
for y = 0 to 5
vcoin(y) = 0
next
return