Tag Archives: Infrared

HC-SR501 PIR motion sensor interface with Arduino

What is PIR sensor?

A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors. HC-SR501 PIR sensors are commonly used in security alarms and automatic lighting applications. PIR sensors detect general movement, but do not give information on who or what moved. For that purpose, an active IR sensor is required. PIR sensors are commonly called simply “PIR”, or sometimes “PID”, for “passive infrared detector”. The term passive refers to the fact that PIR devices do not radiate energy for detection purposes. They work entirely by detecting infrared radiation (radiant heat) emitted by or reflected from objects.

PIR sensor parts

For a DC current, the PIR Sensor works from 3.3v to 5v DC and gives a TTL output which is directly given to a microcontroller or to relay through a transistor. The PIR sensor consists of a pyroelectric sensor and a Fresnel lens. This curved lens concentrates infrared radiation toward a detector’s sensor. The sensor output is inverted by the transistor. Collector of the transistor is connected to the input pin forms the latch circuit which is set when PIR output goes high to indicate the presence of a warm body. Output of the latch pin operates the relay driving circuit formed by transistors arranged in emitter follower mode.

How PIR sensor works?

HC-SR501 PIR sensor can detect changes in the amount of infrared radiation impinging upon it, which varies depending on the temperature and surface characteristics of the objects in front of the sensor. PIR Operation

When an object, such as a person, passes in front of the background, such as a wall, the temperature at that point in the sensor’s field of view will rise from room temperature to body temperature, and then back again. The sensor converts the resulting change in the incoming infrared radiation into a change in the output voltage, and this triggers the detection. Objects of similar temperature but different surface characteristics may also have a different infrared emission pattern, and thus moving them with respect to the background may trigger the detector as well.

PIR Module interface with Arduino

PIR Motion Arduino Interface

Compared to other sensors, this one is much easy to interface & use.

Arduino Code

You can download the above code from here.

Upload above code in your Arduino and check the motion detection output on Arduino LED on Pin 13 or serial monitor of Arduino IDE.

I hope you will learn to use PIR motion sensor by this tutorial & it will be helpful to add live object detection in your DIY stuff. In further of this tutorial, you can add some logical conditions in code to turn ON buzzer or send SMS/Email notification for human/animal detection; Notification to receive in phone, microcontroller, computer, cloud database i.e. Arduino based security system. In future such projects will be uploaded in #BeatYourBit website. If you like this tutorial, share it with your friends & any Arduino newbie you know. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Like/Follow @beatyourbit on FacebookTwitterInstagram & Telegram for latest updates.

Infrared transmitter & receiver interface with Arduino

IR, or infrared, communication is a common, inexpensive, and easy to use wireless communication technology. IR light is very similar to visible light, except that it has a slightly longer wavelength. This means infrared is undetectable to the human eye which means perfect for wireless communication. For example, when you hit a button on your TV remote, an IR LED repeatedly turns on and off, 38,000 time a second, to transmit information (like volume or channel control) to an IR photo sensor on your TV. IR receiving is done by TSOP382 IR photo sensor & IR transmitting is part of IR LED. This tutorial will help you to interface IR sensor with your Arduino or DIY Project.

IR Kit


IR LED is nothing but a normal LED transmitting infrared light with longer wavelength. TSOP382 is a device which combines an IR sensitive photocell, a 38 kHz bandpass filter, and automatic gain control. It operates on a variety of supply voltages including 3.3v and 5v. It de-modulates the received IR signal and gives you a nice clean square wave of off and on pulses at the voltage level of your power supply. This means it is ideal for feeding its output directly into the digital input pin of our Arduino. Last in the picture is IR receiver module with easy pinout for interface with any microcontroller.

TSOP module: It has an inbuilt control circuit for amplifying the coded pulses from the IR transmitter. A signal is generated when PIN photo-diode receives the signals. This input signal is received by an automatic gain control (AGC). For a range of inputs, the output is fed back to AGC in order to adjust the gain to a suitable level. The signal from AGC is passed to a band pass filter to filter undesired frequencies. After this, the signal goes to a demodulator and this demodulated output drives an npn transistor. The collector output of the transistor is obtained at pin 3 of TSOP module. Members of TSOP38xxx series are sensitive to different centre frequencies of the IR spectrum.

Career Frequency  Standard Applications (AGC2/AGC8) Very Noisy Environment (AGC4)
30 kHz TSOP38230 TSOP38430
33 kHz TSOP38233 TSOP32433
36 kHz TSOP38236 TSOP38436
38 kHz TSOP38238 TSOP38438
40 kHz TSOP38240 TSOP38440
56 kHz TSOP38256 TSOP38456

In TSOP1738xx series, last two digit indicates career frequency, ex: TSOP173838 = 38 kHz.

Specifications & Features


  • Forward current (IF) is 100mA (normal condition) and 300mA (max.)
  • 1.5A of surge forward current
  • 1.24v to 1.4v of forward voltage
  • Temperature for storage and operation varies from -40 to 100 ℃
  • Soldering Temperature should not exceed 260 ℃
  • Power Dissipation of 150mW at 25℃ (free air temperature) or below
  • Spectral bandwidth of 45nm
  • Viewing angle is 30 to 40 degree
  • Maximum wavelength is 940nm
  • RoHS certified

TSOP382 IR Receiver:

  • Very low supply current
  • Photo detector and pre-amplifier in one package
  • Internal filter for PCM frequency
  • Improved shielding against EMI
  • Supply voltage: 2.5 V to 5.5 V
  • Improved immunity against ambient light
  • Insensitive to supply voltage ripple and noise
  • Component in accordance to RoHS 2002/95/EC and WEEE 2002/96/EC

IR Receiver Connection With Arduino

As shown in figure, an IR receiver is connected with Arduino UNO. Here we will use an IR remote which is most commonly used for Arduino projects, in your project you can use any remote & can make your own remote as per application. In market you can get a kit which contains an IR Remote, IR Receiver, IR LED for you DIY purpose & jumper wires as shown in image.

Test Program For IR Remote

You can download above code from here.

Code explanation: Here we will use remote as shown in first image of tutorial which is easily available in market. You need IRremote library in this code which is available in library manager. IR receiver signal pin is connected to Pin 11 of Arduino. You need to define two variables; IRrecv irrecv(receiver);- to receive values from IR module, decode_results results;-to compare results value & print text accordingly.

You need to enable receiving using irrecv.enableIRIn(); in void setup() loop which runs in first cycle only. In void loop(), it continuously scans if IR module receives any signal. If it finds any signal then it calls translateIR() loop & then receives new value.

In translateIR() loop switch function is used which compares received value with preset values & print text accordingly. For example, When you press Up/Forward key on remote than remote will transmit a hex value FF629D which is received by IR module, compared in switch condition & print FORWARD in serial monitor. Each key has different value as per make. After printing it will complete the loop with delay of 500ms. Each key of remote has different hex value, you can try other remotes by removing switch condition & directly print hex value in serial monitor, for example;

You can download above code from here.

You can make your own IR remote using a keypad, IR LED & Arduino as per your requirement. Receive key value, compare it with preset & write value on IR LED. In that case you need to add ‘irsend.sendNEC(0x34895725, 32);}’ to transmit the value where 34895725 is the value to transmit & 32 is size of IR signal. For transmitter, IR LED must be connected in Pin 3 as it is defined in IRremote library. (All IR send & receive examples are available in IRremote library).

Device control using IR

You can control device using IR remote/transmitter easily. In this test code, we will control 4 outputs on pin 7, 6, 5 & 4 using numerical keys on IR remote.

You can download above code from here.

As shown in code, it compares received signal with preset values of IR remote control numeric key hex values. You can change the value according to your remote if you know hex values of each button, If you don’t know than use second code in tutorial which is IR remote test code & set it in #define functions.

I hope this tutorial will be helpful to use IR transmission & receiving in your DIY stuff. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Subscribe BYB on FacebookTwitterInstagram & Telegram for latest updates.