0% found this document useful (0 votes)
3 views38 pages

Arduino Tutorial

Arduino is an open-source hardware and software platform designed for building electronic devices, featuring various microcontroller boards that facilitate project development for users with non-technical backgrounds. It includes an Integrated Development Environment (IDE) for programming and supports a range of applications from simple LED projects to complex automation systems. The platform has evolved since its inception in 2005, with a growing community and commercial production of its boards, such as the popular Arduino UNO.

Uploaded by

bhavyabhavvi22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views38 pages

Arduino Tutorial

Arduino is an open-source hardware and software platform designed for building electronic devices, featuring various microcontroller boards that facilitate project development for users with non-technical backgrounds. It includes an Integrated Development Environment (IDE) for programming and supports a range of applications from simple LED projects to complex automation systems. The platform has evolved since its inception in 2005, with a growing community and commercial production of its boards, such as the popular Arduino UNO.

Uploaded by

bhavyabhavvi22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Arduino Tutorial

Arduino is a project, open-source hardware, and software platform used to


design and build electronic devices.

It designs and manufactures microcontroller kits and single-board


interfaces for building electronics projects.

The Arduino boards were initially created to help the students with the
non-technical background.

The designs of Arduino boards use a variety of controllers and


microprocessors.

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.

It also provides an IDE (Integrated Development Environment) project,


which is based on the Processing Language to upload the code to the
physical board.

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.

It is also available in the form of self practicing kits.

The Arduino is used for various purposes, such as:

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 Arduino is a single circuit board, which consists of different interfaces


or parts. The board consists of the set of digital and analog pins that
are used to connect various devices and components, which we want to
use for the functioning of the electronic devices.

Most of the Arduino consists of 14 digital I/O pins.

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:

o Arduino programming is a simplified version of C++, which makes


the learning process easy.
o The Arduino IDE is used to control the functions of boards. It further
sends the set of specifications to the microcontroller.
o Arduino does not need an extra board or piece to load new code.
o Arduino can read analog and digital input signals.
o The hardware and software platform is easy to use and implement.

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.

The ATmega168 Microcontroller was an IDE. It was based on the library


and processing functions, which are used to easily program the
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

In mid-2011, the estimated production of Arduino commercially was


300,000. In 2013, the Arduino boards in use were about 700,000.

Around April 2017, Massimo Banzi introduced the foundation of Arduino as


the "new beginning for Arduino". In July 2017, Musto continued to pull
many Open Source licenses and the code from the websites of the
Arduino. In October 2017, Arduino introduced its collaboration with the
ARM Holdings. The Arduino continues to work with architectures and
technology vendors.

AD

Microcontroller
The most essential part of the Arduino is the Microcontroller, which is
shown below:

o Microcontroller is small and low power computer. Most of the


microcontrollers have a RAM (Random Access Memory), CPU
(Central Processing Unit), and a memory storage like other
computer systems.
o It has very small memory of 2KB (two Kilobytes). Due to less
memory, some microcontrollers are capable of running only one
program at a time.
o It is a single chip that includes memory, Input/Output (I/O)
peripherals, and a processor.
o The GPIO (General Purpose Input Output) pins present on the chip
help us to control other electronics or circuitry from the program.

Electronic devices around Us


We have many electronic devices around us. Most of the appliance
consists of the microcontroller for its functioning. Let's discuss some of
the examples.

o Microcontroller present in Microwave Oven accepts the user input


and controls the magnet run that generate microwave rays to cook
the food and displays the output timer.
o Modern cars also contain dozens of microcontrollers working in
tandem (one after another) to control functions like lighting, radio
interface, etc.

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:

o Home Automation System using IOT (Internet of Things).


o Solar Power water trash collector.
o Fire Detector, etc.

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.

Some of the popular Arduino kits are listed below:

o Arduino Starter kit


o Robot Linking UNO kit for learning
o Arduino UNO 3 Ultimate starter kit
o UNO Super starter kit
o Mega 2560 Starter Kit

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.

Many other companies including Sparkfun Electronics, also make their


own boards that are compatible with Arduino IDE.

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.

Let's discuss some of the popular Arduino boards.

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.

Arduino UNO is based on an ATmega328P microcontroller. It is easy to use


compared to other boards, such as the Arduino Mega board, etc. The
board consists of digital and analog Input/Output pins (I/O), shields, and
other circuits.

The Arduino UNO includes 6 analog pin inputs, 14 digital pins,


a USB connector, a power jack, and an ICSP (In-Circuit Serial
Programming) header. It is programmed based on IDE, which stands for
Integrated Development Environment. It can run on both online and offline
platforms.

The IDE is common to all available boards of Arduino.

The Arduino board is shown below:

The components of Arduino UNO board are shown below:


Let's discuss each component in detail.

o ATmega328 Microcontroller- It is a single chip Microcontroller of


the ATmel family. The processor code inside it is of 8-bit. It
combines Memory (SRAM, EEPROM, and Flash), Analog to
Digital Converter, SPI serial ports, I/O lines, registers, timer,
external and internal interrupts, and oscillator.
o ICSP pin - The In-Circuit Serial Programming pin allows the user to
program using the firmware of the Arduino board.
o Power LED Indicator- The ON status of LED shows the power is
activated. When the power is OFF, the LED will not light up.
o Digital I/O pins- The digital pins have the value HIGH or LOW. The
pins numbered from D0 to D13 are digital pins.
o TX and RX LED's- The successful flow of data is represented by the
lighting of these LED's.
o AREF- The Analog Reference (AREF) pin is used to feed a reference
voltage to the Arduino UNO board from the external power supply.
o Reset button- It is used to add a Reset button to the connection.
o USB- It allows the board to connect to the computer. It is essential
for the programming of the Arduino UNO board.
o Crystal Oscillator- The Crystal oscillator has a frequency of
16MHz, which makes the Arduino UNO a powerful board.
o Voltage Regulator- The voltage regulator converts the input
voltage to 5V.
o GND- Ground pins. The ground pin acts as a pin with zero voltage.
o Vin- It is the input voltage.
o Analog Pins- The pins numbered from A0 to A5 are analog pins.
The function of Analog pins is to read the analog sensor used in the
connection. It can also act as GPIO (General Purpose Input Output)
pins.

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.

In this project, we will connect the LED to the digital pin on


the Arduino board. The LED will work as a simple light that can be turned
ON and OFF for a specified duration.

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.

Components of the project


The components used in the blinking of an LED are listed below:

1. 1 x Arduino UNO board.


We can use any version of the UNO board, such as UNO R3, etc. We can
also use other types of Arduino boards, such as Arduino Zero, Arduino
Micro, etc.
2. 1 x Breadboard
3. 2 x Jump wires
4. 1 x LED
5. 1 x Resistor of 220 Ohm.

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.

Structure of the project


The structure clearly shows the pinout of the UNO board. It also displays
the LED and resistance connected to the board.

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.

Every statement of coding is explained in Arduino coding basics. You can


open the URL for clear understanding.

Note: Make sure the code is free of errors.

The sketch will be uploaded to the board after the correct compiling, as
shown below:

We are required to click on the Verify button 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 Attach an LED on the breadboard. We need to plug-in the two terminals of
an LED into the holes of the breadboard.

We can plug-in the LED anywhere on the breadboard.

o Connect the resistor in series with the LED, as 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 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

The important points to be considered in this project are listed below:

AD

o The resistor must be connected in series with the LED.

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.

Let's start with the project.

Structure of two LED's


The structure of red and green LED is shown below:
The long terminal is called Anode (positive charged), and the short
terminal is called Cathode (negative charged).

Components
The components used in the project are listed below:

1. 1 x Arduino UNO board.


We can also use other types of Arduino boards, such as Arduino Mega,
Arduino Micro, etc.
2. 1 x Breadboard
3. 4 x Jump wires
4. 1 x Red LED
5. 1 x Green LED
We need to take 2 LEDs of any color. Here, we will use the red and green
color LED.
6. 2 x Resistor of 470 Ohm.

Structure of the project


Here, we will use the digital output pin number 13 and 7. The positive
terminal of the red LED is connected to the PIN 13, and the negative
terminal (anode) is connected to the ground.

Similarly, the positive terminal (cathode) of the green LED is connected to


PIN 7 and the negative terminal is connected to the ground.

As mentioned, two resistors each of 470 Ohms, will be connected in series


to the two LEDs in the project.
The structure will represent the pinout diagram of the project. It is shown
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 Plug-in the two LED adjacent to each other on the breadboard.


o Now, plug-in the resistors of 470 Ohm in series with the two LED, as shown
below:

We need to check that the plug-in is performed correctly, as shown above.


For any confusion, check the pin diagram shown above in the heading-
Structure of project.

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).

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. Here, the green and
red LED will light alternatively.

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.

The Simulator helps beginner and professional designers to learn,


program, and create their projects without wasting time on collecting
hardware equipments.

Advantages of using Simulator


There are various advantages of using simulator, which are listed below:

o It saves money, because there is no need to buy hardware equipments to


make a project.
o The task to create and learn Arduino is easy for beginners.
o We need not to worry about the damage of board and related equipments.
o No messy wire structure required.
o It helps students to eliminate their mistakes and errors using simulator.
o It supports line to line debugging, and helps to find out the errors easily.
o We can learn the code and build projects anywhere with our computer and
internet connection.
o We can also share our design with others.

Types of Simulator
There are various simulators available. Some are available for free, while
some require a license to access the simulators.

Some types of simulators are listed below:

o Autodesk Tinkercad
o Emulator Arduino Simulator
o Autodesk Eagle
o Proteus Simulator
o Virtronics Arduino Simulator
o ArduinoSim

AD

Autodesk Eagle is an advanced simulator, which is used to design 2D and


3D models of PCB, modular designs, multi-sheet schematics, real-time
synchronization, etc.

How to access simulator?


Here, we are using the Autodesk Tinkercad Simulator.

The steps to access the TINKERCAD are listed below:

1. Open the official website of


tinkercad. URL: https://www.tinkercad.com/

A window will appear, as shown below:


2. Click on the three horizontal lines present on the upper right corner.

3. Click on the 'Sign in' option, if you have an account in Autodesk.


Otherwise, click on the 'JOIN NOW' option if you don't have an account,
as shown below:
The SIGN IN window will appear as:

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.

The JOIN window will appear as:

Select the preference according to the requirements and sign-in using


Gmail, etc.

AD

4. Now, a window will appear, as shown below:


5. Click on the 'Create new circuit' option to start designing the Arduino
circuit, as shown above.

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

Autodesk Tinkercad Simulator


It is also a simulator that is used to design virtual circuits.

AD

Features of Tinkercad

The features of Tinkercad are listed below:


o Glow and move circuit assembly. It means we can use the components
of a circuit according to the project requirement. Glow here signifies the
glowing of LED.
o Integrated product design. It means the electronic components used in
the circuitry are real.
o Arduino Programming. We can directly write the program or code in the
editor of the simulator.
o We can also consider some ready-made examples provided by the
tinkercad for better understanding.
o Realtime simulation. We can prototype our designs within the browser
before implementing them in real-time.

How to use a simulator?


Sign-in on the Autodesk Tinkercad, as explained above. Now, follow the
below steps:

o Click on 'Create new circuit' option, as shown below:

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 drop list will appear as:

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.

The steps are listed below:

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:

o Select the 'Text' instead of block view, as shown below:


o Click on the code button to write the code, as shown below:

o The coding screen will appear as:

It also displays the error in the code, if any.

o Click on 'Start Simulation' to upload the code on the board.

The LED will light up for 1 second and dim for 1 second.
The lighting LED is shown below:

Click on 'Stop Simulation' to stop the blinking of an LED, as shown


below:

Serial Monitor

The serial monitor is present on the bottom of the coding screen.

It will look like the below image:


Arduino Switch
Switches are used to turn ON/OFF devices and to connect different parts
of a circuit. The slide-switch in Arduino moves the slider of the switch from
the open position (ON) to the closed position (OFF).

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.

There are two types of circuits, which are shown below:

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.

We can use an electronic component switch, to open and close circuits


without the need to disconnect the wires by hand again and again.
Types of Switches
There are major four types of switches in Arduino, which are listed below:

o SPST (Single Pole Single Throw) Switch

It is a switch that has one input and one output. The circuit is ON when the
switch is closed and vice versa.

o SPDT (Single Pole Double Throw) Switch

It is a three-terminal switch. It has a single input, which can switch


between two outputs.

o SP3T (Single Pole Three Throw) Switch

It is a switch with one input and three outputs, where each input
corresponds to any of the output in a circuit.

o DPDT (Double Pole Double Throw) Switch


It is a switch with two inputs and four outputs. Each input of a switch
in Arduino can be connected to either of the two outputs.

where,

Pole: It signifies the number of circuits the switch can control.

Throw: It signifies the number of positions in which each pole of the


switch can connect to it.

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

The required components are listed below:

o Arduino UNO board. Here, we have used UNO R3.


o 1 x 220 ohm resistor
o Jump wires
o 1 x Slide switch
o 1 x green LED (we can take LED of any color)
o 1 x Breadboard

The steps for such an example are listed below:

1. Attach the green LED on the breadboard.

2. Connect a resistor in series with the LED.

3. Attach Slide switch on the breadboard, as shown below:

AD

4. Connect the negative pin of the LED to the Ground.

5. Connect the positive terminal of LED in series with the resistor to PIN 8.

6. Connect the common terminal or the middle terminal to pin number 3.


It is because the middle terminal is the input terminal.

7. Connect one end of slide switch to Ground and another end to 5V.

The circuit is shown below:


Now, we need to write the code on the coding screen.

The code is given below:

const int pinOFswitch = 3;

const int LED = 8;

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);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy