0% found this document useful (0 votes)
28 views11 pages

Ch.sc.u4cse24029 m.charulatha Expt4

Uploaded by

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

Ch.sc.u4cse24029 m.charulatha Expt4

Uploaded by

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

EXPT 4: Interfacing IR sensor with Arduino UNO

Task 1: Count the number of times button 1 is pressed. If any


other button is pressed it should not count
AIM: To count the number of times button 1 is pressed. If any other
button is pressed it should not count
APPARATUS REQUIRED: Arduino UNO, connecting wires, IR_sensor
PROGRAM:
int rcvPin=11;
IRrecv irrecv(rcvPin);

decode_results results;
int count = 0;

void setup()
{

Serial.begin(9600);
irrecv.enableIRIn();
pinMode(5, OUTPUT);

}
void loop() {

if(IrReceiver.decode())
{

auto value= IrReceiver.decodedIRData.decodedRawData;


switch(value)

{
case 4010852096:
count+=1;

Serial.print("1 button pressed");


Serial.print(count);

Serial.println("times");
Serial.println(" ");

break;

default:Serial.println(value);

}
IrReceiver.resume();

CIRCUIT:
RESULT: Counting the number of times button 1 is pressed is done.
Task 2: Increment the counter value if the “VOL + “is pressed
and decrement the value if the “VOL + “is pressed
AIM: To Increment the counter value if the “VOL + “is pressed and
decrement the value if the “VOL + “is pressed
APPARATUS REQUIRED: Arduino UNO, connecting wires, IR_sensor
PROGRAM:
#include<IRremote.hpp>
int rcvPin=13;
IRrecv irrecv(rcvPin);

decode_results results;
int i=0;
void setup()

{
Serial.begin(9600);

irrecv.enableIRIn();

}
void loop() {

if(IrReceiver.decode())
{

auto value= IrReceiver.decodedIRData.decodedRawData;


if(i<100)

{
switch(value)

{
case 4261527296:
Serial.println(++i);
break;

case 4127833856:
Serial.println(--i);

break;
}
}
else

Serial.println("maximum value");

IrReceiver.resume();

CIRCUIT:
RESULT: Incrementing the counter value if the “VOL + “is pressed
and decrementing the value if the “VOL + “is pressed is done.

Task 3: Control the Traffic light based on the remote control.


“VOL +” is north direction should be green and “VOL -” is south
direction should be green, similarly for back ward and forward
button west and east direction should be turned on with green
color. When green in one direction all other directions should be
red.
AIM: To Control the Traffic light based on the remote control.
APPARATUS REQUIRED: Arduino UNO, connecting wires,
IR_sensor,LEDs
PROGRAM:
#include <IRremote.hpp>
int rcvPin=9;
IRrecv irrecv(rcvPin);

decode_results results;
void setup()

{
Serial.begin(9600);

irrecv.enableIRIn();
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

pinMode(10, OUTPUT);
pinMode(4, OUTPUT);

pinMode(3, OUTPUT);
pinMode(6, OUTPUT);

pinMode(2, OUTPUT);
}
void loop() {

if(IrReceiver.decode()) {
auto value= IrReceiver.decodedIRData.decodedRawData;

switch(value)

{
case 4261527296:

digitalWrite(12,HIGH);

digitalWrite(13,LOW);
digitalWrite(2,HIGH);

digitalWrite(3,LOW);
digitalWrite(6,HIGH);
digitalWrite(4,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);

break;
case 4127833856:

digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);

digitalWrite(6,HIGH);
digitalWrite(4,LOW);

digitalWrite(11,HIGH);
digitalWrite(10,LOW);

break;
case 4211392256:

digitalWrite(13,HIGH);
digitalWrite(12,LOW);

digitalWrite(2,HIGH);
digitalWrite(3,LOW);

digitalWrite(4,HIGH);
digitalWrite(6,LOW);

digitalWrite(11,HIGH);
digitalWrite(10,LOW);
break;
case 4177968896:
digitalWrite(13,HIGH);

digitalWrite(12,LOW);
digitalWrite(2,HIGH);

digitalWrite(3,LOW);
digitalWrite(6,HIGH);
digitalWrite(4,LOW);
digitalWrite(10,HIGH);

digitalWrite(11,LOW);
break;

default: Serial.println(value);
}

IrReceiver.resume();
}

CIRCUIT:
RESULT: Controlling the Traffic light based on the remote control is
done

You might also like