Tuesday, 27 January 2015

Arduino LED

Arduino LED

       There is no border to do samething with Arduino. Everything is about over dreams. But, however we cannot run when we born, we should start to try with Arduino from the beginning. The first project with other development boards  and Arduino is LED lighting process. Even though being a simple project, it is very helpful to learn basics about coding and electronics. We will write our codes and make our circuit. After that, we will see the code in Arduino Library. One of the reasons what makes Arduino the most popular development board is its library. We can use codes from the library directly and we can learn how to code from there.
       We need the Arduino interface program to use Arduino. We will load our codes to it with this program which is called as IDE(Integrated Development Environment). You can download it from this 

connection

 .  When we download this IDE, we get the library. Theese codes are developed inspiring from C/C++ language. Knowing basics about this language has advantages. This is basic screen of IDE.





     
       Different versions of software are available. Older versions screen is empty but in the new versions Setup and Loop functions are writed by IDE with small explanations.

When we click on the FOLDER, we can choose the NEW to open a new folder. If we want to open an older file, we can use the OPEN for this. Also, we can choose Examples to reach the library. We use USB cable to connect Arduino with the PC. We use B type USB for this. Lights will be on after connection. We can see the port number when we open the IDE.

       Our first step is LED lighting with Arduino. We need basic electronical information for this. We will use red LED and we should know its voltage and current border to decide our resistor's ohm. LED means Lighting Emitting Diode. It is used to understand current existence. In addition, it is used for the illumination.

       There is a sketch for the connection.


       We should connect the anode(+) pin to digital I/O pin and cathode(-) pin to ground. We will get 5V as a digital output from the 8th pin. But this voltage is high for the LED. So we should use a resistor. Theoretically LED 's current border is 20mA but mostly it is not same in real. So we will choose the resistor for 10mA. Red LED's voltage is 1.7V. To calculate the resistor, 5-1.7=3.3V 3.3:0.01=330 ohm. We get the valeu of the resistor with basic formula V=IR. Resistor's value is 330 ohm. we can connect it to anode or cathode, it does not matter. Now we can write our code. We choose 8th pin for the connectionto cathode.
     

void setup() {

  // we make the 8th pin as output

  pinMode(8, OUTPUT);

}

// the code in loop function repeats during Arduino power on.

void loop() {

  digitalWrite(8, HIGH);   // Make 8th pin HIGH to get digital HIGH
                           // It gives 5V output to turn LED on

  delay(1000);             // To decide LED's working time
                           

  digitalWrite(8, LOW);    // Gives 0V output to turn LED off.

  delay(1000);              // To decide LED'S off time

}

       Our code is ready but we should load it to Arduino. We will use the right sided arrow on the upper left corner of the screen.




       We made our first project with Arduino. You can make a project with more LED. You can change their on/off time to get something interesting. We will meet with next project again. Keep in touch!

No comments :

Post a Comment

Thanks for your comments :)