Professional Documents
Culture Documents
Activity 1113472
Activity 1113472
Activity 1113472
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.
© 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.
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
}
© 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
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.
© Siemens Stiftung 2021. Content licensed under CC BY-SA 4.0 international Page 3 of 3