IR Sensor Arduino- How to Remote Control LED Lighting

If you’re a robotics enthusiast, you should consider undertaking a simple IR Sensor Arduino project. But first, you need to understand how an IR sensor works and how to incorporate an Arduino board into it.  …

If you’re a robotics enthusiast, you should consider undertaking a simple IR Sensor Arduino project.

But first, you need to understand how an IR sensor works and how to incorporate an Arduino board into it. 

Worry not if you’re in the dark concerning the workings of this sensor, as we’ve got you covered.

We’ll delve into details about how to build an IR sensor Arduino from scratch and also tell you where you can apply it. Take a look.  

Table of Contents

What is an Infrared (aka IR) Sensor?

It is an electronic component capable of detecting infrared signals within a particular electromagnetic region and transmitting them to an electric signal.

An infrared sensor can perform the following functions: 

  • Detect the heat amount (infrared) emitted by a device.
  • It can also identify the motion of people as, essentially, we also emit IR radiation. 

One of the most common uses of an IR sensor is in the TV’s remote control.

But why do we use IR sensors? Here are some of the top reasons. 

  1. IR sensors are low-energy gadgets. 
  2. They also have a simplistic design. 
  3. Thirdly, they grant you the convenience of use. An example is the case of a TV remote control. 

Lastly, what is the essence of using IR signals instead of other waves in the electromagnetic spectrum?

The reason is that they can effectively transmit commands across short distances. 

Type of IR Sensors

An embedded IR Receiver. 

An embedded IR Receiver. 

There are two main infrared radiation sensors: 

Passive IR Sensor

Also called PIR sensors, these can only detect infrared radiations from external bodies. They can’t emit IR radiation.

Thus, they are commonly used as motion sensors, whereby they can identify when an object generating infrared light passes within their sensing range. 

Upon detection, the sensor produces an electric signal to a microcontroller such as Arduino Uno, which switches on the alarm. 

Active IR Sensor

This type is capable of both detecting and emitting an Infrared signal.

Unlike the aforementioned passive IR sensor, this type of sensor features two main components:

  • An infrared radiation transmitter (LED)
  • A photodiode detector 

Its main application is as a proximity sensor, whereby the LED generates infrared radiation when an object approaches it.

Next, the photodiode detector senses the emitted radiation and quantifies it to determine the closeness of the radiation emitter (object). 

How Does an IR Sensor Module Work?

Holding an IR sensor on the one hand. 

Holding an IR sensor in one hand. 

An IR sensor module features an IR LED- a special LED that generates an IR signal invisible to the human eye.

It also has an infrared photodiode that acts as a detector of the incoming radiation from the signal producer (infrared LED). 

Once it detects incoming IR radiation, the photodiode encounters a change in its resistance and output voltage.

This shift is directly proportional to the IR signal that hits it. 

Therefore, this is how the sensor detects incoming radiation and quantifies it. 

Interfacing an IR Sensor Module with Arduino

An IR sensor. 

An IR sensor. 

Now, let us explore a simple project on interfacing an IR sensor with an Arduino Uno Board. 

Components Required

Connecting IR Sensor to Arduino

Next, make the right connections by starting your Arduino project with an IR sensor.

Note that the Arduino IR sensor features three main terminals: 

  • VCC
  • GND 
  • Output Pin

Connect the sensor’s VCC pin to the 5V power input terminal of the Arduino board and the GND pin to the GND terminal of the board.

Next, connect the sensor’s output pin to pin 13 of the Arduino board. 

Find Code for Each Remote Control Key

After pressing a remote control key, you must find the codes corresponding to a particular action.

Next, you need to feed this collection of key codes to your Arduino IDE to output your respective outputs. 

Note that each remote control device features unique codes.

Nonetheless, two remote controllers may share the same code for different functions. 

Further, each key code operates at a unique frequency range, ensuring no interferences between two remote controllers.

So how do you identify the codes for your remote? 

You must run a sketch capable of reading each key’s code and transmitting it via a serial port to your PC.

Here’s an example of such a sketch: 

Next, you can access it from your IDE’s Serial Monitor tools. 

Check out the codes for every button by pressing each one every time while noting them somewhere in a table.

You should obtain codes that resemble what we have in the table below. 

Control a Set of LEDs Using IR Remote

After listing the codes for each button, you need to connect the four LEDs to the breadboard to display an output.

Remember, we aim to use the remote controller and the IR module to control the switching of the LEDs. 

How do you primarily connect the LEDs to the circuit and switch each using the remote control?

Check out the table below for the connections. 

Arduino Terminals Connect to
GNDGND terminal of IR sensor
VCCVCC terminal of IR sensor
Pin 13The signal output of the IR sensor
Pin 2Blue LED anode
Pin 3Green LED anode
Pin 4Yellow LED anode
Pin 5Red LED anode
GNDConnect to all cathode terminals of the LEDs via a 220 Ohm resistor. 

The diagram below shows how to make the connections. 

Lastly, upload the code below onto your Arduino.

Notably, you need to replace the codes you obtain for your remote with the values on the code we’ll provide for the setup to work appropriately. 

Essentially, you need to replace the code on the statements that read as follows case 0xXXXXXXXX;

Troubleshooting

Different remote controls. 

Different remote controls. 

The Arduino project is not a seamless process, and you’ll likely encounter some errors. Let us cover the solution to the error you will most likely encounter. 

What to do when you get an FFFFFF key code.

This error is most common when you press and hold onto a button.

Nonetheless, you’ll note that the remote controller module will initially produce a valid code and then give the FFFFFFerror when you keep holding onto the button. 

Hence, to solve the issue, you record the initial code the controller generated, which is the key code for the button. 

Applications of an IR Sensor Arduino

Remote control concept icon. 

Remote control concept icon. 

In what ways can you use an IR sensor interfaced with Arduino, as we’ve illustrated in our above setup?

Or rather, after setting up the circuit above, how do you test it to ascertain if it is working? 

You can switch the LEDs on or off using the remote. Try turning them on or off using the remote controller on or off button. 

Again with this setup, you can be more creative and do other projects, such as starting a DC motor or controlling the movement of a robot.

Lastly, you can even make a traffic lights project and switch the lights on and off using the remote controller. 

FAQs

My sensor detects a code that I’ve never seen before.

There are two possible reasons you’re experiencing the above issue. 

  1. First, it could be that you’re not pointing your remote control directly onto the sensor, altering the codes’ length. Hence, you can manage the issue by pointing directly to the sensor. 
  2. Also, the reason could be that your remote control is cheap and thus incapable of receiving high signal quality. The solution is to improve the quality of your remote control. You can, for instance, use a TV or DVD player’s remote. 

How do I know if a logged code is not garbage?

You can identify this from the structure of the code. Normally the code is in hexadecimal format.

Hence, if it doesn’t follow that form, its structure has a problem. 

How do you find the protocol used by your remote in iR Sensor Arduino Project?

If you intend to create an advanced project, you will need a code to identify the protocol for your project.

You require to run the program below, and you’ll outrightly obtain your remote sensor’s protocol. 

Summary

An IR sensor can be useful for simple DIY projects once you interface it with Arduino.

In this article, we have highlighted how to use your IR remote with an Arduino. 

Also, we’ve provided you with a way to obtain the codes for any IR sensor to facilitate interfacing with Arduino. 

Categories How