Wednesday, January 29, 2014

Getting Started | Turn LED on/off


When you start to learn a new programming language, any tutorial/book usually will start with you by the Hello World example! Because Hello World example gives you a quick start to the new language, and it also makes you so excited about learning more because you see some output in your screen, it seems a good start for the purpose of learning.

So in Arduino too, we will start by making a Hello World program, but it is a little bit different. The Hello world of Arduino is a 
LED(lamp) that turns on as a welcoming message to you in this world. Ready? let's first tell you a small note about Arduino:

* What is Arduino? simply it's a micro-controller , easy to deal with and wonderful to make you enter the field of embedded system quickly, also it's good for the DIY geeks that love to make some real excited stuffs by their own hands(see some examples: Arduino Projects ) without entering in more details about what's micro-controller means, let's describe Arduino now as the mind of our digital system.

> Turn the LED on/off
1) Get the LED
From where to get LED?
a)Buy it from the same shop you have bought the Arduino chip from it.
b)Hack an old mouse or TV remote controller or any device use the LED.

2) Differentiate between cathode and anode ends
LED usually has two ends (one of them is taller than the other). The taller one called anode and the another one called: cathode. if you cannot find which one taller than other there is another way to know which end is cathode: from the top view(Figure 1) you can find one side is flat and the other is not.. the flat side contains the cathode end.
Figure 1: LED ends
3) Connect LED with your Arduino chip

 Once you know where is the cathode and the anode .. start to connect the LED to the Arduino as the cathode connected to the GND pin ( ground)  and anode to pin 13. Figure 2.

Figure 2 - cathode and anode with pin13

4) Install Arduino IDE
5) Connect the Arduino chip with your PC (by the USB connector)
Figure 3 - Connect Arduino to computer

6) Open the IDE
Figure 4 - Arduino IDE



7) Write the following code:
// Example 01 : Blinking LED
const int LED = 13; // LED connected to digital pin 13
void setup()
{
   pinMode(LED, OUTPUT); // sets the digital pin as output
}
void loop()
{
  digitalWrite(LED, HIGH); // turns the LED on
  delay(3000); // waits for a second
  digitalWrite(LED, LOW); // turns the LED off
  delay(3000); // waits for a second
}
8) Verify
Figure 5 - Verify 



9) Upload

Figure 6 - Upload


10) Celebrate
Figure 7 - LED sys Hello World! 

Resources
Sociaty of Robotics- LED TUTORIAL