Arduino uno
Arduino uno
Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins
(of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB
connection, a power jack, an ICSP header and a reset button. It contains everything needed to support
the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC
adapter or battery to get started.
The Arduino Uno is a popular microcontroller board based on the ATmega328P. Here’s a
breakdown of its pins and their functions:
A0 to A5: These are used to read analog signals (voltages) and convert them to digital
values. They can also be used as digital I/O pins if needed.
3. Power Pins
4. Reset Pin
RESET: This pin is used to reset the microcontroller. Pulling this pin low will reset
the board.
AREF: Used to set an external reference voltage for the analog-to-digital converter.
By default, the reference voltage is the same as the operating voltage (5V or 3.3V).
Pin 2 and Pin 3: These can be used for external interrupts. This means they can
trigger interrupts (like on a button press) to execute certain code.
7. PWM Pins
Pins 3, 5, 6, 9, 10, and 11: These pins can output PWM signals. PWM is used to
simulate analog output by varying the duty cycle of the digital signal.
8. ICSP Header
ICSP (In-Circuit Serial Programming): This 6-pin header is used for programming
the ATmega328P directly. It’s also used for firmware updates and other low-level
programming.
RX (Pin 0) and TX (Pin 1): These pins are used for serial communication (UART).
RX is for receiving data, and TX is for transmitting data.
16 MHz Crystal: This crystal oscillator helps keep the timing accurate for the
microcontroller.
USB Port: Used for powering the board and uploading sketches. It connects to a
computer via a standard USB cable.
Here's a quick summary of the pin labels and their typical uses:
This pinout layout allows the Arduino Uno to interface with a wide variety of sensors,
actuators, and communication protocols, making it a versatile tool for electronics and
programming projects.
Arduino IDE
The Arduino IDE is an open-source software, which is used to write and upload code to the
Arduino boards. The IDE application is suitable for different operating systems such
as Windows, Mac OS X, and Linux. It supports the programming languages C and C++.
Here, IDE stands for Integrated Development Environment.
The program or code written in the Arduino IDE is often called as sketching. We need to
connect the Genuino and Arduino board with the IDE to upload the sketch written in the
Arduino IDE software. The sketch is saved with the extension '.ino.'
Toolbar Button
The icons displayed on the toolbar are New, Open, Save, Upload, and Verify.
It is shown below:
If it is unknown, the “Select Other board and port” dialog will open.
See Manually select a board.
If the board could be identified, but you are missing the board platform, you
may be asked to install it:
Select Yes to automatically install the board package in the
background.
Select Install manually to view the package in the Board Manager.
To learn more about installing boards, see Add a board to Arduino IDE
In some cases you may want to individually control the port and board selection:
Select a board that isn’t connected to your computer (you can still write and verify
sketches).
The board cannot be automatically identified.
The board associated with the port is incorrect.
The menu bar can be used to perform many actions, including board and port selection.
Arduino Code
Time to dive into the code
🤓 For this tutorial we are going to use off the shelf example code. In the op
menu of the Arduino IDE you can choose:
File ▸ Examples ▸ 01. Basics ▸ Blink
The IDE should open the code to blink the built-in LED automatically. Take
some time to read the code before you continue. Are you able to figure what
each line does?
Line 1, 2 and 8 start with two slashes //. This line of code is what we
call comment. Comments allow you to provide human readable additional
information which is completely ignored by the computer. Another form of
comment starts with /* and ends with */. Everything between the start and end
will be seen as part of the comment e.g.:
1 /*
2 This is comment
3 over
4 multiple lines
5 */
You can use this syntax for a single line comments as well:
The code has been split into two parts: setup and loop.
When the program starts it executes the setup() function once. After this the
program continues with the loop(). The setup() is for example used to assign
pins.
In this example we are using the pinMode function to specify we want to use
the LED_BUILTIN pin as a OUTPUT. On the Arduino UNO, LED_BUILTIN is
an alias for 13 (the builtin LED pin). Therefore you could have typed 13 as
well. The advantage of using LED_BUILTIN is that it works on all Arduinos.
Even when the builtin LED is connected to another pin.
The loop() function
After the setup(), the program continues with the loop(). This function will be
called over and over again. Every time the function has finished, it will be
called again. The only way to stop the program is to disconnect the power or
to upload a new program.
If you look closely at the code you see two other functions being
called: digitalWrite() and delay(). digitalWrite() writes the value (LOW or HIGH)
specified to a given pin. The pin we are using is specified by the function's
first parameter, in our case LED_BUILTIN. The second parameter specifies
the written value, here HIGH. digitalWrite() in this case, makes sure that the
LED on pin 13 will be lit.
The next line shows the delay() function with a single parameter. Can you
think about what the value of this parameter represents?
Its value is the amount milliseconds the program has to wait. In our case this
is 1000 milliseconds, which is the equivalent of 1 second.
After this brief pause, the program continues and writes LOW to
the LED_BUILTIN pin. As a result the LED goes off.
Now our program is ready to upload to the Arduino. First we have to connect
our Arduino to the computer with the USB cable. Make sure you've selected
the correct board in the IDE:
Tools ▸ Port
If you are not sure which port to use, try them all until you can successfully
upload your code.
The top left shows a round button with a checkmark. By pressing this button
you tell the IDE to verify your code for possible errors. The IDE only checks
if it can read your code. It does not check if you have written correct code for
what you are trying to program.
If everything works the IDE shows the Compiling completed message. You can
now upload your code by pressing the round button with the arrow to the
right. The uploading is complete when the Avrdude done. Thank you. messages
appears. Your program will immediately start after uploading. As a result you
should now see your Arduino LED blink with 1000ms intervals.