Electronic – arduino – Connect LM311 pin 7 to input pin Arduino

arduino

I'm brand new to the world of electronics and not very talented, so have mercy.

This circuit lights up a LED when an IR beam is broken:
enter image description here

I was wondering if I could connect the input pin of an Arduino (or Adruino programmed AVR microcontroller) instead, to count +1 if the beam is broken by a person passing. Possibly with a delay() function of sorts, to keep it from counting up more than once.

EDIT: Apologies for not being accurate on power supply. Unlike this scheme indicates, I used a 9V battery and a 7805 voltage regulator to get 5V on this circuit. Meaning, I believe it would pair well with an ATtiny, programmed via Arduino, that can take 5v as well.

The end goal, to complete the story, is to do this with two IR beams, physically a bit apart, their receivers connected to two pins of an AVR microcontroller. The pins register the time stamp of breaking the beam. By comparing the two, we can determine the direction. Going into the room counts +1, going out – 1. Finally the AVR checks if the sum is larger than 0. If yes, someone is in the room and it lights a red LED.

I understand there are many issues that need to be resolved in the software to make the counting accurate. That's for a later day or, preferably, someone else.:)

Best Answer

The LM311 in your schematic is configured as a open collector output. It will sink current but not source it. This actually makes it very easy to communicate with a system that runs on a different voltage.

schematic

simulate this circuit – Schematic created using CircuitLab

You can omit R1 if you enable the pull-up resistor on the input in software. Both circuits could probably be ran off a single 5V power supply if this suits your needs better.

I'd recommend adding a 100nF decoupling capacitor on the LM311's power pins, as close as possible to the IC. And perhaps another 100nF capacitor on the TSOP1738's power pins as it is actually a complex IC, not a simple detector.