Building a light gate

A light gate a simply a device that can detect movement that occurs between a sender component and a receiver, usually the sender sends infra-red. You may think that they could be used as an intruder detector, and indeed you could use them for this purpose, but there are more elegant solutions to detecting intruders etc. A light gate is more usually used in science experiments (often in schools) to help measures speed, acceleration or momentum. In this article we will look at building the light gate and measuring the speed of a moving object.

How a Light-gate works

An Infra-red LED emits a beam (the more narrow the beam the better). A Infra-red receiver, basically a device sensitive to infra-red, is put into the pat of the beam. A computer monitors the receiver to check if it is receiving a infra-red signal. If so then we know there is nothing in front of the beam, of not then something must be blocking the signal.

That’s basically it, that’s all there is to a light-gate. It’s then up to you to come up with some uses for it.

A video also supports this article, see below or read on

The sender and receiver
The receiver is a little more complicated than just being able to detect infra-red. It is sensitive to the signal being pulsed at a certain frequency (how many times the infra red beam goes on and off per second). The one we will use is sensitive to IR of a frequency of 36Khz (36000 on/offs per second).  The sender is a very simple (and cheap) LED that emits IR light, all we need to do to get it to work with the receiver is to pulse it at 36Khz. Luckily this is a simple task for virtually all micro-controllers that you commonly come across.

Building the Gate – Parts List

MCU : 1 x Arduino Nano (other MCU’s could be used but you may need to adjust the pins used/code to suit your choice).

IR Receiver : 1 x TSOP38236 (or any TSOP382xx series should be fine, probably even TSOP384xx series – but not tested).  More on this later.

IR Sender : Any Infra-Red LED at around 940nm (940nm is the particular wavelength of infra red we are using, but anything around this should be OK).

Housings
I housed the sender and receiver in large board marker lids to restrict stray infra-red getting out at angles. But this may not be that necessary as the beam did seam fairly narrow on camera.

Notes on the IR Receiver
Try not to be tempted to buy other types of IR receiver, they may not work in this circuit. This is because a lot of IR Receivers are designed to go intoTV’s etc. and they expect a short burst of IR Data from a remote and after a short amount of time (i.e. about half a second, maybe less) they stop detecting IR until it goes off and then on again. The result of this is you will initially detect the beam but then it will look like the beam has been cut and you will have to move your sender to point away from the receiver and then back again for it to see the beam again. This is great for TV remote control data etc. but not for us. There are some ways around it but it’s a hassle and makes our design less elegant. If you look at the datasheet for the TSOP38xxx series receivers we are using you would see that they are labelled as suitable for “long burst” data. Basically meaning they will respond to long duration of IR and not go into an effective “shut-down”.

The circuit

Connection Table

ConnectionConnected to
IR Sender LED NegativeNano Gnd
IR Sender LED PositiveNano D3 (PWM pin)
IR Receiver NegativeNano Gnd
IR Receiver PositiveNano +5v (VCC)
IR Receiver SignalNano D2

Looking at the circuit above you can see that we have not included a resistor in series with the IR LED. A resistor is usually essential for any LED to stop it drawing too much current which may destroy the LED and damage other circuitry. The reason we can do away with it here is because of the way the LED is pulsed on and off at 36Khz. Looking at the signal on a oscilloscope below we can see what signal the Arduino is sending to the IR LED. You can see that the LED is only switched on for 1/3 of the total time of one complete wave

This means that the average power/current flowing is reduced considerably removing the need for a resistor.

Why must you connect the LED to a PWM pin?
The receivers you buy (TSOP382xx, TSOP384xx etc.) are sensitive to the IR being pulsed at an exact frequency, for our design we are using a TSOP38236, the last two digits show the frequency of the device. Therefore the IR we send must be pulsed at this (or very near to) this frequency. The most accurate way to do this is using the in built hardware of many MCU’s  that is designed for this purpose. We just basically tell it what frequency we want on a certain pin and let it do the rest, we no longer have to worry about it with our code. For the Nano pin D3 has the hardware internally connected to it to do PWM (Pulse Width Modulation), so we use that pin.

If you use a different TSOP382xx
If you cannot get hold of the TSOP38236 used in this article then as stated you can use many other variants, however in the code you must ensure the IR LED pulses at the required frequency for this detector. It’s a simple change but if you don’t do it then your circuit will not work.

Warnings on the supply of TSOP38xxx (and possibly any detector)
I originally ordered TSOP38238 detectors and set my LED to emit IR at 38Khz, but it would not work. So a hooked up the scope and checked the frequency being output by the Arduino which was 38Khz. Then for whatever reason (inspiration maybe!) I wondered if I’d been supplied a different TSOP38xxx chip. It was impossible to see markings on the actual device and the delivery note stated TSOP38238. So I changed the code to 36Khz and right away it all started working, so I’d actually been sent TSOP38236. If you have any issues with your circuit it may be worth changing the LED frequency to see if that helps.

Test Code
To use the test code below you will need to ensure you have the IRremote library installed. You can do this from within the Arduino IDE by simply clicking on “Sketch->Include Library->Manage Libraries”. In the search box type “IRRemote” and the library will appear. Click install and your done! Load up the code below onto your Nano (or whatever board you have used) Remembering to change line 12  to whatever frequency you are using if you are not using a 36Khz sensitive receiver.

If all goes well you will note that the on board LED connected to pin 13 on the Nano lights up when there is no IR signal and goes out when there is, it’s inverse logic, off when there’s an IR beam, on when there isn’t.

 Troubleshooting
If you do experience any issues you should try these things.

  1. Check all wiring is correct
  2. Check that the IR LED is outputting IR by putting a camera or mobile phone camera in front of it. You should see a purple light coming out. If you don’t confirm your camera detects IR by testing with a known working remote control.
  3. Point a Remote control at the receiver and press a button, does it detect it.

What next?
In the next article in this series we’ll look at using the light gate to measure the speed of a small moving object