Coin acceptor with Raspberry Pi

These instructions are based on the Adafruit 4 type coin accepter

Setup and training instructions

Wiring to the Raspberry Pi

Sample code

import RPi.GPIO as GPIO
import time

credit = 0
print(f"You have {credit/100} CHF in credit")

def pulse_received(pin):
    global credit
    print("Pulse received")
    credit += 50
    print(f"You have {credit/100} CHF in credit")

counter_pin = 27 # or whatever...
GPIO.setmode( GPIO.BCM )
GPIO.setup( counter_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(counter_pin, GPIO.RISING)
GPIO.add_event_callback(counter_pin, pulse_received)

Credit: Code and wiring instructions derived from