Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a project that has 6 IR led's and detectors.

The project needs to detect when any of the 6 beams get broken, and exactly which one got broken. I would like to be able to use only one input pin to detect if any of these have been broken.

What kind of hardware setup would I need to achieve this?

Some more notes: Currently a high is read when the beam is interrupted. The actual breakage in the IR beam is extremely short. (A falling coin) My preferred method would be to use an interrupt if this is even possible.

share|improve this question
If you're doing this because you're short of pins, have you looked at how you're driving the emitters? Charlieplexing them may allow you to reduce the number of pins needed for emitters, freeing up more to act as receivers. – Nick Johnson Nov 15 '12 at 14:53
Yes, I am short on pins, but unfortunately not due to the emitters. The emitters are not connected to any pins. Only power. I am short on pins because of a graphical display that is connected to the ATMega chip, plus the need for 2 buttons. – Michael Frey Nov 15 '12 at 17:36

Edit: Changed answer after clarification by OP about simultaneous presses
If multiple detectors, up to 6, need to be sensed for possible simultaneous interruptions, the solution described in this posting on the Arduino forums is usable. Substitute the "buttons" referred to in the post, with your high-when-interrupted lines from the 6 sensors. Each detector line will connect to the resistor specified in that post, and the ADC values received will indicate what combination of detectors is interrupted:

btn 1          837-838    220
btn 2          737-738    390
btn 3          610-611    680
btn 4          318-319    2.2k
btn 5          178-179    4.7k
btn 6          91-92      10k
btn 1 + btn 2  896-897      
btn 1 + btn 3  877-878      
btn 1 + btn 4  851-852      
btn 1 + btn 5  844-845      
btn 1 + btn 6  840-841      
btn 2 + btn 3  821-822      
btn 2 + btn 4  769-770      
btn 2 + btn 5  753-754      
btn 2 + btn 6  745-746      
btn 3 + btn 4  674-675      
btn 3 + btn 5  643-644      
btn 3 + btn 6  627      
btn 4 + btn 5  408-409      
btn 4 + btn 6  363-364      
btn 5 + btn 6  243

If your MCU of choice has a comparator with edge triggering on analog inputs, generating an interrupt each time the voltage rises over 0.5 Volt or so will work.

If you need more that 2 simultaneous interruptions detected, an alternative would be to use a key scanning IC that provides serial output, like MAX6955 or TCA8418, then read said IC's output using an I2C read on a single input line.

share|improve this answer
or use this i.stack.imgur.com/qhOWB.jpg – Tony Stewart Nov 16 '12 at 3:24
Thank you for this detailed answer. Unfortunately several can be triggered at the same time in my project. – Michael Frey Nov 16 '12 at 8:28

Do you have a system clock? How about using a shift register? Hook up the six IR inputs to the parallel side of the shift register and the serial to your microcontroller. The disadvantage here, since you only have one pin, is you'll need to continually read in the parallel inputs at a sufficient frequency and check for a one in the serial byte. The one obviously indicates the sensor that fired. This also works if more than one beam is broken at a time. I think you can diode connect each of the parallel inputs to the parallel load clock, but I'm not positive this will work. I think an extensive look through some data sheets would tell if this were worth testing or not. You can always fall back on the excellent analog solution provided.

share|improve this answer

The hardware setup depends what your software can handle.

You can have 6 detectors with logic level output to preset a counter and generate a number of pulses OR a pulse width that corresponds to each coin value. It could be a polled input but preferably a interrupt input that can be measured for pulse count or width.

Which do you prefer?

But more important, what are your space and budget contraints and have you considered anti-hack security protection and patent copyrights from "said light sensor and said coin in said coinbox"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.