I am a beginner in field of circuits, so excuse me for my amateur questions. Let me explain my task:

I have to build a low cost proximity sensor for a sense and spray device. I have read various posts on IR proximity sensors in this site. But I am still not clear in understanding the concepts. As I am a beginner, I get stuck at some silly amateur doubts.

So, this is what I am planning to do:

Build a IR sensor transmitter by pulsing the signal to 56 kHz using the oscillator from PIC MCU and then build the receiver part by using IR photodiode, band pass filter that allows only signals with 56khz carrier frequency, amplifier, op amp as a comparator and then the output is given to the microcontroller.

My objective:

When someone walks by the device, it should detect the movement and spray the liquid. after that it should go to standby mode for 15 min. It should not spray even if anyone passes at this time. After 15 min, it should come back to running mode.

This is the link for a similar type of product in the market.

My hurdles so far which I haven't crossed yet:

  1. To reduce the effect of ambient light and other IR sources, I decided to pulse the signal. But I couldn't get the right circuit in the receiver end to demodulate and amplify the signal. Because it has to be sensitive up to 50- 75 cms (even more would be better). I can use a tsop series photodiode which comes with bpf and amplifier. But I want to build the circuit with as simple of components as possible.

  2. When a black body is in front of sensor it absorbs all the IR radiation and does not reflect back any. I don't know how to solve this problem.

I have to design a circuit and then write a program for a PIC18F4550 microcontroller. But I think I can find a solution for the program. But the circuit diagram seems to be a bit difficult for me.

Please suggest a circuit diagram for the receiver part with the band pass filter that allows only 56khz signals, amplifier and opamp. Any kind of help and suggestions are welcome. Please don't hesitate to explain in a simple way.

  • 1
    \$\begingroup\$ Just a guess, as I haven't done this myself, but if you are pulsing the transmitter with the PIC, you could probably avoid using a hardware bandpass filter by using the PIC's knowledge of when the transmitter is off or on to sample the recieved signal at appropriate times to determine TX on vs TX off signal levels. \$\endgroup\$ Commented May 9, 2014 at 15:54
  • \$\begingroup\$ At first I thought you were trying to spray paint, and this would be some sort of anti-theft/anti-break-in device spraying paint on offenders. Then I saw your similar product link. \$\endgroup\$
    – Marsh
    Commented May 9, 2014 at 17:20
  • \$\begingroup\$ "2.When a black body is in front of sensor it absorbs all the IR radiation and does not reflect back any. I don't know how to solve this problem." And you don't need to. Totally non-reflective surfaces are hard to come by, and "perfect black-body" clothing is not to be found in most stores. \$\endgroup\$ Commented May 9, 2014 at 18:24
  • \$\begingroup\$ Just a suggestion about nomenclature - you can call your "standby mode" and "running mode" with "armed" and "disarmed" terms. \$\endgroup\$
    – Kamil
    Commented May 9, 2014 at 20:28
  • \$\begingroup\$ ok.. I have tested the basic proximity sensor circuit which works just for 5- 10 cms. i need it to operate at the range of 1- 2 feet. Now, the next step would be to pulse the signal at 56 khz to increase the range and efficiency of led. could anyone please guide me how to do it with Pic mcu. Please tell me what to know and what to study to that beacause I would like to learn from basics and not just do the project. Any kind of help would be greatly appreciated. you could also mail me at [email protected] \$\endgroup\$
    – tony
    Commented May 13, 2014 at 11:30

3 Answers 3


Depending on what type of human proximity you are trying to detect, here are a couple of options that might work well:

Method 1: If you are trying to detect motion, the cheapest way is to use a photodiode or CDS cell connected with a pulldown resistor and read by one of your PIC's ADC pins. You will need to write an algorithm that senses rapidly changing values on the ADC pin, which will indicate some sort of motion. If you want a narrow detection area, you can use a tube over the photodiode as a blinder.

Method 2: If you are trying yo detect proximity by using an IR source and measuring its reflection from an object within proximity, you already have the correct setup. However, you will need to check the datasheet of your IR receiver module for its carrier frequency. I think 30Khz to 40Khz is the most common. You can use the hardware PWM pin on your PIC to constantly produce this carrier frequency on one of the IR LED pins. Connect the other pin of the IR LED to an IO pin on your PIC. Now you can send pulses or even serial data to that pin and it will automatically have the carrier frequency on it. With IR proximity, however, you will always run into the trouble of not being able to detect non-reflective dark objects. In which case, see method 3.

Method 3: Use an ultrasonic transducer for proximity detection. Typically two are used. Use one for pinging a pulse (at the resonant frequency) and use the other for detection. You will most likely need an op-amp or comparator circuit to amplify the output of the receiving transducer for greater ranges. The benefit of this method is being able to calculate exact distance to your object based on the flight time of the "ping" and its return. Flight time will be approximately 1/2 the speed of sound since the "ping" has to travel to the source (1) and back (2).

  • \$\begingroup\$ hey Jason, thanks for your reply. I have started with method 2 for now. I have tried pwm with pic mcu and pulsed the Ir led at 56 khz. I gave the o/p of mcu to a transistor which drives the Ir led on. I have used a tsop 4856khz for detecting the pulses. the circuit is working but only for a very short range of about 10 cms. I want to acheive a range of about 1.5 meters. I have tried with high range ir led's, but couldnt improve the range. I have no idea how to do this and i dont want to give up yet. could you please suggest me some options to increase the range \$\endgroup\$
    – tony
    Commented Jun 5, 2014 at 9:01
  • \$\begingroup\$ Hey Tony, a couple of things to help your detection range. Make sure you are using a suitable transistor for driving your IR LED. I recommend a MOSFET so you can get enough current through your IR LED. Make sure you are pushing enough current through your IR LED since these can take quite a bit more current than the average LED indicator. If that's still not enough, add more IR LED's in parallel. IR Receiver Modules also self-adjusts its sensitivity inversely to the amount of ambient light. It will be most sensitive in a dark environment and less sensitive in bright surroundings. \$\endgroup\$
    – Jason G.
    Commented Jun 7, 2014 at 1:04
  • \$\begingroup\$ If it is running in bright conditions such as outside in the sunlight, you may have to use a binder such as a short matte black tube to block any unwanted ambient light from hitting the IR Receiver Module and causing a decrease in its sensitivity. \$\endgroup\$
    – Jason G.
    Commented Jun 7, 2014 at 1:05
  • \$\begingroup\$ Hey Jason, I have tried with a npn transistor, but found no improvement. But as you mentioned an Idea on using just a photodiode to detect motion, I have found a product which i broke down and looks like this tronixstuff.com/tag/glade It looks like a normal photodiode to me but i dont know how to use a photodiode to detect motion. could you explain me in detail how can i do that \$\endgroup\$
    – tony
    Commented Jun 11, 2014 at 9:04
  • \$\begingroup\$ I'll try to upload a basic schematic for using MOSFETs and driving your IR LED's for more output. What supply voltage are you using to power your circuit? The photodiode method is a relatively simple and cheap concept but also slightly tricky to get right. This method will also work with a photo-resistor (CDS cell). The way it detects motion is by measuring the changes in light level against a time base. If the circuit detects a drastic change in light level, it will trigger. However slow light changes, such as from dusk to dawn, will not cause the system to trigger. \$\endgroup\$
    – Jason G.
    Commented Jun 17, 2014 at 19:19

My advice to you is to go for an IR transmitter reciever circuit that is readily available in the market. Since you are a starter first try it out in the simple way. I would suggest Sharp-GP2Y0A21YK IR sensor. http://www.sharpsma.com/webfm_send/1208 The above link provides a pdf stating its information. I have used it successfully for my project of a blind guidence system using MCU 8051.


Use synchronous detection.

  • Turn IR transmit LED on
  • Digitize input
  • Add to sum
  • Turn IR transmit LED off
  • Digitize input
  • Subtract from sum

Do this 1000 times and if the IR light is coming back the sum will climb.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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