HELLO THERE!!!!
What a beautiful day today, I hope anybody reading this article is fine and happy always. I would like to share one of the most simple experiments that I actually did while tinkering with arduino. The main aim of this experiment will be to:
1. Familiarize with the Arduino IDE environment
2. To light up an LED by coding in Arduino
Ok, now lets go to the hardwares/softwares needed for this experiment.
Hardware:
1. Arduino UNO
2. LED
3. Resistor (330 ohms should be fine)
The LED and the resistor is optional. This is because the Arduino has a LED at pin 13 which can be used in this experiment.
Software:
1.Arduino IDE
You can download the IDE here: https://www.arduino.cc/en/Main/Software
Alright, now that the hardware and software requirements are done, let's go to the circuit assembly. If you do not have any LED and resistor, just plug in the arduino into your computer/laptop.There is a LED right off the pin 13 if you see closely labeled L. We'll use it to blink in this experiment. If you are using the LED and resistor, the image below visualizes the assembly of the circuit:
Precaution: Inverting the polarity of the LED may burn the LED. Long leg goes to the output pin while the short leg goes to the GND.
Now for the code. You can find the arduino blink code easily on the web. I'll also post the code here with explanation. Before that, lets see the blank arduino IDE sketch:
You can see the blank sketch on the image left. It has few things in it, mainly the void setup and the void loop. Ok before we write the code, we need to need where and when to write the code.
1. All variable initialization will go before the void setup. For an example, in this experiment, we are using a LED in pin 13 of arduino. To initialize it, we will write this before void setup:
int LED = 13;
the name LED can be customized according to your preference. The number 13 represents the position of the LED on the Arduino board. If you use pin 12, then, the number will be 12 and so on.
Next, the void setup. This is where you initialize your input and output of the program. In this case, our LED is going to be our output. So we need to write this in our void setup:
pinMode(LED, OUTPUT);
The line above is shows that the mode of the LED pin (which is pin 13) is going to be output.
Next, void loop. This is where all the "magic" happens. This is where you will write the process of the program. In our experiment, we want our LED on and off with the time delay of 5 seconds. So in void loop we will write this:
digitalWrite (LED, HIGH);
delay(5000);
digitalWrite(LED, LOW);
delay(5000);
Ok, the first line of the code turns on the LED. The second line of the code gives delay for about 5 seconds. This means that the LED will be turned on for about 5 seconds. The third line turns off the LED while the fourth line gives delay for about 5 seconds. The LED will turn on for five seconds and turn off for five seconds and on and off again. You can try decreasing the delay to 1000(1 second), 500(0.5 second) and other values to see what happens.
Now that the code is completed, compile, save and upload the code to the Arduino board and see the LED turns on and off according to the written code. It is that simple!!! For next experiment, I might show on how to turn on and off multiple LED's by using arduino. Until then, I hope you guys could take benefit from this experiment and have fun!!!
What a beautiful day today, I hope anybody reading this article is fine and happy always. I would like to share one of the most simple experiments that I actually did while tinkering with arduino. The main aim of this experiment will be to:
1. Familiarize with the Arduino IDE environment
2. To light up an LED by coding in Arduino
Ok, now lets go to the hardwares/softwares needed for this experiment.
Hardware:
1. Arduino UNO
2. LED
3. Resistor (330 ohms should be fine)
The LED and the resistor is optional. This is because the Arduino has a LED at pin 13 which can be used in this experiment.
Software:
1.Arduino IDE
You can download the IDE here: https://www.arduino.cc/en/Main/Software
Alright, now that the hardware and software requirements are done, let's go to the circuit assembly. If you do not have any LED and resistor, just plug in the arduino into your computer/laptop.There is a LED right off the pin 13 if you see closely labeled L. We'll use it to blink in this experiment. If you are using the LED and resistor, the image below visualizes the assembly of the circuit:
The Arduino blink circuit. The circuit was made using fritzing. Go ahead and try download it, it will come in handy for circuit building |
Precaution: Inverting the polarity of the LED may burn the LED. Long leg goes to the output pin while the short leg goes to the GND.
Now for the code. You can find the arduino blink code easily on the web. I'll also post the code here with explanation. Before that, lets see the blank arduino IDE sketch:
You can see the blank sketch on the image left. It has few things in it, mainly the void setup and the void loop. Ok before we write the code, we need to need where and when to write the code.
1. All variable initialization will go before the void setup. For an example, in this experiment, we are using a LED in pin 13 of arduino. To initialize it, we will write this before void setup:
int LED = 13;
the name LED can be customized according to your preference. The number 13 represents the position of the LED on the Arduino board. If you use pin 12, then, the number will be 12 and so on.
Next, the void setup. This is where you initialize your input and output of the program. In this case, our LED is going to be our output. So we need to write this in our void setup:
pinMode(LED, OUTPUT);
The line above is shows that the mode of the LED pin (which is pin 13) is going to be output.
Next, void loop. This is where all the "magic" happens. This is where you will write the process of the program. In our experiment, we want our LED on and off with the time delay of 5 seconds. So in void loop we will write this:
digitalWrite (LED, HIGH);
delay(5000);
digitalWrite(LED, LOW);
delay(5000);
Ok, the first line of the code turns on the LED. The second line of the code gives delay for about 5 seconds. This means that the LED will be turned on for about 5 seconds. The third line turns off the LED while the fourth line gives delay for about 5 seconds. The LED will turn on for five seconds and turn off for five seconds and on and off again. You can try decreasing the delay to 1000(1 second), 500(0.5 second) and other values to see what happens.
Now that the code is completed, compile, save and upload the code to the Arduino board and see the LED turns on and off according to the written code. It is that simple!!! For next experiment, I might show on how to turn on and off multiple LED's by using arduino. Until then, I hope you guys could take benefit from this experiment and have fun!!!
Comments
Post a Comment