Activity 1113472

You might also like

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

Using Arduino – D1 Blinking LED (worksheet) For the students

D1 Blinking LED
How do you modify an Arduino sketch so that an LED blinks differently?

You are probably familiar with objects from your everyday life that transmit information
through light signals. LEDs are used in everything from advertising signs and traffic
signs to household items. To send the detailed information, microcontrollers are often
used, in which a specific flashing sequence is programmed.
In this project you will program the Arduino so that an LED will blink in a sequence of
your choice.
An Arduino sketch always consists of at least two parts. The part “void setup” is run
through once when starting the Arduino. The part “void loop” is repeated over and over
again. Every command that the Arduino is supposed to execute ends with a semicolon.
Further explanations of the Arduino sketch can be found in the comments behind the
commands (//).

Components:
 Arduino Uno  resistor 220 , colors:
 breadboard red – red – brown – silver or
 jumping wires red – red – brown – gold
 LED
First, build the circuit with the Arduino and the breadboard as shown in the left figure.
A breadboard gives you an easy way to connect electrical components without using a
soldering iron. There are vertical groups of five holes with springs inside which are
interconnected. Holes in horizontal lines, joined by blue and red lines, are also
interconnected.

You can easily insert the metal wires of


the resistor and the LED into these
holes. When it comes to colors always
use the holes on the red side for the pos-
Figure 1: Layout of the circuit on the breadboard itive power (+5V or Vcc) and the holes
and connection to the Arduino. on the blue or black side for the negative
or ground (GND).

© Siemens Stiftung 2021. Content licensed under CC BY-SA 4.0 international Page 1 of 3
Using Arduino – D1 Blinking LED (worksheet) For the students

Make sure that the long end of the LED is connected to pin 3 via the resistor and the
short end to the GND pin. There are three pins named GND and you can use any of
them. Check again that you have built the circuit correctly.
Now start the Arduino IDE if you have not done it yet.

The Arduino icon should appear on the desktop of your computer.


In case the IDE shows another program, press open FILE – NEW to get an empty
window showing only the setup and the loop function.
You can delete the existing text and copy and paste the complete program that you find
below.
If you type in the commands manually, please note that the Arduino language is case
sensitive; use the shift key for capital or upper case letters and no shift key for lower
case.
Also notice: If you had two copies of the setup or the loop function, you will get an error
message.

Sketch 1:
const byte ledPin = 3;

void setup() { // the setup is run once when the Arduino is started
pinMode(ledPin, OUTPUT); // make ledPin to operate as output
}

void loop() { // this loop is run continuously


digitalWrite(ledPin, HIGH); // apply a potential of 5 V to ledPin
delay(1000); // delay 1 second
digitalWrite(ledPin, LOW); // apply a potential of 0 V to ledPin
delay(1000); // delay 1 second
}

Now connect the Arduino to a computer using a USB cable.


Make sure that in TOOLS – BOARD Arduino Uno is selected. And make sure that in
TOOLS – PORT a valid port is selected, e.g. COM3 or COM4 or something else. If you
connect your Arduino board to a different USB port most probably, a different port
number will be shown. The selected port will also be shown in the bottom right corner of
the IDE window.
When you are finished press the upload button to upload the program onto the Arduino.
If you have done everything correctly, the LED will flash every second.
Error messages will be printed in red on black at the bottom of the Arduino window.
If in the beginning you do not fully understand these messages, simply ask your teacher
for assistance.
It is a good idea to save your program on the hard disk of the computer by using the
FILE – SAVE AS menu command. The Arduino system will create a new folder with this
name and put your file into this folder, adding “.ino” to that name. Do not save or move
other Arduino programs into that folder.
You can open your saved program by using the FILE – OPEN command.

© Siemens Stiftung 2021. Content licensed under CC BY-SA 4.0 international Page 2 of 3
Using Arduino – D1 Blinking LED (worksheet) For the students

Observing and documenting:

Consider how the Arduino circuit with microcontroller differs from a conventional circuit
with two buttons and lamp.
Microcontroller circuits can be programmed using a computer. This programming
involves sensing the input states of the pins and controlling the output pins according to
the programming. The behavior of the LED can be adjusted by programming (off, on,
dim, flash, ...).
Change the Arduino sketch so that the LED ...
 … flashes twice as fast.
 … flashes half as fast.
 … flashes twice quickly and twice slowly in succession.
 … flashes in a rhythm of your choice.

Describe your approach and contact your teacher for further information.

1. Think about how to adjust the Arduino sketch to make two different LEDs blink.
2. Build a simple signal control where two LEDs light up alternately.
3. What number of flashes can a person just recognize as single light and when does
the flashing appear as a permanent light?
To check this, change the flashing duration and the pause in the sketch
(20-19-18-17-16 milliseconds (ms). Distribute these tasks among the different
groups.
Here is a little trick to detect faster flashings: do not focus on the LED directly but
look somewhere else.
Example: 20 ms flashing and 20 ms pause result in a 40 ms action duration.
One second equals 1,000 milliseconds. When you divide 1,000 ms by 40 ms, you
get 25, which means the on-off cycle is repeated 25 times per second.
The number of cycles per second is the frequency, and the unit of frequency is
Hertz, abbreviated as Hz. You can simply say the flashing frequency is 25 Hz.

 Where would such a circuit prove useful?


 Can you think of everyday examples for which light signal circuits are used?

© Siemens Stiftung 2021. Content licensed under CC BY-SA 4.0 international Page 3 of 3

You might also like