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

PL Report

This document provides instructions for blinking an LED using an Arduino board. It explains that the built-in LED on the Arduino is connected to a digital pin and can be controlled through code. The code turns the LED on for 1 second, then off for 1 second, repeating indefinitely. This is done by setting the pin to OUTPUT mode and using digitalWrite to set it HIGH or LOW, with delay commands in between to control the timing. The loop function runs these commands continuously to blink the LED on and off each second.

Uploaded by

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

PL Report

This document provides instructions for blinking an LED using an Arduino board. It explains that the built-in LED on the Arduino is connected to a digital pin and can be controlled through code. The code turns the LED on for 1 second, then off for 1 second, repeating indefinitely. This is done by setting the pin to OUTPUT mode and using digitalWrite to set it HIGH or LOW, with delay commands in between to control the timing. The loop function runs these commands continuously to blink the LED on and off each second.

Uploaded by

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

NED UNIVERSITY OF ENGINEERING

AND TECHNOLOGY

DEPARTMENT OF TELECOMMUNICATIONS ENGINEERING


BATCH 2023

OEL REPORT

COURSE CODE AND TITLE: PROGRAMMING LANGUAGES


(TC-105)

 MAHRUKH ARIF (TC-013)

ASSIGNED BY:

DR AMIR ZEB
Blinking LED
Turn an LED on and off every second.

In this introductory Arduino example, we explore the most basic output function
– blinking the on-board LED. Before diving into the code, let's understand some
fundamentals.

An LED, or Light Emitting Diode, is a semiconductor device that only allows


electricity to flow in one direction. It has two leads – the longer one, known as
the anode, is positive, and the shorter one, called the cathode, is negative. The
Arduino board includes a built-in LED, usually connected to a digital pin, and
we'll control it using a simple sketch.

COMPONENTS:
Arduino Board

LED

220 ohm resistor

Circuit
This example uses the built-in LED that most Arduino boards have. This LED is connected to a
digital pin and its number may vary from board type to board type. To make your life easier, we have
a constant that is specified in every board descriptor file. This constant is pinled and allows you to
control the built-in LED easily.

If you want to light an external LED with this sketch, you need to build this circuit, where you connect
one end of the resistor to the digital pin correspondent to the pinled constant. Connect the long leg
of the LED (the positive leg, called the anode) to the other end of the resistor. Connect the short leg
of the LED (the negative leg, called the cathode) to the GND. In the diagram below we show an UNO
board that has D13 as the pinled value.

The value of the resistor in series with the LED may be of a different value than 220 ohms; the LED
will light up also with values up to 1K ohm.
CODE FOR BLINKING LIGHT

/*

blink

1. Turn on LED for 1 second

2. Turn off LED for 1 second

3. Repeat

*/

int pinled = 9;

void setup() {

// initialize the digital pin as an output.

pinMode(pinled, OUTPUT);

// the loop routine runs over and over again forever:

void loop() {

digitalWrite(pinled, HIGH); // turn the LED on

delay(1000); // wait for a second

digitalWrite(pinled, LOW); // turn the LED off

delay(1000); // wait for a second

After you build the circuit plug your Arduino board into your computer, start the Arduino
Software (IDE) and enter the code below. You may also load it from the menu
File/Examples/01.Basics/Blink . The first thing you do is to initialize pinled pin as an output
pin with the line

pinMode(pinled,OUTPUT);
Your setup function only has one statement and that is pinMode, which telling the Arduino
that you want to set the mode of one of your pins to be in OUTPUT mode, rather than INPUT
mode. This also means that the Arduino is writing to a pin instead of reading from it.
Within the parenthesis, you put the pin number and the mode (OUTPUT or INPUT). Your pin
number is pinled, which is the variable that has been previously set to the value 9. Therefore, this
statement is simply telling the Arduino that Digital Pin 9 is to be set to OUTPUT mode. As
the setup( ) function runs only once, you now move onto the main function which is the loop
function.

In the main loop, you turn the LED on with the line:

digitalWrite(pinled,HIGH);
This supplies 5 volts to the LED anode. That creates a voltage difference across the pins of the
LED, and lights it up. Then you turn it off with the line:

digitalWrite(pinled, LOW);
That takes the pinled pin back to 0 volts, and turns the LED off. In between the on and the off, you want
enough time for a person to see the change, so the
delay()
commands tell the board to do nothing for 1000 milliseconds, or one second. When you use the
delay()
command, nothing else happens for that amount of time. Once you've understood the basic examples,
check out the BlinkWithoutDelay example to learn how to create a delay while doing other things.

The loop( ) function runs continuously as long as the Arduino is turned on. Every statement within
the loop( ) function (that is within it’s curly braces) is carried out, one by one, step by step, until
the bottom of the function is reached, then the loop starts again at the top of the function, and so
on forever or until you turn the Arduino off or press the Reset switch on your Arduino board.
In this project, you want the LED to turn on, stay on for one second, turn off and remain off for
one second, and then repeat. The commands to tell the Arduino to do this are contained within
the loop ( ) function because you want them to repeat over and over. The first statement is
digitalWrite(pinled, HIGH);

Conclusion:

This simple project serves as a starting point for Arduino beginners. As you progress, explore
advanced examples like "BlinkWithoutDelay" to incorporate delays while performing
additional tasks. The loop() function runs continuously until the Arduino is powered off or
reset, providing a foundation for more complex projects.

You might also like