- Notifications
You must be signed in to change notification settings - Fork1
a blinking LED activity as the intro for Arduino Code programming
License
jdevfullstack-tutorials/blinking-led-arduino
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
updated 21 April 2022
This is a blinking LED activity as the intro forArduino Code programming.
Arduino is both software and hardware. Right there,you can control your design (hardware) throughthe code (software). So, it's one of the reasonsalso that Arduino is used extensively in prototyping.
There are two built-in functions in Arduino Code:void setup
andvoid loop
.
void setup
is where you tell the computer whetheran electronic component being programmed is anoutput device. Other initial setup can bedone here, like the initial mode of an LEDis turned on.
void loop
is where the execution of commandshappens. Take note,void loop
is a repeatforever loop.
Take note of the wordvoid
. Avoid
typeof function will simply execute all the commandsand will not return any value. Other functionswhich are not void do return values.
You need 3 basic LEDs, 3 resistors, 1 breadboard andthe Arduino UNO board.
Follow the setup as shown in the picturebelow:
Then, go toCode
section and copy the initialcode below:
void setup(){ pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT);}void loop(){ digitalWrite(13, HIGH); digitalWrite(12, LOW); digitalWrite(11, LOW); delay(1000); digitalWrite(13, LOW); digitalWrite(12, HIGH); digitalWrite(11, LOW); delay(1000); digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, HIGH); delay(1000);}
There are just 3 commands being usedhere:
pinMode
is the command you tell the Arduinoboard what is the mode of a particular pin.If not, then the default isinput
.
digitalWrite
is the command whetherthere will be supply of voltageHIGH
or there is noneLOW
for a particularpin, like in our example,Arduino Digital Pin 13. For a basic LED,we all know that when there is sufficientvoltage, it is turned on and if thereis too low or none at all, it isturned off.
delay
is the command for temporarily delayinga program, just like a pause. If prior tothis, an LED is turned on, it will pause fora certain amount of time with the initialstatus of the LED. It's in terms of milliseconds,because for computers, they work in terms ofmilliseconds or even nanoseconds.For example, they can accomplish, say,a thousand tasks in just 1 second.For high-powered servers, it's more than that.For advanced programmers, this is very critical:it can be used for multitasking, say,that 1 second delay can be usedto do other tasks within the main program.
Now, talking about the initial code above,it will simply have blinking LEDs fromright to left and the interval is 1 second.And since it is a repeat forever loop,it will simply continue doing the samething until you stop it.
You can modify the code to blink at the sametime or another pattern with rhythm by changingthe delay at different parts. As you can see,you have the full control through your code, aslong as you know how to modify it withoutbreaking it.
Finally, here is the actual project link:
https://www.tinkercad.com/things/achHRTDWDhW
You may want additional information about theArduino UNO board, the breadboard and anotherproject, so check this out:
About
a blinking LED activity as the intro for Arduino Code programming
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.