Arduino Tutorial
Arduino Tutorial
The Arduino boards were initially created to help the students with the
non-technical background.
The Arduino board consists of sets of analog and digital I/O (Input /
Output) pins, which are further interfaced to breadboard, expansion
boards, and other circuits. Such boards feature the model, Universal
Serial Bus (USB), and serial communication interfaces, which are used
for loading programs from the computers.
The projects are authorized under the GPL and LGPL. The GPL is
named as GNU General Public License. The licensed LGPL is named
as GNU Lesser General Public License. It allows the use of Arduino
boards, it's software distribution, and can be manufactured by anyone.
o Finger button
o Button for motor activation
o Light as a sensors
o LED button
o Designing
o The Building of electronic devices
What is Arduino?
Arduino is a software as well as hardware platform that helps in making
electronic projects. It is an open source platform and has a variety of
controllers and microprocessors. There are various types of Arduino
boards used for various purposes.
The analog pins in Arduino are mostly useful for fine-grained control. The
pins in the Arduino board are arranged in a specific pattern. The other
devices on the Arduino board are USB port, small components (voltage
regulator or oscillator), microcontroller, power connector, etc.
Features
The features of Arduino are listed below:
AD
History
The project began in the Interaction Design Institute in Ivrea, Italy. Under
the supervision of Casey Reas and Massimo Banzi, the Hernando Bar in
2003 created the Wiring (a development platform). It was considered as
the master thesis project at IDII. The Wiring platform includes the PCB
(Printed Circuit Board). The PCB is operated with the ATmega168
Microcontroller.
In 2005, Massimo Banzi, David Cuartielles, David Mellis, and another IDII
student supported the ATmega168 to the Wiring platform. They further
named the project as Arduino.
The project of Arduino was started in 2005 for students in Ivrea, Italy. It
aimed to provide an easy and low-cost method for hobbyists and
professionals to interact with the environment using the actuators and the
sensors. The beginner devices were simple motion detectors, robots, and
thermostats.
AD
AD
Microcontroller
The most essential part of the Arduino is the Microcontroller, which is
shown below:
Projects
Let's consider a simple project of LED blink.
AD
We need a software to install our sketch or code to the Arduino board. The
LED will blink after the successful uploading of code. The software is
called as Arduino IDE (Integrated Development Environment).
There are various projects created with the help of the Arduino. Some of
the projects are listed below:
Some projects require a list of components. So, for easy convenience and
hands-on projects, the Arduino kits are available easily in market.
Arduino Kits
We can easily start with our electronics projects using the complete kit. It
also helps us to create hand-on and engaging projects.
Arduino IDE
The IDE makes the traditional projects even easier and simpler. The USB
cable is used to load the program or sketch on the specific Arduino board.
The IDE application is suitable for Windows, Mac OS X, and Linux. It
supports the programming language C and C++. We need to connect the
Genuino and Arduino board with the IDE to upload the sketch written in
the Arduino IDE software.
Arduino Boards
There are variety of Arduino board used for different purposes. The board
varies in I/O pins, size, etc. The various components present on
the Arduino boards are Microcontroller, Digital Input/Output pins, USB
Interface and Connector, Analog Pins, Reset Button, Power button, LED's,
Crystal Oscillator, and Voltage Regulator. Some components may differ
depending on the type of board.
o Arduino UNO
o Arduino Nano
o Arduino Mega
o Arduino Due
o Arduino Bluetooth
Arduino UNO
The Arduino UNO is a standard board of Arduino. Here UNO means 'one' in
Italian. It was named as UNO to label the first release of Arduino Software.
It was also the first USB board released by Arduino. It is considered as the
powerful board used in various projects. Arduino.cc developed the Arduino
UNO board.
Blinking an LED
It is the simple basic project created using Arduino. LED (Light Emitting
Diode) is an electronic device, which emits light when the current passes
through its terminals. LED's are used in various applications. It is also
used as an ON/OFF indicator in different electronic devices.
Structure of LED
An LED is a two-terminal device. The two terminals are called as Cathode
and Anode.
It is shown below:
The long terminal is called Anode, and the shorter terminal is called
Cathode. Here, cathode is the negative terminal and anode is the positive
terminal.
We can use a resistor of any value upto 470 Ohms. We can use other
value of resistors as well, depending on our circuit requirements. Usually,
the value should not exceed the allowable forward current.
It is shown below:
Sketch
We need to install the Arduino IDE, to begin with the coding, which is
already discussed.
Open the IDE and start with the coding, which is given below:
1. void setup ( )
2. {
3. pinMode ( 8, OUTPUT); // to set the OUTPUT mode of pin number 8.
4. }
5. void loop ( )
6. {
7. digitalWrite (8, HIGH);
8. delay(1000); // 1 second = 1 x 1000 milliseconds
9. digitalWrite (8, LOW);
10.delay(500); // 0.5 second = 0.5 x 1000 milliseconds
11.}
We can modify the delay duration according to our choice or as per the
requirements.
The sketch will be uploaded to the board after the correct compiling, as
shown below:
The RX and TX LED on the board will light up after the successful
uploading of the code.
Procedure
The procedure to join the components of the project is shown below:
AD
o Attach an LED on the breadboard. We need to plug-in the two terminals of
an LED into the holes of the breadboard.
AD
o Connect the left leg of the resistor (connected in series with red LED) to
the digital output pin of the UNO board, i.e., PIN 8.
o Connect the negative/shorter terminal (Cathode) of the LED to the GND
pin of the UNO board using the wire, as shown below:
Here, the orange wire is connected to the PIN 8, and the blue wire is
connected to the GND.
The shorter terminal indicates the negative. So, we will connect the
shorter terminal to the Ground (GND).
o Connect the USB cable.
o Select the board and serial port in the Arduino IDE.
o Upload the sketch or code on the board.
o The LED will dim and light for the specified duration.
Important points
AD
The resistor prevents the excess current from reaching the LED. The
excess current in the connection can burn the LED. Hence, a resistor in
series with the LED is used in the connection.
o We can use any pin as the OUTPUT pin. For example, 8, 13, 7, 4, and 3.
The other pins are PWM and analog pins.
o One terminal of the LED is connected to the Ground while the other
terminal is connected to the digital pin. The digital pin has only two values
0 or 1.
o HIGH = 1
o LOW = 0
o Arduino UNO board is recommended for all basic projects because it is
easy to understand and implement. It is also the standard Arduino board
from all types of boards used. It supplies power and also acts as a serial
port.
Blinking Two LED
We have already discussed a project of blinking an LED. Here, we will
discuss a project of blinking two LED's.
The concept of blinking two LED's is similar to the blinking of a single LED.
As we know, we can use the resistance of any value, so let's take the
resistors of 470 Ohms. The resistors reduce the amount of current
reaching the LED, which saves the LED from being burnt.
We can also use other resistors depending on the circuit limit and
requirements.
Components
The components used in the project are listed below:
Sketch
Open the Arduino IDE (Integrated Development Environment) and start
with the coding, which is given below:
1. void setup ()
2. {
3. pinMode ( 13, OUTPUT); // to set the OUTPUT mode of pin number 13.
4. pinMode ( 7, OUTPUT); // to set the OUTPUT mode of pin number 7.
5. }
6. void loop ()
7. {
8. digitalWrite (13, HIGH);
9. digitalWrite (7, LOW);
10.delay(1500); // 1.5 second = 1.5 x 1000 milliseconds
11.digitalWrite (13, LOW);
12.digitalWrite (7, HIGH);
13.delay(1000); // 1 second = 1 x 1000 milliseconds
14.}
We can modify the delay duration according to our choice or as per the
requirements.
The sketch will be uploaded to the board after the correct compiling, as
shown below:
Click on the Verify button present on the toolbar to compile the code.
The RX and TX LED on the board will light up after the successful
uploading of the code.
Procedure
The procedure to join the components of the project is shown below:
AD
o Connect the left leg of the resistor (connected in series with red LED) to
the digital output pin of the UNO board, i.e., PIN 13.
o Connect the left leg of the resistor (connected in series with green LED) to
the digital output pin of the UNO board, i.e., PIN 7.
o Connect the negative/shorter terminal (Cathode) of the red and green LED
to the GND pin of the UNO board using the wire, as shown below:
AD
Here, the red wire is connected to the PIN 13, and the blue wire is
connected to the GND.
Similarly, the green wire is connected to the PIN 7, and the orange wire is
connected to the GND.
Note: The different colors of wire are used only for a better understanding.
The shorter terminal indicates the ground. So, we will connect the shorter
terminal to the Ground (GND).
It means when the red LED will be ON, the green LED will be OFF and vice
versa.
Arduino Simulator
The Arduino simulator is a virtual portrayal of the circuits of
Arduino in the real world. We can create many projects using a simulator
without the need for any hardware.
Types of Simulator
There are various simulators available. Some are available for free, while
some require a license to access the simulators.
o Autodesk Tinkercad
o Emulator Arduino Simulator
o Autodesk Eagle
o Proteus Simulator
o Virtronics Arduino Simulator
o ArduinoSim
AD
We can select any sign-in method. Specify the username and password.
We already have an account in Autodesk, so we will sign-in directly with
the username and password.
AD
The 'Circuits' option will also show the previous circuits created by user.
The design option is used for creating the 3D design, which is of no use
in Arduino.
6. We are now ready to start with the Autodesk Tinkercad. We can start
creating our projects.
AD
AD
Features of Tinkercad
o A window will appear. We need to drag and drop the desired components
in the project screen. It is shown below:
o Click on the drop list of components and select the 'All' option.
The selected option 'All' will display all the components and starter
examples when we scroll down a little, as shown below:
Code example to blink an LED
Let's understand with an example to blink an LED. We can use both
( blinking an LED in basic projects and the one specified below) methods
to blink an LED.
o Search UNO R3 and drag-drop the board on the project screen. We can
select any board according to the requirements.
o Search a LED, and 1 resistor of 220 ohms and drag-drop them on the
project screen.
After selecting the resistor, a box to set the resistance will appear, as
shown below:
Here, we have selected the red color for LED. We can also choose other
colors.
After selecting the LED, a box to set the color will appear, as shown below:
o Now, connect the wires. For wiring, just select the point on the board to
the terminal of the component. We are not required to search for wires in
the search box.
o The circuit will now appear as:
The LED will light up for 1 second and dim for 1 second.
The lighting LED is shown below:
Serial Monitor
It allows the flow of current in the circuit without the need for splice wire.
The slide switches are widely used in small circuits applications.
o Closed circuits
The closed circuits have closed loop. Electrons can easily flow in a closed
circuit and light up an LED.
o Open circuits
AD
The open circuits have open ends, due to which electrons cannot flow
through the circuit.
It is a switch that has one input and one output. The circuit is ON when the
switch is closed and vice versa.
It is a switch with one input and three outputs, where each input
corresponds to any of the output in a circuit.
where,
Code Example
Let's discuss an example to light an LED using a Switch. Here, we will use
the SPDT (Single Pole Double Throw) Switch.
If we leave one side of the switch, it can work as SPST (Single Pole Single
Throw) switch.
Components Required
AD
AD
5. Connect the positive terminal of LED in series with the resistor to PIN 8.
7. Connect one end of slide switch to Ground and another end to 5V.
void setup( ) {
pinMode(pinOFswitch, INPUT);
pinMode(LED, OUTPUT);
void loop( )
int ValueOFswitch;
ValueOFswitch = digitalRead(pinOFswitch);
if (ValueOFswitch == HIGH)
digitalWrite(LED, HIGH);
delay(500);
else
digitalWrite(LED, LOW);
delay(500);