Wednesday, August 15, 2018

Getting started with Raspberry Pi 3B+, Arduino, IR Receiver( KY022) , RGB Full Color LED ( KY009)



Hi,

Everyone knows what Infrared Rays ( IR ) are. They are not visible to our eyes but it is used in day to day life in remote control for controlling household devices like TV, AC , Audio system.

 Lets test  whether RGB Full Color LED ( KY009 ) emits any IR rays using IR Receiver ( KY 022 )

I.Things Needed :

 1. Raspberry Pi 3 Model B+


 2. Arduino Board

         

 3. Solderless board

 4. Male to Male Jumper wires


5. Female to Male Jumper Wires






6. IR Receiver Sensor ( KY 022 )

7. RGB Full Color LED ( KY009)





8. Any Remote Control  ( of TV , Audio system , AC etc.. )



9. 390 ohm Resistors  to safeguard RGB Full color LED ( minimum 300 ohms recommended ).



10. USB A to USB B Connector ( to connect Raspberry Pi 3 B+ with Arduino )






II.  Install necessary packages :

a) Install Arduino IDE in Raspberry Pi 3 B+ with :

sudo apt-get install arduino
After installation, you will see the Arduino IDE as follows in Raspberry desktop :

                    
b) Connect Arduino and Raspberry Pi using USB A to USB B Cable :



You will be seeing board light blinking in Arduino board.



III.  Circuit Completion

a) Take the IR receiver  sensor ( KY 022 )  and use the female-to-male jumper wires and connect it as shown below :

White wire  : Signal  ,  S will be seen near the pin
Red wire     : VCC +5V
Black wire  : Ground ,     minus sign  will be seen near the pin

The reason why we use female-to-male jumper wire is to enable to move the IR receiver sensor. If it is fixed to breadboard, movement will be restricted.




b) Take the RGB Full color LED ( KY009 ) and connect to the breadboard as shown below :

i) R Pin  to  390 ohm resistor  to   Pin 9 of  Arduino.
ii) G Pin to 390 ohm resistor  to   Pin 10 of Arduino.
iii) B Pin to 390 ohm resistor to Pin 11 of Arduino.
iv) Ground Pin ( - ) pin to ground of Arduino.




c)  Connect  IR receiver sensor to Arduino Board

i) S Pin to Pin 6 of Arduino
ii) VCC Pin to 5V pin of  Arduino
iii) Ground Pin to Ground pin of Arduino.

Completed Circuit diagram will look as below :





   
IV. IR Receiver & LED  program

a)  Go to Arduino IDE, Choose the type of Arduino board : go to Tools > Board > Arduino Uno.

b) Select the port the Arduino is connected to, look under Serial Port under the Tools menu ( serial port in the raspberry Pi will be like /dev/ttyACM0).

c)  To work on IR , we need IR Arduino library. Download  the library ( zip file ) from :

      https://github.com/shirriff/Arduino-IRremote.

I have cloned the github and you can get the same package from :

     https://github.com/johnsylvester1/Adruino_IRRemote

d) Extract the Arduino-IRremote-master.zip file and rename the folder as IR folder as shown below :


e) Copy the IR folder to  Arduino IDE  libraries folder using sudo command.

            sudo cp -R /home/pi/Downloads/IR  /usr/share/arduino/libraries

f)You can see the IR library installed in Arduino IDE  as shown below Sketch  > Import Library > IR:


g)  Open a new sketch and copy the below program :

#include <IRremote.h>
int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin = 9;// select the pin for the green LED
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
for(val = 255; val > 0; val--)
{
analogWrite(redpin, val); //set PWM value for red
analogWrite(bluepin, 255 - val); //set PWM value for blue
analogWrite(greenpin, 128 - val); //set PWM value for green
delay(1);
}
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}


}

You can download the code from :

https://gist.github.com/johnsylvester1/f5ee91ed415a79fa2908867a732a6631

h) Click Verify button  to compile the sketch and then upload the code :




IV. Executing the  program

a) You will see the RGB LED ( KY009 ) light blinking:



b)  Go to Arduino IDE > Tools > Serial Monitor and keep it ready. If the IR sensor senses any IR signal, it will display the hex value of it :





c) Now bring the IR receiver sensor ( KY022 )  near the RGB LED light ( KY009) . You will see there are no IR rays from the RGB LED light.




d) Now take the remote and then press the remote button , you will see the IR button hex value returned to Serial monitor  as shown in the video below :




Now , you have received the hex value of the remote control button and also verified there are no IR rays returned by RGB LED light.

Kindly share your comments to improve my posting.









No comments:

Post a Comment

Mastering IoT Development

Hi, Before reading this post, I would recommend to read the post : https://johnsylvester-johnsylvester.blogspot.com/2018/09/iot-key-co...