Arquivo de arduino tutorial - Electronic Circuits https://www.elcircuits.com/tag/arduino-tutorial/ Circuits, tips, projects, and electronics tutorials for beginners and enthusiasts. Sat, 20 Dec 2025 19:28:40 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://www.elcircuits.com/wp-content/uploads/2025/11/cropped-LOGO-ELC-500x500px-elcircuits.com_-1-32x32.png Arquivo de arduino tutorial - Electronic Circuits https://www.elcircuits.com/tag/arduino-tutorial/ 32 32 Arduino Lesson 9 – LED Sequencing with Arrays (Practical Guide) https://www.elcircuits.com/arduino-lesson-9-led-sequencing-arrays/ https://www.elcircuits.com/arduino-lesson-9-led-sequencing-arrays/#respond Sun, 07 Nov 2021 00:08:00 +0000 https://elcircuits.com/arduino-lesson-9-led-sequencing-using-array-data-structure/ Arduino: Lesson 9 – LED Sequencing using Array Data Structure Welcome to Lesson 9 – Basic Arduino Course In today’s lesson, we will learn how to use 5 LEDs connected to 5 Arduino ports, which will light up in sequence and right after the cycle ends, will go out in sequence. With that, we will learn a new instruction, the Array data structure. What is Array? An array is a collection of variables that are accessed with an index number. However, the “array” data structure is not exactly an existing data type. There are arrays of variables like “char“, “int“, “boolean“, “float” and so on. This means that an array can be variables of any type mentioned above. An array, orvector, for example, is a collection of variables of a specific type, which may even use the same nomenclature, but which will be distinguished by an indexed number. For example: We can use a variable type “float” with a single name indexed by number, instead of different variables (VarFloat_1, VarFloat_2, VarFloat_3…) we can use a single grouped array with the same nomenclature that will allow each variable be manipulated separately by a numerical index, (VarFloat [0], VarFloat [1], VarFloat [2] …). Hardware Required Arduino Board 5 – LEDs 5 – 250 ohms resistor – (brown, green, brown, gold) Jumper Wires Protoboard (optional) The Circuit Connections The circuit is a bit simple, we connect the longer “Anode” legs of the 5 LEDs to the positive 5V of the Arduino, and the other shorter leg “Cathode“, we connect to the 150 ohm resistor and in series with GND, negative of the Arduino, as shown in Figure 2 below. Fig. 2 – LED Sequencing using Array Data Structure – tinkercad.com We use a protoboard to facilitate the connections, but you can also connect the wires directly to the Arduino. The Code The code can be implemented in the normal way in programming, as shown in the code below. But the code is quite large, we use 42 lines of code to create this kind of sequential LED circuit. To write less lines of code, an “optimizer” is required. // Arduino: Lesson 9 - LED Sequencing using Array Data Structure const int Led1 = 2; // Select the output LED1 PIN const int Led2 = 3; // Select the output LED2 PIN const int Led3 = 4; // Select the output LED3 PIN const int Led4 = 5; // Select the output LED4 PIN const int Led5 = 6; // Select the output LED5 PIN void setup() { // This function is called once when the program starts pinMode(Led1, OUTPUT); // Initialize digital pin LED1 as an output. pinMode(Led2, OUTPUT); // Initialize digital pin LED2 as an output. pinMode(Led3, OUTPUT); // Initialize digital pin LED3 as an output. pinMode(Led4, OUTPUT); // Initialize digital pin LED4 as an output. pinMode(Led5, OUTPUT); // Initialize digital pin LED5 as an output. } void loop() { // The loop function runs over and over again as long as the Arduino has power. // Turn ON each LED sequence in order digitalWrite(Led1, HIGH); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led2, HIGH); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led3, HIGH); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led4, HIGH); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led5, HIGH); delay(150); // Wait for 150 millisecond(s) // Turn OFF each LED sequence in order digitalWrite(Led1, LOW); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led2, LOW); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led3, LOW); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led4, LOW); delay(150); // Wait for 150 millisecond(s) digitalWrite(Led5, LOW); delay(150); // Wait for 150 millisecond(s) } //------------------------------------- www.elcircuits.com -------------------------------------------- This is where the Array data structure comes into play, we can use it to drastically reduce the number of lines of code, as shown in the code example below. // Arduino: Lesson 9 - LED Sequencing using Array Data Structure const int Leds = 5; //Number of LEDs in the circuit const int PinLeds[Leds] = {2, 3, 4, 5, 6}; //LEDs connected to pins 2 to 6 void setup() { // This function is called once when the program starts for (int i = 0; i < Leds; i++) { // Go through each of the elements in our array pinMode(PinLeds[i], OUTPUT); // And set them as OUTPUT } } void loop() { // The loop function runs over and over again as long as the Arduino has power. for(int i = 0; i < Leds; i++) { // Go through each of the Leds elements in our array digitalWrite(PinLeds[i], HIGH); // And set each of the PinLeds in HIGH level delay(150); // Wait 150 millis seconds, and back to structure For } for(int i = 0; i < Leds; i++) { // Go through each of the Leds elements in our array digitalWrite(PinLeds[i], LOW); // And set each of the PinLeds in LOW level delay(150); // Wait 150 millis seconds, and back to structure For } } //------------------------------------- www.elcircuits.com -------------------------------------------- Using the Array Data Structure technique, we could practically save half a line of the previous code, that's really cool, right? After building the circuit, connect your Arduino board to your computer, run the Arduino software (IDE), copy the code below and paste it into your Arduino IDE. But first let us understand the code line by line. In Line 3, we declared the number of LEDs in the circuit. In Line 4, We are using an Array to index each pin of the LEDs in the corresponding Arduino Ports. In Line 6, we enter the void setup() function. This function is read only once when the Arduino is started. In Line 7, we enter in the FOR structure control, to access each Leds element. in Line 8, we set each PinLeds as OUTPUT, through each elements in ou array. In Line 11, we enter in the loop() function does precisely what its name suggests, and loops consecutively. In Line 12, we enter in the For structure control, to go through each of

O post Arduino Lesson 9 – LED Sequencing with Arrays (Practical Guide) apareceu primeiro em Electronic Circuits.

]]>
Arduino: Lesson 9 - LED Sequencing using Array Data Structure

Arduino: Lesson 9 – LED Sequencing using Array Data Structure

Welcome to Lesson 9 – Basic Arduino Course

In today’s lesson, we will learn how to use 5 LEDs connected to 5 Arduino ports, which will light up in sequence and right after the cycle ends, will go out in sequence. With that, we will learn a new instruction, the Array data structure.

What is Array?

An array is a collection of variables that are accessed with an index number. However, the “arraydata structure is not exactly an existing data type.

There are arrays of variables like “char“, “int“, “boolean“, “float” and so on. This means that an array can be variables of any type mentioned above.

An array, orvector, for example, is a collection of variables of a specific type, which may even use the same nomenclature, but which will be distinguished by an indexed number.

For example: We can use a variable type “float” with a single name indexed by number, instead of different variables (VarFloat_1, VarFloat_2, VarFloat_3…) we can use a single grouped array with the same nomenclature that will allow each variable be manipulated separately by a numerical index, (VarFloat [0], VarFloat [1], VarFloat [2] …).

Hardware Required

  • Arduino Board
  • 5 – LEDs
  • 5 – 250 ohms resistor – (brown, green, brown, gold)
  • Jumper Wires
  • Protoboard (optional)

The Circuit Connections

The circuit is a bit simple, we connect the longer “Anode” legs of the 5 LEDs to the positive 5V of the Arduino, and the other shorter leg “Cathode“, we connect to the 150 ohm resistor and in series with GND, negative of the Arduino, as shown in Figure 2 below.

Fig. 2 - LED Sequencing using Array Data Structure - tinkercad.com

Fig. 2 – LED Sequencing using Array Data Structure – tinkercad.com

We use a protoboard to facilitate the connections, but you can also connect the wires directly to the Arduino.

The Code

The code can be implemented in the normal way in programming, as shown in the code below. But the code is quite large, we use 42 lines of code to create this kind of sequential LED circuit. To write less lines of code, an “optimizer” is required.

// Arduino: Lesson 9 - LED Sequencing using Array Data Structure
const int Led1 =  2;     // Select the output LED1 PIN
const int Led2 =  3;     // Select the output LED2 PIN
const int Led3 =  4;     // Select the output LED3 PIN
const int Led4 =  5;     // Select the output LED4 PIN
const int Led5 =  6;     // Select the output LED5 PIN
void setup() {            // This function is called once when the program starts
  pinMode(Led1, OUTPUT);  // Initialize digital pin LED1 as an output.
  pinMode(Led2, OUTPUT);  // Initialize digital pin LED2 as an output.
  pinMode(Led3, OUTPUT);  // Initialize digital pin LED3 as an output.
  pinMode(Led4, OUTPUT);  // Initialize digital pin LED4 as an output.
  pinMode(Led5, OUTPUT);  // Initialize digital pin LED5 as an output.
}
void loop() {                           // The loop function runs over and over again as long as the Arduino has power.
  // Turn ON each LED sequence in order
  digitalWrite(Led1, HIGH);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led2, HIGH);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led3, HIGH);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led4, HIGH);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led5, HIGH);
  delay(150);               // Wait for 150 millisecond(s)
  // Turn OFF each LED sequence in order
  digitalWrite(Led1, LOW);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led2, LOW);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led3, LOW);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led4, LOW);
  delay(150);               // Wait for 150 millisecond(s)
  digitalWrite(Led5, LOW);
  delay(150);               // Wait for 150 millisecond(s)
}
//------------------------------------- www.elcircuits.com --------------------------------------------

This is where the Array data structure comes into play, we can use it to drastically reduce the number of lines of code, as shown in the code example below.

// Arduino: Lesson 9 - LED Sequencing using Array Data Structure
const int Leds = 5;                          //Number of LEDs in the circuit
const int PinLeds[Leds] = {2, 3, 4, 5, 6};   //LEDs connected to pins 2 to 6
void setup() {            // This function is called once when the program starts
  for (int i = 0; i < Leds; i++) {    // Go through each of the elements in our array
    pinMode(PinLeds[i], OUTPUT);  // And set them as OUTPUT
  }
}
void loop() {                                        // The loop function runs over and over again as long as the Arduino has power.
  for(int i = 0; i < Leds; i++) {    // Go through each of the Leds elements in our array
    digitalWrite(PinLeds[i], HIGH);   // And set each of the PinLeds in HIGH level
    delay(150);   // Wait 150 millis seconds, and back to structure For
  }
  for(int i = 0; i < Leds; i++) {    // Go through each of the Leds elements in our array
    digitalWrite(PinLeds[i], LOW);   // And set each of the PinLeds in LOW level
    delay(150);   // Wait 150 millis seconds, and back to structure For
  }
}
//------------------------------------- www.elcircuits.com --------------------------------------------

Using the Array Data Structure technique, we could practically save half a line of the previous code, that's really cool, right?

After building the circuit, connect your Arduino board to your computer, run the Arduino software (IDE), copy the code below and paste it into your Arduino IDE. But first let us understand the code line by line.

  • In Line 3, we declared the number of LEDs in the circuit.
  • In Line 4, We are using an Array to index each pin of the LEDs in the corresponding Arduino Ports.
  • In Line 6, we enter the void setup() function. This function is read only once when the Arduino is started.
  • In Line 7, we enter in the FOR structure control, to access each Leds element.
  • in Line 8, we set each PinLeds as OUTPUT, through each elements in ou array.
  • In Line 11, we enter in the loop() function does precisely what its name suggests, and loops consecutively.
  • In Line 12, we enter in the For structure control, to go through each of the Leds elements in our array.
  • In Line 13, we continue in the For structure control, and set each of the PinLeds in HIGH level, turn on Led by Led.
  • In Line 14, we enter in the delay function, to wait 150 millis seconds, and back to structure For while it is true.
  • In Line 16, we enter in the For structure control, to go through each of the Leds elements in our array.
  • In Line 17, we continue in the For structure control, and set each of the PinLeds in LOW level, turn off Led by Led.
  • In Line 18, we enter in the delay function, to wait 150 millis seconds, and back to structure For while it is true.

All ready! After you have assembled the entire circuit, and uploaded this code, what you should see is the sequence of LEDs turning on and off, giving the impression that the LEDs are moving forward.

Next Lesson

  • Arduino: Lesson 10 - How to Read Temperature and Humidity with Arduino, Using the DHT11 Sensor

Previous Lesson


✨ Our Gratitude and Next Steps


We sincerely hope this guide has been useful and enriching for your
projects! Thank you for dedicating your time to this content.


Your Feedback is Invaluable:


Have any questions, suggestions, or corrections? Feel free to share them
in the comments below! Your contribution helps us refine this
content for the entire ElCircuits community.


If you found this guide helpful, spread the knowledge!


🔗 Share This
Guide


Best regards,

The ElCircuits Team ⚡

O post Arduino Lesson 9 – LED Sequencing with Arrays (Practical Guide) apareceu primeiro em Electronic Circuits.

]]>
https://www.elcircuits.com/arduino-lesson-9-led-sequencing-arrays/feed/ 0
Arduino Lesson 6 – How to Use Analog Output to Fade an LED https://www.elcircuits.com/arduino-lesson-6-analog-output-led-fade/ https://www.elcircuits.com/arduino-lesson-6-analog-output-led-fade/#respond Fri, 01 Oct 2021 22:19:00 +0000 https://elcircuits.com/arduino-lesson-6-how-to-use-analog-output-to-fade-an-led/ Arduino: Lesson 6 – How to use analog output to fade an LED Welcome to Lesson 6 – Basic Arduino Course In today’s lesson, we will learn how to use an analog output to increase and decrease the brightness of a LED. In this example, we will use the analogWrite() function, which triggers a PWM wave on an Arduino pin. We will use PWM to vary the brightness of a LED as an example, but nothing prevents us from also using it to drive a motor and control its speed, the concept is the same. The analogWrite() function triggers a square wave at the specified duty cycle until the next analogWrite() call. The frequency of the PWM signal is around 490 Hz on most Arduinos, however on Arduino Uno and some similar boards, pins 5 and 6 use a frequency of about 980 Hz. On most Arduino boards with ATmega168 or ATmega328 chips, this function works on pins 3, 5, 6, 9, 10 and 11. On the Arduino Mega this function works on pins 2 to 13 and 44 to 46. Hardware Required Arduino Board LED 200 ohms resistor Jumper Wires Protoboard (optional) The Circuit The circuit is quite simple, we connect a LED in series with a 220 ohm resistor used to limit the current in the LED as we learned in the previous lessons, and we connect the PWM 9 port of the Arduino UNO as shown in Figure 2 below. Fig. 2 – Using an analog output to fade an LED – tinkercad.com We use a Protoboard to facilitate the connections, but you can also connect the wires directly to the Arduino. The Code The analogWrite() function writes an analog value to the Arduino pin. It is important to remember that this output is not a pure analog output that we can use to generate a pure sine wave, but this output is a PWM wave control. When we execute the call to the analogWrite() function, the pin will generate a constant square wave with the specified duty cycle until the next function call. After building the circuit, connect your Arduino board to your computer, launch Arduino Software (IDE), copy the code below and paste it into your Arduino IDE. But first let us understand the code line by line. In Line 3, we declared ledPin to digital Pin 9 where we connect the LED to the digital Pin 9. In Line 5, we enter the void setup() function. This function is read only once when the Arduino is started. In Line 6, we define Port 9 as the output, using the pinMode(); function; 010203040506070809 //Arduino: Lesson 6 – How to use Analog Output to fade an LED int ledPin = 9;                                // LED connected to digital pin 9 void setup() {                                    // This function is called once when the program startspinMode(ledPin, OUTPUT);        // Set the digital pin as output: }//———————- www.elcircuits.com —————————– In Line 09, we enter in the loop() function does precisely what its name suggests, and loops consecutively. In Line 11, the control structure For, is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. In Line 12, we run the analogWrite() function, this function writes an analog value (PWM wave) to pin 9, in this case we are increasing the PWM value from 5 to 5, to increase the LED brightness up to the maximum value of 255. In Line 13, we use the function delay(); to wait for 30 milliseconds to see the dimming effect. 1…0910111213141516 // Arduino: Lesson 6 – How to use Analog Output to fade an LED void loop() { // The loop function runs over and over again forever  for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5 { // fade in from min to max in increments of 5 points:   analogWrite(ledPin, fadeValue);          // sets the value (range from 0 to 255)   delay(30);                                             // wait for 30 milliseconds to see the dimming effect  }//————————– www.elcircuits.com ———————————- In Line 16, the control structure For, is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. In Line 17, we run the analogWrite() function, this function writes an analog value (PWM wave) to pin 9, in this case, we are decreasing the PWM value from 5 to 5, to decrease the LED brightness to the minimum value of 0. In Line 18, we use the function delay(); to wait for 30 milliseconds to see the dimming effect. 1…16171819202122 // Arduino: Lesson 6 – How to use Analog Output to fade an LED for (int fadeValue = 255; fadeValue >= 0; fadeValue -=5){ //fade out from max to min in increments of 5 points   analogWrite(ledPin, fadeValue);           // sets the value (range from 255 to 0)   delay(30);                                              // wait for 30 milliseconds to see the dimming effect  }}//———————– www.elcircuits.com ——————————  Below you can see the full code, which we can be copying and pasting into your Arduino IDE, and uploading to Arduino. The complete code is showed in the sketch below! 1234567891011121314151617181920212223 // Arduino: Lesson 6 – How to use Analog Output to fade an LED int ledPin = 9;                                          // LED connected to digital pin 9 void setup() {                                           // This function is called once when program starts  pinMode(ledPin, OUTPUT);                   // Set the digital pin as output: }void loop() { // The loop function runs over

O post Arduino Lesson 6 – How to Use Analog Output to Fade an LED apareceu primeiro em Electronic Circuits.

]]>

Arduino: Lesson 6 - How to use analog output to fade an LED

Arduino: Lesson 6 – How to use analog output to fade an LED

Welcome to Lesson 6 – Basic Arduino Course

In today’s lesson, we will learn how to use an analog output to increase and decrease the brightness of a LED. In this example, we will use the analogWrite() function, which triggers a PWM wave on an Arduino pin.

We will use PWM to vary the brightness of a LED as an example, but nothing prevents us from also using it to drive a motor and control its speed, the concept is the same.

The analogWrite() function triggers a square wave at the specified duty cycle until the next analogWrite() call.

The frequency of the PWM signal is around 490 Hz on most Arduinos, however on Arduino Uno and some similar boards, pins 5 and 6 use a frequency of about 980 Hz.

On most Arduino boards with ATmega168 or ATmega328 chips, this function works on pins 3, 5, 6, 9, 10 and 11. On the Arduino Mega this function works on pins 2 to 13 and 44 to 46.

Hardware Required

  • Arduino Board
  • LED
  • 200 ohms resistor
  • Jumper Wires
  • Protoboard (optional)

The Circuit

The circuit is quite simple, we connect a LED in series with a 220 ohm resistor used to limit the current in the LED as we learned in the previous lessons, and we connect the PWM 9 port of the Arduino UNO as shown in Figure 2 below.

Using an analog output to fade an LED - tinkercad.com

Fig. 2 – Using an analog output to fade an LED – tinkercad.com

We use a Protoboard to facilitate the connections, but you can also connect the wires directly to the Arduino.

The Code

The analogWrite() function writes an analog value to the Arduino pin. It is important to remember that this output is not a pure analog output that we can use to generate a pure sine wave, but this output is a PWM wave control.

When we execute the call to the analogWrite() function, the pin will generate a constant square wave with the specified duty cycle until the next function call.

After building the circuit, connect your Arduino board to your computer, launch Arduino Software (IDE), copy the code below and paste it into your Arduino IDE. But first let us understand the code line by line.

  • In Line 3, we declared ledPin to digital Pin 9 where we connect the LED to the digital Pin 9.
  • In Line 5, we enter the void setup() function. This function is read only once when the Arduino is started.
  • In Line 6, we define Port 9 as the output, using the pinMode(); function;
01
02
03
04
05
06
07
08
09
//Arduino: Lesson 6 – How to use Analog Output to fade an LED
 
int ledPin = 9;                                // LED connected to digital pin 9
 
void setup() {                                    // This function is called once when the program starts
pinMode(ledPin, OUTPUT);        // Set the digital pin as output:
 
}
//———————- www.elcircuits.com —————————–
  • In Line 09, we enter in the loop() function does precisely what its name suggests, and loops consecutively.
  • In Line 11, the control structure For, is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop.
  • In Line 12, we run the analogWrite() function, this function writes an analog value (PWM wave) to pin 9, in this case we are increasing the PWM value from 5 to 5, to increase the LED brightness up to the maximum value of 255.
  • In Line 13, we use the function delay(); to wait for 30 milliseconds to see the dimming effect.
1

09
10
11
12
13
14
15
16
// Arduino: Lesson 6 – How to use Analog Output to fade an LED
 
void loop() { // The loop function runs over and over again forever
 
 for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5 { // fade in from min to max in increments of 5 points:
   analogWrite(ledPin, fadeValue);          // sets the value (range from 0 to 255)
   delay(30);                                             // wait for 30 milliseconds to see the dimming effect
  }
//————————– www.elcircuits.com ———————————-
  • In Line 16, the control structure For, is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop.
  • In Line 17, we run the analogWrite() function, this function writes an analog value (PWM wave) to pin 9, in this case, we are decreasing the PWM value from 5 to 5, to decrease the LED brightness to the minimum value of 0.
  • In Line 18, we use the function delay(); to wait for 30 milliseconds to see the dimming effect.
1

16
17
18
19
20
21
22
// Arduino: Lesson 6 – How to use Analog Output to fade an LED
 
for (int fadeValue = 255; fadeValue >= 0; fadeValue -=5){ //fade out from max to min in increments of 5 points
   analogWrite(ledPin, fadeValue);           // sets the value (range from 255 to 0)
   delay(30);                                              // wait for 30 milliseconds to see the dimming effect
  }
}
//———————– www.elcircuits.com ——————————
 
Below you can see the full code, which we can be copying and pasting into your Arduino IDE, and uploading to Arduino.

The complete code is showed in the sketch below!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Arduino: Lesson 6 – How to use Analog Output to fade an LED
 
int ledPin = 9;                                          // LED connected to digital pin 9
 
void setup() {                                           // This function is called once when program starts
  pinMode(ledPin, OUTPUT);                   // Set the digital pin as output:
 
}
void loop() { // The loop function runs over and over again forever
 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {  // fade in from min to max in increments of 5 points:
   analogWrite(ledPin, fadeValue);           // sets the value (range from 0 to 255)
   delay(30);                                              // wait for 30 milliseconds to see the dimming effect
  }
 
   for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {  // fade out from max to min in increments of 5 points:
   analogWrite(ledPin, fadeValue);           // sets the value (range from 0 to 255)
   delay(30);                                              // wait for 30 milliseconds to see the dimming effect
  }
}
//—————— www.elcircuits.com ———————–

Next Lesson

Previous Lesson

✨ Our Gratitude and Next Steps

We sincerely hope this guide has been useful and enriching for your
projects! Thank you for dedicating your time to this content.

Your Feedback is Invaluable:

Have any questions, suggestions, or corrections? Feel free to share them
in the comments below! Your contribution helps us refine this
content for the entire ElCircuits community.

If you found this guide helpful, spread the knowledge!


🔗 Share This
Guide

Best regards,

The ElCircuits Team ⚡

O post Arduino Lesson 6 – How to Use Analog Output to Fade an LED apareceu primeiro em Electronic Circuits.

]]>
https://www.elcircuits.com/arduino-lesson-6-analog-output-led-fade/feed/ 0
Arduino Lesson 5 – Reading Potentiometer Values on Serial Monitor https://www.elcircuits.com/arduino-lesson-5-potentiometer-serial-monitor/ https://www.elcircuits.com/arduino-lesson-5-potentiometer-serial-monitor/#respond Sun, 19 Sep 2021 22:12:00 +0000 https://elcircuits.com/arduino-lesson-5-reading-potentiometer-and-showing-values-on-serial-monitor/ Arduino Lesson 5 – Reading Potentiometer Values on Serial Monitor Arduino Lesson 5 – Reading Potentiometer and Showing Values On Serial Monitor Welcome to Lesson 5 – Basic Arduino Course Today we are going to learn how to read a Potentiometer end showing the Values on Serial Monitor.In this example, we will use a potentiometer, however, this same concept is used for most analog sensors. What will differentiate will be the type of calculation used, with reference to each sensor. We will use the analogRead() function, to read A0 PIN, in Arduino we have 6 Analog Ports, which goes from A0 to A5, so we can make readings from up to 6 sensors simultaneously without having to use external hardware. Hardware Required Arduino Board A 10K Potentiometer Wires Protoboard (optional) The Circuit The potentiometer works like a voltage divider. When you turn the shaft of the potentiometer, you change the resistance on either side of the center pin (or wiper) of the potentiometer. This changes the relative resistances between the center pin and the two outer pins, so you get a different voltage at the analog input. When the shaft is fully rotated in one direction, there is no resistance between the center pin and the pin connected to ground. The middle pin varies from 0Kohms to 10Kohms, which is the value of the potentiometer we will use. This resistance is sensed by the voltages at the ends of the potentiometer, causing the center pin to vary between 0V and 5V. And the voltage variation that comes from the Center Pin of the potentiometer goes to the A0 Analog Port. In Figure 2, you can see the schematic of the potentiometer and the Arduino. We use a breadboard to make the connections easier, but you can also connect the wires directly from the A0 terminal in the middle of the potentiometer, connecting the outer pin to 5V positive and the outer pin to the negative GND of the Arduino. Fig. 2 – Reading Potentiometer and Showing Values On Serial Monitor – tinkercad.com The Code The analogRead() function converts the input voltage range, 0 to 5 volts, to a digital value between 0 and 1023. This is done by a circuit within the microcontroller called analog-to-digital converter, or ADC. Then, if the voltage at the center pin is 0 volts, analogRead() returns 0. When the shaft is turned all the way the other way, there is no resistance between the middle pin and the pin connected to 5 volts. If the voltage on the middle pin is then 5 volts, analogRead() returns 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the voltage applied to the pin. After building the circuit, connect your Arduino board to your computer, launch Arduino Software (IDE), copy the code below and paste it into your Arduino IDE. But first let us understand the code line by line. In Line 3, we declared variable sensorPin which is set to Analog Pin A0 where we receive the value of the connected potentiometer. In Line 4, we create a variable senorPin that stores the value of the sensor that we also use for the potentiometer. // Arduino: Lesson 5 - Reading Potentiometer and Showing Values On Serial Monitor int sensorPin = A0; // Read the Analogic Pin A0 Values into a variable int sensorValue = 0; // Variable to store the value coming from the sensor "Potentiometer" In Line 6, we enter the void setup() function. This function is read only once when the Arduino is started. In Line 7, we begin serial communication by declaring the Serial.begin() function. At 9600 bits of data per second, this is the speed at which your computer will communicate with your Arduino Serial. void setup() { // This function is called once when the program starts Serial.begin(9600); // Begin the Serial Monitor with bounce rate in 115200 } After setting the initializations, in Line 10 we will enter the void loop() function. In Line 11, we use the variable sensorValue to store the resistance value, which is between 0 and 10K (read by the Arduino as a value between 0 and 1023) and controlled by the potentiometer. In Line 13, we use the command Serial.println(), it is print out the value controlled by the potentiometer, this value will read with value between 0 and 1023 in your Serial Monitor. In Line 14, we run the delay() function, for greater system stability. void loop() { // The loop function runs over and over again forever sensorValue = analogRead(sensorPin); // Read the input on analog pin A0 Serial.println(sensorValue); // Print out the value you read delay(1); // delay in between reads for stability } Now you can copy the code and upload it to your Arduino. After that, if you open your Serial Monitor in Arduino Software (IDE) (by clicking on the icon that looks like a lens on the right side of the green top bar or using the keyboard shortcut Ctrl+Shift+M), you should see a steady stream of numbers in the range 0-1023 that correlate with the position of the pot. When you turn your potentiometer, these numbers respond almost instantly. The complete code is showed in the sketch below! // Arduino: Lesson 5 - Reading Potentiometer and Showing Values On Serial Monitor int sensorPin = A0; // Read the Analogic Pin A0 Values into a variable int sensorValue = 0; // Variable to store the value coming from the sensor "Potentiometer" void setup() { // This function is called once when the program starts Serial.begin(9600); // Start serial connection } void loop() { // The loop function runs over and over again forever sensorValue = analogRead(sensorPin); // Read the input on analog pin A0 Serial.println(sensorValue); // Print out the value you read delay(1); // delay in between reads for stability } //------------------------------------- www.elcircuits.com -------------------------------------------- Next Lesson Arduino: Lesson 6 – How to use Analog Output to fade an LED Arduino: Lesson 7 –

O post Arduino Lesson 5 – Reading Potentiometer Values on Serial Monitor apareceu primeiro em Electronic Circuits.

]]>
Fig. 1 - Arduino Lesson 5 - Reading Potentiometer and Showing Values On Serial Monitor

Arduino Lesson 5 – Reading Potentiometer and Showing Values On Serial Monitor


Welcome to Lesson 5 – Basic Arduino Course

Today we are going to learn how to read a Potentiometer end showing the Values on Serial Monitor.
In this example, we will use a potentiometer, however, this same concept is used for most analog sensors.

What will differentiate will be the type of calculation used, with reference to each sensor.

We will use the analogRead() function, to read A0 PIN, in Arduino we have 6 Analog Ports, which goes from A0 to A5, so we can make readings from up to 6 sensors simultaneously without having to use external hardware.

Hardware Required

  • Arduino Board
  • A 10K Potentiometer
  • Wires
  • Protoboard (optional)

The Circuit

The potentiometer works like a voltage divider. When you turn the shaft of the potentiometer, you change the resistance on either side of the center pin (or wiper) of the potentiometer.

This changes the relative resistances between the center pin and the two outer pins, so you get a different voltage at the analog input.

When the shaft is fully rotated in one direction, there is no resistance between the center pin and the pin connected to ground.

The middle pin varies from 0Kohms to 10Kohms, which is the value of the potentiometer we will use.

This resistance is sensed by the voltages at the ends of the potentiometer, causing the center pin to vary between 0V and 5V.

And the voltage variation that comes from the Center Pin of the potentiometer goes to the A0 Analog Port.

In Figure 2, you can see the schematic of the potentiometer and the Arduino. We use a breadboard to make the connections easier, but you can also connect the wires directly from the A0 terminal in the middle of the potentiometer, connecting the outer pin to 5V positive and the outer pin to the negative GND of the Arduino.

Fig. 2 - Reading Potentiometer and Showing Values On Serial Monitor - tinkercad.com

Fig. 2 – Reading Potentiometer and Showing Values On Serial Monitor – tinkercad.com

The Code

The analogRead() function converts the input voltage range, 0 to 5 volts, to a digital value between 0 and 1023. This is done by a circuit within the microcontroller called analog-to-digital converter, or ADC.

Then, if the voltage at the center pin is 0 volts, analogRead() returns 0. When the shaft is turned all the way the other way, there is no resistance between the middle pin and the pin connected to 5 volts.

If the voltage on the middle pin is then 5 volts, analogRead() returns 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the voltage applied to the pin.

After building the circuit, connect your Arduino board to your computer, launch Arduino Software (IDE), copy the code below and paste it into your Arduino IDE. But first let us understand the code line by line.

  • In Line 3, we declared variable sensorPin which is set to Analog Pin A0 where we receive the value of the connected potentiometer.
  • In Line 4, we create a variable senorPin that stores the value of the sensor that we also use for the potentiometer.
// Arduino: Lesson 5 - Reading Potentiometer and Showing Values On Serial Monitor

int sensorPin = A0;    // Read the Analogic Pin A0 Values into a variable
int sensorValue = 0;   // Variable to store the value coming from the sensor "Potentiometer"
  • In Line 6, we enter the void setup() function. This function is read only once when the Arduino is started.
  • In Line 7, we begin serial communication by declaring the Serial.begin() function. At 9600 bits of data per second, this is the speed at which your computer will communicate with your Arduino Serial.
void setup() {                 // This function is called once when the program starts
  Serial.begin(9600);          // Begin the Serial Monitor with bounce rate in 115200
}
  • After setting the initializations, in Line 10 we will enter the void loop() function.
  • In Line 11, we use the variable sensorValue to store the resistance value, which is between 0 and 10K (read by the Arduino as a value between 0 and 1023) and controlled by the potentiometer.
  • In Line 13, we use the command Serial.println(), it is print out the value controlled by the potentiometer, this value will read with value between 0 and 1023 in your Serial Monitor.
  • In Line 14, we run the delay() function, for greater system stability.
void loop() {                                                // The loop function runs over and over again forever
  sensorValue = analogRead(sensorPin);     // Read the input on analog pin A0
  
  Serial.println(sensorValue);             // Print out the value you read
  delay(1);                                // delay in between reads for stability
}

Now you can copy the code and upload it to your Arduino. After that, if you open your Serial Monitor in Arduino Software (IDE) (by clicking on the icon that looks like a lens on the right side of the green top bar or using the keyboard shortcut Ctrl+Shift+M), you should see a steady stream of numbers in the range 0-1023 that correlate with the position of the pot. When you turn your potentiometer, these numbers respond almost instantly.

The complete code is showed in the sketch below!

// Arduino: Lesson 5 - Reading Potentiometer and Showing Values On Serial Monitor

int sensorPin = A0;    // Read the Analogic Pin A0 Values into a variable
int sensorValue = 0;   // Variable to store the value coming from the sensor "Potentiometer"

void setup() {                 // This function is called once when the program starts
  Serial.begin(9600);          // Start serial connection
}

void loop() {                                                // The loop function runs over and over again forever
  sensorValue = analogRead(sensorPin);     // Read the input on analog pin A0
  
  Serial.println(sensorValue);             // Print out the value you read
  delay(1);                                // delay in between reads for stability
}
//------------------------------------- www.elcircuits.com --------------------------------------------

Next Lesson

Previous Lesson

✨ Our Gratitude and Next Steps

We sincerely hope this guide has been useful and enriching for your projects! Thank you for dedicating your time to this content.

Your Feedback is Invaluable:

Have any questions, suggestions, or corrections? Feel free to share them in the comments below! Your contribution helps us refine this content for the entire ElCircuits community.

If you found this guide helpful, spread the knowledge!

🔗 Share This Guide

Best regards,
The ElCircuits Team ⚡

O post Arduino Lesson 5 – Reading Potentiometer Values on Serial Monitor apareceu primeiro em Electronic Circuits.

]]>
https://www.elcircuits.com/arduino-lesson-5-potentiometer-serial-monitor/feed/ 0
Arduino UNO R3: Pinout and Key Features https://www.elcircuits.com/arduino-uno-r3-pinout-features/ https://www.elcircuits.com/arduino-uno-r3-pinout-features/#respond Sat, 12 Sep 2020 23:53:00 +0000 https://elcircuits.com/pinout-arduino-uno-board-atmega328pu/ Pinout diagram of the Arduino UNO R3 development board 🌐 You can read this article in: Português | Español The Arduino UNO R3 board is, without a doubt, one of the most popular and accessible electronic prototyping platforms in the world. Ideal for beginners, educators, and professionals, its simplicity and vast community make it the perfect choice to bring innovative projects to life. At the heart of this board is the ATmega328P microcontroller, a robust and versatile chip that offers an excellent balance between performance and power consumption. In this comprehensive guide, we will dive deep into the pinout of the Arduino UNO R3. We will cover each pin, from the digital and analog input and output pins to the power and communication pins. Our goal is to provide a clear and detailed reference so you can use your board with maximum confidence and take full advantage of its potential in your projects. Pinout Diagram I/O (Input/Output) Pin Table Pin on Board GPIO (Chip) Main Functions Critical Notes / Default State D0 / RX PD0 UART (RX) Receives serial data. Used for communication with the computer via USB. Avoid using during sketch upload. D1 / TX PD1 UART (TX) Transmits serial data. Used for communication with the computer via USB. Avoid using during sketch upload. D2 / ~2 PD2 PWM, INT0 PWM output. Can be used as external interrupt 0. D3 / ~3 PD3 PWM, INT1 PWM output. Can be used as external interrupt 1. D4 PD4 Digital General purpose digital pin. D5 / ~5 PD5 PWM PWM output. D6 / ~6 PD6 PWM PWM output. D7 PD7 Digital General purpose digital pin. D8 PB0 Digital General purpose digital pin. D9 / ~9 PB1 PWM PWM output. D10 / ~10 PB2 PWM, SS PWM output. ‘Slave Select’ pin for SPI communication. D11 / ~11 PB3 PWM, MOSI PWM output. ‘Master Out Slave In’ pin for SPI communication. D12 / ~12 PB4 PWM, MISO PWM output. ‘Master In Slave Out’ pin for SPI communication. D13 PB5 Digital, SCK, LED ‘Serial Clock’ pin for SPI communication. Connected to the onboard LED (‘L’). A0 PC0 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D14). A1 PC1 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D15). A2 PC2 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D16). A3 PC3 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D17). A4 / SDA PC4 Analog Input, I2C (SDA) Analog reading. Data pin (SDA) for I2C communication. Can also be used as digital pin (D18). A5 / SCL PC5 Analog Input, I2C (SCL) Analog reading. Clock pin (SCL) for I2C communication. Can also be used as digital pin (D19). Power and Control Pins Table Pin on Board Name Function Technical Description VIN Input Voltage External Power Voltage input (recommended 7-12V) for the board’s voltage regulator. 5V 5 Volts Output/Input Power Regulated 5V output from VIN or USB. Can be used as input to power the board (be careful not to damage the regulator). 3.3V 3.3 Volts Output Power Provided by the onboard regulator. Maximum of 50mA. To power components that operate at 3.3V. GND Ground Ground Ground reference pins (0V). The board has multiple GND pins for convenience. AREF Analog Reference Analog Reference Reference voltage for analog inputs (0-5V by default). Can be used to improve ADC reading accuracy. RESET Reset Reset Microcontroller Putting this pin at low level (LOW) resets the ATmega328P microcontroller. IOREF I/O Reference I/O Reference Provides the reference voltage that the microcontroller operates at (5V on UNO). Useful for shields that need to adapt to the board’s voltage. Schematic Diagram The schematic diagram goes beyond the pinout, showing how the internal electronic components of the board are connected. It is essential to understand the flow of power and signals, allowing for more advanced diagnostics and the possibility of modifying or creating your own versions of the board. Analyzing the schematic helps to understand the role of each component, such as the voltage regulator, the USB-Serial converter, and the main microcontroller. Fig. 2 – Arduino UNO R3 Schematic Diagram To view the Arduino UNO R3 schematic, you can access the official Arduino documentation. The document contains complete and up-to-date technical information about the module’s hardware. Click here to access the PDF schematic on the official Arduino website. 🔗 Related Content If you liked this project, you might also be interested in these other articles: Arduino Mega 2560 R3: Complete Pinout and Key Features What is Arduino? How to Install Arduino Software (IDE) on Windows – Step by Step! Summary of Electrical Characteristics and Limitations Microcontroller: The board is equipped with the ATmega328P chip, operating at a clock frequency of 16 MHz. Operating Voltage: The board operates at a voltage of 5V, which is internally regulated from an external source (VIN pin) or from the USB connection. Power Supply (VIN): The VIN pin accepts an input voltage recommended between 7V and 12V. The absolute range can reach 6-20V, but higher voltages may overheat the regulator. Current per I/O Pin: Each digital I/O pin can supply or receive a maximum of 20mA of current. The absolute maximum value is 40mA, but exceeding 20mA can permanently damage the pin. Total Current I/O Pins: The sum of currents from all I/O pins and the 5V pin should not exceed 200mA. USB-Serial Converter: Communication with the computer is managed by an ATmega16U2 chip, which acts as a USB to serial converter, allowing programming and debugging via a virtual serial port. Memory: The ATmega328P has 32KB of Flash memory (for code, with 0.5KB used by the bootloader), 2KB of SRAM (for variables), and 1KB of EEPROM (for non-volatile data storage). Analog Input Pins (ADC): It has 6 analog input pins (A0-A5) with a resolution of 10 bits (values from 0 to 1023). Understanding the pinout and electrical characteristics of the Arduino

O post Arduino UNO R3: Pinout and Key Features apareceu primeiro em Electronic Circuits.

]]>
Pinout diagram of the Arduino UNO R3 development board
Pinout diagram of the Arduino UNO R3 development board

🌐 You can read this article in: Português | Español

The Arduino UNO R3 board is, without a doubt, one of the most popular and accessible electronic prototyping platforms in the world. Ideal for beginners, educators, and professionals, its simplicity and vast community make it the perfect choice to bring innovative projects to life. At the heart of this board is the ATmega328P microcontroller, a robust and versatile chip that offers an excellent balance between performance and power consumption.

In this comprehensive guide, we will dive deep into the pinout of the Arduino UNO R3. We will cover each pin, from the digital and analog input and output pins to the power and communication pins. Our goal is to provide a clear and detailed reference so you can use your board with maximum confidence and take full advantage of its potential in your projects.

Pinout Diagram

I/O (Input/Output) Pin Table

Pin on Board GPIO (Chip) Main Functions Critical Notes / Default State
D0 / RX PD0 UART (RX) Receives serial data. Used for communication with the computer via USB. Avoid using during sketch upload.
D1 / TX PD1 UART (TX) Transmits serial data. Used for communication with the computer via USB. Avoid using during sketch upload.
D2 / ~2 PD2 PWM, INT0 PWM output. Can be used as external interrupt 0.
D3 / ~3 PD3 PWM, INT1 PWM output. Can be used as external interrupt 1.
D4 PD4 Digital General purpose digital pin.
D5 / ~5 PD5 PWM PWM output.
D6 / ~6 PD6 PWM PWM output.
D7 PD7 Digital General purpose digital pin.
D8 PB0 Digital General purpose digital pin.
D9 / ~9 PB1 PWM PWM output.
D10 / ~10 PB2 PWM, SS PWM output. ‘Slave Select’ pin for SPI communication.
D11 / ~11 PB3 PWM, MOSI PWM output. ‘Master Out Slave In’ pin for SPI communication.
D12 / ~12 PB4 PWM, MISO PWM output. ‘Master In Slave Out’ pin for SPI communication.
D13 PB5 Digital, SCK, LED ‘Serial Clock’ pin for SPI communication. Connected to the onboard LED (‘L’).
A0 PC0 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D14).
A1 PC1 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D15).
A2 PC2 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D16).
A3 PC3 Analog Input Analog sensor readings (0 to 1023). Can also be used as digital pin (D17).
A4 / SDA PC4 Analog Input, I2C (SDA) Analog reading. Data pin (SDA) for I2C communication. Can also be used as digital pin (D18).
A5 / SCL PC5 Analog Input, I2C (SCL) Analog reading. Clock pin (SCL) for I2C communication. Can also be used as digital pin (D19).

Power and Control Pins Table

Pin on Board Name Function Technical Description
VIN Input Voltage External Power Voltage input (recommended 7-12V) for the board’s voltage regulator.
5V 5 Volts Output/Input Power Regulated 5V output from VIN or USB. Can be used as input to power the board (be careful not to damage the regulator).
3.3V 3.3 Volts Output Power Provided by the onboard regulator. Maximum of 50mA. To power components that operate at 3.3V.
GND Ground Ground Ground reference pins (0V). The board has multiple GND pins for convenience.
AREF Analog Reference Analog Reference Reference voltage for analog inputs (0-5V by default). Can be used to improve ADC reading accuracy.
RESET Reset Reset Microcontroller Putting this pin at low level (LOW) resets the ATmega328P microcontroller.
IOREF I/O Reference I/O Reference Provides the reference voltage that the microcontroller operates at (5V on UNO). Useful for shields that need to adapt to the board’s voltage.

Schematic Diagram

The schematic diagram goes beyond the pinout, showing how the internal electronic components of the board are connected. It is essential to understand the flow of power and signals, allowing for more advanced diagnostics and the possibility of modifying or creating your own versions of the board. Analyzing the schematic helps to understand the role of each component, such as the voltage regulator, the USB-Serial converter, and the main microcontroller.

Schematic Diagram Arduino UNO Rev 3 - fvml.com.br
Fig. 2 – Arduino UNO R3 Schematic Diagram

To view the Arduino UNO R3 schematic, you can access the official Arduino documentation. The document contains complete and up-to-date technical information about the module’s hardware. Click here to access the PDF schematic on the official Arduino website.

🔗 Related Content

If you liked this project, you might also be interested in these other articles:

Summary of Electrical Characteristics and Limitations

  • Microcontroller: The board is equipped with the ATmega328P chip, operating at a clock frequency of 16 MHz.
  • Operating Voltage: The board operates at a voltage of 5V, which is internally regulated from an external source (VIN pin) or from the USB connection.
  • Power Supply (VIN): The VIN pin accepts an input voltage recommended between 7V and 12V. The absolute range can reach 6-20V, but higher voltages may overheat the regulator.
  • Current per I/O Pin: Each digital I/O pin can supply or receive a maximum of 20mA of current. The absolute maximum value is 40mA, but exceeding 20mA can permanently damage the pin.
  • Total Current I/O Pins: The sum of currents from all I/O pins and the 5V pin should not exceed 200mA.
  • USB-Serial Converter: Communication with the computer is managed by an ATmega16U2 chip, which acts as a USB to serial converter, allowing programming and debugging via a virtual serial port.
  • Memory: The ATmega328P has 32KB of Flash memory (for code, with 0.5KB used by the bootloader), 2KB of SRAM (for variables), and 1KB of EEPROM (for non-volatile data storage).
  • Analog Input Pins (ADC): It has 6 analog input pins (A0-A5) with a resolution of 10 bits (values from 0 to 1023).

Understanding the pinout and electrical characteristics of the Arduino UNO R3 is the first step to creating robust and functional electronic projects. This guide serves as a quick reference to avoid common mistakes, such as overloading a pin or using an inadequate power supply. Mastering these concepts, you will be ready to explore the entire universe of possibilities that the Arduino platform offers, from simple LED activations to complex automation and IoT systems.

🤔 Frequently Asked Questions (FAQ): About the Arduino UNO R3 Pinout

To ensure your project is a success, we’ve compiled some of the most common questions about the Arduino UNO R3 pinout. Check it out!

What is the difference between the VIN and 5V pins? 🔽

The VIN pin is a raw voltage input (recommended 7-12V) that powers the board’s voltage regulator, which in turn generates the stable 5V. The 5V pin is the already regulated output. You can power the Arduino through the 5V pin, but you must ensure that the source is exactly 5V and stable, as this bypasses the voltage regulator, which can be risky for the microcontroller.

Why do some digital pins have a tilde (~) next to the number? 🔽

The tilde (~) indicates that the pin supports PWM (Pulse Width Modulation or Pulse Width Modulation). These pins can simulate an analog output by varying the “width” of the voltage pulse at high frequency. It is widely used to control the brightness of LEDs or the speed of DC motors. On the Arduino UNO, the PWM pins are ~3, ~5, ~6, ~9, ~10, ~11.

Can I use the A0-A5 pins as digital pins? 🔽

Yes! The analog input pins (A0 to A5) can also function as digital pins. In the code, you can refer to them simply as A0, A1, etc., or using their equivalent digital pin numbers (A0 is 14, A1 is 15, and so on up to A5 which is 19).

How do the I2C and SPI communication pins work? 🔽

I2C uses two pins: SDA (data line) on pin A4 and SCL (clock line) on pin A5. It is a communication protocol with multiple slaves and master. SPI uses four pins: MOSI (D11), MISO (D12), SCK (D13) and SS (D10). It is faster than I2C, ideal for high-speed communication with devices like displays and SD cards.

What happens if I exceed the maximum current of an I/O pin? 🔽

Exceeding the maximum current of 20mA (recommended value) per pin can permanently damage the GPIO port of the ATmega328P microcontroller. This can make the pin unusable for input or output. To drive loads that require more current (like motors or relays), always use a driver circuit, such as a transistor or a relay module.

What is the AREF pin used for? 🔽

The AREF (Analog Reference) pin is used to provide an external and more precise reference voltage for the analog-to-digital converter (ADC) conversions. By default, the Arduino uses 5V as the reference, which means a reading of 1023 corresponds to 5V. If you connect a more stable and precise voltage (e.g., 3.3V) to the AREF pin, you can improve the accuracy of your analog readings, especially when working with sensors that operate in a lower voltage range.

✨ Our Gratitude and Next Steps

We sincerely hope this guide has been useful and enriching for your projects! Thank you for dedicating your time to this content.

Your Feedback is Invaluable:

Have any questions, suggestions, or corrections? Feel free to share them in the comments below! Your contribution helps us refine this content for the entire ElCircuits community.

If you found this guide helpful, spread the knowledge!

🔗 Share This Guide

Best regards,

The ElCircuits Team ⚡

O post Arduino UNO R3: Pinout and Key Features apareceu primeiro em Electronic Circuits.

]]>
https://www.elcircuits.com/arduino-uno-r3-pinout-features/feed/ 0