For something I’m building I need have the Arduino detect a coin being dropped trough a slot, for this I have built an IR detector, it comprises of an IR LED, IR Photo-Diode, Op-amp and ATtiny85 micro-controller.

The circuit works by having the IR LED flood the Photo-diode so that when an object passes between them the Photo-diode stops letting current through, this is fed into the op-amp to provide a consistent output for the ATtiny85 micro-controller to detect the change in signal to then flash a couple of LED’s and provide a signal to an Arduino.

Here is a program that flashes a couple of LED’s and makes output pin 4 high:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
/* * coin detector for attiny85 micro-controller * detects a change pulse on pin0, makes a couple of LED's on pins 1 and 2 * flash and makes pin3 go high for 120ms. * * v1.0, October 2013 * * pin change interrupt code taken from; http://www.insidegadgets.com/ */ #include const int ledA = 1; const int ledB = 2; const int pinIn = 0; const int pinOut = 4; volatile int state = HIGH; volatile int lastState = state; #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif #ifndef sbi #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif #define PTIME 30 void pulse(int times) { int k = times - 2; // increase x (times - x) for a longer pulse: p = (PTIME * 2) * x // (30*2)*2 = 120ms // (30*2)*3 = 180ms digitalWrite(pinOut, HIGH); do { digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); delay(PTIME); digitalWrite(ledA, LOW); digitalWrite(ledB, LOW); delay(PTIME); if (times < k) { digitalWrite(pinOut, LOW); } } while (times--); } void setup(){ pinMode(ledA, OUTPUT); pinMode(ledB, OUTPUT); pinMode(pinOut, OUTPUT); pinMode(pinIn,INPUT); sbi(GIMSK,PCIE); // Turn on Pin Change interrupt sbi(PCMSK,PCINT0); // Which pins are affected by the interrupt digitalWrite(pinOut, LOW); delay(1000); } void loop() { if (state != lastState) { pulse(20); lastState = state; } digitalWrite(ledA, HIGH); digitalWrite(ledB, HIGH); system_sleep(); //delay(5); } // From http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/ void system_sleep() { cbi(ADCSRA,ADEN); // Switch Analog to Digital converter OFF set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode sleep_mode(); // System sleeps here sbi(ADCSRA,ADEN); // Switch Analog to Digital converter ON state = !state; } ISR(PCINT0_vect) { } |
Sources:
will it be able to determine the type of the coin means whether its 1 rupee ,2 rupee or 5 rupee coin..
Not this one. You will probably need to measure the diameter and possibly the thickness of the coin.