4
\$\begingroup\$

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.:)

\$\endgroup\$
  • \$\begingroup\$ you can i dont know what you want to do, probably i would use interrupt pin and in that update a volatile variable. no delays \$\endgroup\$ – Hasan alattar Feb 21 at 14:26
  • \$\begingroup\$ What is safe to try is this: take a 10 kohm resistor and connect it between the output of the LM311 (pin 7) and an input of the Arduino. Also the grounds need to be common so connect the - of the battery to GND of Arduino. Then you might be able to detect pulses on the Arduino input. I suggested using a 10 k resistor because that will limit the current and prevent damage in case there are voltage differences between Arduino and this circuit. The delay you can do in software, when a pulse is detected, just wait like 0.1 second and then test if there still is a signal present. \$\endgroup\$ – Bimpelrekkie Feb 21 at 14:50
  • \$\begingroup\$ @Bimpelrekkie Afaik LM311 is open collector output. (In that configuration with pin1 to ground). \$\endgroup\$ – Unimportant Feb 21 at 14:55
  • 2
    \$\begingroup\$ OK, I missed that, then OP needs to add a resistor between the LM311 output and the supply (+ of battery), make it a 4.7 kohm resistor. Who will draw a nice schematic in an answer to earn some points ;-) ? \$\endgroup\$ – Bimpelrekkie Feb 21 at 15:03
  • 3
    \$\begingroup\$ You can enable pin pullup in software and simply connect the LM311 output to the input pin (removing buzzer, R3, LED). \$\endgroup\$ – Spehro Pefhany Feb 21 at 15:07
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Also, a very good idea would be a 100k to 1M resistor between pins 7 and 2 to provide a snap-action (hysteresis) for the transition from on to off and vice versa. \$\endgroup\$ – WhatRoughBeast Feb 21 at 20:04
0
\$\begingroup\$

Caution - the circuit is powered by 6 V, and an Arduino runs on either 3.3 V or 5 V. Consider adding a diode to drop the circuit output voltage from 6 V to 5.3 V (a safe enough value):

10K resistor from pin 7 to 6 V.

Diode (1N4004, 1N4148, etc.) from pin 7 to uC input. Anode to pin 7.

100K resistor from uC input to GND.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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