Exp. No - 1

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

FUNDAMENTALS OF IOT

AND SENSOR – 23EC1101


Experiment Number - 1
Experiment No 1 Student ID
Date Student Name

LED INTERFACE WITH ARDUINO


Aim/Objective: The main objective of this experiment is,
a. To blink an LED with a delay of 2 seconds.
b. To Blink 2 LED'S alternatively with a delay of 1 second.
Description:
LED blinking is the most beginner & easy step to start experiments with arduino. Firstly, identify
anode(+ve) & cathode (-ve) leg of LED. Following diagram gives a clear idea of LED.

Now connect a resistor to positive leg and other end of resistor to 5V.Cathode will be connected
to Arduino GPIO, in this case pin 13. Final circuit will look as below.
Connection Diagram:

Fig.1 LED Interface with Aurdino

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 1 of 10
Experiment No 1 Student ID
Date Student Name

a. Blink an LED with delay of 2 seconds

b. Blink an 2 LED’s alternatively

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 2 of 10
Experiment No 1 Student ID
Date Student Name

Circuit/Schematic Diagram:

Pre-Requisites:
• Electronics fundamentals
• Basic knowledge about Arduino Pins

Pre-Lab:
1. What are the components required for blinking LED using Arduino?

• 1 × Breadboard.
• 1 × Arduino Uno R3.
• 1 × LED.
• 1 × 330Ω Resistor.
• 2 × Jumper.
2. What is the use of Arduino program with LED blink?
Arduino program in LED blink is useful to see the physical output of the experiment. It
blinks the on-board LED and turns it on and off according to the delay given in the
code/program.
3. List out the types of LED’s.

• Dual In-Line Package (DIP) LEDs. DIP LED Lights. DIP LED chips are the

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 3 of 10
Experiment No 1 Student ID
Date Student Name

original
LED chips
• Surface Mounted Diode (SMD) LEDs.
• Chip on Board (COB) LEDs.
4. How many analog pins are present in the Arduino Boards?
The Arduino UNO has 6 analog inputs, labeled A0 through A5, each of which provide 10
bits of resolution.
5. List the important uses of LEDs.
LEDs are commonly used in,
• Streetlights
• Parking garage lighting
• Refrigerated case lighting.
• Walkway and other outdoor area lighting

In-Lab:
Procedure:
1. Give the connections to the Arduino board as shown in the connection diagram.
2. Open Arduino IDE in the computer
3. Create new file File_--→ New
4. Type your program and Save it in appropriate location in your computer.
5. Compile your program by clicking Verify option in the menu.
6. Once the program compiled successfully, connect the Arduino board to the computer
using USB cable.
7. After connecting, go to Tools ----→Board ---→ Select Arduino/Genuino Uno option
8. After selecting board, go to Tools ----→Port ---→ Select Arduino Uno COM port 3
(name may appear differently for other computers).
9. Note that this port option will be displayed only when board is connected to
computer
10. Now upload the program to the Arduino board by clicking Upload option.
11. Observe the output.

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 4 of 10
Experiment No 1 Student ID
Date Student Name

Programs:
A. Blink an LED with delay of 2 seconds
#define LED 13
void setup()
{
//put your code inside this setup()to execute one time
pinMode(LED, OUTPUT); // making 13 pin as output
}
void loop()
{
//put your code inside this loop()to execute infinite no of times
digitalWrite(LED, HIGH); //turning on the LED
delay(2000); // Wait for 2000 millisecond(s)
digitalWrite(LED, LOW); //turning on the LED
delay(2000); // Wait for 2000 millisecond(s)
}

B. Blink 2 LED’s alternatively with a delay of one second


#define RED_LED 13
#define GREEN_LED 12
void setup()
{
//put your code inside this setup()to execute one time
pinMode(RED_LED, OUTPUT); // making 13 pin as output
pinMode(GREEN_LED, OUTPUT); // making 13 pin as output
}
void loop()
{
//put your code inside this loop()to execute infinite no of times
digitalWrite(RED_LED, HIGH); //turning on the LED
digitalWrite(GREEN_LED, LOW); //turning off the LED
delay(1000); // Wait for 1000 millisecond(s)

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 5 of 10
Experiment No 1 Student ID
Date Student Name

digitalWrite(GREEN_LED, HIGH); //turning on the LED


digitalWrite(RED_LED, LOW); //turning off the LED
delay(1000); // Wait for 1000 millisecond(s)
}
Results:

Analysis and Inferences:

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 6 of 10
Experiment No 1 Student ID
Date Student Name

VIVA-VOCE Questions (In-Lab):


1. What is the Command used to declare the inputs/outputs in Arduino?
The pinMode() function is used to configure a specific pin to behave either as an input or an
output.
2. What is the Use of resistor in connection Diagram (Fig.1)?
The LED's legs are connected to two pins on the Arduino: ground and pin 13. The component
between the LED and pin 13 is a resistor, which helps limit the current to prevent the LED
from burning itself out.
3. What do you think the function digitalWrite( ) does? What information must go in its
parentheses for it to work?
This function is used to turn a digital I/O pin on (HIGH) or off (LOW). In order for it to work,
this function requires two arguments. digitalWrite(arg1, arg2). The first argument is the number
of the digital pin you’re looking to control, and the second is the state to which you want to set
that pin (either HIGH or LOW).
4. What do you think the function delay ( ) does? What does the number inside its
parentheses represent?
The delay function tells the Arduino to wait for a certain amount of time before moving onto
and executing the next line of code. The number inside the parentheses is the number of
milliseconds that the Arduino will wait before continuing on.
5. Figure out how to change the blink-rate of the LED. For example, try to get the LED
to blink twice as fast, twice as slow, or with a completely new pattern. Describe what you
changed in the program to do this.
An easy way to change the blink rate of the LED is to change the numbers in the delay
functions. In order to get the LED to blink twice as fast, change the number in each delay to
500. In order to make the LED blink twice as slow, change each delay to 2000.
6. Figure out how to add a second LED and get it to blink opposite the first LED (when
the first one is on, the second one should be off). Sketch the new setup below and describe
the changes you made to the program to accomplish this.
Add an additional LED to the original setup as follows. Place the two legs of the new LED into
two new rows. Connect the shorter leg to a resistor that on the other end connects to the GND
column. Using a wire, connect the long leg of the LED to another
digital pin, such as pin 6. Then modify the code as follows (the differences are in bold).

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 7 of 10
Experiment No 1 Student ID
Date Student Name

Post-Lab:
1. To Blink an LED with a random delay.

Program:
int ledPin=8; //definition digital 8 pins as pin to control the LED
void setup()
{
pinMode(ledPin,OUTPUT); //Set the digital 8 port mode, OUTPUT: Output mode
}
void loop()
{
digitalWrite(ledPin,HIGH); //HIGH is set to about 5V PIN8
delay(3000); //Set the delay time, 1000 = 1S

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 8 of 10
Experiment No 1 Student ID
Date Student Name

digitalWrite(ledPin,LOW); //LOW is set to about 5V PIN8


delay(1000); //Set the delay time, 1000 = 1S
}
2. To Blink 3 LED'S with a delay.

Program:
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 9 of 10
Experiment No 1 Student ID
Date Student Name

digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
}

Results:

Evaluator Remark (if Any):


Marks Secured:_____out of 50

Signature of the Evaluator with Date

Course Title 23EC1101 ACADEMIC YEAR: 2023-24


Course Code(s) FUNDAMENTALS OF IOT AND SENSORS Page 10 of 10

You might also like