Xathrya Sabertooth |
Arduino Project: Simple Blinking LED Posted: 25 Mar 2014 06:43 AM PDT Blink LED, like what it should be, we make certain LED blinking. We can define “blinking” as continuous condition switching between ON and OFF condition. This is the simplest project we can do for Arduino. Objective
Prerequisite
RequirementFollowing is all materials I use for this tutorial.
You can change the Arduino board to higher specification if you like. The LED I use will emit red light as it is powered by electricity. You also need an USB A to B cable for upload our program to our Arduino. CircuitHere is the circuit image, created using Fritzing. To build the circuit, attach the LED as shown in the figure. Attach the long leg of an LED (positif leg or anode) to pin 13. Attach the short leg (negative leg or cathode) to the ground (GND). On Arduino Uno, there is also a built in status LED which connected to pin 13. When our Arduino running successfully, both status LED and external LED will start to blink. We don’t need extra resistor for this project, but make sure you are using pin 13. If you do connect it to other pin, it might be destroyed. The reason is that pin 13 has an internal resistor that other pins don’t have which limit current to our LED. CodeLet’s see what code we use for this project and discuss it later. const unsigned int LED_PIN = 13; const unsigned int PAUSE = 500; void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { digitalWrite(LED_PIN, HIGH); delay(PAUSE); digitalWrite(LED_PIN, LOW); delay(PAUSE); } Notice that we define two constant here, LED_PIN which is pin we use, and PAUSE for the delay interval which is 500 ms. The heart of this project is pin 13. We use this pin as output pin. Therefore we initialize pin 13 as an output pin with the statement: pinMode(LED_PIN,OUTPUT); Next in the main loop, we turn the LED on by: digitalWrite(LED_PIN, HIGH); and turn it off by: digitalWrite(LED_PIN, LOW); And we now know that digitalWrite() function is used to output signal on a pin. The delay() command is used to tell Arduino to do nothing for given time. In our case, we make Arduino wait for 500 miliseconds. ResultLED is blinking. Why it WorksThere are two condition of logic in circuit, HIGH and LOW. Some microcontrollers might define HIGH and LOW difference, but in Arduino Uno we have HIGH logic as 5V and LOW logic as 0V. If you know boolean value, yes this is boolean value with HIGH is true and LOW is false. The LED we use is active-high LED, which means it can turn on when it is given HIGH voltage. |
You are subscribed to email updates from Xathrya Sabertooth To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
Tidak ada komentar:
Posting Komentar