Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Table of Contents

Experiment Title 3
Objectives 3
Equipment List 3
Circuit Diagram 3
Code/Program 4
Hardware Output Results 8
Simulation Output Results 10
Discussion 13
References 13

Page 2 of 13
Experiment Title: Familiarization with a microcontroller, the study of blink test using and
implementation of a traffic control system using microcontroller and Proteus Simulation platform.

Objectives:
The objectives of this experiment are to-
1. Familiarize with the Arduino microcontroller
2. Implement a simple circuit to make an LED light to blink using the delay function
3. Implement a simple traffic control system

Equipment List:
1. Arduino board
2. Breadboard
3. LED lights (red, yellow, green)
4. Jumper wires

Circuit Diagram:
The Arduino platform is made up of the following components.

Fig. 1 Hardware circuit diagram for the blink light

Page 3 of 13
Fig. 2 Hardware circuit diagram for the traffic light

Code/Program:
(i) Codes for Fig. 1
void setup() {
// put your setup code here, to run once:
pinMode(5,OUTPUT);

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(5,HIGH);
delay(1000);
digitalWrite(5,LOW);
delay(1000);

Page 4 of 13
Explanation:
Line 1: void setup()
This line is to setup the Arduino devices.

Line 2: pinMode(5,OUTPUT);
This line is to setup the pin 5 of the Arduino device as output.

Line 3: void loop()


This is a function where main code is inputted which will run repeatedly.

Line 4: digitalWrite(5,HIGH);
In this line a function, digitalWrite where parameters are 5 and HIGH. 5 indicates pin 5 and HIGH
indicates the output of the pin as high.

Line 5: delay(1000);
In this line a function, delay is called. Where parameter is 1000. Here 1000 means 1000ms. During
1000ms there will be no changes in the output of the Arduino device.

Line 6: digitalWrite(5,LOW);
In this line a function, digitalWrite where parameters are 5 and LOW. 5 indicates pin 5 and LOW
indicates the output of the pin as low.

Line 7: delay(1000);
Same as line 5.

(ii) Code for traffic light


#define redPin 3
#define yellowPin 6
#define greenPin 11

int redOn=3000;
int yellowBlink=1000;
int greenOn=5000;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}

void loop() {
digitalWrite(greenPin, HIGH);
delay(greenOn);
digitalWrite(greenPin, LOW);
for(int i=0; i<=3; i++)
{

Page 5 of 13
digitalWrite(yellowPin, HIGH);
delay(yellowBlink);
digitalWrite(yellowPin, LOW);
delay(yellowBlink);
}
digitalWrite(redPin, HIGH);
delay(redOn);
digitalWrite(redPin, LOW);

Explanation:
Line 1: #define redPin 3
In this line redPin is defined as pin 3 of the Arduino device.

Line 2: #define yellowPin 6


In this line yellowPin is defined as pin 6 of the Arduino device.

Line 3: #define greenPin 11


In this line greenPin is defined as pin 11 of the Arduino device.

Line 4: int redOn=3000;


An int type variable, redOn, is declared which is initialized as 3000.

Line 5: int yellowBlink=1000;


An int type variable, yellowBlink, is declared which is initialized as 1000.

Line 6: int greenOn=5000;


An int type variable, greenOn, is declared which is initialized as 5000.

Line 7: void setup()


This line is to setup the Arduino devices.

Line 8: pinMode(redPin, OUTPUT);


This line is to setup the pin redPin (pin 3) of the Arduino device as output.

Line 9: pinMode(yellowPin, OUTPUT);


This line is to setup the pin redPin (pin 6) of the Arduino device as output.

Line 10: pinMode(greenPin, OUTPUT);


This line is to setup the pin greenPin (pin 11) of the Arduino device as output.

Line 11: void loop()


This is a function where main code is inputted which will run repeatedly.

Page 6 of 13
Line 12: digitalWrite(greenPin, HIGH);
In this line a function, digitalWrite where parameters are greenPin (pin 11) and HIGH. 11 indicates
pin 3 and HIGH indicates the output of the pin as high.

Line 13: delay(greenOn);


In this line a function, delay is called. Where parameter is greenOn. The value of greenOn is 5000.
Here 5000 means 5000ms. During 5000ms there will be no changes in the output of the Arduino device.

Line 14: digitalWrite(greenPin, LOW);


In this line a function, digitalWrite where parameters are greenPin (pin 11) and LOW. 11 indicates
pin 3 and LOW indicates the output of the pin as low.

Line 15: for(int i=0; i<=3; i++)


This line is a for statement which is known as for loop. Here int type variable i starts from 0 and
ends to 3. The variable i is increased by 1 for every loop. So the loop is run for 4 times.

Line 16: digitalWrite(yellowPin, HIGH);


In this line a function, digitalWrite where parameters are yellowPin (pin 3) and HIGH. 3 indicates
pin 3 and HIGH indicates the output of the pin as high.

Line 17: delay(yellowBlink);


In this line a function, delay is called. Where parameter is yellowBlink. The value of yellowBlink
is 1000. Here 1000 means 1000ms. During 5000ms there will be no changes in the output of the Arduino
device.

Line 18: digitalWrite(yellowPin, LOW);


In this line a function, digitalWrite where parameters are yellowPin (pin 6) and LOW. 3 indicates pin 3
and LOW indicates the output of the pin as low.

Line 19: delay(yellowBlink);


Same as line 17.

Line 12: digitalWrite(redPin, HIGH);


In this line a function, digitalWrite where parameters are redPin (pin 3) and HIGH. 3 indicates pin
3 and HIGH indicates the output of the pin as high.

Line 13: delay(redOn);


In this line a function, delay is called. Where parameter is redOn. The value of redOn is 3000.
Here 3000 means 3000ms. During 3000ms there will be no changes in the output of the Arduino device.

Line 14: digitalWrite(redPin, LOW);


In this line a function, digitalWrite where parameters are redPin (pin 3) and LOW. 3 indicates pin
3 and LOW indicates the output of the pin as low.

Page 7 of 13
Hardware Output Results:

Blink Light: In this figure the light is turned on and off repeatedly after 1000ms.

Fig. 1.1: Blink Light (Light is off)

Fig. 1.2: Blink Light (Light is on)

Page 8 of 13
Traffic light: In this figure the green is turned on for 5000ms. Then the yellow light is turned on for
1000ms and turned off for 1000ms for 4 times repeatedly. Then the red light is turned on for 3000ms. This
whole process will be repeated forever until change.

Fig. 2.1: Traffic Light (Green light is on)

Fig. 2.2: Traffic Light (Yellow light is on)

Page 9 of 13
Fig. 2.3: Traffic Light (Red light is on)

Simulation Output Results:


Blink light: For this simulation, 1 Arduino Uno R3, 1 resistor and a led light was used. Pin 5 of the
Arduino device, resistor, led light, and the ground pin of Arduino device was connected in series. Then
the code of blink light was inputted into the Arduino device.

Fig. 1.1: Blink Light (Light is off)

Page 10 of 13
Fig. 1.2: Blink Light (Light is on)
Traffic Light: For this simulation, 1 Arduino Uno R3, 3 resistor, 1 red led light, 1 yellow led light, 1
green led light and a breadboard was used. Pin 11 of the Arduino devices, a resistor, the green led, and
ground was connected in series. Like this Pin 6 was in series with yellow led and Pin 3 was in series with
red led. Then the code of traffic light was inputted into the Arduino device.

Fig. 2.1: Traffic Light (Green light is on)

Page 11 of 13
Fig. 2.2: Traffic Light (Yellow light is on)

Fig. 2.3: Traffic Light (Red light is on)

Page 12 of 13
Discussion:
 In this lab experiment we learned how to use Arduino device. For that we had to use Arduino
software.
 In this experiment we simulated two simple task, blink light and traffic lights.
 For the blink light we had to setup a pin for output. Then in the loop function we had to call
function to turn the light on, off and delay.
 For the traffic lights we had to setup 3 pins for the output. The pins are for green, yellow and red.
In the loop function first, we had to call function digitalWrite and delay to turn on the green light
for few times. Then we had to use same functions in a for loop to blink the yellow light for 4 times.
Finally using same functions, we turned on the red light for few times.
 There was no issue in both hardware and software simulations.

References:
1) https://www.arduino.cc/.
2) https://www.coursera.org/learn/arduino/lecture/ei4ni/1-10-first-glance-at-a-program
3) Jeremy Blum; Exploring Arduino: Tools and Techniques for Engineering Wizardry

Page 13 of 13

You might also like