Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
81 views31 pages

Arduino 37-in-1 Sensor Kit Guide

This kit contains 37 different sensors and actuators for use with Arduino projects. It includes sensors for light, sound, temperature, motion and other environmental factors as well as output devices like LEDs, buzzers and relays.

Uploaded by

Aji EC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views31 pages

Arduino 37-in-1 Sensor Kit Guide

This kit contains 37 different sensors and actuators for use with Arduino projects. It includes sensors for light, sound, temperature, motion and other environmental factors as well as output devices like LEDs, buzzers and relays.

Uploaded by

Aji EC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

37 in 1 Sensors Kit for Arduino

Description
This is the most comprehensive sensors kit for Arduino lover, of course it can also be
used for every project. The kit comes with 37 different modules, sensors(input) and
actuators(output).
Note: Arduino Main Board or the Compatible Arduino Main Board is not included.
Here is the list of sensors and actuators in the kit:
 1 x 2 axis Analog Joystick
 1 x Relay
 1 x Big sound, big microphone for audio detection
 1 x Small sound, small microphone for audio detection
 1 x Tracking, small IR sensor
 1 x Avoidance, IR sensor
 1 x Flame
 1 x Linear hall, hall effect sensor to detect magnetic
 1 x Touch sensor
 1 x Digital temperature, thermistor
 1 x Active buzzer, audio output
 1 x Passive buzzer, Piezo buzzer
 1 x RGB LED, Through-hole LED
 1 x SMD RGB, SMD LED
 1 x Two-color, through LED
 1 x Mini two-color
 1 x Reed switch
 1 x Mini reed switch
 1 x Heartbeat
 1 x 7 color flash, auto flash LED
 1 x Laser emitter
 1 x Button, push button
 1 x Shock
 1 x Rotary encoders
 2 x Light cup
 1 x Ball switch
 1 x Tilt-switch, mercury
 1 x Photo-resistor, LDR
 1 x Temp and humidity
 1 x Analog hall
 1 x Hall magnetic
 1 x 18B20 temp
 1 x Analog temp, thermistor
 1 x IR emission
 1 x IR receiver
 1 x Tap module
 1 x Light blocking
Yup, you will get all these sensors and actuators in a nice plastic casing.
Link: https://my.cytron.io/c-sensor-kits/p-37-in-1-sensors-kit-for-arduino
HOW TO SET UP AN IR REMOTE AND
RECEIVER ON AN ARDUINO

Infrared (IR) communication is a widely used and easy to implement wireless


technology that has many useful applications. The most prominent examples
in day-to-day life are TV/video remote controls, motion sensors, and infrared
thermometers.

There are plenty of interesting


Arduino projects that use IR
communication too. With a simple IR
transmitter and receiver, you can
make remote controlled robots,
distance sensors, heart rate
monitors, DSLR camera remote
controls, TV remote controls, and
lots more.

In this tutorial I’ll first explain what infrared is and how it works. Then I’ll
show you how to set up an IR receiver and remote on an Arduino. I’ll also
show you how to use virtually any IR remote (like the one for your TV) to
control things connected to the Arduino.

Now let’s get into the details…

WHAT IS INFRARED?
Infrared radiation is a form of light similar to the light we see all around us.
The only difference between IR light and visible light is the frequency and
wavelength. Infrared radiation lies outside the range of visible light, so
humans can’t see it:
Because IR is a type of light, IR communication requires a direct line of sight
from the receiver to the transmitter.

It can’t transmit through walls or other materials like Wi-Fi or Bluetooth.

HOW IR REMOTES AND RECEIVERS WORK


A typical infrared communication system requires an IR transmitter and an IR
receiver. The transmitter looks just like a standard LED, except it produces
light in the IR spectrum instead of the visible spectrum. If you have a look at
the front of a TV remote, you’ll see the IR transmitter LED:

The IR receiver is a photodiode and


The same type of LED is used in IR
pre-amplifier that converts the IR
transmitter breakout boards for the
light into an electrical signal. IR
Arduino. You can see it at the front of
receiver diodes typically look like
this Keyes IR transmitter:
this:
Some may come on a breakout board like this:

IR SIGNAL MODULATION
IR light is emitted by the sun, light bulbs, and anything else that produces
heat. That means there is a lot of IR light noise all around us. To prevent this
noise from interfering with the IR signal, a signal modulation technique is
used.

In IR signal modulation, an encoder on the IR remote converts a binary


signal into a modulated electrical signal. This electrical signal is sent to the
transmitting LED. The transmitting LED converts the modulated electrical
signal into a modulated IR light signal. The IR receiver then demodulates the
IR light signal and converts it back to binary before passing on the
information to a microcontroller:

The modulated IR signal is a series of IR light pulses switched on and off at a


high frequency known as the carrier frequency. The carrier frequency used by
most transmitters is 38 kHz, because it is rare in nature and thus can be
distinguished from ambient noise. This way the IR receiver will know that the
38 kHz signal was sent from the transmitter and not picked up from the
surrounding environment.

The receiver diode detects all frequencies of IR light, but it has a band-pass
filter and only lets through IR at 38 kHz. It then amplifies the modulated
signal with a pre-amplifier and converts it to a binary signal before sending it
to a microcontroller.
IR TRANSMISSION PROTOCOLS
The pattern in which the modulated IR signal is converted to binary is defined
by a transmission protocol. There are many IR transmission protocols. Sony,
Matsushita, NEC, and RC5 are some of the more common protocols.

The NEC protocol is also the most common type in Arduino projects, so I’ll
use it as an example to show you how the receiver converts the modulated IR
signal to a binary one.

Logical ‘1’ starts with a 562.5 µs long HIGH pulse of 38 kHz IR followed by a
1,687.5 µs long LOW pulse. Logical ‘0’ is transmitted with a 562.5 µs long
HIGH pulse followed by a 562.5 µs long LOW pulse:

This is how the NEC protocol encodes and decodes the binary data into a
modulated signal. Other protocols differ only in the duration of the individual
HIGH and LOW pulses.

IR CODES
Each time you press a button on the remote control, a unique hexadecimal
code is generated. This is the information that is modulated and sent over IR
to the receiver. In order to decipher which key is pressed, the receiving
microcontroller needs to know which code corresponds to each key on the
remote.

Different remotes send different codes for the keypresses, so you’ll need to
determine the code generated for each key on your particular remote. If you
can find the datasheet, the IR key codes should be listed. If not though, there
is a simple Arduino sketch that will read most of the popular remote controls
and print the hexadecimal codes to the serial monitor when you press a key.
I’ll show you how to set that up in a minute, but first we need to connect the
receiver to the Arduino…
HOW TO CONNECT AN IR RECEIVER TO THE
ARDUINO
There are several different types of IR
receivers, some are stand-alone, and
some are mounted on a breakout board.
Check the datasheet for your particular
IR receiver since the pins might be
arranged differently than the HX1838 IR
receiver and remote set I am using here.
However, all IR receivers will have three
pins: signal, ground, and Vcc.

Lets get started with the hardware


connections. The pin layout on most
breakout boards looks like this:

The pinout of most stand-alone diodes is like this:

To connect a breakout board mounted IR receiver, hook it up to the Arduino


like this:

To connect a stand-alone receiver diode, wire it like this:


PROGRAMMING THE IR RECEIVER
Once you have the receiver connected, we can install the Arduino library and
start programming. In the examples below, I’ll show you how to find the
codes sent by your remote, how to find the IR protocol used by your remote,
how to print key presses to the serial monitor or an LCD, and finally, how to
control the Arduino’s output pins with a remote.

INSTALL THE IRREMOTE LIBRARY


We’ll be using the IRremote library for all of the code examples below. You
can download a ZIP file of the library from here.

To install the library from the ZIP file, open up the Arduino IDE, then go to
Sketch > Include Library > Add .ZIP Library, then select the IRremote ZIP file
that you downloaded from the link above.

FIND THE CODES FOR YOUR REMOTE


To find the key codes for your remote control, upload this code to your
Arduino and open the serial monitor:

#include <IRremote.h>

const int RECV_PIN = 7;


IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}

void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
irrecv.resume();
}
}

Now press each key on your remote and record the hexadecimal code printed
for each key press.

Using the program above, I derived a table of keys and their corresponding
codes from the remote that came with my HX1838 IR receiver and remote
set. Note that you will receive a 0XFFFFFFFF code when you press a key
continuously.

Key Code D

0xFFA25 0xFFC23
CH- D >|| D

0xFF629 – 0xFFE01F
CH D
0xFFA85
0xFFE21 + 7
CH+ D
EQ 0xFF906F
0xFF22D
<< D 100 0xFF986
+ 7
>> 0xFF02F
200 0xFFB04 4 0xFF10EF
+ F
0xFF38C
0XFF689 5 7
0 7
0xFF5AA
0xFF30C 6 5
1 F
0xFF42B
0xFF18E 7 D
2 7
8 0xFF4AB5
0xFF7A8
3 5 9 0xFF52AD

FIND THE PROTOCOL USED BY YOUR REMOTE


Knowing which protocol your remote uses can be useful if you want to work
on some more advanced projects. Or you might just be curious. The program
below will identify the protocol used by your remote. It should even work on
most of the remote controls around your house.

#include <IRremote.h>

const int RECV_PIN = 7;


IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}

void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
switch (results.decode_type){
case NEC: Serial.println("NEC"); break ;
case SONY: Serial.println("SONY"); break ;
case RC5: Serial.println("RC5"); break ;
case RC6: Serial.println("RC6"); break ;
case DISH: Serial.println("DISH"); break ;
case SHARP: Serial.println("SHARP"); break ;
case JVC: Serial.println("JVC"); break ;
case SANYO: Serial.println("SANYO"); break ;
case MITSUBISHI: Serial.println("MITSUBISHI"); break ;
case SAMSUNG: Serial.println("SAMSUNG"); break ;
case LG: Serial.println("LG"); break ;
case WHYNTER: Serial.println("WHYNTER"); break ;
case AIWA_RC_T501: Serial.println("AIWA_RC_T501"); break ;
case PANASONIC: Serial.println("PANASONIC"); break ;
case DENON: Serial.println("DENON"); break ;
default:
case UNKNOWN: Serial.println("UNKNOWN"); break ;
}
irrecv.resume();
}
}

PRINT KEYS TO THE SERIAL MONITOR


I extended the code above to print the key value instead of the hexadecimal
code:

#include <IRremote.h>

const int RECV_PIN = 7;


IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}

void loop(){
if (irrecv.decode(&results)){

if (results.value == 0XFFFFFFFF)
results.value = key_value;

switch(results.value){
case 0xFFA25D:
Serial.println("CH-");
break;
case 0xFF629D:
Serial.println("CH");
break;
case 0xFFE21D:
Serial.println("CH+");
break;
case 0xFF22DD:
Serial.println("|<<");
break;
case 0xFF02FD:
Serial.println(">>|");
break ;
case 0xFFC23D:
Serial.println(">|");
break ;
case 0xFFE01F:
Serial.println("-");
break ;
case 0xFFA857:
Serial.println("+");
break ;
case 0xFF906F:
Serial.println("EQ");
break ;
case 0xFF6897:
Serial.println("0");
break ;
case 0xFF9867:
Serial.println("100+");
break ;
case 0xFFB04F:
Serial.println("200+");
break ;
case 0xFF30CF:
Serial.println("1");
break ;
case 0xFF18E7:
Serial.println("2");
break ;
case 0xFF7A85:
Serial.println("3");
break ;
case 0xFF10EF:
Serial.println("4");
break ;
case 0xFF38C7:
Serial.println("5");
break ;
case 0xFF5AA5:
Serial.println("6");
break ;
case 0xFF42BD:
Serial.println("7");
break ;
case 0xFF4AB5:
Serial.println("8");
break ;
case 0xFF52AD:
Serial.println("9");
break ;
}
key_value = results.value;
irrecv.resume();
}
}

If your remote sends different codes than the ones in the table above, just
replace the hex code in each line where it says:

case 0xFFA25D:
Serial.println(“CH-“);

In these lines, when the hex code 0xFFA25D is received, the Arduino prints
“CH-“.
HOW THE CODE WORKS
For any IR communication using the IRremote library, first we need to create
an object called irrecv and specify the pin number where the IR receiver is
connected (line 3). This object will take care of the protocol and processing of
the information from the receiver.

The next step is to create an object called results, from


the decode_results class, which will be used by the irrecv object to share the
decoded information with our application (line 5).

In the void setup() block, first we configure the serial monitor baud rate. Next
we start the IR receiver by calling the IRrecv member
function enableIRIn() (line 10).

The irrecv.blink13(true) function on line 11 will blink the Arduino’s on board LED
every time the receiver gets a signal from the remote control, which is useful
for debugging.

In the void loop() block, the function irrecv.decode will return true if a code is
received and the program will execute the code in the if statement. The
received code is stored in results.value. Then I used a switch to handle each IR
code and print the corresponding key value.

Before the switch block starts there is a conditional block:

if (results.value == 0XFFFFFFFF)
results.value = key_value;

If we receive 0XFFFFFFFF from the remote, it means a repetition of the


previous key. So in order to handle the repeat key pattern, I am storing the
hex code in a global variable key_value every time a code is received:
key_value = results.value;

When you receive a repeat pattern, then the previously stored value is used
as the current key press.

At the end of the void loop() section, we call irrecv.resume() to reset the
receiver and prepare it to receive the next code.

PRINT KEYS TO AN LCD


Instead of printing the key values to the serial monitor, you can also display
the information on an LCD. Check out our article on setting up and
programming an LCD on the Arduino for more information on programming
the LCD, but the basic setup looks like this:
The resistor sets the LCD’s backlight brightness. It can be anything from 200
ohms to about 2K ohms. The potentiometer sets the character contrast. I
normally use a 10K ohm potentiometer for this one.

Once everything is connected, upload this code to the Arduino:

#include <IRremote.h>
#include <LiquidCrystal.h>

const int RECV_PIN = 7;


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
lcd.begin(16, 2);
}

void loop(){
if (irrecv.decode(&results)){

if (results.value == 0XFFFFFFFF)
results.value = key_value;
lcd.setCursor(0, 0);
lcd.clear();

switch(results.value){

case 0xFFA25D:
lcd.print("CH-");
break;
case 0xFF629D:
lcd.print("CH");
break;

case 0xFFE21D:
lcd.print("CH+");
break;

case 0xFF22DD:
lcd.print("|<<");
break;

case 0xFF02FD:
lcd.print(">>|");
break ;

case 0xFFC23D:
lcd.print(">|");
break ;

case 0xFFE01F:
lcd.print("-");
break ;

case 0xFFA857:
lcd.print("+");
break ;

case 0xFF906F:
lcd.print("EQ");
break ;

case 0xFF6897:
lcd.print("0");
break ;

case 0xFF9867:
lcd.print("100+");
break ;

case 0xFFB04F:
lcd.print("200+");
break ;

case 0xFF30CF:
lcd.print("1");
break ;

case 0xFF18E7:
lcd.print("2");
break ;

case 0xFF7A85:
lcd.print("3");
break ;
case 0xFF10EF:

lcd.print("4");
break ;

case 0xFF38C7:
lcd.print("5");
break ;

case 0xFF5AA5:
lcd.print("6");
break ;

case 0xFF42BD:
lcd.print("7");
break ;

case 0xFF4AB5:
lcd.print("8");
break ;

case 0xFF52AD:
lcd.print("9");
break ;
}

key_value = results.value;
irrecv.resume();
}
}

Again, if the hex codes don’t match the codes output by your remote, just
replace them for each character where it says case 0xXXXXXXXX;.

USING THE IR REMOTE TO CONTROL THINGS


Now I’ll show you a simple demonstration of how you can use the IR remote
to control the Arduino’s output pins. In this example, we will light up an LED
when a particular button is pressed. You can easily modify the code to do
things like control servo motors, or activate relays with any button press from
the remote.

The example circuit has the IR receiver connected to the Arduino, with a red
LED connected to pin 10 and a green LED connected to pin 11:
The code below will write digital pin 10 HIGH for 2 seconds when the “5”
button is pressed, and write digital pin 11 HIGH for 2 seconds when the “2”
button is pressed:

#include <IRremote.h>

const int RECV_PIN = 7;


IRrecv irrecv(RECV_PIN);
decode_results results;
const int redPin = 10;
const int greenPin = 11;

void setup(){
irrecv.enableIRIn();
irrecv.blink13(true);

pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}

void loop(){
if (irrecv.decode(&results)){

switch(results.value){
case 0xFF38C7: //Keypad button "5"
digitalWrite(redPin, HIGH);
delay(2000);

digitalWrite(redPin, LOW);
}

switch(results.value){
case 0xFF18E7: //Keypad button "2"
digitalWrite(greenPin, HIGH);
delay(2000);

digitalWrite(greenPin, LOW);
}

irrecv.resume();
}
}
So far we have covered the properties of infrared radiation and how
communication happens between the transmitter and receiver. We saw how
to identify the IR key codes for a given remote control. We learned how
to display key presses on serial monitor and on an LCD screen.

Finally I showed you how to control the Arduino’s output with the remote.
Have fun playing with this and be sure to let us know in the comments if you
have any questions or trouble setting this up!

Link:
https://www.circuitbasics.com/arduino-ir-remote-receiver-tutorial/
ir-receiver.ino – Wokwi ESP32, STM32,
Arduino Simulator
Code:

#include <IRremote.h>
#include <LiquidCrystal.h>
#define PIN_RECEIVER 2 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
lcd.begin(16, 2);
lcd.print("<press a button>");
receiver.enableIRIn(); // Start the receiver
}
void loop() { // Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
}
void lcdPrint(char* text) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("button pressed:");
lcd.setCursor(0, 1);
lcd.print(text);
lcd.print(" code: ");
lcd.print(receiver.decodedIRData.command);
}
void translateIR() { // Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 162:
lcdPrint("POWER");
break;
case 226:
lcdPrint("MENU");
break;
case 34:
lcdPrint("TEST");
break;
case 2:
lcdPrint("PLUS");
break;
case 194:
lcdPrint("BACK");
break;
case 224:
lcdPrint("PREV.");
break;
case 168:
lcdPrint("PLAY");
break;
case 144:
lcdPrint("NEXT");
break;
case 104:
lcdPrint("num: 0");
break;
case 152:
lcdPrint("MINUS");
break;
case 176:
lcdPrint("key: C");
break;
case 48:
lcdPrint("num: 1");
break;
case 24:
lcdPrint("num: 2");
break;
case 122:
lcdPrint("num: 3");
break;
case 16:
lcdPrint("num: 4");
break;
case 56:
lcdPrint("num: 5");
break;
case 90:
lcdPrint("num: 6");
break;
case 66:
lcdPrint("num: 7");
break;
case 74:
lcdPrint("num: 8");
break;
case 82:
lcdPrint("num: 9");
break;
default:
lcd.clear();
lcd.print(receiver.decodedIRData.command);
lcd.print(" other button");
}
}

Link: https://wokwi.com/projects/298934082074575369
Arduino Tutorial:
IR Transmitter and IR Receiver (HX-M121, HX-53,
KY-005, KY-022, Keyes, Iduino, Open Smart, …)

Infrared (IR) communication is a widely used communication technology. A


typical example for IR communication is a TV remote control that sends IR
signals to a TV. In particular, the remote’s IR light is repeatedly switched on
and off (typically 38kHz / 38.000 times per second). The advantages of IR
technology are it’s inexpensive and undetectable to the human eye. The
disadvantage is that the IR light must be directed towards the IR receiver. As
a consequence, IR communication should not be applied if sender and
receiver are in different rooms (Bluetooth or WiFi might be a better choice
then).

This tutorial gives an introduction to the “IR transmitter” and “IR receiver”
modules. My pairs of IR transmitter and receiver are no-name products.
Often, you find these products also under different names (e.g. IR emitter, IR
sender) or with a version number as postfix (e.g. V1.0). The good news is
that they are built up very much alike. Therefore, this tutorial should also
work for similar products (HX-M121, HX-53, KY-005, KY-022, YL-55) from
other manufacturers and vendors (Keyes, Iduino, Open Smart,…).

Related products
 IR transmitter
 IR receiver
 2x Arduino Uno
 Jumper wires
 Third hand (used only for pictures)
IR Transmitter and IR Receiver modules.

IR Transmitter
The IR transmitter module has an IR LED to send signals. Normally, the LED
operates around 940nm, i.e. the LED is very bright in the IR spectrum.
Besides the LED, the module has three pins to power and control the module:
GND, VCC, and DAT. And that’s about basically everything that is needed to
send signals over IR communication. In fact, this is the reason why IR
communication is so cheap. You need only an (IR) LED to get started.

The pins GND and VCC are for powering the module with a 5V power supply
(e.g. Arduino GND and 5V pin header). The DAT pin corresponds to the data
signal that should be sent to an IR receiver. If you have another type of IR
sender, the SIG pin might have a different name. For example, S for Iduino
module and KY-005, …

IR Receiver
IR receiver modules have typically an integrated IR receiver unit, such as the
TSOP382, TSSP4P38 etc. These units have already everything included that is
needed to sense an IR signal (PIN diode, bandpass, demodulator, …).

The pin layout is very similar to the IR transmitter. There is a GND and VCC
pin to power the module with a 5V voltage supply. The received IR data can
be read from the DAT pin. The pin layout is basically also the same for other
IR receiver modules. The DAT pin has often a different name. For example, S
for KY-022, DO for YL-55,…

IR Communication Protocols
There exist different protocols that define how a signal/message is sent from
an IR transmitter to an IR receiver. The use of different protocols are, e.g.,
one reason why a remote control of a TV does often not work for with
another TV. This tutorial does not dive deeper into the topic of IR protocols.
Nonetheless, it’s already good to know that there exist different protocols
(NEC, JVC, Samsung, …) for IR communication.

Example Application
The idea of the example application is to have an IR receiver and IR
transmitter module. Each module is controlled by an Arduino Uno (=two
different Arduinos are used). The sending Arduino Uno uses the “NEC
protocol” to send a message with the IR transmitter module. The receiving
Arduino Uno uses the IR receiver module to receive the message and then
prints out the message’s content.

Wiring
The wiring for powering is the same for both pairs of Arduinos and modules.
Both modules have an operating voltage of 5V. For each module, use a
jumper wire and connect the Arduino’s GND pin to the module’s GND pin. Do
the same for each module to connect the Arduino’s 5V pin to the module’s
VCC pin.

For the sending Arduino Uno, wire the Arduino’s pin 3 to the module’s DAT
pin.

Wiring between Arduino Uno and IR Transmitter.

Wire (sending) Arduino Uno Pin IR Transmitter Pin

Black GND GND

Red 5V VCC

Yellow 3 DAT

Wiring between sending Arduino Uno and IR transmitter module.


For the receiving Arduino Uno, wire the Arduino’s pin 2 to the module’s DAT
pin.

Wiring between Arduino Uno and IR Receiver.

(receiving) Arduino Uno


Wire IR Receiver Pin
Pin

Black GND GND

Red 5V VCC

Green 2 DAT

Wiring between receiving Arduino Uno and IR receiver module.

Programming
In this tutorial, we make use of the IRremote Arduino library. The library
supports many protocols and devices (Arduino Uno, ESP32, …). If you use the
Arduino IDE, you can install the library with the Library Manager. If you run
into any problems, please check which version you use. This tutorial uses
version >3.0.0 of the IRremote Arduino Library.

Let’s start with programming the sending Arduino. In the setup function, we
initialize the IRSender with pin number 3. In the loop function, we have only
two calls. First, we make a function call for sending a message with the NEC
protocol (data to be sent: address = 0x0102 and command=0x34). The
second call is a delay in order to wait one second for the next IR sending call.
/*
MIT License
Copyright 2021 Michael Schoeffler (https://www.mschoeffler.com)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* This is an example source code of a tutorial on how to do IR
communication with the Arduino Uno.
* This program is for a sending Arduino Uno that sends an IR
signal each second.
*/

#include <IRremote.h> // >v3.0.0

#define PIN_SEND 3

void setup()
{
IrSender.begin(PIN_SEND); // Initializes IR sender
}

void loop()
{
IrSender.sendNEC(0x0102, 0x34, true, 0); // the address 0x0102
with the command 0x34 is sent
delay(1000); // wait for one second
}

Next, comes the receiving Arduino Uno. The program is also very simple. In
the setup function we initialize the serial connection and the IrReceiver. In
the loop function, we check whether an IR signal could be received and
decoded. If so, we print out the signal on the serial monitor.

Luckily, the library provides a convenience function (printIRResultShort) for


this. When we are done with decoding, we must call the resume function of
the library to receive the next IR signal.
/*
MIT License
Copyright 2021 Michael Schoeffler (https://www.mschoeffler.com)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* This is an example source code of a tutorial on how to do IR
communication with the Arduino Uno.
* This program is for a receiving Arduino Uno that receives IR
signals.
*/

#include <IRremote.h> // >v3.0.0

#define PIN_RECV 2

void setup()
{
Serial.begin(9600);
//initialize serial connection to print on the Serial
//Monitor of the Arduino IDE

IrReceiver.begin(PIN_RECV);
// Initializes the IR receiver object
}

void loop()
{
if (IrReceiver.decode()) {
Serial.println("Received something...");
IrReceiver.printIRResultShort(&Serial);
// Prints a summary of the received data

Serial.println();
IrReceiver.resume();
// Important, enables to receive the next IR signal

If both programs are transferred to the Arduinos, you should be able to see
some communication. If it does not work, please make sure that receiver and
transmitter have a line of sight to each other.
Example application: The IR transmitter module sends NEC commands to the
IR receiver module.

Example application: Serial output of the “receiving” Arduino Uno.

Conclusion
The IR transmitter and IR receiver modules are very useful when someone
wants to get started with IR communication. These cheap modules work very
well for a wide range of applications and are very simple to use.

If you plan to use them under difficult conditions (shining sunlight, no direct
line of sight, …), I recommend to evaluate first, whether these cheap modules
fit to your requirements. The good news is, “more expensive / better” IR
modules work in the same way as presented here.
Link:
https://mschoeffler.com/2021/05/01/arduino-tutorial-ir-transmitter-and-ir-
receiver-hx-m121-hx-53-ky-005-ky-022-keyes-iduino-open-smart/

You might also like