experiment 1 identification of components and breadboard ... · pdf fileintroduction to...
TRANSCRIPT
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 1
Experiment – 1
Identification of Components and Breadboard Realization
Aim:
Introduction to the lab and identification of various components and realization using bread board.
Hardware/Software Required:
1) Jumper/connecting Wires
2) Breadboard
3) Resistor
Procedure:
In this part, students are be familiarized with breadboard, various resistors and basic components.
To accomplish this experiment using Breadboard follow the steps as below:
1) Realize series, parallel connections and functioning of breadboard with understanding of
ground.
2) Practice connecting various resistors and connecting wires to understand given simple
sample circuit.
Circuit Realization:
In this section student should practice breadboard connections with random components and
connecting wires using various combinations in series and parallel.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 2
ARDUINO L
E
D
Experiment - 2
Interfacing LED to Arduino
Aim:
Write a program and demonstrate blinking of LED interfacing with Arduino UNO
Hardware/Software Required:
1) Personal Computer
2) Arduino UNO Hardware
3) Arduino UNO Software
4) LED
5) Jumper/connecting Wires
6) Breadboard
7) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
In this part, students should write a program to blink led by connecting on breadboard with
various delays of ON and OFF time.
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 3
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
7) After connections select upload option from sketch menu.
8) Observe the output.
Program Code:
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Circuit Realization:
Figure: Circuit connections
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 4
Experiment - 3
Interfacing of Push Button to Arduino
Aim:
Write a program and demonstrate blinking of LED using switch interfacing with Arduino UNO.
Hardware/Software Required:
1) Personal Computer
2) Arduino UNO Hardware
3) Arduino UNO Software
4) LED
5) Push Button
6) Jumper/connecting Wires
7) Breadboard
8) Resistor
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
In this part, students should write a program to read the state of a button connected to pin 2 (it
may be changed).
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
ARDUINO
B
U
T
T
O
N
L
E
D
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 5
7) After connections select upload option from sketch menu.
8) Observe the output.
Program Code:
const int buttonPin = 2;
const int ledPin = 3;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else if (buttonState == LOW)
{
digitalWrite(ledPin, LOW);
}
}
Circuit Realization:
Figure: Circuit connections
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 6
ARDUINO
B
U
T
T
O
N
7-SEGMENT
LED
Experiment - 4
Interfacing of 7-Segment Display to Arduino
Aim:
Write a program and demonstrate 7-Segment display interfacing with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) Seven Segment Display
4) Jumper/connecting Wires
5) Breadboard
6) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 7
7) After connections select upload option from sketch menu.
8) Observe the output.
Program Code:
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(9, 0); // start with the "dot" off
}
void loop()
{
// write '0'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 0);
delay(1000);
// write '1'
digitalWrite(2, 0);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
delay(1000);
// write '2'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 0);
digitalWrite(8, 1);
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 0);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '6'
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '7'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
delay(1000);
// write '8'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '9'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 8
delay(1000);
// write '3'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 1);
delay(1000);
// write '4'
digitalWrite(2, 0);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '5'
digitalWrite(6, 0);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
}
Circuit Realization:
Figure: Circuit connections
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 9
Figure: On board connections example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 10
ARDUINO
B
U
T
T
O
N
LCD
Experiment - 5
Interfacing of LCD Display to Arduino
Aim:
Write a program and demonstrate liquid crystal display (LCD) interfacing with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) LCD
4) Jumper/connecting Wires
5) Breadboard
6) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
7) After connections select upload option from sketch menu.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 11
8) Observe the output.
Program Code:
// include the LCD library
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("EMBEDDED SYSTEMS");
lcd.setCursor(0, 1);
lcd.print("KLU HYDERABAD");
}
Circuit Realization:
Figure: Circuit connections
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 12
Figure: On board connections example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 13
ARDUINO DC MOTOR
D
R
I
V
E
R
DC MOTOR
Experiment - 6
Interfacing of DC Motor with Arduino
Aim:
Write a program and demonstrate DC Motor interfacing with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) DC Motor
4) Motor Driver
5) Jumper/connecting Wires
6) Breadboard
7) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 14
7) After connections select upload option from sketch menu.
8) Observe the output.
Program Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
//RF Robot
int sw1 =4;
int sw2 =5;
int sw3 =6;
int out1=2;
int out2=3;
void setup()
{
pinMode(out1,OUTPUT);
pinMode(out2,OUTPUT);
pinMode(sw1,INPUT);
pinMode(sw2,INPUT);
lcd.begin(16, 2);
lcd.print("DC MOTOR");
lcd.setCursor(0,1);
lcd.print("CONTROL");
delay(1000);
}
void loop()
{
digitalWrite(sw1,HIGH);
digitalWrite(sw2,HIGH);
if ((digitalRead(sw1)==LOW) && (digitalRead(sw2)==HIGH))
{
digitalWrite(out1,HIGH);
digitalWrite(out2,LOW);
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 15
lcd.clear();
lcd.print("MOTOR CCW");
delay(500);
}
else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==LOW))
{
digitalWrite(out1,LOW);
digitalWrite(out2,HIGH);
lcd.clear();
lcd.print("MOTOR CW");
delay(500);
}
else if ((digitalRead(sw1)==HIGH) && (digitalRead(sw2)==HIGH) &&
(digitalRead(sw3)==LOW))
{
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
lcd.clear();
lcd.print("MOTOR STOP");
delay(500);
}
}
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 16
Circuit Realization:
Figure: Possible Circuit with Display connections
Figure: On board connections example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 17
ARDUINO LM35
(TEMP.
SENSOR)
MONITOR
Experiment - 7
Interfacing Temperature Sensor (LM35) to Arduino
Aim:
Write a program and demonstrate LM-35 (temperature sensor) interfacing with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) LM-35
4) Display (Optional)
5) Jumper/connecting Wires
6) Breadboard
7) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 18
7) After connections select upload option from sketch menu.
8) Observe the output.
Program Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int tempPin = A0; // the output pin of LM35
int temp;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("TEMPERATURE");
lcd.setCursor(0,1);
lcd.print("INDICATOR");
delay(2000);
lcd.clear();
}
void loop()
{
temp = 0.48828125*analogRead(A0);
Serial.print("Temperature:");
Serial.print(temp);
Serial.println("degree");
lcd.print("TEMP: ");
lcd.print(temp); // display the temperature
lcd.print(" C ");
delay(500);
lcd.clear();
}
Circuit Realization:
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 19
Figure: Possible Circuit with Display connections
Figure: On board connections example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 20
ARDUINO
B
U
T
T
O
N
R
E
L
A
Y
B
U
L
B
Experiment - 8
Interfacing of Relay to Arduino
Aim:
Write a program and demonstrate relay interfacing with Arduino UNO to glow a bulb.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) LM-35
4) Display (Optional)
5) Jumper/connecting Wires
6) Breadboard
7) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
7) After connections select upload option from sketch menu.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 21
8) Observe the output.
Program Code:
void setup() {
// initialize digital pin 5 as an output.
pinMode(5, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(5, HIGH); // turn the Relay on (HIGH is the voltage level)
delay(3000); // wait for 3 seconds
digitalWrite(5, LOW); // turn the Relay off by making the voltage LOW
delay(5000); // wait for 5 seconds
}
Circuit Realization:
Figure: On board connections example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 22
ARDUINO LDR
MONITOR
Experiment - 9
Interfacing LDR Sensor with Arduino
Aim:
Write a program and demonstrate light dependent register (LDR) interfacing with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) LDR
4) Display (Optional)
5) Jumper/connecting Wires
6) Breadboard
7) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
7) After connections select upload option from sketch menu.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 23
8) Observe the output.
Program Code:
void setup() {
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
int x=analogRead(A0);
Serial.println(x);
Int y=x/4;
analogWrite(5,y);
delay(100);
}
Circuit Realization:
Figure: On board connections example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 24
ARDUINO DH11
MONITOR
Experiment - 10
Interfacing of Humidity and Temperature Sensor(DHT11) to Arduino
Aim:
Write a program and display temperature and humidity by interfacing DHT 11 with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) DHT11
4) Display (Optional)
5) Jumper/connecting Wires
6) Breadboard
7) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) Import DHT11 Library
3) On the Arduino menu, select file and create a new file.
4) Type the program as given below.
5) Go to sketch menu and click on select/verify.
6) Rectify errors if any.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 25
7) Connect Arduino and related components as shown in figure.
8) After connections select upload option from sketch menu.
9) Observe the output.
Program Code:
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal.h>
LiquidCrystal lcd( 12, 11, 7, 6, 5, 4);
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int h = dht.readHumidity();
int t = dht.readTemperature();
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 26
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
lcd.print("Temp: ");
lcd.print(t);
lcd.print("C");
// set the cursor to (16,1):
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
delay(200);
}
Circuit Realization:
Figure: On board connections example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 27
ARDUINO
D
R
I
V
E
R
STEPPER
MOTOR
Experiment - 11
Interfacing of Stepper Motor to Arduino
Aim:
Write a program and demonstrate rotation of stepper motor interfacing with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) Stepper Motor
4) ULN2003 Driver
5) Display (Optional)
6) Jumper/connecting Wires
7) Breadboard
8) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 28
7) After connections select upload option from sketch menu.
8) Observe the output.
Program Code:
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino. The motor should revolve one
revolution in one direction, then one revolution in the other direction.
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Circuit Realization:
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 29
Figure: On board circuit example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 30
ARDUINO MONITOR MQX
(GAS
SENSOR)
Experiment - 12
Interfacing of Gas Sensor(MQ2) to Arduino
Aim:
Write a program and demonstrate gas sensor (MQX) interfacing with Arduino UNO.
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) MQ2 Sensor
4) Display (Optional)
5) Jumper/connecting Wires
6) Breadboard
7) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
To accomplish this experiment using Breadboard Arduino Board and Arduino software follow
the steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
7) After connections select upload option from sketch menu.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 31
8) Observe the output.
Program Code:
void setup() {
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
int x=analogRead(A0);
Serial.println(x);
delay(1000);
}
Circuit Realization:
Figure:) On board circuit example
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 32
ARDUINO 4-LED’s IR Sensor
Experiment - 13
Interfacing of IR Remote(TSOP-1738) to Arduino
Aim:
Write a program and demonstrate IR sensor TSOP-1738 interfacing with Arduino UNO
Hardware/Software Required:
1) Arduino UNO Hardware
2) Arduino UNO Software
3) TSOP-1738
4) LEDs (It can be used for any other devise such as Television remote control)
5) Display (Optional)
6) Jumper/connecting Wires
7) Breadboard
8) Resistor (Optional)
Block Diagram:
Figure: Block diagram of Experiment
Procedure (Arduino Program Code & Hardware Implementation):
By using arduino and IR Receiver TSOP 1738 we can decode any infrared remote code
into hex or some other format. Before constructing the circuit check datasheet of IR
receiver having in your hand, hence you can connect proper bias pins and output pin. To
accomplish this experiment using Breadboard Arduino Board and Arduino software follow the
steps given below:
1) Open Arduino IDE.
2) On the Arduino menu, select file and create a new file.
3) Type the program as given below.
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 33
4) Go to sketch menu and click on select/verify.
5) Rectify errors if any.
6) Connect Arduino and related components as shown in figure.
7) After connections select upload option from sketch menu.
8) Observe the output.
Circuit Realization:
Figure: IR Sensor application for remote control
Figure: Final Connections
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 34
Figure: On board circuit example
In this experiment first student have to execute the IRrecvDemo example program from the
arduino IR library example and decoded IR rays from remote.
(Note: If you have any error while running this library, remove “IRremoteTools.cpp” from
libraries\RobotIRremote\IRremoteTools.cpp)
Part1: Receiving IR Hex Code
Arduino Code for Receiving IR as Hex code is given in program 1.
Program Code 1:
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 35
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop(){
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value }
}
Part-2: Remote Control With Arduino
Then we used decoded data as switching condition in arduino sketch to turn on and off the three
LEDs.
Program Code 2:
#include <IRremote.h>
int RECV_PIN = 11; //
int output1 = 2;
int output2 = 4;
int output3 = 6;
int itsONled[] = {0,0,0,0};
#define code1 0xFF807F //
#define code2 0xFFA05F //
#define code3 0xFF906F //
IRrecv irrecv(RECV_PIN);
decode_results results;
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 36
void setup() {
Serial.begin(9600); //
irrecv.enableIRIn(); //
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
pinMode(output3, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
if(itsONled[1] == 1) { //
digitalWrite(output1, LOW); //
itsONled[1] = 0; // } else { //
digitalWrite(output1, HIGH); //
itsONled[1] = 1; //
}
break;
case code2:
INTRODUCTION TO ELECTRONICS ENGINEERING DEPARTMENT OF ECE
KL UNIVERSITY 37
if(itsONled[2] == 1) {
digitalWrite(output2, LOW);
itsONled[2] = 0; } else {
digitalWrite(output2, HIGH);
itsONled[2] = 1;
}
break;
case code3:
if(itsONled[3] == 1) {
digitalWrite(output3, LOW);
itsONled[3] = 0; } else {
digitalWrite(output3, HIGH);
itsONled[3] = 1;
}
break;
}
Serial.println(value); // you can comment this line
irrecv.resume(); // Receive the next value
}
}