In this tutorial post, you will learn the basic of Arduino IDE & Arduino UNO. If you're interested in learning via video you can watch the below video which covers all the topics which are shared in this post.
Note: The video doesn't cover the explanation for the sketch
Click here to watch the video on YouTube
Whom does this post help?
This post is helpful for people who are just getting started with Arduino and who have no knowledge of Arduino IDE or Arduino UNO.
About Arduino
Arduino is an open-source electronics platform that offers various kinds of Microcontroller boards and shields for various types of applications. Arduino also offers easy to use software. Arduino boards are capable of reading inputs from various sensors like LDR, LM35, Gas sensors & many more.
Arduino Uno is based on the microcontroller ATmega328P which is a high-performance Microchip 8-bit AVR RISC microcontroller combines 32KB ISP flash memory with simultaneously read-write capabilities, 1024 bytes EEPROM, 2KB SRAM, 23 I/O lines, 32 working registers, 3 flexible timer/counters with compare modes, Internal & external interrupts, serial programmable USART, a byte-oriented 2- wire serial interface, SPI serial port, and a 6 channel 10-bit A?D converter.
Arduino UNO has 14 digital pins of which 6 pins can be used as PWM outputs, 6 Analog Pins, Vin pin for input voltage, 2 GND points, a 5V pin, a 3.3V pin, a built-in LED for output which is associated to the PIN 13 of the UNO (built-in LED can be called in the sketch using LED_BUILTIN), a 16 MHz resonator, a USB connection for power and programming, a DC power jack, ICSP header & a reset button.
The operating voltage of the Arduino UNO is 5V & the recommended input voltage is between 7 to 12V
The operating voltage of the Arduino UNO is 5V & the recommended input voltage is between 7 to 12V
Source: Arduino Website
To download the Arduino IDE click here & scroll down and select the Arduino IDE according to your OS. Once the download is complete, extract the files from .zip folder
and open the extracted folder & click on Arduino executable file which should open the Arduino IDE. Arduino website now also offers a web-based editor which you can check by clicking here.
and open the extracted folder & click on Arduino executable file which should open the Arduino IDE. Arduino website now also offers a web-based editor which you can check by clicking here.
Running First Sketch
To run the first sketch first connect the Arduino UNO to a laptop or a desktop and then open the Arduino IDE
Next, go to the Port > select your COM port.
Next, let's upload the example sketch which comes along with Arduino IDE. To upload the example sketch go to File > Basics and select Blink Sketch
Next, click on Verify to compile the sketch
and then click on upload button to upload your sketch to Arduino UNO
and then click on upload button to upload your sketch to Arduino UNO
Now if your upload is successful you can see TX, RX LED's rapidly flashing
and then the L LED will start blinking.
How to connect external components with Arduino UNO
Take a breadboard and mount 220-ohm resistor and connect +ve lead of the LED to one end of the resistor, next connect two breadboard wires to the outer end of the circuit as shown in the below image
Take a breadboard and mount 220-ohm resistor and connect +ve lead of the LED to one end of the resistor, next connect two breadboard wires to the outer end of the circuit as shown in the below image
Next, connect the Red wire to Pin 9 and Black wire to the GND pin. After making the connections connect the Arduino UNO to a laptop or desktop and open the Arduino IDE and then follow the process showed in "Running First Sketch".
Note: For this example, you need to use the sketch Fade which is under File > Examples > Basics > Fade
Note: For this example, you need to use the sketch Fade which is under File > Examples > Basics > Fade
Sketch Explanation for sketches used in this post
Blink Sketch: Blink is an example sketch which comes with Arduino IDE
Blink Sketch: Blink is an example sketch which comes with Arduino IDE
Sketch Start
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Sketch End
Sketch Explanation - Blink
void setup() {} - Setup function runs when you power the board or press reset button.
void loop() {} - Loop function runs statements inside it over and over again forever
pinMode(LED_BUILTIN, OUTPUT); - declaring the built in digital pin LED_BUILTIN to Output
Sketch Explanation - Blink
void setup() {} - Setup function runs when you power the board or press reset button.
void loop() {} - Loop function runs statements inside it over and over again forever
pinMode(LED_BUILTIN, OUTPUT); - declaring the built in digital pin LED_BUILTIN to Output
digitalWrite(LED_BUILTIN, HIGH); - This turns the LED ON (Voltage = +5V)
digitalWrite(LED_BUILTIN, LOW); - This turns the LED OFF (Voltage = 0V)
delay(1000); - delays execution of next statement by 1second(1second = 1000milli Second)
Fade Sketch: Fade is an example sketch which comes with Arduino IDE
Sketch Start
Sketch Start
int led = 9;
int brightness = 0;
int fadeAmount = 5;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}
Sketch End
Sketch Explanation - Fade
int led = 9; - assigning PIN 9 to LED
brightness = brightness + fadeAmount; - changing the brightness for the next time when it goes through the loop. Lets see the iteration of the this statement
So now brightness = 255 + (-5); and this Iteration will continue until brightness reaches 0 when this happens it enters the IF statement once again since the condition brightness <= 0 becomes true and the new value for the fadeAmount will be assigned which now becomes +5 since negative multiplied by negative is positive and this cycle goes on foreverSketch Explanation - Fade
int led = 9; - assigning PIN 9 to LED
int brightness = 0; - Assigning the brightness of the LED at the start
int fadeAmount = 5; - Points to fade the LED by
brightness = brightness + fadeAmount; - changing the brightness for the next time when it goes through the loop. Lets see the iteration of the this statement
1st Iteration brightness = 0 + 5; - so brightness = 5 Now2nd Iteration brightness = 5 + 5 - at the end of 2nd Iteration the brightness = 10. this will continue until the brightness value becomes 255
if (brightness <= 0 || brightness >= 255) {fadeAmount = -fadeAmount;} - this reverse the direction of fading at the end the fade.
A detailed explanation of the IF Statement
if (brightness <= 0 || brightness >= 255) this translates to 'if brightness is less than or equal to zero OR brightness greater than or equal to 255 enter inside or get out'
When brightness reaches the value 255 one of the conditions inside the IF statement (brightness >= 255) becomes true and goes through the IF statement.
Once inside the IF statement, the statement fadeAmount = -fadeAmount; assigns a new value to the fadeAmount which is -5 and then exists the IF statement
Thank You for Reading Guys !!!
No comments:
Post a Comment
Hi, Thanks for Commenting !!!