Address
304 North Cardinal
St. Dorchester Center, MA 02124
Work Hours
Monday to Friday: 7AM - 7PM
Weekend: 10AM - 5PM
Address
304 North Cardinal
St. Dorchester Center, MA 02124
Work Hours
Monday to Friday: 7AM - 7PM
Weekend: 10AM - 5PM
In this tutorial, we will start the journey of learning Arduino UNO. To begin,
let’s learn how to make blink LED.
In this lesson, we will program the Arduino’s GPIO output high level (+5V) and low level (0V), and then make the LED which is connected to the Arduino’s GPIO flicker with a certain frequency.
The LED is the abbreviation of light emitting diode. It is usually made of
gallium arsenide, gallium phosphide semiconductor materials. The LED has two electrodes: a positive electrode and a negative one. It lights up only when a forward current passes, and it can flash red, blue, green, yellow, etc. The color of the light depends on the material it is made.
In general, the drive current for the LED is 5-20mA. Therefore, in reality, it usually needs an extra resistor for current limitation to protect the LED.
The main function of the resistor is to limit currents. In the circuit, the character ‘R’ represents a resistor, and the unit of resistor is ohm(Ω).
A band resistor is used in this experiment. It is a resistor with a surface coated with some particular color through which the resistance can be identified directly.
There are two methods for connecting LED to pins of an Arduino board:
As shown in the schematic diagram, the anode of the LED is connected to Arduino’s GPIO via a resistor, and the cathode to ground (GND). When the GPIO outputs a high level, the LED is on; when it outputs low, the LED is off.
The resistance of a current-limiting resistor is calculated as follows: 5~20mA current is required to make an LED on, and the output voltage of the Arduino UNO’s GPIO is 5V, so we can get the resistance:
R = U / I = 5V / (5~20mA) = 250Ω~1kΩ
Since an LED is a resistor itself, here we use a 220ohm resistor
As shown in the schematic diagram above, the anode of the LED is connected toVCC(+5V), and the cathode of the LED is connected to the Arduino’s GPIO. When the GPIO output low level, the LED is on; when the GPIO output high level, the LED is off.
The experiment is made based on method ① – use pin D8 of the Arduino board to control an LED. When D8 is programmed to output high level, the LED will
be turned on. Next, delay for some time. Then D8 is programmed to output
low level to turn the LED off. Repeat the above process and you can get a blinking LED then.
●setup()
The setup() function is called when a sketch starts. Use it to initialize variables,
pin modes, start using libraries, etc. The setup function will only run once,
after each power up or reset of the Arduino board.
●loop()
After creating a setup() function, which initializes and sets the initial values,
the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.
●pinMode()
Configures the specified pin to behave either as an input or an output.
As of Arduino 1.0.1, it is possible to enable the internal pull up resistors with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pull-ups.
●digitalWrite()
Write a HIGH or a LOW value to a digital pin.
If the pin has been configured as an OUTPUT with pinMode(), its voltage will beset to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable(LOW) the internal pull up on the input pin. It is recommended to set thepinMode() to INPUT_PULLUP to enable the internal pull-up resistor.
●delay()
Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.)
Step 1: Build the circuit
Step 2: Program
/****************************************************************************************************
File name: 01_blinkingLed.in
Description: Lit LED, let LED blinks.
Website: www.Iduino.co.in
E-mail: support@Iduino.co.in
Modified BY: IDUINO
****************************************************************************************************/
int ledPin=8; //definition digital 8 pin 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(1000); //Set the delay time, 1000 = 1S
digitalWrite(ledPin,LOW); //LOW is set to about 5V PIN8
delay(1000); //Set the delay time, 1000 = 1S
}
Step 3: Compile the program and upload to Arduino UNO board
Now you can see the LED blinking.