[vc_row][vc_column width=”1/1″][vc_column_text]LED (Light-Emitting Diode) is a semiconductor diode that converts applied voltage to light and is used in lamps and digital displays.
The long leg is positive and the short leg is negative. When apply positive voltage, we need to use resistor in serial to limit the current. The limiting resistor value can be computed as follows:
R=(E-U)/I
where E is the applied voltage, U is the voltage drop across the LED, I is the working current of the LED. A LED working voltage is normally 1.5V to 2.0V, and working current is 10mA to 20mA. So in this case, the resistor we choose is 220R.
[/vc_column_text][vc_text_separator title=”Experiment 1-1 Single LED Blink” title_align=”separator_align_center”][vc_tour][vc_tab title=”BOM” tab_id=”1383865268-1-35″][vc_column_text]To do this experiment, we need the following components:
Arduino Board Package
- Arduino Uno
- USB cable
- Jumper wire
1 x LED
1 x Resistor of 220 ohm
Several jumper wires[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1383865268-2-86″][vc_column_text]
[/vc_column_text][/vc_tab][vc_tab title=”Principle” tab_id=”1383865642264-2-0″][vc_column_text]We will turn on the LED for one second, and turn off the LED for one second, and so on. In the code, we will use pin 13 to control the LED. There is also a LED on pin 13 on the Arduino board, so that both LEDs will blink at the same frequency.
[/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1383865723929-3-5″][vc_column_text]
/*
LED blink
*/
// Define LED to use pin 13
int LED = 13;
void setup() {
//Configure pin 13 to be output
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH); // Turn on LED
delay(1000); //Keep for 1 second
digitalWrite(LED, LOW); // Turn off LED
delay(1000); // Keep for 1 second
}
Download the code here (LED_blink).
[/vc_column_text][/vc_tab][/vc_tour][vc_text_separator title=”Experiment 1-2: Mutiple LEDs blink” title_align=”separator_align_center”][vc_tour][vc_tab title=”BOM” tab_id=”1383865737-1-87″][vc_column_text]To do this experiment, we need the following components:
Arduino Board Package
- Arduino Uno
- USB cable
- Jumper wire
6 x LED
6 x Resistor of 220 ohm
Several jumper wires[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1383865737-2-57″][vc_column_text]
[/vc_column_text][/vc_tab][vc_tab title=”Principle” tab_id=”1383865953872-2-6″][vc_column_text]We will implement the following:
1. Turn on in sequence, and then turn off in sequence
2. All 6 LEDs blink at the same time
3. Two LEDs blink at the same time.[/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1383866032885-3-0″][vc_column_text]
/*
Multiple LEDs blink
*/
int LED1=8;
int LED2=9;
int LED3=10;
int LED4=11;
int LED5=12;
int LED6=13;
int n;
void setup()
{ //Configure the pins
for(n=8;n<=13;n++)
{
pinMode(n, OUTPUT);
}
}
void loop()
{
turn1();//Turn on all LEDs in sequence, and then turn on in sequence
clean(); //Turn off all LEDs
turn2();//All 6 LEds blink
clean();//Turn off all LEDs
turn3();
clean();//Turn off all LEDs
}
void turn1()
{
for(n=8;n<=13;n++)
{
digitalWrite(n,HIGH);
delay(300);
}
for(n=8;n<=13;n++)
{
digitalWrite(n,LOW);
delay(300);
}
}
void turn2()
{ for(int x=0;x<=2;x++)
{
for(n=8;n<=13;n++)
{
digitalWrite(n,HIGH);
}
delay(300);
for(n=8;n<=13;n++)
{
digitalWrite(n,LOW);
}
delay(300);
}
}
void turn3()
{
for(int x=0;x<=2;x++)
{
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
for(n=10;n<=13;n++){
digitalWrite(n,LOW);
}
delay(300);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(300);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
for(n=8;n<=11;n++){
digitalWrite(n,LOW);
}
delay(300);
}
}
void clean()
{ for(n=8;n<=13;n++)
{
digitalWrite(n,LOW);
}
delay(300);
}
Download the code here (MoreLED_blink ).
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.