100% found this document useful (2 votes)
1K views

School of Electronics Engineering

The document is a lab manual for an embedded systems design course. It contains: 1. An introduction and list of 11 challenging experiments to be completed, including working with LEDs, serial ports, 7-segment displays, IR LEDs, ADCs, LCDs, keypads, stepper motors, ultrasonic sensors, SPI and I2C. 2. Details and code for an experiment to blink three LEDs (green, yellow, red) in a repeating sequence using an Arduino Uno. 3. Details and code for an experiment to control the state of two LEDs (green, red) using a switch, turning one on and the other off depending on the switch position.

Uploaded by

WINORLOSE
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
1K views

School of Electronics Engineering

The document is a lab manual for an embedded systems design course. It contains: 1. An introduction and list of 11 challenging experiments to be completed, including working with LEDs, serial ports, 7-segment displays, IR LEDs, ADCs, LCDs, keypads, stepper motors, ultrasonic sensors, SPI and I2C. 2. Details and code for an experiment to blink three LEDs (green, yellow, red) in a repeating sequence using an Arduino Uno. 3. Details and code for an experiment to control the state of two LEDs (green, red) using a switch, turning one on and the other off depending on the switch position.

Uploaded by

WINORLOSE
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 160

SCHOOL OF ELECTRONICS ENGINEERING

B.TECH. ELECTRONICS AND COMMUNICATION ENGINEERING

ECE4003 – EMBEDDED SYSTEM DESIGN


LAB MANUAL

Prepared by

Hemant Pamnani : 18BEC1241

Under the guidance of


Dr. VIJAYAKUMAR P
Emp. ID : 50441
Associate Professor

VELLORE INSTITUTE OF TECHNOLOGY, CHENNAI


Vandalur – Kelambakkam Road
Chennai – 600127
JUNE2021

1
LIST OF CHALLENGING EXPERIMENT
S.No ExP.NO. Title of the Date of the Page No.
Experiment Experiment
1. 1 Working with LED 08/02/2021
& Switches
2. 2 Working with 15/02/2021
Serial Port

3. 3 Working with 7 22/0/2021


Segment Display
4. 4 Working with IR 11/03/2021
LED
5. 5 Working With 18/03/2021
ADC
6. 6 Virtual Lab : 25/03/2021
Working With
LCD
7. 7 Working with 03/04/2021
Keypad on the
given date and time
8. 8 Working with  19/04/2021
Stepper Motor on
the given date and
time
9. 9 Working with  22/04/2021
Ultrasonic Sensor
on the given date
and time

10. 10 Working with SPI 23/04/2021

11. 11 Working with I2C 25/05/2021

2
Working with LED & Switches
Date : 08/02/2021
Exp.No.: 1 Page No. 1
Task 1: LED Blinking
Aim :
Write a program to blink three LEDs (Green, Yellow, Red) interfaced with three
digital pins of Arduino Uno as per following sequence.
⮚ First turn ON Green LED for 15 Sec. while other LEDs in OFF state
⮚ Then turn ON Yellow LED for 3 Sec. while other LEDs in OFF state
⮚ Then turn ON Red LED for 10 Sec. while other LEDs in OFF state
⮚ Repeat this sequence continuously
Simulate and verify this logic on Arduino Uno using Tinkercadcircuits simulator.

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 Green LED, Red LED, Yellow LED
 C Language
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a
button, or a Twitter message - and turn it into an output - activating a motor, turning on an
LED, publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
Serial.begin( )
- Configures a serial port with specified baud rate
Println
- To perform printing text followed by a newline character
Delay()
- Pauses the program for the amount of millisecond (ms)
Val
- Specify value or text to be printed on serial monitor
Digitalwrite()
- Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
Program :
int GREEN = 0;
int YELLOW=1;
int RED=2;

3
void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
delay(15000);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
delay(3000);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
delay(10000);
}
Output :

Fig.1 –Circuit for blinking of LED


Inference :
Thus, the circuit for blinking LEDs using ARDUINO UNO has been verified using
Tinkercad simulator and has been verified.

Task 2: Controlling LED blinking using Switch


Aim : Write a program to control two LEDs (Green, Red) state using a switch as per
following logic.
 When switch is not pressed (LOW) turn ON Red LED continuously and Green LED in
OFF state

4
 Whenever switch is pressed (HIGH) turn OFF Red LED and turn ON Green LED for 10
Sec.
 After 10 Sec. delay turn OFF Green LED and proceed to turn ON Red LED continuously

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.
Software / Components Required :
 Tinker CAD
 Arduino UNO
 Resistor
 Green LED, Red LED
 C Language
 Switch
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a
button, or a Twitter message - and turn it into an output - activating a motor, turning on an
LED, publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
Serial.begin( )
- Configures a serial port with specified baud rate
Println
- To perform printing text followed by a newline character
Delay()
- Pauses the program for the amount of millisecond (ms)
Val
- Specify value or text to be printed on serial monitor
Digitalwrite()
- Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
Program :
int RED= 0;
int GREEN =1;
int SWITCH=2;
int SWITCHSTATE;
void setup()
{
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(SWITCH, INPUT);

5
}
void loop()
{
SWITCHSTATE = digitalRead(SWITCH);
if(SWITCHSTATE==HIGH)
{
digitalWrite(RED,LOW);
digitalWrite(GREEN,HIGH);
delay(10000);
}
else
{
digitalWrite(RED,HIGH);
digitalWrite(GREEN,LOW);
}
}

Output :

Fig.2-Circuit for controlling LED blinking through switch


Inference :
Thus, the circuit for controlling LED blinking through switch using ARDUINO UNO
has been verified using Tinkercad simulator and has been verified.

Task 3: Controlling LED glowing sequence using Switch


Aim : Write a program to blink four LEDs one at a time from left to right with 0.5 sec delay.
Whenever a switch is pressed, the LED blinking happens from right to left witcontrh delay of
0.25s between each LED. When the Switch is released again the sequence change to left to
right with 0.5s delay.

Software / Components Required :


 Tinker CAD
 Arduino UNO
6
 Resistor
 Green LED, Red LED, Yellow LED
 C Language
 Switch
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a
button, or a Twitter message - and turn it into an output - activating a motor, turning on an
LED, publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
Serial.begin( )
- Configures a serial port with specified baud rate
Println
- To perform printing text followed by a newline character
Delay()
- Pauses the program for the amount of millisecond (ms)
Val
- Specify value or text to be printed on serial monitor
Digitalwrite()
- Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
Program :
int switchstate;
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, INPUT);
}
void loop()
{
switchstate=digitalRead(4);
if(switchstate==LOW)
{
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
digitalWrite(1,LOW);
digitalWrite(0,LOW);

7
delay(500);
digitalWrite(3,LOW);
digitalWrite(2,HIGH);
digitalWrite(1,LOW);
digitalWrite(0,LOW);
delay(500);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(1,HIGH);
digitalWrite(0,LOW);
delay(500);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(1,LOW);
digitalWrite(0,HIGH);
delay(500);
}
else
{
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(1,LOW);
digitalWrite(0,HIGH);
delay(250);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(1,HIGH);
digitalWrite(0,LOW);
delay(250);
digitalWrite(3,LOW);
digitalWrite(2,HIGH);
digitalWrite(1,LOW);
digitalWrite(0,LOW);
delay(250);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
digitalWrite(1,LOW);
digitalWrite(0,LOW);
delay(250);
}
}
Output :

8
Fig.3 – Circuit for controlling LED glowing sequence using Switch
Inference :
Thus, the circuit for controlling LED glowing sequence using switch using
ARDUINO UNO has been verified using Tinkercad simulator and has been verified.
Task 4: Display Hexadecimal pattern from 0 to F using 4 LEDs
Aim : Write a program to control four LEDs in a Hexadecimal pattern from 0 (0000) to F
(1111) in a sequential order with 0.5 Sec delay between each. Once it reach F, the sequence
must continue again from 0. Simulate and verify this logic on Arduino Uno using Tinkercad
circuits simulator.

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 Green LED, Red LED, Yellow LED, Blue LED
 C Language
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a
button, or a Twitter message - and turn it into an output - activating a motor, turning on an
LED, publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
Serial.begin( )
- Configures a serial port with specified baud rate
Println
- To perform printing text followed by a newline character
Delay()

9
- Pauses the program for the amount of millisecond (ms)
Val
- Specify value or text to be printed on serial monitor
Digitalwrite()
- Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
Program :
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
void setup()

{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop()
{
if(a>15)
{
a=0;
}
f=a;
b=a%2;
a=a/2;
c=a%2;
a=a/2;
d=a%2;
a=a/2;
e=a%2;
a=f+1;
digitalWrite(0, b);
digitalWrite(1, c);
digitalWrite(2, d);
digitalWrite(3, e);
delay(500); }

Output :

10
Fig.4 –Circuit for displaying Hexadecimal pattern from 0 to F using 4 LEDs
Inference :
Thus, the circuit for displaying Hexadecimal pattern from 0 to F using 4 LEDs using
ARDUINO UNO has been verified using Tinkercad simulator and has been verified.
Task 5: Challenging Task
Aim : Write a program to design a traffic light controller system for a four lane junction
(North, South, East, West) to coordinate the traffic moves.
Use 12 LEDs (3 for each direction) for traffic light signal indication

In normal signalling operation, similar signal sequence are applied in opposite lanes (for ex.
east and west) with Green signal for 15 Sec. then Yellow for 2 Sec. and then Red.
Meanwhile, north & south lane will be at red.
Once this sequence is completed, switch to next opposite lanes (i.e north & south) and
carry out signalling with Green signal for 10 Sec. then Yellow signal for 2 Sec. and then Red
meanwhile, east & west lane will be in red.
Continuously switch between these two signal sequence.
Simulate and verify your design on Arduino Uno using Tinkercad circuits simulator.
Hint: Use 6 Digital pins for lane signalling LEDs (3 for East & West, 3 for North & South).

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 Green LED, Red LED, Yellow LED (4 each)
 C Language
General information:

11
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a
button, or a Twitter message - and turn it into an output - activating a motor, turning on an
LED, publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
Serial.begin( )
- Configures a serial port with specified baud rate
Println
- To perform printing text followed by a newline character
Delay()
- Pauses the program for the amount of millisecond (ms)
Val
- Specify value or text to be printed on serial monitor
Digitalwrite()
- Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
Program :
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop()
{
digitalWrite(0,HIGH);
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(15000); digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(2000);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);

12
digitalWrite(0,LOW);
digitalWrite(1,LOW);
digitalWrite(2,HIGH);
delay(15000);
digitalWrite(0,LOW);
digitalWrite(1,HIGH);
digitalWrite(2,LOW);
delay(2000);
}
Output :

Fig.5- Circuit for traffic light controller system

Inference :
Thus, the circuit for traffic light controller system using ARDUINO UNO has been
verified using Tinkercad simulator and has been verified.

13
Working with Serial Port
Date : 15/02/2021
Exp.No.: 2 Page No. 1
Task 1: Transmit a message to Serial port
Aim :
Write a program to transmit a message “WELCOME TO SENSE AND VIT CHENNAI ” using
serial port (Tx and Rx pins) to PC serial monitor window for every 2 seconds. Simulate and
verify this logic on Arduino Uno using Tinkercad circuits simulator.
Software / Components Required :
 Tinker CAD
 Arduino UNO
 C Language
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
 Serial.begin(speed) - Configures a serial port with specified baud rate.
- Serial: To access serial port in Arduino Uno.
- begin: To configuring serial port.
- speed: To specify the baud rate for serial communication
 Serial.println(val) - Prints data on serial port as human-readable ASCII text. -
println: To perform printing text followed by a newline character.
- val: Specify value or text to be printed on serial monitor.
Program :
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Welcome to SENSE and VIT Chennai");
delay(2000);
}
Output :

14
Fig.1 –Circuit for Transmiting the message

Inference :
Thus, the circuit for transmiting a message “WELCOME TO SENSE AND VIT CHENNAI ”
using serial port (Tx and Rx pins) using ARDUINO UNO has been verified using Tinkercad
simulator and has been verified.

Task 2 : Transmiting a message on serial window based on the slide switch state
Aim : Write a program to transmit a message on serial window based on the slide switch state.

 Connect the slide switch on one of the digital pins


 If the slide switch state is HIGH print your name on serial window
 If the slide switch state is LOW print your reg. no. on serial window
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

Software / Components Required :


 Tinker CAD
 Arduino UNO
 C Language
 Slide switch
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
 Serial.begin(speed) - Configures a serial port with specified baud rate.

15
- Serial: To access serial port in Arduino Uno.
- begin: To configuring serial port.
- speed: To specify the baud rate for serial communication
 Serial.println(val) - Prints data on serial port as human-readable ASCII text. -
println: To perform printing text followed by a newline character.
- val: Specify value or text to be printed on serial monitor.
 digitalRead(val) – reads the state of a digital pin.
- val: digital pin value.
Program :
int slide;
void setup()
{
pinMode(12,INPUT);
Serial.begin(9600);
}
void loop()
{
slide=digitalRead(12);
if(slide==HIGH)
{
Serial.println("Hemant Pamnani");
delay(2000);
}
else
{
Serial.println("18BEC1241");
delay(2000);
}
}
Output :

Fig.2-Circuit for Transmiting a message on serial window based on the slide switch state

16
Inference :
Thus, the circuit for transmiting a message on serial window based on the slide switch state using
ARDUINO UNO has been verified using Tinkercad simulator and has been verified.

Task 3: Controlling LED based on the input string received from user via serial port

Aim : Write a program to control the LED connected at pin 12 of digital pin based on the input
string received from user via serial port

 If the string is “ON”, print “ON” on serial window and switch ON the LED for 5 Seconds
 If the string is “OFF”, print “OFF” on serial window and switch ON the LED for 5 Seconds
 Otherwise print “BLINK” on serial window and blink the LED with the delay of 1 second

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 Green LED, Red LED, Yellow LED
 C Language
 Switch
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :

 Serial.begin(speed) - Configures a serial port with specified baud rate.


- Serial: To access serial port in Arduino Uno.
- begin: To configuring serial port.

17
- speed: To specify the baud rate for serial communication.

 Serial.println(val) - Prints data on serial port as human-readable ASCII text.


- println: To perform printing text followed by a newline character.
- val: Specify value or text to be printed on serial monitor.
 Serial.readString() - reads characters from the serial buffer into a String.
- readString: A String read from the serial buffer.
 digitalWrite(val) – Writes the state of a digital pin.
- val: In digital case it is HIGH or LOW.
Program :
String Readinput;
void setup()
{
pinMode(12, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Readinput=Serial.readString();
if(Readinput=="ON")
{
Serial.println("ON");
digitalWrite(12,HIGH);
delay(5000);
}
else if(Readinput=="OFF")
{Serial.println("OFF");
digitalWrite(12, LOW);
delay(5000);}
else
{
Serial.println("BLINK");
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(1000);
}}
Circuit :

18
Fig.3 – Circuit for controlling LED based on the input string received from user via serial
port

Inference :
Thus, the circuit for controlling LED based on the input string received from user via serial port
using ARDUINO UNO has been verified using Tinkercad simulator and has been verified.

Task 4: Controlling the LED based on received input string from user
Aim : Write a program to control three LEDs (Red, Green, Blue) connected at digital pins 9, 10 and
11 respectively. Get input string received from user via serial port and control the LED as per
following logic.

 If “RED”, print “RED” on serial window and switch ON only Red LED for 5 Seconds
 If “GREEN”, print “GREEN” on serial window and switch ON only Green LED for 5
Seconds
 If “BLUE” print “BLUE” on serial window and switch ON only Blue LED for 5 Seconds
 Otherwise print “ALL LEDs OFF” on serial window and make all LEDs in OFF state

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 Green LED, Red LED, Yellow LED, Blue LED
 C Language
General information:

19
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
Serial.begin( )
- Configures a serial port with specified baud rate
Println
- To perform printing text followed by a newline character
Delay()
- Pauses the program for the amount of millisecond (ms)
Val
- Specify value or text to be printed on serial monitor
Digitalwrite()
- Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
Program :
String Readinput;
void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}

void loop()
{
Readinput=Serial.readString();
if(Readinput=="RED")
{
Serial.println("RED");
digitalWrite(9,HIGH);
delay(5000);
}
else if(Readinput=="GREEN")
{Serial.println("GREEN");
digitalWrite(10, HIGH);
delay(5000);}
else if(Readinput=="BLUE")
{Serial.println("BLUE");

20
digitalWrite(11, HIGH);
delay(5000);}
else
{
Serial.println("ALL LEDs OFF");
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
delay(1000);
}}
Circuit:

Fig.4 –Circuit for controlling the LED based on received input string from user
Output:-

Inference :
Thus, the circuit for controlling the LED based on received input string from user using
ARDUINO UNO has been verified using Tinkercad simulator and has been verified.

21
Task 5
Aim : Write a program to control the LED brightness using PWM signal generated on digital pin
6 with different duty cycle. Verify the duty cycle using oscilloscope.
Case-1: 0% duty cycle
Case-2: 50% duty cycle
Case-3: 100% duty cycle
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 Green LED, Red LED, Yellow LED (4 each)
 C Language
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
Serial.begin( )
- Configures a serial port with specified baud rate
Println
- To perform printing text followed by a newline character
Delay()
- Pauses the program for the amount of millisecond (ms)
Val
- Specify value or text to be printed on serial monitor
Digitalwrite()
- Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
Program :
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);

22
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop()
{
digitalWrite(0,HIGH);
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(15000); digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(2000);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(0,LOW);
digitalWrite(1,LOW);
digitalWrite(2,HIGH);
delay(15000);
digitalWrite(0,LOW);
digitalWrite(1,HIGH);
digitalWrite(2,LOW);
delay(2000);
}
Output :

Fig.5- Circuit for traffic light controller system


Inference :
Thus, the circuit for traffic light controller system using ARDUINO UNO has been
verified using Tinkercad simulator and has been verified
Task 6: Working with RGB LED

Aim : Write a program to control the RGB LED state in yellow, cyan, magenta using PWM
signal. Find the correct combination value of RGB for different colours and blink each LED with

23
3 seconds delay between them. Simulate and verify this logic on Arduino Uno using Tinkercad
circuits simulator.

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 RGB LED
 C Language
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
analogWrite(pin, value) - Writes an analog value (PWM wave) to a pin.
- pin: Arduino pin to write to. Allowed data types: int.
- value: duty cycle: between 0 (OFF) and 255 (ON). Allowed data types: int.

Example:
- analogWrite(6, 0) means a signal of 0% duty cycle generated on pin 6.
- analogWrite(6, 127) means a signal of 50% duty cycle generated on pin 6.
- analogWrite(6, 255) means a signal of 100% duty cycle generated on pin 6.
Program :
int GREEN=9;
int BLUE=10;
int RED=11;
void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop()
{
analogWrite(GREEN,255);
analogWrite(BLUE,0);
analogWrite(RED,255);
delay(3000);
analogWrite(GREEN,255);
analogWrite(BLUE,255);
analogWrite(RED,0);
delay(3000);
analogWrite(GREEN,0);

24
analogWrite(BLUE,255);
analogWrite(RED,255);
delay(3000);
}
Output :

Fig.5- Circuit for controlling RGB state using PWM signal


Inference :
Thus, the circuit for controlling RGB state using PWM signal using ARDUINO UNO has been
verified using Tinkercad simulator and has been verified.
Challenging Task 1:-
Aim:- Write a program to control the DC motor at different speed levels using PWM signal by
generating following duty cycle when corresponding DIP switch is activated. Verify the duty cycle
value on oscilloscope.
 If DIP switch-1 is ON then generate 0% duty cycle
 If DIP switch-2 is ON then generate 25% duty cycle
 If DIP switch-3 is ON then generate 50% duty cycle
 If DIP switch-4 is ON then generate 75% duty cycle
 Otherwise generate 100% duty cycle
 Print the duty cycle value on the serial window

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor
 RGB LED
 C Language
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a

25
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
analogWrite(pin, value) - Writes an analog value (PWM wave) to a pin.
- pin: Arduino pin to write to. Allowed data types: int.
- value: duty cycle: between 0 (OFF) and 255 (ON). Allowed data types: int.

Example:
- analogWrite(6, 0) means a signal of 0% duty cycle generated on pin 6.
- analogWrite(6, 127) means a signal of 50% duty cycle generated on pin 6.
- analogWrite(6, 255) means a signal of 100% duty cycle generated on pin 6.
Program :
int SWITCH1 = 5;
int SWITCH2 = 4;
int SWITCH3 = 3;
int SWITCH4 = 2;
int SWITCHSTATE1;
int SWITCHSTATE2;
int SWITCHSTATE3;
int SWITCHSTATE4;

void setup()
{
pinMode(6, OUTPUT);
pinMode(SWITCH1, INPUT);
pinMode(SWITCH2, INPUT);
pinMode(SWITCH3, INPUT);
pinMode(SWITCH4, INPUT);
Serial.begin(9600);
}
void loop()
{
SWITCHSTATE1 = digitalRead(SWITCH1);
SWITCHSTATE2 = digitalRead(SWITCH2);
SWITCHSTATE3 = digitalRead(SWITCH3);
SWITCHSTATE4 = digitalRead(SWITCH4);
if(SWITCHSTATE1 == HIGH && SWITCHSTATE2 == LOW && SWITCHSTATE3 ==
LOW && SWITCHSTATE4 == LOW)
{
analogWrite(6,0);
Serial.println("0% DUTY CYCLE");
}
else if(SWITCHSTATE1 == LOW && SWITCHSTATE2 == HIGH && SWITCHSTATE3
== LOW && SWITCHSTATE4 == LOW)
{

26
analogWrite(6,64);
Serial.println("25% DUTY CYCLE");
}
else if(SWITCHSTATE1 == LOW && SWITCHSTATE2 == LOW && SWITCHSTATE3 ==
HIGH && SWITCHSTATE4 == LOW)
{
analogWrite(6,127);
Serial.println("50% DUTY CYCLE");
}
else if(SWITCHSTATE1 == LOW && SWITCHSTATE2 == LOW && SWITCHSTATE3 ==
LOW && SWITCHSTATE4 == HIGH)
{
analogWrite(6,192);
Serial.println("75% DUTY CYCLE");
}
else
{
analogWrite(6,255);
Serial.println("100% DUTY CYCLE");
}
}
Output :
0 % (Switch 2 ON):

27
25 % (Switch 2 ON):

28
50 % (Switch 2 ON):

29
75 % (Switch 2 ON):

30
100 % (Switch 2 ON):

31
Inference:-
We have learnt how to integrate a DIP Switch SPSTx4 with Arduino Uno. Using the DIP Switch
and the if condition, we were able to produce different duty cycle square waveforms on pin 6
using PWM and API analogWrite(). The Duty Cycle percentage was also displayed in Serial
Monitor.

Result:-
Thus, we have written a program to control the DC motor at different speed levels using PWM
signal by generating following duty cycle when corresponding DIP switch is activated was
verified and simulated using TinkerCad Simulator.

Challenging Task2:-
Aim:- Write a program to glow the selective LED colour on RGB LEB by receiving input from
user via serial port as per below logic.
 If user press a key “G” then glow grey colour on RGB led for 2 seconds
 If user press a key “T” then glow teal colour on RGB led for 2 seconds
 If user press a key “M” then glow maroon colour on RGB led for 2 second
 If user press a key “O” then glow olive colour on RGB led for 2 seconds
 If user press a key “P” then glow purple colour on RGB led for 2 seconds
 If none of these pressed then glow an random colour on RGB LED
 For every selected colour, print its colour name of serial window

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

Software / Components Required :


 Tinker CAD
 Arduino UNO
 Resistor

32
 RGB LED
 C Language
General information:
Tinker CAD:- Tinkercad is a free, online 3D modeling program that runs in a web browser,
known for its simplicity and ease of use. Since it became available in 2011 it has become a
popular platform for creating models for 3D printing as well as an entry-level introduction to
constructive solid geometry in schools.
Arduino UNO:- Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online.
LED:- A light-emitting diode (LED) is a semiconductor light source that emits light when
current flows through it.
API used :
analogWrite(pin, value) - Writes an analog value (PWM wave) to a pin.
- pin: Arduino pin to write to. Allowed data types: int.
- value: duty cycle: between 0 (OFF) and 255 (ON). Allowed data types: int.

Example:
- analogWrite(6, 0) means a signal of 0% duty cycle generated on pin 6.
- analogWrite(6, 127) means a signal of 50% duty cycle generated on pin 6.
- analogWrite(6, 255) means a signal of 100% duty cycle generated on pin 6.
Program :
String ch;
void setup()
{
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}

void loop()
{
ch=Serial.readString();
if(ch=="G")
{
analogWrite(6,128);
analogWrite(5,128);
analogWrite(3,128);
delay(2000);
Serial.println("grey");
}
else if(ch=="T")
{
analogWrite(6,0);
analogWrite(5,128);
analogWrite(3,128);
delay(2000);
}

33
else if(ch=="M")
{
analogWrite(6,128);
analogWrite(5,0);
analogWrite(3,0);
delay(2000);
Serial.println("teal");
}
else if(ch=="O")
{
analogWrite(6,128);
analogWrite(5,128);
analogWrite(3,0);
delay(2000);
Serial.println("maroon");
}
else if(ch=="P")
{
analogWrite(6,128);
analogWrite(5,0);
analogWrite(3,128);
delay(2000);
Serial.println("purple");
}
else
{
analogWrite(6,255);
analogWrite(5,0);
analogWrite(3,0);
delay(2000);
}
}
Output :

34
Fig.7- Circuit for glowing the selective LED colour on RGB LEB by receiving input from
user via serial port

Inference :
Thus, the circuit for glowing the selective LED colour on RGB LEB by receiving input from
user via serial port using ARDUINO UNO has been verified using Tinkercad simulator and has
been verified.

35
Working with 7 Segment Display
Date : 03/02/2021
Exp.No.: 3 Page No. 1

TASK-1Display hexadecimal values from 0 to F


AIM:
Write a program to display hexa decimal values from 0 to F on the 7-segment display
interfaced with digital pins of Arduino Uno board. Once the sequence is completed
from 0 to F then repeat the sequence again.Simulate and verify this logic on Arduino
Uno using Tinkercad circuits simulator.

API REQUIRED:
 pinMode(pin, mode) - Configures the specified pin to either input or output.
- pin: the Arduino pin number to set the mode of.
- mode: INPUT, OUTPUT, or INPUT_PULLUP.
 digitalWrite(pin, value) - Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
 delay(ms) - Pauses the program for the amount of time (in milliseconds)
- ms: the number of milliseconds to pause.

PROGRAM:
int segPins[] = {4,5,7,8,9,11,10,6};
int segCode[16][8] = {
{0,0,0,0,0,0,1,1},//0
{1,0,0,1,1,1,1,1},//1
{0,0,1,0,0,1,0,1},//2
{0,0,0,0,1,1,0,1},//3
{1,0,0,1,1,0,0,1},//4
{0,1,0,0,1,0,0,1},//5
{0,1,0,0,0,0,0,1},//6
{0,0,0,1,1,1,1,1},//7
{0,0,0,0,0,0,0,1},//8
{0,0,0,0,1,0,0,1},//9
{0,0,0,0,0,1,0,1},//a
{1,1,0,0,0,0,0,1},//b
{0,1,1,0,0,0,1,1},//c
{1,0,0,0,0,1,0,1},//d

[18BEC1241] ECE4003-Embedded System Design


{0,0,1,0,0,0,0,1},//e
{0,1,1,1,0,0,0,1}//f
};
void setup()
{
for(int i=0;i<8;i++)
{
pinMode(segPins[i],OUTPUT);
}
}
void loop()
{
for(int n=0;n<16;n++)
{
displayDigit(n);
delay(1000);
}
}
void displayDigit(int digit)
{
for(int i=0;i<8;i++)
{
digitalWrite(segPins[i],segCode[digit][i]);
}
}

OUTPUT: Screenshot of circuit from tinkercad simulator


1

[18BEC1241] ECE4003-Embedded System Design


Fig. 1 Circuit to display hexa decimal values from 0 to F on the 7-segment display
9

INFERENCE:
Here we are using 7 segment display in common anode configuration and we are
displaying hexadecimal number from 0 to f continuously using it. In order to display 0 we
are making a=0, b=0, c=0, d=0, e=0, f=0 , g=1and dp=1 where 0 signifies ON mode and 1
signifies OFF mode. Similarly, we are doing for the rest
RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.

[18BEC1241] ECE4003-Embedded System Design


TASK-2
AIM:
To write a program to display a two digit decimal numbers from 00 to 99 using 7- segment
LEDs. Use common digital pins of Arduino Uno for both 7-segments LED connection and
display the digit using multiplexing logic i.e one digit at a time on each 7-Segment with
small delay values (few ms). Use a slide switch to stop the number sequencing. Simulate
and verify this logic on Arduino Uno using Tinkercad circuits simulator.
API REQUIRED:
 pinMode(pin, mode) - Configures the specified pin to either input or output.
- pin: the Arduino pin number to set the mode of.
- mode: INPUT, OUTPUT, or INPUT_PULLUP.
 digitalWrite(pin, value) - Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
 delay(ms) - Pauses the program for the amount of time (in milliseconds)
- ms: the number of milliseconds to pause.
 digitalRead(pin) – Read a HIGH or a LOW value from a digital pin.
-pin: the Arduino pin number.
 millis() - record number of milliseconds passed since the current program began the
execution.

PROGRAM:
int segPins[]={4,5,7,8,9,11,10,6};
int displayPins[2]={12,13}; int displayBuf[2];

[18BEC1241] ECE4003-Embedded System Design


int sw=3; int i=0,j=0;
int startTime=0; unsigned long endTime;

int segCode[11][8]={
{0,0,0,0,0,0,1,1}, //0
{1,0,0,1,1,1,1,1}, //1
{0,0,1,0,0,1,0,1}, //2
{0,0,0,0,1,1,0,1}, //3
{1,0,0,1,1,0,0,1}, //4
{0,1,0,0,1,0,0,1}, //5
{0,1,0,0,0,0,0,1}, //6
{0,0,0,1,1,1,1,1}, //7
{0,0,0,0,0,0,0,1}, //8
{0,0,0,0,1,0,0,1}, //9
{1,1,1,1,1,1,1,0}, //.
};
void Display(int digit1,int digit0)
{
digitalWrite(displayPins[0],HIGH); digitalWrite(displayPins[1],LOW);
setSegments(digit0);
delay(5);
digitalWrite(displayPins[0],LOW); digitalWrite(displayPins[1],HIGH);
setSegments(digit1);
delay(5);
}
void setSegments(int n)
{
for(int i=0;i<8;i++)
{
digitalWrite(segPins[i],segCode[n][i]);
}
}
void setup()
{
for(int i=0;i<8;i++)

{
pinMode(segPins[i],OUTPUT);
}
pinMode(displayPins[0],OUTPUT); pinMode(displayPins[1],OUTPUT);
pinMode(sw,INPUT); displayBuf[0]=0;
displayBuf[1]=0;
}

[18BEC1241] ECE4003-Embedded System Design


void loop()
{
int swstate=digitalRead(sw); if(swstate==HIGH)
{
Display(displayBuf[1],displayBuf[0]); endTime=millis();
if((endTime-startTime)>=1000)
{
if(++i>9)
{
i=0;
if(++j>9)
{
j=0;
}
}
displayBuf[0]=i; displayBuf[1]=j; startTime=endTime;
}
}

else
{
Display(displayBuf[1],displayBuf[0]);
}
}

OUTPUT: Screenshot of circuit from tinkercad simulator


01

[18BEC1241] ECE4003-Embedded System Design


Fig 2. Circuit for displaying a two digit decimal numbers from 00 to 99 using 7-
segment LEDs

09

INFERENCE:
Here we are using two 7 segment display to display number from 00 to 99 in decimal
format. millis() API is used to record number of milliseconds passed since the current
program began the execution and according to this command is send to the display to
display numbers in required format.
RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.

TASK-3:

AIM:
Write a program to design a token display system which helps to serve the customer
without the need of standing in a queue. This display system consist of two 7-sevensgment
display to display token numbers from 00 to 99, and token numbers are received into
Arduino Uno via serial port from PC. For every token displayed on 7-segment activate the

[18BEC1241] ECE4003-Embedded System Design


buzzer to alert the customer. Simulate and verify this logic on Arduino Uno using
Tinkercad circuits simulator.

API REQUIRED:
digitalWrite(x,y) :- It will make the pin x high if y=HIGH otherwise low if y=LOW
delay(x) :- It will create a delay of x seconds.
PinMode(x,y) :- it will make the pin x as input pin if y=INPUT otherwise output if
y=OUTPUT.
Serial.begin(x) :- it will start the serial communication with a speed of x baud rate.
Serial.parseInt() :- It is used to read an integer from the serial window.
Serial.available() :- It is used to check if the user is typing something in the serial monitor
or not.

PROGRAM:
int segPins[]={4,5,7,8,9,11,10,6};
int displayPins[2]={12,13};
int displayBuf[2];
int sw=3;
int i=0,j=0;
int startTime=0;
int a1;
int a2=0;
int a3=0;
unsigned long endTime;
int segCode[11][8]={
{0,0,0,0,0,0,1,1}, //0
{1,0,0,1,1,1,1,1}, //1
{0,0,1,0,0,1,0,1}, //2
{0,0,0,0,1,1,0,1}, //3
{1,0,0,1,1,0,0,1}, //4
{0,1,0,0,1,0,0,1}, //5
{0,1,0,0,0,0,0,1}, //6
{0,0,0,1,1,1,1,1}, //7
{0,0,0,0,0,0,0,1}, //8
{0,0,0,0,1,0,0,1}, //9
{1,1,1,1,1,1,1,0}, //.
};
void Display(int digit1,int digit0)
{
digitalWrite(displayPins[0],HIGH);
digitalWrite(displayPins[1],LOW);
setSegments(digit0);
delay(5);
digitalWrite(displayPins[0],LOW);

[18BEC1241] ECE4003-Embedded System Design


digitalWrite(displayPins[1],HIGH);
setSegments(digit1);
delay(5);
}
void setSegments(int n)
{
for(int i=0;i<8;i++)
{
digitalWrite(segPins[i],segCode[n][i]);
}
}
void setup()
{
Serial.begin(9600);
for(int i=0;i<8;i++)
{pinMode(segPins[i],OUTPUT);
}
pinMode(displayPins[0],OUTPUT);
pinMode(displayPins[1],OUTPUT);
pinMode(sw,INPUT);
pinMode(2,OUTPUT);
displayBuf[0]=0;
displayBuf[1]=0;
}
void loop()
{
a1=Serial.parseInt();
a3=a1/10;
a2=a1-a3*10;
digitalWrite(2,HIGH);
while (Serial.available()==0){
Display(a3,a2);
digitalWrite(2,LOW);
}
}
OUTPUT:-

[18BEC1241] ECE4003-Embedded System Design


INFERENCE:
Whenever we will type an integer between 0 to 99 in the serial window it will be displayed
in the two seven segment display in correct format and also buzzer will become ON for
some time.
RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.

CHALLENGING TASK-1
AIM:
Write a program to a digital stop watch with start/stop and reset option. This system
consist of three 7-segment LED unit to display the timing in milliseconds precision.
 First and second 7-segment LED display seconds value
 The last 7-segment LED displays milliseconds value
 Use slide switch to start/stop the counting (HIGH-Start, LOW-Stop)
 Use push button to reset the counting to initial value (HIGH-Reset)
 Once it reaches it’s maximum counting, continue again with initial value

[18BEC1241] ECE4003-Embedded System Design


Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
pinMode(pin, mode) - Configures the specified pin to either input or output.
- pin: the Arduino pin number to set the mode of.
- mode: INPUT, OUTPUT, or INPUT_PULLUP.
● digitalWrite(pin, value) - Write a HIGH or a LOW value to a digital pin.
- pin: the Arduino pin number.
- value: HIGH or LOW.
● delay(ms) - Pauses the program for the amount of time (in milliseconds)
- ms: the number of milliseconds to pause.

PROGRAM:
int segPins[]={4,5,7,8,9,11,10,6};
int displayPins[3]={2,12,13}; int displayBuf[3];
int sw=3;
int i=0,j=0,k=0; int startTime=0;
unsigned long endTime;

int segCode[11][8]={
{0,0,0,0,0,0,1,1}, //0
{1,0,0,1,1,1,1,1}, //1
{0,0,1,0,0,1,0,1}, //2
{0,0,0,0,1,1,0,1}, //3
{1,0,0,1,1,0,0,1}, //4
{0,1,0,0,1,0,0,1}, //5

{0,1,0,0,0,0,0,1}, //6
{0,0,0,1,1,1,1,1}, //7
{0,0,0,0,0,0,0,1}, //8
{0,0,0,0,1,0,0,1}, //9
{1,1,1,1,1,1,1,0}, //.
};

void Display(int digit2,int digit1,int digit0)


{
digitalWrite(displayPins[0],HIGH); digitalWrite(displayPins[1],LOW);
digitalWrite(displayPins[2],LOW); setSegments(digit0);
delay(5);

digitalWrite(displayPins[0],LOW); digitalWrite(displayPins[1],HIGH);
digitalWrite(displayPins[2],LOW); setSegments(digit1);
delay(5);

[18BEC1241] ECE4003-Embedded System Design


digitalWrite(displayPins[0],LOW); digitalWrite(displayPins[1],LOW);
digitalWrite(displayPins[2],HIGH); setSegments(digit2);
delay(5);
}
void setSegments(int n)
{
for(int i=0;i<8;i++)
{
digitalWrite(segPins[i],segCode[n][i]);

}
}

void setup()
{
for(int i=0;i<8;i++)
{
pinMode(segPins[i],OUTPUT);
}
pinMode(displayPins[0],OUTPUT); pinMode(displayPins[1],OUTPUT);
pinMode(displayPins[2],OUTPUT); pinMode(sw,INPUT); pinMode(1,INPUT);
displayBuf[0]=0;
displayBuf[1]=0; displayBuf[2]=0;
}

void loop()
{
int l1=0; int l2=0; int l3=0;
int swstate=digitalRead(sw); int l5=digitalRead(1); if(swstate==HIGH)
{
while(l1<6)
{
while(l2<9)
{

while(l3<9)
{
Display(l1,l2,l3); delay(100); l3++;

} l2++; l3=0;

[18BEC1241] ECE4003-Embedded System Design


}
l1++; l2=0;
}
}
if(l5==HIGH)
{
l1=0; l2=0; l3-0;
}
}

OUTPUT:

INFERENCE:
Here we are using rightmost 7 segment display to display the milli-seconds . Leftmost and
middle situated 7 segment display is used to display the seconds. Push button is used to
reset the clock and slide switch is used to pause the clock.

RESULT:
Hence, we have designed the required circuit and also verified the result using Tinkercad
circuit simulator.

[18BEC1241] ECE4003-Embedded System Design


Working with IR sensor
Date : 10/03/2021
Exp.No.: 4 Page No. 1

TASK-1 Identifying IR code/values for each key on IR Remote


AIM:
Write a program to identify the IR code/values (in decimal) for each key on IR Remote and
print it on the serial monitor. The IR receiver is connected one of the digital pin to receive
the IR code/value. Simulate and verify this logic on Arduino Uno using Tinkercad circuits
simulator.
API REQUIRED:
 IRrecv irrecv(receivePin) : Create the receiver object, using a name of your
choice.
 irrecv.enableIRIn() : Begin the receiving process.
 irrecv.decode(&results) : Attempt to receive a IR code and stored into "results".
Returns true if a code was received, or false if nothing received yet.
- results.value: The actual IR code (0 if type is UNKNOWN)
- results.bits: The number of bits used by this code
 irrecv.resume() : After receiving, this must be called to reset the receiver and
prepare it to receive another code.

PROGRAM:
#include<IRremote.h>
decode_results results;
IRrecv irrecv(12);
void setup()
{
irrecv.enableIRIn();
Serial.begin(9600);
}

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

OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 49


[18BEC1241] ECE4003-Embedded System Design LabPage No: 50
INFERENCE:
Whenever a button in the remote is pressed it sends a signal in the form of IR and it is
received by IR sensor. After receiving the signal, it is decoded and the decoded output is
shown in the serial window.
RESULT:
Hence, we have made the required circuit and verified the result using tinkercad.com.

TASK-2
AIM
Write a program for IR Remote Controlled Home Automation using Arduino Uno, in
which IR remote control two appliances (Blub and Fan) via relay as per following logic.
 When “power button” is pressed switch ON both appliances, if the same
button is pressed again switch OFF both appliances
 When key “1” is pressed switch ON bulb, if the same key pressed again
switch OFF the bulb
 When key “2” is pressed switch ON fan(DC motor), if the same key pressed
again switch OFF the FAN (DC motor)
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.
API REQUIRED:
 IRrecv irrecv(receivePin) : Create the receiver object, using a name of your
choice.
 irrecv.enableIRIn() : Begin the receiving process.
 irrecv.decode(&results) : Attempt to receive a IR code and stored into "results".
Returns true if a code was received, or false if nothing received yet.
- results.value: The actual IR code (0 if type is UNKNOWN)
- results.bits: The number of bits used by this code
 irrecv.resume() : After receiving, this must be called to reset the receiver and
prepare it to receive another code.
PROGRAM:
#include <IRremote.h>
#define code1 16582903
#define code2 16615543
#define code3 16580863
int RECV_PIN=12;
IRrecv irrecv(RECV_PIN);
decode_results results;
int BULB=3;
int FAN=2;
int BULB_STATUS=0;
int FAN_STATUS=0;
void setup()

[18BEC1241] ECE4003-Embedded System Design LabPage No: 51


{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(BULB,OUTPUT);
pinMode(FAN,OUTPUT);
}
void loop()
{
if(irrecv.decode(&results))
{
unsigned int value=results.value;
switch(value)
{
case code1:
if(BULB_STATUS==1)
{
digitalWrite(BULB,LOW);
BULB_STATUS=0;
}
else
{
digitalWrite(BULB,HIGH);
BULB_STATUS=1;
}
break;
case code2:
if(FAN_STATUS==1)
{
digitalWrite(FAN,LOW);
FAN_STATUS=0;
}
else
{
digitalWrite(FAN,HIGH);
FAN_STATUS=1;
}
break;
case code3:
if(BULB_STATUS==1 && FAN_STATUS==1)
{
digitalWrite(BULB,LOW);
BULB_STATUS=0;
digitalWrite(FAN,LOW);
FAN_STATUS=0;

[18BEC1241] ECE4003-Embedded System Design LabPage No: 52


}
else
{
digitalWrite(BULB,HIGH);
BULB_STATUS=1;
digitalWrite(FAN,HIGH);
FAN_STATUS=1;
}
}
Serial.println(value);
irrecv.resume();
}
}
OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 53


INFERENCE:
Whenever 1 is pressed in the remote then bulb will be turned ON, similarly
whenever 2 is pressed in the remote then motor will be turned ON. Also whenever
power button will bepressed then if both the devices will be in OFF stage then both
the devices will be turned ON other wise both the devices will be turned OFF.
RESULT:
Hence, we have made the required circuit and also verified the result using
tinkercad.com

TASK-3
AIM:
Write a program for automatic staircase light using PIR sensor in which this system switch
ON the staircase light automatically when someone enters on the stairs and gets off after 5
Seconds. Simulate and verify this logic on Arduino Uno using Tinkercad circuits
simulator.
API REQUIRED:
 IRrecv irrecv(receivePin) : Create the receiver object, using a name of your
choice.
 irrecv.enableIRIn() : Begin the receiving process.
 irrecv.decode(&results) : Attempt to receive a IR code and stored into "results".

[18BEC1241] ECE4003-Embedded System Design LabPage No: 54


Returns true if a code was received, or false if nothing received yet.
- results.value: The actual IR code (0 if type is UNKNOWN)
- results.bits: The number of bits used by this code
 irrecv.resume() : After receiving, this must be called to reset the receiver and
prepare it to receive another code.

PROGRAM:
int sensor_pin=11;
int relay_pin=2;
int output;

void setup()
{
Serial.begin(9600);
pinMode(relay_pin,OUTPUT);
pinMode(sensor_pin,INPUT);
//digitalWrite(relay_pin,HIGH);

void loop()
{
output=digitalRead(sensor_pin);
if(output==1)
{
digitalWrite(relay_pin,LOW);
delay(5000);
}
else if(output==0)
{
digitalWrite(relay_pin,HIGH);
}
Serial.println(output);
delay(100);
}

OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 55


[18BEC1241] ECE4003-Embedded System Design LabPage No: 56
INFERENCE:
Whenever motion is detected by the PIR sensor then the bulb will be turned ON for
5 seconds otherwise bulb will be in OFF stage.

RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.

CHALLENGING TASK-1
AIM:
Write a program for IR Remote Controlled robot using Arduino Uno, in which IR remote
control the movement of the robot by controlling its left and right wheels (DC motor) as
per following logic.
 When “UP” key is pressed make the robot to move in forward direction with
left and right wheel on same rpm (positive)

[18BEC1241] ECE4003-Embedded System Design LabPage No: 57


 When “DOWN” key is pressed make the robot to move in reverse direction
with left and right wheel on same rpm (negative)
 When “LEFT” key is pressed, stop the left wheel( 0 rpm) and maximum
positive rpm on right wheel to move towards left direction
 When “RIGHT” key is pressed, stop the right wheel( 0 rpm) and maximum
positive rpm on left wheel to move towards right direction
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
 IRrecv irrecv(receivePin) : Create the receiver object, using a name of your
choice.
 irrecv.enableIRIn() : Begin the receiving process.
 irrecv.decode(&results) : Attempt to receive a IR code and stored into "results".
Returns true if a code was received, or false if nothing received yet.
- results.value: The actual IR code (0 if type is UNKNOWN)
- results.bits: The number of bits used by this code
 irrecv.resume() : After receiving, this must be called to reset the receiver and
prepare it to receive another code.

PROGRAM:
#include<IRremote.h>
#define code1 16613503
#define code2 16617583
#define code3 16605343
#define code4 16589023
int RECV_PIN=7;
IRrecv irrecv(RECV_PIN);
decode_results results;
int right_clockwise=13;
int right_anticlockwise=11;
int left_clockwise=12;
int left_anticlockwise=9;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(right_clockwise,OUTPUT);
pinMode(right_anticlockwise,OUTPUT);
pinMode(left_clockwise,OUTPUT);
pinMode(left_anticlockwise,OUTPUT);
}

[18BEC1241] ECE4003-Embedded System Design LabPage No: 58


void loop()
{
if (irrecv.decode(&results))
{
unsigned int value = results.value; switch (value) {

case code1: digitalWrite(right_clockwise,HIGH); digitalWrite(left_clockwise,HIGH);


digitalWrite(right_anticlockwise,LOW); digitalWrite(left_anticlockwise,LOW); break;

case code2: digitalWrite(right_clockwise,LOW); digitalWrite(left_clockwise,LOW);


digitalWrite(right_anticlockwise,HIGH); digitalWrite(left_anticlockwise,HIGH); break;
case code3: digitalWrite(right_clockwise,HIGH); digitalWrite(right_anticlockwise,LOW);
digitalWrite(left_clockwise,LOW); digitalWrite(left_anticlockwise,LOW);

break; case code4:


digitalWrite(right_clockwise,LOW); digitalWrite(right_anticlockwise,LOW);
digitalWrite(left_clockwise,HIGH); digitalWrite(left_anticlockwise,LOW); break;
}
Serial.println(value); irrecv.resume();
}

OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 59


INFERENCE:

[18BEC1241] ECE4003-Embedded System Design LabPage No: 60


Here whenever vol + key is pressed then both the dc motor will start rotating in
clockwise direction at same speed and whenever vol – key is pressed then both the dc
motor will start rotating in anticlockwise direction. Also whenever left key is pressed
then only right dc motor will rotate in clockwise direction and whenever right key is
pressed then only left motor will rotate in clockwise direction.

RESULT:
Hence, we have designed the required circuit and verified the result using tinkercad.com.

CHALLENGING TASK-2

AIM:
Write a program to design a bidirectional visitor counter using PIR sensor. This system
consist of two PIR sensor, one on the entry another on exit side. For every human detection
on entry side increment count value and every human detection on exit side decrement
count value. Whenever human presence detected on entry/exit open the automatic door
(DC motor) for 5 seconds and close automatically. Use one 7-segment to display number
of human inside the room. Also, ensure always maximum number of human present inside
the room must be 9. If an whenever any attempt made to enter the room when number of
human count is already 9 inside the room then switch ON the buzzer. Simulate and verify
this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
1. digitalWrite(x,y) :- It will make the pin x high if y=HIGH otherwise low if y=LOW
2. delay(x) :- It will create a delay of x seconds.
3. PinMode(x,y) :- it will make the pin x as input pin if y=INPUT otherwise output if
y=OUTPUT.
4. digitalRead(x) :- Used to read the input from the pin x

PROGRAM:
int segPins[]={4,5,7,8,9,11,10,6};
int count=0;
int segCode[10][8]={
{0,0,0,0,0,0,1,1}, //0
{1,0,0,1,1,1,1,1}, //1
{0,0,1,0,0,1,0,1}, //2
{0,0,0,0,1,1,0,1}, //3

[18BEC1241] ECE4003-Embedded System Design LabPage No: 61


{1,0,0,1,1,0,0,1}, //4
{0,1,0,0,1,0,0,1}, //5
{0,1,0,0,0,0,0,1}, //6
{0,0,0,1,1,1,1,1}, //7
{0,0,0,0,0,0,0,1}, //8
{0,0,0,0,1,0,0,1}, //9
};
void setup()
{
for(int i=0;i<8;i++)
{
pinMode(segPins[i],OUTPUT);
}
pinMode(12,INPUT);
pinMode(3,INPUT);
pinMode(2,OUTPUT);
}
void displayDigit(int digit)
{
for(int i=0;i<8;i++)
{
digitalWrite(segPins[i],segCode[digit][i]);
}
}
void loop()
{
int x=digitalRead(3);
int y=digitalRead(12);
if(x==1)
{
if(count>9)
{
count--;
digitalWrite(1,HIGH);
delay(5000);
digitalWrite(1,HIGH);
}
else
{
count=count+1;
digitalWrite(2,HIGH);
delay(5000);
digitalWrite(2,LOW);
}

[18BEC1241] ECE4003-Embedded System Design LabPage No: 62


}
else if(y==1 && count>0)
{
count=count-1;
digitalWrite(13,HIGH);
delay(5000);
digitalWrite(13,LOW);
}
if(count>=0 && count<=9)
{
displayDigit(count);
}
else
{
displayDigit(9);
}
}
OUTPUT:

INFERENCE:
Here, whenever a motion is detected by the right PIR sensor then count is incremented by 1
if it is less than 9 and also DC motor in the right is turned ON for 5 seconds otherwise if it
is greater than 9 then buzzer will be turned ON for warning purpose. Also when PIR sensor
in the left detects a motion then count is decremented by 1 if it is greater than zero also DC
motor in the left is turned ON for 5 seconds.
RESULT:
Hence, we have designed the circuit and verified the result using tinkercad.com .

[18BEC1241] ECE4003-Embedded System Design LabPage No: 63


Working with ADC
Date : 24/03/2021
Exp.No.: 5 Page No. 1

TASK-1 Read the Potentiometer and print its value on the Serial Window
AIM:
Write a program to identify the IR code/values (in decimal) for each key on IR Remote and
print it on the serial monitor. The IR receiver is connected one of the digital pin to receive
the IR code/value. Simulate and verify this logic on Arduino Uno using Tinkercad circuits
simulator.

API REQUIRED:
 analogRead(pin) - Reads the value from a specified analog pin with a 10-bit
resolution

PROGRAM:
int sensorValue=0;
float volt=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
sensorValue=analogRead(A0);
volt=(sensorValue*4.88)/1000;
Serial.print("sensorValue=");
Serial.println(sensorValue);
Serial.print("Voltage");
Serial.println(volt);
delay(1000);
}
OUTPUT:
(output screenshot with register number)

[18BEC1241] ECE4003-Embedded System Design LabPage No: 64


Fig 1 Circuit diagram for identification of the IR code/values

RESULT:
Hence, we have made the required circuit and verified the result using tinkercad.com.

TASK-2
AIM
Write a program for controlling the speed of the DC motor by varying the potentiometer
connected to one of the analog pin. Simulate and verify this logic on Arduino Uno using
Tinkercad circuits simulator.
API REQUIRED:

 analogRead(pin) - Reads the value from a specified analog pin with a 10-bit
resolution
 analogWrite(pin,value) - Writes the analog value to the specified pin with a 10-bit
resolution.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 65


PROGRAM:
int sensorValue=0;
float volt=0;
int speed=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
sensorValue=analogRead(A0);
speed=sensorValue/4;
volt=(sensorValue*4.88)/1000;
analogWrite(6,speed);
Serial.print("sensorValue=");
Serial.println(sensorValue);
Serial.print("Voltage=");
Serial.println(volt);
delay(1000);
}
OUTPUT: Screenshot of circuit from tinkercad simulator

Fig. 2 Circuit diagram for controlling the speed of the DC motor by varying the
potentiometer

[18BEC1241] ECE4003-Embedded System Design LabPage No: 66


INFERENCE:
Here, we are taking input from an analog pin A0 through a potentiometer. Then we are
giving that analog input value to the motor. As we vary the input using potentiometer we
can observe the variation in the speed of the motor.
RESULT:
Hence, we have made the required circuit and also verified the result using
tinkercad.com

TASK-3

AIM:
Write a program to design a voltage level indicator system using potentiometer and LEDs.
The system must display the different level of the voltage with the help of 5 LEDs as per
following conditions.
 If the voltage is between 0 to 1V glow LED1
 If the voltage is between 1 to 2V glow LED1 and LED2
 If the voltage is between 2 to 3V glow LED1 to LED3
 If the voltage is between 3 to 4V glow LED1 to LED4
 If the voltage is between 4 to 5V glow LED1 to LED5
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:

[18BEC1241] ECE4003-Embedded System Design LabPage No: 67


 analogRead(pin) - Reads the value from a specified analog pin with a 10-bit
resolution

PROGRAM:
int sensorValue=0;
float volt=0;
void setup()
{
for(int i=3; i<=7;i++)
{
pinMode(i,OUTPUT);
}
Serial.begin(9600);
}

void loop()
{
sensorValue=analogRead(A0);
volt=(sensorValue*4.88)/1000;
Serial.print("sensorValue=");
Serial.println(sensorValue);
Serial.print("Voltage");
Serial.print(volt);
delay(1000);
if(volt>0 && volt<1)
{
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
else if(volt>1 && volt<2)
{
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
else if(volt>2 && volt<3)
{
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);

[18BEC1241] ECE4003-Embedded System Design LabPage No: 68


digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
else if(volt>3 && volt<4)
{
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
else if(volt>4 && volt<5)
{
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
}
else
{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
}
OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 69


Fig.3 Circuit diagram for a voltage level indicator system

INFERENCE:
Here, we are taking analog input from the potentiometer and converting it into voltage.
Then output is like this :-

 If the voltage is between 0 to 1V LED1 glows


 If the voltage is between 1 to 2V LED1 and LED2 glow

[18BEC1241] ECE4003-Embedded System Design LabPage No: 70


 If the voltage is between 2 to 3V LED1 to LED3 glow
 If the voltage is between 3 to 4V glow LED1 to LED4 glow
 If the voltage is between 4 to 5V glow LED1 to LED5 glow

RESULT:
Hence, we have made the required circuit and also verified the result using
tinkercad.com

TASK4
AIM:
Write a program to read the temperature value from TMP36 temperature sensor connected
to one of the analog pin and print its Fahrenheit and Celsius value on serial window.
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
➢ analogRead(pin) - Reads the value from a specified analog pin with a 10-bit resolution

PROGRAM:
const int TMP36_pin=A0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int temp_adc_val;
float tempC;
temp_adc_val=analogRead(TMP36_pin);
tempC=(temp_adc_val*4.88);
tempC=(tempC/10);
tempC=tempC-50;
Serial.print("Temperature = ");
Serial.print(tempC);
Serial.println(" Degree Celsius");
float tempF=((tempC)*9.0/5.0)+32.0;
Serial.print("Temperature = ");
Serial.print(tempF);
Serial.println(" Degree Farenheit");
delay(1000);
}
OUTPUT:-

[18BEC1241] ECE4003-Embedded System Design LabPage No: 71


Fog. 4 Circuit diagram for reading the temperature value and printing its Fahrenheit and
Celsius value

INFERENCE:
(understanding from the obtained output)
Here we are using temperature sensor to read the temperature using analog pin A0 of
Arduino uno. Then we are printing equivalent Celsius and Fahrenheit values.

RESULT:
Hence, we have designed the required circuit and verified the result using tinkercad circuit
simulator.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 72


CHALLENGING TASK 1:-

AIM:
Write a program to design a automatic room temperature control system to monitor the
room temperature using TMP36 sensor and display its value on two digit 7-Segment
display. Whenever the room temperature crosses 25°C the system must switch ON the Fan
(DC motor with relay) to control the room temperature. Once the temperature goes below
25°C Fan must be switch OFF automatically. Simulate and verify this logic on Arduino
Uno using Tinkercad circuits simulator.

API REQUIRED:
analogRead(pin) - Reads the value from a specified analog pin with a 10-bit resolution

PROGRAM:
int segPins[]={4,5,7,8,9,11,10,6};
int displayPins[2]={12,13};
int displayBuf[2];
int sw=3;
int i=0,j=0;
int startTime=0;
unsigned long endTime;
int a=0;
int b=0;
float tempC=0;
int temp_adc_val=0;
int segCode[11][8]={
{0,0,0,0,0,0,1,1}, //0
{1,0,0,1,1,1,1,1}, //1
{0,0,1,0,0,1,0,1}, //2
{0,0,0,0,1,1,0,1}, //3
{1,0,0,1,1,0,0,1}, //4
{0,1,0,0,1,0,0,1}, //5
{0,1,0,0,0,0,0,1}, //6
{0,0,0,1,1,1,1,1}, //7
{0,0,0,0,0,0,0,1}, //8
{0,0,0,0,1,0,0,1}, //9
{1,1,1,1,1,1,1,0}, //.
};
void Display(int digit1,int digit0)
{
digitalWrite(displayPins[0],HIGH);
digitalWrite(displayPins[1],LOW);
setSegments(digit0);

[18BEC1241] ECE4003-Embedded System Design LabPage No: 73


delay(5);
digitalWrite(displayPins[0],LOW);
digitalWrite(displayPins[1],HIGH);
setSegments(digit1);
delay(5);
}
void setSegments(int n)
{
for(int i=0;i<8;i++)
{
digitalWrite(segPins[i],segCode[n][i]);
}
}
void setup()
{
for(int i=0;i<8;i++)
{
pinMode(segPins[i],OUTPUT);
}
pinMode(displayPins[0],OUTPUT);
pinMode(displayPins[1],OUTPUT);
pinMode(sw,INPUT);
displayBuf[0]=0;
displayBuf[1]=0;
pinMode(3,OUTPUT);
}
void loop()
{
temp_adc_val=analogRead(A0);
tempC=(temp_adc_val*4.88);
tempC=(tempC/10);
tempC=tempC-50;
a=(int)tempC/10;
b=(int)tempC%10;
Display(a,b);
if(tempC>25)
{
digitalWrite(3,HIGH);
}
else
{
digitalWrite(3,LOW);
}
}

[18BEC1241] ECE4003-Embedded System Design LabPage No: 74


OUTPUT:

Fig. 5 Circuit diagram for automatic room temperature control system

INFERENCE:
Here we are reading temperature using analog pin A0 and temperature sensor. We are
displaying temperature using 7 segment display in degree centigrade. Also if temperature is
greater than 25 degree centigrade then fan will be turned on otherwise fan will be turned
off.

RESULT:

[18BEC1241] ECE4003-Embedded System Design LabPage No: 75


Hence, we have designed the required circuit and verified the result using tinkercad.com.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 76


Working with LCD
Date : 28/03/2021
Exp.No.: 6 Page No. 1
LAB TASK-1
AIM:
Write a program to accepts serial input from a host computer and displays it on the
LCD. Assume LCD operates in 4-bit with EN and RS active state.
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
1. lcd.begin(x,y):- Initialize LCD with x columns and y rows
2. lcd.clear():- Clear all the contents on the LCD
3. lcd.write(x):- Write the value of x on the LCD
4. lcd.setCursor(y,x):- Set the cursor to the y column and x row.
5. lcd.print(x):- Print the value x on the LCD
PROGRAM:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
lcd.begin(16,2); Serial.begin(9600);
}
void loop()
{
if(Serial.available())
{
delay(100);
lcd.clear();
while(Serial.available()>0)
{
lcd.write(Serial.read());
}
}
}

OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 77


Fig 1 Circuit diagram for receiving serial input from a host computer and displays it on the
LCD

INFERENCE:
Here, we are taking input from the serial window using serial communication and it is
displayed on the LCD. The most recent serial input is displayed on the LCD.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 78


LABTASK-2
AIM:
Write a program for LCD to display “18BEC1241” at the beginning first line and
“ABCDEFGH” at beginning of the second line. Also print the number of seconds
since the execution on first line 10th position and smiley in the second line last
position.

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
1. lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
2. lcd.clear() :- It is used to clear all the contents on the LCD.
3. lcd.write(x):- It is used to write the value of x on the LCD.
4. lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
5. lcd.print(x) :- It is used to print the x on the LCD.
6. lcd.createChar() :- It is used to create emoji.
7. millis() :- It is used to give the value of milliseconds denoting the time
elapsed once the program started executing.

PROGRAM:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte smiley[8]={B00000,B10001,B00000,B00000,B10001,B01110,B00000,};
void setup() {
lcd.begin(16,2);
lcd.clear();
}
void loop() {
lcd.setCursor(0,0);
lcd.print("18BEC1078");
lcd.setCursor(10,0);
lcd.print(millis()/1000);
lcd.setCursor(0,1);
lcd.print("ABCDEFGH");
lcd.createChar(0, smiley);
lcd.setCursor(15, 1);
lcd.write(byte(0));

[18BEC1241] ECE4003-Embedded System Design LabPage No: 79


delay(500);
lcd.display();
}

OUTPUT: Screenshot of circuit from tinkercad simulator

Fig2. Circuit Diagram for displaying “18BEC1241” at the beginning first line and
“ABCDEFGH” at beginning of the second line

[18BEC1241] ECE4003-Embedded System Design LabPage No: 80


INFERENCE:
Here we are printing “18BEC1241” and then the value of millis()/1000 in the first row
of the LCD. Then we are printing “ABCDEFGH” and a smile emoji in the second row
of the LCD.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.

LABTASK-3
AIM:
Write a program to measure the gas intensity using MQ series gas sensor and display it in
serial monitor. Whenever gas concentration exceeds digital value of 500 then switch ON
the alarm and LED.
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 81


API REQUIRED:
1. pinMode(x, OUTPUT):- It is used to make the pin x as output .
2. digitalWrite(x,y) :- It is used to make the digital pin x as High or Low depending
on the value of y.
3. analogRead(x):- It is used to read the analog value from the pin x.

PROGRAM:
int pin8 = 8;
int pin9 = 9;
int sensor = A0;
int sensorValue = 0;
void setup(){
pinMode(pin8,OUTPUT);
pinMode(pin9,OUTPUT);
Serial.begin(9600);
}
void loop(){
sensorValue = analogRead(sensor);
Serial.println(sensorValue);
if(sensorValue > 350){
digitalWrite(pin8,HIGH);
digitalWrite(pin9,HIGH);
}
else{
digitalWrite(pin8,LOW);
digitalWrite(pin9,LOW);
}
}

OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 82


Fig3. Circuit diagram for measuring the gas intensity using MQ series gas sensor

INFERENCE:
Here, we are reading the concentration of smoke using gas sensor and when the
concentration reaches above 500 ppm then we are turning on the buzzer and the led
otherwise the buzzer and the led are in off stage.
RESULT:

[18BEC1241] ECE4003-Embedded System Design LabPage No: 83


Hence, we have designed the required circuit and also verified the result using Tinkercad
circuit simulator.

LABTASK-4
AIM:
Write a program to measure the air quality using MQ series gas sensor and display it in
LCD as “AirQ= XYZ ppm”, where XYZ is a CO2 value. Simulate and verify this logic on
Arduino Uno using Tinkercad circuits simulator.
API REQUIRED:

➢ pinMode(x, OUTPUT):- It is used to make the pin x as output .


➢ digitalWrite(x,y) :- It is used to make the digital pin x as High or Low depending on the
value of y.
➢ analogRead(x):- It is used to read the analog value from the pin x.
➢ lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
➢ lcd.clear() :- It is used to clear all the contents on the LCD.
➢ lcd.write(x):- It is used to write the value of x on the LCD.
➢ lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
➢ lcd.print(x) :- It is used to print the x on the LCD.
➢ lcd.createChar() :- It is used to create emoji

PROGRAM:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int sensor=A0;
int sensorValue=0;
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
}
void loop()
{
delay(1000);
lcd.noDisplay();
delay(500);
lcd.display();
int valor_sensor = analogRead(A0);
lcd.clear();
lcd.setCursor(0,0);

[18BEC1241] ECE4003-Embedded System Design LabPage No: 84


lcd.write("AirQ= ");
lcd.print(valor_sensor);
lcd.write(" ppm");
delay(1);
}

OUTPUT: Screenshot of circuit from tinkercad simulator

INFERENCE:
Here, we are calculating the CO2 concentration in the air using gas sensor and then we are
printing the value as “AirQ= “CO2_concetration “ppm”.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.

CHALLENGING TASK-1

[18BEC1241] ECE4003-Embedded System Design LabPage No: 85


AIM:
Write a program to design a weather monitoring station which display temperature, CO2
level and light intensity on LCD. Print “Weather station” on first line and print the timing
as “08:MM:SS” after a delay of 3 Seconds display values of temp, CO2 and light in a
rolling display moving from right to left direction. Then repeat the sequence again.
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
4. pinMode(x, OUTPUT):- It is used to make the pin x as output .
5. digitalWrite(x,y) :- It is used to make the digital pin x as High or Low depending
on the value of y.
6. analogRead(x):- It is used to read the analog value from the pin x.
7. lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
8. lcd.clear() :- It is used to clear all the contents on the LCD.
9. lcd.write(x):- It is used to write the value of x on the LCD.
10.lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
11.lcd.print(x) :- It is used to print the x on the LCD.
12.lcd.createChar() :- It is used to create emoji.
13.millis() :- It is used to give the value of milliseconds denoting the time
elapsed once the program started executing.

PROGRAM:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int hour=8;
int minute=0;
int second=0;
void setup()
{
lcd.begin(16,2);
pinMode(13, OUTPUT);
}

void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.write("Weather station ");

[18BEC1241] ECE4003-Embedded System Design LabPage No: 86


lcd.setCursor(0,1);
second=(millis()/(1000));
minute=second/60;
second=second%60;
hour=minute/60;
minute=minute%60;
if(hour<10)
{
lcd.print(0);
}
lcd.print(hour);
lcd.write(":");
if(minute<10)
{
lcd.print(0);
}
lcd.print(minute);
lcd.write(":");
if(second<10)
{
lcd.print(0);
}
lcd.print(second);
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("CO2: ");
lcd.print(analogRead(A0));
lcd.print(" Temp: ");
lcd.print(analogRead(A1));
lcd.print(" Light_int: ");
lcd.print(analogRead(A2));
int i=0;
for(i=0;i<34;i++)
{
lcd.scrollDisplayLeft();
delay(100);
}
}

OUTPUT: Screenshot of circuit from tinkercad simulator

[18BEC1241] ECE4003-Embedded System Design LabPage No: 87


Fig5. Circuit diagram for weather monitoring station

INFERENCE:

[18BEC1241] ECE4003-Embedded System Design LabPage No: 88


Here, we are printing “Weather station” in the first row of the LCD and “HH:MM:SS” in
the second row of the LCD for 3 seconds. Then we are clearing the display and printing
the concentration of CO2, light intensity and temperature in the LCD and then moving the
printed stuffs from right to left. After that we are repeating the above processes again and
again.

RESULT:
Hence, we have designed the required circuit and also verified the result using Tinkercad
circuit simulator.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 89


Working with Keypad
Date : 03/03/2021
Exp.No.: 7 Page No. 1

TASK-1
AIM: -
Write a program to accepts input from a 4x4 keypad and displays it on the LCD. Assume
LCD operates in 4-bit with EN and RS active state. Simulate and verify this logic on
Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:-
➢ lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
➢ lcd.clear() :- It is used to clear all the contents on the LCD.
➢ lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
➢ lcd.print(x) :- It is used to print the x on the LCD.
➢ char getKey() - Returns the key that is pressed, if any.

PROGRAM: -
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A0, A1, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
int LCDRow = 0

[18BEC1241] ECE4003-Embedded System Design LabPage No: 90


Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(LCDRow, 0);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
lcd.print(key);
lcd.setCursor (++LCDRow, 0);
}
}
OUTPUT: -

Fig1. Circuit diagram for accepting input from a 4x4 keypad and displaying it on the LCD

[18BEC1241] ECE4003-Embedded System Design LabPage No: 91


INFERENCE:-
Here, we are taking input from the keypad and displaying the pressed keypad button on the
LCD and also on the serial window.
RESULT:-
Hence, we have made the required circuit and verified the result using tinkercad.com.

TASK-2
AIM: -
Write a program to design a password based door locking system in which the system
accept 4-digit password (last 4-digit of your reg. no) via keypad and activate the relay to
open the door. Also use the LCD display to message based on correctness of the password.
Use * symbol to represent password on LCD. Simulate and verify this logic on Arduino
Uno using Tinkercad circuits simulator.

API REQUIRED: -
➢ lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
➢ lcd.clear() :- It is used to clear all the contents on the LCD.
➢ lcd.write(x):- It is used to write the value of x on the LCD.
➢ lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
➢ lcd.print(x) :- It is used to print the x on the LCD.
➢ char getKey() - Returns the key that is pressed, if any.

PROGRAM: -
#include <Keypad.h>
#include <LiquidCrystal.h>

[18BEC1241] ECE4003-Embedded System Design LabPage No: 92


LiquidCrystal lcd(5, 4, 3, 2, A4, A5);

const byte ROWS = 4;


const byte COLS = 4;
int door = 12;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A0, A1, 11, 10};
byte colPins[COLS] = {9, 8, 7, 6};
int LCDRow = 0;

int c=0;
String input="";
String pswrd="1241";

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(LCDRow, 0);
pinMode(door,OUTPUT);
}

void loop(){
char key = keypad.getKey();
digitalWrite(door,LOW);
if (key){
Serial.println(key);
lcd.print("*");
lcd.setCursor (++LCDRow, 0);
input = input + String(key);
c++;
}
if(c==4){
if(input==pswrd){
lcd.clear();
Serial.println("Access allowed");

[18BEC1241] ECE4003-Embedded System Design LabPage No: 93


lcd.print("Access allowed");
digitalWrite(door,HIGH);
delay(3000);
digitalWrite(door,LOW);
lcd.clear();
}
else{
lcd.clear();
Serial.println("Access denied");
lcd.print("Access denied");
delay(2000);
lcd.clear();
}
String input="";
c=0;
LCDRow=0;
}
}
OUTPUT:

Fig. 2 Circuit diagram for password based door locking system

[18BEC1241] ECE4003-Embedded System Design LabPage No: 94


INFERENCE:
Here, we are taking input as password using keypad. Password is nothing but last four
digits of our registration number. For each input we are displaying a star symbol on the
display and at last if the password is matched then we are turning on the DC motor and
displaying a success message otherwise un-success message is shown.
RESULT:
Hence, we have made the required circuit and also verified the result using
tinkercad.com
TASK-3

AIM:
Write a program to design a simple calculator system that perform addition, subtraction,
multiplication and division operation. This system accept input numerals and operations
from 4x4 alphanumeric key pad and display result on the LCD screen. Assume symbol “#”
represent answer display (=) operation “A” perform addition, “B” perform “Subtraction,
“C” performs multiplication and “D” perform division. Simulate and verify this logic on
Arduino Uno using Tinkercad circuits simulator.
API REQUIRED:
➢ lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
➢ lcd.clear() :- It is used to clear all the contents on the LCD.
➢ lcd.write(x):- It is used to write the value of x on the LCD.
➢ lcd.setCursor(y,x):- It will set the cursor to the y column and x row.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 95


➢ lcd.print(x) :- It is used to print the x on the LCD.
➢ char getKey() - Returns the key that is pressed, if any.

PROGRAM:
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'}, {'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A0, A1, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
int LCDRow = 0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int getashish(char a)
{
if(a=='0')
{
return 0;
}
else if(a=='1')
{
return 1;
}
else if(a=='2')
{
return 2;
}
else if(a=='3')
{
return 3;
}
else if(a=='4')
{
return 4; }
else if(a=='5')
{
return 5;
}
else if(a=='6')

[18BEC1241] ECE4003-Embedded System Design LabPage No: 96


{
return 6;
}
else if(a=='7')
{
return 7;
}
else if(a=='8')
{
return 8;
}
else
{
return 9;
}
}
void setup(){
lcd.begin(16, 2);
lcd.setCursor(LCDRow, 0);
}
void loop(){
char key = keypad.getKey();
while(!key){
key = keypad.getKey();}
lcd.print(key);
lcd.setCursor (++LCDRow, 0);
char key1 = keypad.getKey();
while(!key1){
key1 = keypad.getKey();
}
lcd.print(key1);
lcd.setCursor (++LCDRow, 0);
int a=0;
int b=0;
a=getashish(key);
b=getashish(key1);
char key2=keypad.getKey();
while(!key2)
{
key2=keypad.getKey();
}
lcd.print(key2);
if(key2=='A')
{

[18BEC1241] ECE4003-Embedded System Design LabPage No: 97


lcd.setCursor(0,1);
lcd.print(a+b);
lcd.print(" =answer");
}
else if(key2=='S')
{
lcd.setCursor(0,1);
lcd.print(a-b);
lcd.print(" =answer");
}
else if(key2=='M')
{
lcd.setCursor(0,1);
lcd.print(a*b);
lcd.print(" =answer");
}
else
{
lcd.setCursor(0,1);
lcd.print(a/b);
lcd.print(" =answer");
}
delay(10000);
lcd.clear();
}
OUTPUT:

Fig3. Circuit diagram for simple calculator system

[18BEC1241] ECE4003-Embedded System Design LabPage No: 98


INFERENCE:
(understanding from the obtained output)
Here, we are taking input as two one digit number from the keypad and showing the typed
number on the display. Also after that we are taking input as ‘A’ , ‘S’,’D’, ‘M’ where A
signifies addition S signifies subtraction D signifies Division and M signifies
multiplication. So, whatever mentioned char is pressed the corresponding operation is
performed and the result is displayed in display.

RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.
CHALLENGING TASK

AIM:
Write a program to design home security system that consists of two main modules (1)
Intruder detection (2) password based door lock system. The intruder detection system
consists of PIR sensor interfaced with processing unit to detect and alert under human
presence condition. In password based door lock system numeric keypad to accept the
password (last 4-digit of your reg. no) from user and LCD to display the message whether
permission is granted or not. Upon receiving correct password signal, enable motor to open
the door. In case of password mismatch or intruder detection condition activate the buzzer.
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
➢ pinMode(x, OUTPUT):- It is used to make the pin x as output .

[18BEC1241] ECE4003-Embedded System Design LabPage No: 99


➢ digitalWrite(x,y) :- It is used to make the digital pin x as High or Low depending on the
value of y.
➢ lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
➢ lcd.clear() :- It is used to clear all the contents on the LCD.
➢ lcd.write(x):- It is used to write the value of x on the LCD.
➢ lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
➢ lcd.print(x) :- It is used to print the x on the LCD.
➢ char getKey() - Returns the key that is pressed, if any.

PROGRAM:
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A0, A1, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
int LCDRow = 0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
lcd.begin(16, 2);
lcd.setCursor(LCDRow, 0);
pinMode(13,OUTPUT);
pinMode(12,INPUT);
pinMode(1,OUTPUT);
}
void loop(){
int x=digitalRead(12);
if(x==1)
{
lcd.setCursor(0,0);
lcd.print("HUMAN ALERT");
delay(2000);
}
lcd.clear();

[18BEC1241] ECE4003-Embedded System Design LabPage No: 100


lcd.setCursor(0,0);
char key1 = keypad.getKey();
while(!key1)
{
key1 = keypad.getKey();
x=digitalRead(12);
if(x==1){
lcd.setCursor(0,0);
lcd.print("HUMAN ALERT");
delay(2000);
}
}
if (key1){
lcd.setCursor(0,1);
lcd.print('*');
lcd.setCursor (++LCDRow, 1);
}
char key2 = keypad.getKey();
while(!key2)
{
key2 = keypad.getKey();
x=digitalRead(12);
if(x==1)
{
lcd.setCursor(0,0);
lcd.print("HUMAN ALERT");
delay(2000);
}
}
if (key2){
lcd.print('*');
lcd.setCursor (++LCDRow, 1);
}
char key3 = keypad.getKey();
while(!key3)
{
key3 = keypad.getKey();
x=digitalRead(12);
if(x==1)
{
lcd.setCursor(0,0);
lcd.print("HUMAN ALERT");
delay(2000);
}

[18BEC1241] ECE4003-Embedded System Design LabPage No: 101


}
if (key3){
lcd.print('*');
lcd.setCursor (++LCDRow, 1);
}
char key4 = keypad.getKey();
while(!key4)
{
key4 = keypad.getKey();
}
if (key4){
lcd.print('*');
lcd.setCursor (++LCDRow, 1);
x=digitalRead(12);
if(x==1)
{
lcd.setCursor(0,0);
lcd.print("HUMAN ALERT");
delay(2000);
}
}
if(key1=='1' && key2=='2' && key3=='4' && key4=='1')
{
lcd.setCursor(0,1);
lcd.print("Correct Password");
digitalWrite(13,HIGH);}
else
{
lcd.setCursor(0,1);
lcd.print("Wrong Password");
digitalWrite(13,LOW);
digitalWrite(1,HIGH);
}
delay(5000);
}

OUTPUT:

[18BEC1241] ECE4003-Embedded System Design LabPage No: 102


Fig4. Circuit diagram for home security system

INFERENCE:
(understanding from the obtained output)
Here, we are using PIR sensor to detect the presence of any human and if human is
detected the a required output is shown in the lcd. Also we are taking the password as input
using keypad and checking if it matches or not if it matches then “correct password” is
displayed otherwise “incorrect password” is displayed in the display. Also if you type the
password then it will be displayed as star format on the display.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 103


RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.

[18BEC1241] ECE4003-Embedded System Design LabPage No: 104


Working with  Stepper Motor
Date : 19/04/2021
Exp.No.: 8 Page No. 1

TASK-1
AIM:-

Write a program to control the servo motor by rotating slowly from 0 degrees to 180 degrees, one degree
at a time. When the motor has to be rotated 180 degrees, it will begin to rotate in the other direction until
it returns to the initial position. Simulate and verify this logic on Arduino Uno using Tinkercad circuits
simulator.

API REQUIRED:
 servo.write(angle) - Writes a value to the servo, controlling the shaft accordingly.
– angle: the value to write to the servo, from 0 to 180
 servo.writeMicroseconds(uS)- Writes a value in microseconds (uS) to the servo, controlling the
shaft accordingly.
– uS: the value of the parameter in microseconds (int)
 servo.read()- Read the current angle of the servo, The angle of the servo, from 0 to 180 degrees.
 servo.attached() – Check whether the Servo variable is attached to a pin. Return true if the servo is
attached to pin; false otherwise.
 servo.detach()- Detach the Servo variable from its pin. If all Servo variables are detached, then pins
9 and 10 can be used for PWM output with analogWrite().

PROGRAM:
#include<Servo.h>
Servo servo_test;
int angle=0;
void setup()
{
servo_test.attach(9);
}

void loop()
{
for(angle=0;angle<180;angle+=1)
{
servo_test.write(angle);
delay(100);
}

for(angle=180;angle>=1;angle-=1){
servo_test.write(angle);
delay(100);
}
}

OUTPUT:-
Fig 1. Circuit for controlling the servo motor

INFERENCE:
Here, we are rotating the servo motor from 0 to 180 degree, one degree at a time, and then we are
rotating the servo motor from 180 to 0 degree, one degree at a time. The above given process is
performed again and again.
RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.
TASK-2
AIM:
Write a program to control rotation angle of the servo motor by rotating potentiometer knob. If the
potentiometer at one end, the servo motor must be at 0 degree, when the knob is rotated to other extreme
end the motor must reach 180 degree. Also display the Voltage value from potentiometer (1st row) and the
present angle (2nd row) of servo motor on LCD. Simulate and verify this logic on Arduino Uno using
Tinkercad circuits simulator.

API REQUIRED:
 servo.write(angle) - Writes a value to the servo, controlling the shaft accordingly.
– angle: the value to write to the servo, from 0 to 180
 servo.writeMicroseconds(uS)- Writes a value in microseconds (uS) to the servo, controlling the
shaft accordingly.
– uS: the value of the parameter in microseconds (int)
 servo.read()- Read the current angle of the servo, The angle of the servo, from 0 to 180 degrees.

 servo.attached() – Check whether the Servo variable is attached to a pin. Return true if the servo is
attached to pin; false otherwise.

 servo.detach()- Detach the Servo variable from its pin. If all Servo variables are detached, then pins
9 and 10 can be used for PWM output with analogWrite().

 lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.

 lcd.clear() :- It is used to clear all the contents on the LCD.

 lcd.write(x):- It is used to write the value of x on the LCD.

 lcd.setCursor(y,x):- It will set the cursor to the y column and x row.

 lcd.print(x) :- It is used to print the x on the LCD.

 lcd.createChar() :- It is used to create emoji.

 millis() :- It is used to give the value of milliseconds denoting the time elapsed once the program
started executing.

PROGRAM:
#include<Servo.h>
Servo servo_test;
int angle=0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
void setup()
{
pinMode(A0,INPUT);
servo_test.attach(9);
lcd.begin(16, 2);
lcd.setCursor(0,0);
Serial.begin(9600);
}

void loop()
{
float x=analogRead(A0);
float voltage=(5.0/1023)*x;
float angle=(180.0/1023)*x;
servo_test.write(angle);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(voltage);
lcd.setCursor(0,1);
lcd.print(angle);
delay(2000);
}

OUTPUT: -

Fig 2 Circuit for controlling rotation angle of the servo motor by rotating potentiometer knob
INFERENCE:
Here, we are taking input from the potentiometer and converting it into a voltage value between 0 and 5.
Also we are converting the potentiometer value to an angle value between 0 and 180. Then we are
rotating the servo meter by the angle value and also displaying the voltage and the angle value on the
display.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.
TASK-3
AIM:
Write a program to design auto intensity street light controller. This system helps the street light to get
switched on automatically as per surrounding brightness. For example, sometimes when the weather
become hazy its quite difficult to see anything then at that point this auto intensity street light gets
switched on based on present lighting condition. Simulate and verify this logic on Arduino Uno using
Tinkercad circuits simulator.

API REQUIRED:
 pinMode(x,y):- It will set the pin x in input mode if y=INPUT and in output mode if
y=OUTPUT.
 analogRead(x):- It will read the analog value from the pin x and return it.
 analogWrite(x,y):- It will write the value y to the analog pin x.
PROGRAM:
int value=0;
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(A0, INPUT);
}

void loop()
{
value= analogRead(A0);
if(value<100)
{
digitalWrite(11, HIGH);
Serial.println("Light ON");
Serial.println(value);
}
else
{
digitalWrite(11, LOW);
Serial.println("Light OFF");
Serial.println(value);
}
}
OUTPUT:
Fig3. Circuit design auto intensity street light controller

INFERENCE:
Here, we are taking analog input from the photoresistor and converting it into a required value such
that during low intensity of light our street light should become ON otherwise it should be turned OFF
automatically.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.
Working with  Ultrasonic Sensor
Date : 22/04/2021
Exp.No.: 9 Page No. 1

TASK-1
AIM:-
Read the distance value from HC-SR04 and print it on serial monitor Write a program to
read distance value from HC-SR04 ultrasonic sensor module in cm and print it on the serial
monitor.
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
 pulseIn() – Reads a pulse (either HIGH or LOW) on a pin

PROGRAM:
int distanceThreshold=0;
int trigPin=12;
int echoPin=11;
float timeduration;
float distance;

void setup(){
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
Serial.begin(9600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
}

void loop(){
distanceThreshold=250;
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);

timeduration=pulseIn(echoPin,HIGH);
distance=timeduration*0.034/2;
Serial.print("Distance:");
Serial.println(distance);
if(distance>distanceThreshold){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}
if(distance<=distanceThreshold && distance>distanceThreshold-100){
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}
if(distance<=distanceThreshold-100 && distance>distanceThreshold-150){
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
}
if(distance<=distanceThreshold-150&& distance>distanceThreshold-250){
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}
delay(500);
}

OUTPUT:
Fig.1 Circuit diagram for reading distance value from HC-SR04 ultrasonic sensor
module in cm and printing it on the serial monitor

INFERENCE:
Here, we are reading the distance of the obstacle using ultrasonic sensor and printing the
distance in the serial window.
RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.
TASK-2
AIM:
Write a program to design a reverse parking sensor module. This module consists of HC-
SR04 ultrasonic sensor, LCD and buzzer interfaced with Arduino. The ultrasonic sensor
continuously measure the distance (in cm) between the car and obstacle, then display it on
LCD. Whenever the measured distance is lesser than 30cm generate warning signal to
driver using buzzer also display a message “Obstacle !!!” on the first row of the LCD
display.

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.

API REQUIRED:
 pulseIn() - Reads a pulse (either HIGH or LOW) on a pin. lcd.begin(x,y) :- It is
used to initialize a LCD with x columns and y rows.
 lcd.clear() :- It is used to clear all the contents on the LCD.
 lcd.write(x):- It is used to write the value of x on the LCD.
 lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
 lcd.print(x) :- It is used to print the x on the LCD.

PROGRAM:
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
int trig=12;
int echo=11;
float timeduration;
float distance;

void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0,0);
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo,INPUT);
pinMode(8,OUTPUT);
}

void loop(){
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
timeduration=pulseIn(echo,HIGH);
distance=0.034*(timeduration/2.0);

if(distance>=30){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Distance is ");
lcd.setCursor(13,0);
lcd.print(distance);
}

else{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Obstacle !!!");
digitalWrite(8,HIGH);
}

delay(2000);
digitalWrite(8,LOW);
}

OUTPUT: Screenshot of circuit from tinkercad simulator

Fig2. Circuit diagram for a reverse parking sensor module


INFERENCE:
Here, we are taking input from the ultrasonic sensor. When distance measured by the
ultrasonic sensor is less than 30 cm then we turn on the buzzer and display a message
“Obstacle !!!” on the display otherwise we display the distance on the display and
buzzer is in OFF state.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.

TASK-3:
AIM: -
Write a program to design smart parking system using HC-SR04 ultrasonic sensor, servo
motor, buzzer, LCD and Arduino Uno.
➢ The ultrasonic sensor module place near the gate entrance continuously check for the
incoming vehicles. The LCD display “Smart Parking” on the first row and “Avail. slot:
XY” in second row of the display.
➢ When a vehicle comes closer to the ultrasonic sensor detection area and parking slot is
available then the system open a gate barrier to 90° (close after 10 seconds) to allow the
vehicle to the parking slot and decrement parking slot by 1.
➢ If no parking slot available then display a message “No Parking slot” on LCD (2ndline)
and switch on the buzzer (for 5 Seconds). Have a similar system on the exit and increment
the free slot by 1 for every vehicle leaves the parking slot.

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.
Note: XY is number of available slot and initially assume total available parking slot is 15

API REQUIRED:
➢ pinMode(x,y):- It will set the pin x in input mode if y=INPUT and in output mode if
y=OUTPUT.
➢ pulseIn() -Reads a pulse (either HIGH or LOW) on a pin. lcd.begin(x,y) :- It is used to
initialize a LCD with x columns and y rows.
➢ servo.write(angle) - Writes a value to the servo, controlling the shaft accordingly. o
angle: the value to write to the servo, from 0 to 180
➢ servo.writeMicroseconds(uS)- Writes a value in microseconds (uS) to the servo,
controlling the shaft accordingly.

➢ uS: the value of the parameter in microseconds (int)


➢ servo.read()- Read the current angle of the servo, The angle of the servo, from 0 to 180
degrees.
➢ servo.attached() – Check whether the Servo variable is attached to a pin. Return true if
the servo is attached to pin; false otherwise.
➢ servo.detach()- Detach the Servo variable from its pin. If all Servo variables are
detached, then pins 9 and 10 can be used for PWM output with analogWrite().
➢ lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
➢ lcd.clear() :- It is used to clear all the contents on the LCD.
➢ lcd.write(x):- It is used to write the value of x on the LCD.
➢ lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
➢ lcd.print(x) :- It is used to print the x on the LCD.

PROGRAM:
#include<Servo.h>
Servo servo_test;
int angle=90;
int count=15;
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
int trig=12;
int echo=11;
float timeduration;
float distance;
float timeduration1;
float distance1;
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0,0);
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo,INPUT);
pinMode(13, OUTPUT);
pinMode(10,INPUT);
pinMode(8,OUTPUT);
servo_test.attach(9);
} void loop()
{
servo_test.write(0);
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
timeduration=pulseIn(echo,HIGH);
distance=0.034*(timeduration/2.0);
digitalWrite(13,LOW);
delayMicroseconds(2);
digitalWrite(13,HIGH);
delayMicroseconds(10);
digitalWrite(13,LOW);
timeduration1=pulseIn(10,HIGH);
distance1=0.034*(timeduration1/2.0);
if(distance>=30)
{
servo_test.write(0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Smart Parking");
lcd.setCursor(0,1);
lcd.print("Avail. slot:");
lcd.setCursor(13,1);
lcd.print(count);
delay(2000);
}
else if(distance<30 && count>0){
servo_test.write(angle);
count--;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Smart Parking");
lcd.setCursor(0,1);
lcd.print("Avail. slot:");
lcd.setCursor(13,1);
lcd.print(count);
delay(10000);
servo_test.write(0);
}
else if(count==0)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Smart Parking");
lcd.setCursor(0,1);
lcd.print("No Parking slot");
digitalWrite(8,HIGH);
delay(5000);
digitalWrite(8,LOW);
}
if(distance1<30 && count<15){
count++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Smart Parking");
lcd.setCursor(0,1);
lcd.print("Avail. slot:");
lcd.setCursor(13,1);
lcd.print(count);
delay(10000);
}
OUTPUT:-
Fig3. Circuit diagram for smart parking system

INFERENCE:
Here, we are using upper ultrasonic sensor at entry gate of a car parking system. Whenever
upper ultrasonic sensor detects a car at a distance less than 30 cm then it checks for the
empty slot if it is available then it turns the servo motor by 90 degree for 10 seconds
indicating opening of the gate and also decrease the available parking slots by 1. If distance
measured by the upper ultrasonic sensor is less than 30 cm and available parking slot is 0
then buzzer will become ON for 5 seconds and display will show “Smart Parking No
Parking slot”. Display first row will always show “Smart Parking “ and second column will
show “No of parking slot: “ with number of available parking slot if available parking slot
is greater than 0 otherwise it will show “No parking slot”. Similarly lower ultrasonic sensor
is at exist gate where if it founds distance to be less than 30 cm and available parking slot <
15 then it will increase the available parking slot by 1.

RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.

CHALLENGING TASK:-
AIM:-
Write a program to design a Adaptive cruise control (ACC) system to help the vehicle to
maintain a safe following distance and stay within the speed limit. This system adjusts a
car's speed automatically so drivers don't have to and the detailed function of the system is
as follows:
1. This system consists of one slide switch (to select normal or cruise mode), 4 DIP
switches (to select different cruise speed), LCD (to display mode and speed of the vehicle),
DC motor (to indicate the vehicle speed in rpm), a potentiometer (to control the vehicle
speed in normal mode) and a buzzer (to indicate vehicle is very close to others)
2. Control switch(slide) decide whether the vehicle to be operated in Normal mode (LOW)
or cruise mode(HIGH)
3. In normal mode, vehicle speed is controlled by adjusting the potentiometer knob. Also,
display a message “Normal mode” in first row and “Speed:XYkmph” on the second row of
the LCD. XY is the present vehicle speed.
4. In cruise mode, DIP Switch-1 to 4 select vehicle speed as 40, 60, 80 and 90 kmph
respectively. Display the message “Cruising:ABkmph” on the first row and “Speed: XY
kmph” on the second row of the LCD. AB is either 40/60/80/90 and XY is the present
vehicle speed.
5. Using ultrasonic sensor, map the selected cruise speed with the distance. If other vehicle
are not near to the coverage area of the ultrasonic sensor operate the vehicle at its
maximum selected cruise speed with high rpm on DC motor.
6. If other vehicle is detected by ultrasonic sensor vicinity, depends on its distance adjust
the speed (DC motor) of the vehicle accordingly.
7. Whenever other vehicle reaches very near to our vehicle (<1m) activate the buzzer to
warn the driver. Also display the message “Very close alert” on first row of the LCD.

Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.
API REQUIRED:
➢ pinMode(x,y):- It will set the pin x in input mode if y=INPUT and in output mode if
y=OUTPUT.
➢ pulseIn() -Reads a pulse (either HIGH or LOW) on a pin. lcd.begin(x,y) :- It is used to
initialize a LCD with x columns and y rows.
➢ lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
➢ lcd.clear() :- It is used to clear all the contents on the LCD.
➢ lcd.write(x):- It is used to write the value of x on the LCD.
➢ lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
➢ lcd.print(x) :- It is used to print the x on the LCD.

PROGRAM:
int s1=1;
int s2=6;
int s3=7;
int s4=9;
int count=15;
int slideswitch=LOW;
int potentiometervalue=0;
int motor=13;
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 4, 3, 2, A4, A5);
int trig=12;
int echo=11;
float timeduration;
float distance;
void setup(){
lcd.begin(16, 2);
lcd.setCursor(0,0);
pinMode(trig, OUTPUT);
pinMode(echo,INPUT);
pinMode(8,OUTPUT);
pinMode(A0,INPUT);
pinMode(0,INPUT);
pinMode(s1,INPUT_PULLUP);
pinMode(s2,INPUT_PULLUP);
pinMode(s3,INPUT_PULLUP);
pinMode(s4,INPUT_PULLUP);
pinMode(motor,OUTPUT);
}
void loop()
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
timeduration=pulseIn(echo,HIGH);
distance=0.034*(timeduration/2.0);
int s1_reading=digitalRead(s1);
int s2_reading=digitalRead(s2);
int s3_reading=digitalRead(s3);
int s4_reading=digitalRead(s4);
int s5_reading=digitalRead(0);
if(s5_reading==LOW){
float x=analogRead(A0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Normal mode");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
float speed=(x/1023.0)*100;
lcd.print(speed);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,x);
delay(1000);
}
else{
if(distance>1000){
if(s1_reading==LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:40kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
int speed=(100.0/40)*1023;
lcd.print(40);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
else if(s2_reading==LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:60kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
int speed=(100.0/60)*1023;
lcd.print(60);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
else if(s3_reading==LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:80kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
int speed=(100.0/80)*1023;
lcd.print(80);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
else if(s4_reading==LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:90kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
int speed=(100.0/90)*1023;
lcd.print(90);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
}
else if(distance<=100){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Very close alert");
digitalWrite(8,HIGH);
digitalWrite(motor,0);
delay(5000);
digitalWrite(8,LOW);
}
else{ if(s1_reading==LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:40kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
float speed1=40.0-(40.0/distance);
float speed=(100.0/speed1)*1023;
lcd.print(speed1);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
else if(s2_reading==LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:60kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
float speed1=60.0-(60.0/distance);
float speed=(100.0/speed1)*1023;
lcd.print(speed1);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
else if(s3_reading==LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:80kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
float speed1=80.0-(80.0/distance);
float speed=(100.0/speed1)*1023;
lcd.print(speed1);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
else{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Crusing:90kmph");
lcd.setCursor(0,1);
lcd.print("Speed:");
lcd.setCursor(8,1);
float speed1=90.0-(90.0/distance);
float speed=(100.0/speed1)*1023;
lcd.print(speed1);
lcd.setCursor(12,1);
lcd.print("kmph");
digitalWrite(motor,speed);
delay(1000);
}
}
}
}
OUTPUT:-

Fig4. Circuit diagram for Adaptive cruise control (ACC) system


INFERENCE:
Here, we have designed a circuit which is performing following tasks :-
➢ This system consists of one slide switch (to select normal or cruise mode), 4 DIP
switches (to select different cruise speed), LCD (to display mode and speed of the vehicle),
DC motor (to indicate the vehicle speed in rpm), a potentiometer (to control the vehicle
speed in normal mode) and a buzzer (to indicate vehicle is very close to others)
➢ Control switch(slide) decide whether the vehicle to be operated in Normal mode (LOW)
or cruise mode(HIGH)
➢ In normal mode, vehicle speed is controlled by adjusting the potentiometer knob. Also,
display a message “Normal mode” in first row and “Speed:XYkmph” on the second row of
the LCD. XY is the present vehicle speed.
➢ In cruise mode, DIP Switch-1 to 4 select vehicle speed as 40, 60, 80 and 90 kmph
respectively. Display the message “Cruising:ABkmph” on the first row and “Speed: XY
kmph” on the second row of the LCD. AB is either 40/60/80/90 and XY is the present
vehicle speed.
➢ Using ultrasonic sensor, map the selected cruise speed with the distance. If other vehicle
are not near to the coverage area of the ultrasonic sensor operate the vehicle at its
maximum selected cruise speed with high rpm on DC motor.
➢ If other vehicle is detected by ultrasonic sensor vicinity, depends on its distance adjust
the speed (DC motor) of the vehicle accordingly.
➢ Whenever other vehicle reaches very near to our vehicle (<1m) activate the buzzer to
warn the driver. Also display the message “Very close alert” on first row of the LCD.

RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.
Working with SPI
Date : 23/04/2021
Exp.No.: 10 Page No. 1

TASK-1
AIM:-
Write a program to implement a SPI communication between two Arduino Uno. Configure one of the
Arduino as master and other as slave. Master is interfaced with 4x4 keypad and slave is connected with
16x2 LCD. Establish a SPI communication between master and slave display each key press on the master
to the slave LCD. Simulate and verify this logic on Arduino Uno using Tinkercad circuit simulator.
API REQUIRED:
 SPI.begin() - Initialize the SPI bus
 SPI.end() – Disables the SPI bus
 SPI.beginTransaction() – Initialize SPI bus using SPI Settings
 SPI.endTransaction() – Stop using SPI bus
 SPI.setClockDivider(divider) – Set the SPI clock divider (divider - 2, 4, 8, 16, 32, 64 or 128)
 SPI.setDataMode(mode) – Set the data mode (Mode_0, Mode_1, Mode_2,Mode_3)
 SPI.transfer(val) - the byte data to be transferred (send and receive) over the bus
 SPI.transfer(buffer, size) – the array of data to be transferred (send and receive)
 SPI.usingInterrupt(interruptNumber) – Used for registering interrupt number
PROGRAM:
#include <Keypad.h>
#define CLK 10
#define SS 11
#define MOSI 12
#define MISO 13
#define FALSE 0
#define TRUE 1
voidsetBits(char keypressed);
unsigned long prevTick=0.0;
unsigned long lastTime=0.0;
intclockState=LOW;
intprevClkState=LOW;
unsignedintclkCounter=0;
unsignedintpressTime;
charkeypressed;
intbitNum[4];
intbitSent[]={FALSE, FALSE, FALSE, FALSE};
intbitsToSend=0;
int ii;

const byte numRows = 4; //four rows


const byte numCols = 4; //four columns
char keys[numRows][numCols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
byterowPins[numRows]={9,8,7,6};
bytecolPins[numCols]={5,4,3,2};

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, numRows, numCols);

void setup(){
pinMode(CLK,OUTPUT);
pinMode(SS,OUTPUT);
pinMode(MOSI,OUTPUT);
pinMode(MISO,INPUT);

digitalWrite(CLK,LOW);
digitalWrite(MOSI,LOW);
digitalWrite(SS,HIGH);
}

void loop(){
if((millis()-prevTick)>=1000){
clockState=!clockState;
digitalWrite(CLK,clockState);
prevTick=millis();
clkCounter++;
}
if(bitsToSend>0){
if(!(bitSent[bitsToSend-1])){
if((clkCounter-pressTime)>(-1*bitsToSend+5)){
if((clockState==LOW) && ((millis()-lastTime)>1000)){
digitalWrite(SS,LOW);
digitalWrite(MOSI,bitNum[bitsToSend-1]);
bitSent[bitsToSend-1]=TRUE;
bitsToSend--;
lastTime=millis();
}
}
}
}
else{
if(digitalRead(MISO)==HIGH){
if((millis()-lastTime)>2000){
digitalWrite(SS,HIGH);
digitalWrite(MOSI,LOW);
}
}
keypressed=myKeypad.getKey();
if(keypressed!=NO_KEY){
setBits(keypressed);
pressTime=clkCounter;
lastTime=millis();

bitsToSend=4;
for(ii=0; ii<4; ii++){
bitSent[ii]=FALSE;
}
}
}
delay(10);
}

voidsetBits(char keypressed){
switch(keypressed){
case '0':
bitNum[3]=0;
bitNum[2]=0;
bitNum[1]=0;
bitNum[0]=0;
break;
case '1':
bitNum[3]=0;
bitNum[2]=0;
bitNum[1]=0;
bitNum[0]=1;
break;
case '2':
bitNum[3]=0;
bitNum[2]=0;
bitNum[1]=1;
bitNum[0]=0;
break;
case '3':
bitNum[3]=0;
bitNum[2]=0;
bitNum[1]=1;
bitNum[0]=1;
break;
case '4':
bitNum[3]=0;
bitNum[2]=1;
bitNum[1]=0;
bitNum[0]=0;
break;
case '5':
bitNum[3]=0;
bitNum[2]=1;
bitNum[1]=0;
bitNum[0]=1;
break;
case '6':
bitNum[3]=0;
bitNum[2]=1;
bitNum[1]=1;
bitNum[0]=0;
break;
case '7':
bitNum[3]=0;
bitNum[2]=1;
bitNum[1]=1;
bitNum[0]=1;
break;
case '8':
bitNum[3]=1;
bitNum[2]=0;
bitNum[1]=0;
bitNum[0]=0;
break;
case '9':
bitNum[3]=1;
bitNum[2]=0;
bitNum[1]=0;
bitNum[0]=1;
break;
case 'A':
bitNum[3]=1;
bitNum[2]=0;
bitNum[1]=1;
bitNum[0]=0;
break;
case 'B':
bitNum[3]=1;
bitNum[2]=0;
bitNum[1]=1;
bitNum[0]=1;
break;
case 'C':
bitNum[3]=1;
bitNum[2]=1;
bitNum[1]=0;
bitNum[0]=0;
break;
case 'D':
bitNum[3]=1;
bitNum[2]=1;
bitNum[1]=0;
bitNum[0]=1;
break;
case '*':
bitNum[3]=1;
bitNum[2]=1;
bitNum[1]=1;
bitNum[0]=0;
break;
case '#':
bitNum[3]=1;
bitNum[2]=1;
bitNum[1]=1;
bitNum[0]=1;
break;
default:
;
}
}
Slave Code:
#include <LiquidCrystal.h>

#define CLK 7
#define SS 8
#define MOSI 9
#define MISO 10

intclkState=LOW;
intprevClkState=LOW;
byte data=0x00;
intbitPos=3;
unsigned long timerStart;
LiquidCrystallcd(12, 11, 5, 4, 3, 2);

void setup(){
pinMode(CLK,INPUT);
pinMode(MOSI,INPUT);
pinMode(SS,INPUT);
pinMode(MISO,OUTPUT);

digitalWrite(MISO,LOW);
lcd.begin(16,2);
lcd.setCursor(0,1);
}

void loop(){
clkState=digitalRead(CLK);
if(clkState!=prevClkState){
prevClkState=clkState;
if(digitalRead(SS)==LOW){
if(clkState==HIGH){
if(digitalRead(MOSI)==LOW){
data&=~(0x01<<bitPos);
bitPos--;
}
else{
data |=(0x01<<bitPos);
bitPos--;
}
if(bitPos<0){
delay(500);
digitalWrite(MISO,HIGH);
delay(1000);
digitalWrite(MISO,LOW);
bitPos=3;
lcd.clear();
lcd.print(data);
}
}
}
}
delay(10);
}
OUTPUT:

Fig.1 Circuit diagram for implementing a SPI communication between two Arduino Uno

Case -1 When 8 is pressed:-

Case-2 When 2 is pressed:-


INFERENCE:
Here, we established a SPI communication between master and slave display each key press on the master
to the slave LCD.
RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.
TASK-2
AIM:
Write a program to implement a SPI communication between two Arduino Uno. Configure one of the
Arduino as master and other as slave. Both Arduino are attached with a LED & a push button separately.
Master LED can be controlled by using slave Arduino’s push button and slave Arduino’s LED can be
controlled by master Arduino’s push button using SPI communication protocol.
Simulate and verify this logic on Arduino Uno using Tinkercad circuit simulator.

API REQUIRED:
 SPI.begin() - Initialize the SPI bus
 SPI.end() – Disables the SPI bus
 SPI.beginTransaction() – Initialize SPI bus using SPI Settings
 SPI.endTransaction() – Stop using SPI bus
 SPI.setClockDivider(divider) – Set the SPI clock divider (divider - 2, 4, 8, 16, 32, 64 or 128)
 SPI.setDataMode(mode) – Set the data mode (Mode_0, Mode_1, Mode_2,Mode_3)
 SPI.transfer(val) - the byte data to be transferred (send and receive) over the bus
 SPI.transfer(buffer, size) – the array of data to be transferred (send and receive)
 SPI.usingInterrupt(interruptNumber) – Used for registering interrupt number
PROGRAM:
Master Code:
#define CLK 10
#define SS 11
#define MOSI 12
#define MISO 13
intm_push = 9;
intm_led = 8;
intm_pushstate =0;
unsigned long prevTick = 0.0;
unsigned long lastTime = 0.0;
intclockState = LOW;
intprevClkState = LOW;
unsignedintclkCounter = 0;

void setup()
{
pinMode(CLK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SS, OUTPUT);
pinMode(m_led,OUTPUT);
pinMode(m_push,INPUT);
digitalWrite(CLK, LOW);
digitalWrite(MOSI, LOW);
digitalWrite(SS, HIGH);
}
void loop()
{
if ((millis() - prevTick ) >= 1000)
{
clockState = !clockState;
digitalWrite(CLK, clockState);
prevTick = millis();
clkCounter++;
}
m_pushstate = digitalRead(m_push);
if(m_pushstate == HIGH)
{
if((clockState == LOW) && ((millis() - lastTime) > 1000))
{
digitalWrite(SS, LOW);
digitalWrite(MOSI,HIGH);
lastTime = millis();
}
}
else
{
if(digitalRead(MISO) == HIGH)
{
digitalWrite(m_led,HIGH);
if((millis() - lastTime) > 2000)
{
digitalWrite(SS, HIGH);
digitalWrite(MOSI, LOW);
digitalWrite(m_led,LOW);
}
}
}
if(millis() - lastTime> 2000)
{
digitalWrite(MOSI, LOW);
}
delay(10);
}
Slave Code:
#define CLK 10
#define SS 11
#define MOSI 12
#define MISO 13
intclkState = LOW;
intprevClkState = LOW;
ints_push = 6;
ints_led = 5;
ints_pushstate = 0;
long unsigned intstarttime = 0.0;
void setup()
{
pinMode(CLK, INPUT);
pinMode(MOSI, INPUT);
pinMode(MISO, OUTPUT);
pinMode(SS, INPUT);
pinMode(s_led,OUTPUT);
pinMode(s_push,INPUT);

digitalWrite(MISO, LOW);
}
void loop()
{
clkState = digitalRead(CLK);
s_pushstate = digitalRead(s_push);
if (clkState != prevClkState)
{
prevClkState = clkState;
if (digitalRead(SS) == LOW)
{
if (clkState == HIGH)
{
if (digitalRead(MOSI) == HIGH)
{
digitalWrite(s_led, HIGH);
starttime = millis();
}
}
}
if (s_pushstate == HIGH)
{
delay(500);
digitalWrite(MISO, HIGH);
delay(1000);
digitalWrite(MISO, LOW);
}
}
if(millis() - starttime>1000)
{
digitalWrite(s_led,LOW);
}
delay(10);
}

OUTPUT: Screenshot of circuit from tinkercad simulator

Fig2. Circuit diagram for controlling Master LED by using slave Arduino’s push button and slave
Arduino’s LED by master Arduino’s push button using SPI communication
Case 1 -When Master push button is pressed:-
Case 2- When slave button is pressed

INFERENCE:
Here, we are implemented SPI communication between two Arduino Uno. Master LED can be
controlled by using slave Arduino’s push button and slave Arduino’s LED can be controlled by
master Arduino’s push button using SPI communication protocol.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.
CHALLENGING TASK

AIM:-
Write a program to implement a SPI communication between two Arduino Uno. Configure one of the
Arduino as master and other as slave. Master Arduino connected with LCD and slave Arduino connected
with temperature sensor. Transfer temperature value read by slave to master and display it on LCD using
SPI communication protocol. Simulate and verify this logic on Arduino Uno using Tinkercad circuits
simulator.
API REQUIRED:
 SPI.begin() - Initialize the SPI bus
 SPI.end() – Disables the SPI bus
 SPI.beginTransaction() – Initialize SPI bus using SPI Settings
 SPI.endTransaction() – Stop using SPI bus
 SPI.setClockDivider(divider) – Set the SPI clock divider (divider - 2, 4, 8, 16, 32, 64 or 128)
 SPI.setDataMode(mode) – Set the data mode (Mode_0, Mode_1, Mode_2,Mode_3)
 SPI.transfer(val) - the byte data to be transferred (send and receive) over the bus
 SPI.transfer(buffer, size) – the array of data to be transferred (send and receive)
 SPI.usingInterrupt(interruptNumber) – Used for registering interrupt number
PROGRAM:
// SLAVE
#define CLK 10
#define SS 11
#define MOSI 12
#define MISO 13
#define FALSE 0
#define TRUE !FALSE
#define sensorPin A5

unsigned long prevTick = 0.0;


unsigned long lastTime = 0.0;
int clockState = LOW;
int prevClkState = LOW;
unsigned int clkCounter = 0;
unsigned int pressTime;
int bitNum[8];
int bitSent[] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
int bitsToSend = 0;
int ii;
void setup()
{

pinMode(CLK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SS, OUTPUT);

digitalWrite(CLK, LOW);
digitalWrite(MOSI, LOW);
digitalWrite(SS, HIGH);
}

void loop()
{

if ((millis() - prevTick) >= 1000)


{
clockState = !clockState;
digitalWrite(CLK, clockState);
prevTick = millis();
clkCounter++;
}

if (bitsToSend > 0)
{
if (!(bitSent[bitsToSend - 1]))
{
if ((clkCounter - pressTime) > (-1 * bitsToSend + 9))
{
if ((clockState == LOW) && ((millis() - lastTime) > 1000))
{
digitalWrite(SS, LOW);
digitalWrite(MOSI, bitNum[bitsToSend - 1]);
bitSent[bitsToSend - 1] = TRUE;
bitsToSend--;
lastTime = millis();
}
}
}
}
else
{
if (digitalRead(MISO) == HIGH)
{
if ((millis() - lastTime) > 2000)
{
digitalWrite(SS, HIGH);
digitalWrite(MOSI, LOW);
}
}

int temp_adc_val;
float tempC;
temp_adc_val = analogRead(sensorPin);
tempC = (temp_adc_val * 4.88);
tempC = tempC / 10;
tempC = tempC - 50;
int t = (int)tempC;

intToByteset(t);
pressTime = clkCounter;
lastTime = millis();

bitsToSend = 8;
for (ii = 0; ii < 8; ii++)
{
bitSent[ii] = FALSE;
}
}
delay(10);
}
void intToByteset(int n)
{
int t = n;
int i = 0;
while (n != 0)
{
bitNum[i] = n % 2;
n = n / 2;
i++;
}
for (int j = i; j < 8; j++)
{
bitNum[i] = 0;
}
if (t < 0)
{
bitNum[7] = 1;
}
}

OUTPUT: Screenshot of circuit from tinkercad simulator

Fig3. Circuit diagram for transfering temperature value read by slave to master and display it on
LCD using SPI communication protocol
INFERENCE:
Here, we are implemented SPI communication between two Arduino Uno. Master Arduino
connected with LCD and slave Arduino connected with temperature sensor. Temperature value read
by slave to master and displayed on LCD using SPI communication protocol.

RESULT:
Hence, we have made the required circuit and also verified the result using tinkercad.com.
Working with I2C
Date : 25/05/2021
Exp.No.: 11 Page No. 1

TASK-1
AIM:-
Write a program to implement a I2C communication between two Arduino Uno. Configure
one of the Arduino as master and other as slave. Master is interfaced with Switch (Push
button) and slave is connected with LED. Establish a I2C communication between master
and slave, blink a LED on slave whenever switch is pressed on Master. Simulate and verify
this logic on Arduino Uno using Tinkercad circuits simulator.
API REQUIRED:

 Wire.begin() -Initialize the I2C bus


 Wire.requestFrom(address, quantity) -Used by master to request bytes from a slave
address-7 bit address of the device to request bytes
 quantity-The number of bytes to request
 Wire.receive() –receives a byte of data transmitted from slave to master
 Wire.send() –sends data to master from slave on request
 Wire.onRequest(handler) –register a function to call when master request data from
slave
 Wire.onReceive(handler) -Registers a function to be called when a slave device
receives a transmission from a master
 Wire.read() –reads a byte transmitted form slave to master
 .write() –writes data to slave on request from master
 Wire.setClock()-modifies the clock frequency of I2C

MASTER PROGRAM:-
#include<Wire.h>
int pushbutton=13;
void setup()
{
Wire.begin();
Serial.begin(9600);
pinMode(13, INPUT);
}
int x=0;
void loop()
Wire.beginTransmission(4);
x=digitalRead(pushbutton);
Wire.write(x);
Serial.println(x);
Wire.endTransmission();
delay(500);
}
SLAVE PROGRAM:-
#include<Wire.h>
int led=13;
void setup()
{
Wire.begin(4);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop()
{
delay(100);
}
void receiveEvent(int howMany){
int x=Wire.read();
Serial.println(x);
if(x==1){
digitalWrite(led,HIGH);
}
else{
digitalWrite(led,LOW);
}
}

OUTPUT:
Fig1. Circuit diagram for establishing a I2C communication between master and
slave, blinking a LED on slave whenever switch is pressed on Master.

INFERENCE
Here, we are blinking the LED of slave whenever push-button is pressed on master.

RESULT:
Hence, we have designed the required circuit and verified the result using tinkercad.com.
TASK-2
AIM:
Write a program to implement a I2C communication between two Arduino Uno. Configure
one of the Arduino as master and other as slave. Both Arduino are attached with a LED &
a push button separately. Master LED can be controlled by using slave Arduino’s push
button and slave Arduino’s LED can be controlled by master Arduino’s push button using
I2C communication protocol. Simulate and verify this logic on Arduino Uno using
Tinkercad circuits simulator..
API REQUIRED:
 Wire.begin() -Initialize the I2C bus
 Wire.requestFrom(address, quantity) -Used by master to request bytes from a slave
address-7 bit address of the device to request bytes
 quantity-The number of bytes to request
 Wire.receive() –receives a byte of data transmitted from slave to master
 Wire.send() –sends data to master from slave on request
 Wire.onRequest(handler) –register a function to call when master request data from
slave
 Wire.onReceive(handler) -Registers a function to be called when a slave device
receives a transmission from a master
 Wire.read() –reads a byte transmitted form slave to master
 .write() –writes data to slave on request from master
 Wire.setClock()-modifies the clock frequency of I2C

PROGRAM:
#include<Wire.h>
int pushbutton=13;
void setup()
{
Wire.begin();
Serial.begin(9600);
pinMode(13, INPUT);
pinMode(12,OUTPUT);
}
int x=0;
void loop()
{
Wire.requestFrom(8,4);
if(Wire.available())
{
int y=Wire.read();
Serial.print("value of y is ");
Serial.println(y);
if(y>0){
digitalWrite(12,HIGH);
}
else{
digitalWrite(12,LOW);
}
}
Wire.beginTransmission(8);
x=digitalRead(pushbutton);
Wire.write(x);
Serial.println(x);
Wire.endTransmission();
delay(500);
}
SLAVE PROGRAM:
#include<Wire.h>
int led=12;
int pushbutton=13;
void setup()
{
Wire.begin(8);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(13,INPUT);
Wire.onRequest(requestEvent);
}
void loop()
{
delay(100);
}
void receiveEvent(int howMany){
int x=Wire.read();
Serial.println(x);
if(x==1){
digitalWrite(led,HIGH);
}
else{
digitalWrite(led,LOW);
}
}
void requestEvent(){
int y=digitalRead(13);
Serial.print("y value is");
Serial.println(y);
Wire.write(y);

OUTPUT: Screenshot of circuit from tinkercad simulator

Fig2. Circuit Diagram for controlling Master LED and slave Arduino’s LED by slave
and master Arduino’s push button respectively using I2C communication protocol
Case-1 When Master Push button is clicked ,Slave LED glows

Case-2 When Slave Push button is clicked ,Master LED glows

INFERENCE:
Here, we are blinking the LED of slave whenever push-button is pressed on master. Also
we are blinking the LED of master whenever push-button is pressed on slave.
RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.

TASK -3

AIM:-
Write a program to implement a I2C communication between two Arduino Uno. Configure
one of the Arduino as master and other as slave. Master Arduino connected with
temperature sensor and slave Arduino connected with LCD. Transfer temperature value
read by Master to slave and display it on LCD using I2C communication protocol.
Simulate and verify this logic on Arduino Uno using Tinkercad circuits simulator.
API REQUIRED:

 Wire.begin() -Initialize the I2C bus


 Wire.requestFrom(address, quantity) -Used by master to request bytes from a slave
address-7 bit address of the device to request bytes
 quantity-The number of bytes to request
 Wire.receive() –receives a byte of data transmitted from slave to master
 Wire.send() –sends data to master from slave on request
 Wire.onRequest(handler) –register a function to call when master request data from
slave
 Wire.onReceive(handler) -Registers a function to be called when a slave device
receives a transmission from a master
 Wire.read() –reads a byte transmitted form slave to master
 .write() –writes data to slave on request from master
 Wire.setClock()-modifies the clock frequency of I2C
 lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
 lcd.clear() :- It is used to clear all the contents on the LCD.
 lcd.write(x):- It is used to write the value of x on the LCD.
 lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
 lcd.print(x) :- It is used to print the x on the LCD.

Program:-
MASTER PROGRAM:
#include<Wire.h>
const int pinTemp=0;
#define SlaveAdres 8
float valVolt;
float valGradenC;
char tempBuff[7];
void setup()
{
Serial.begin(9600);
Wire.begin();
}
float getVolt(int pin)
{
return (analogRead(pin)*0.004882814);
}
void loop()
{
valVolt=getVolt(pinTemp);
valGradenC=(valVolt-0.5)*100.0;
dtostrf(valGradenC,7,2,tempBuff);
Serial.print("Temp. : ");
Serial.print(valGradenC);
Serial.print(" ");
Serial.println("C");
Wire.beginTransmission(SlaveAdres);
Wire.write(tempBuff);
Wire.endTransmission();
delay(200);
}
SLAVE PROGRAM:
#include<LiquidCrystal.h>
#include<Wire.h>
LiquidCrystal lcd(12,11,5,4,3,2);
#define SlaveAddress 8
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Temperature: ");
Wire.begin(SlaveAddress);
Wire.onReceive(Temp);
}
void loop()
{
delay(100);
}
void Temp(int howMany)
{
String dataString="";
float valinC=0.0;
while(Wire.available()){
char c=Wire.read();
dataString=dataString+c;
}
valinC=dataString.toFloat();
OUTPUT:-

Fig3. Circuit Diagram for transfering temperature value read by Master to slave and
display it on LCD using I2C communication protocol.
INFERENCE:
Here, we are reading temperature value using temperature sensor and sending this value to
the slave using master. Also we are printing the value on a 16*2 LCD using slave.

RESULT:-
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.
Challenging task 1:

AIM:
Write a program to implement a Single master multi-slave I2C communication between 4
Arduino Uno. Configure one of the Arduino as master and all other 3 as slave. Master
Arduino connected with LCD and 3 slave Arduino are connected with temperature sensor,
light intensity and gas sensor respectively. Transfer value read from sensor by slave to
master (for 2 sec delay between them) and display it on LCD using I2C communication
protocol. Simulate and verify this logic on Arduino Uno using Tinkercad circuits
simulator.

API REQUIRED:
 Wire.begin() -Initialize the I2C bus
 Wire.requestFrom(address, quantity) -Used by master to request bytes from a slave
address-7 bit address of the device to request bytes
 quantity-The number of bytes to request
 Wire.receive() –receives a byte of data transmitted from slave to master
 Wire.send() –sends data to master from slave on request
 Wire.onRequest(handler) –register a function to call when master request data from
slave
 Wire.onReceive(handler) -Registers a function to be called when a slave device
receives a transmission from a master
 Wire.read() –reads a byte transmitted form slave to master
 .write() –writes data to slave on request from master
 Wire.setClock()-modifies the clock frequency of I2C
 lcd.begin(x,y) :- It is used to initialize a LCD with x columns and y rows.
 lcd.clear() :- It is used to clear all the contents on the LCD.
 lcd.write(x):- It is used to write the value of x on the LCD.
 lcd.setCursor(y,x):- It will set the cursor to the y column and x row.
 lcd.print(x) :- It is used to print the x on the LCD.

PROGRAM:-
#include<LiquidCrystal.h>
#include<Wire.h>
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
Wire.begin();
Serial.begin(9600);
lcd.begin(16,2);
}
int x=0;
void loop(){
Wire.requestFrom(8,4);
lcd.clear();
if(Wire.available())
{
float y=Wire.read();
y=y*0.004882814;
y=(y-0.5)*100.0;
Serial.print("value read by temperature sensor is ");
Serial.println(y);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp in Celcius:");
lcd.setCursor(0,1);
lcd.print(y);
}
delay(2000);
Wire.requestFrom(7,4);
if(Wire.available())
{
int y=Wire.read();
Serial.print("value read by photo diode is ");
Serial.println(y);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Light intensity ");
lcd.setCursor(0,1);
lcd.print("value = ");
lcd.setCursor(9,1);
lcd.print(y);
} delay(2000);
Wire.requestFrom(6,4);
if(Wire.available())
{
int y=Wire.read();
Serial.print("value read by gas sensor is ");
Serial.println(y);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gas sensor value");
lcd.setCursor(0,1);
lcd.print("=");
lcd.setCursor(3,1);
lcd.print(y);
}
delay(2000);
}
SLAVE PROGRAM(SLAVE HAVING TEMPERATURE SENSOR) :-
#include<Wire.h>
int pushbutton=13;
void setup()
{
Wire.begin(7);
Serial.begin(9600);
pinMode(A0,INPUT);
Wire.onRequest(requestEvent);
}
void loop()
{
delay(100);
}
void requestEvent(){
int y=analogRead(A0);
Serial.print("y value is");
Serial.println(y);
Wire.write(y);
}
SLAVE PROGRAM(SLAVE HAVING PHOTORESISTOR) :-
#include<Wire.h>
int pushbutton=13;
void setup()
{
Wire.begin(7);
Serial.begin(9600);
pinMode(A0,INPUT);
Wire.onRequest(requestEvent);
}
void loop()
{
delay(100);
}
void requestEvent(){
int y=analogRead(A0);
Serial.print("y value is");
Serial.println(y);
Wire.write(y);
}
SLAVE PROGRAM(SLAVE HAVING GAS SENSOR) :-
#include<Wire.h>
int pushbutton=13;
void setup()
{
Wire.begin(6);
Serial.begin(9600);
pinMode(A0,INPUT);
Wire.onRequest(requestEvent);
}
void loop()
{
delay(100);
}
void requestEvent(){
int y=analogRead(A0);
Serial.print("y value is");
Serial.println(y);
Wire.write(y);
}

OUTPUT:-

Fig4. Circuit Diagram for transfering value read from sensor by slave to master (for 2
sec delay between them) and display it on LCD using I2C communication protocol.
INFERENCE:
Here, we are reading the value of current temperature, light intensity and gas concentration
using sensors and slave devices. After that we are printing all these values on a LCD with a
delay of 2 seconds using master.

RESULT:
Hence, we have designed the required circuit and also verified the result using
tinkercad.com.

You might also like