0% found this document useful (0 votes)
10 views

Introduction To Arduino

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Introduction To Arduino

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Introduction to

Arduino
ROBOTICS AND MACHINE INTELLIGENCE (RMI)
er Mic
al Tim rop
igit roc
D IDE e
ing sso
Analog oll rs
P RX
&T
PW X
Arduino
M C
AD
cad
ker
GPI Tin
O pts CP
erru U
Int lers
trol
USA con
RT icro
M
MICROPROCESSORS MICROCONTROLLERS
Contains only a powerful processing unit A single chip contains a processing unit
without integrated memory or other along with a small amount of memory
components. (ROM, RAM,etc.)

Requires additional hardware chips, such Includes a few I/O ports for peripherals,
as memory (RAM), peripheral boards, etc. timers, and other features.

It can be used for a wide range of It is used to perform particular tasks with
applications with interfacing different targeted applications.
peripherals.

Cannot function as a stand-alone unit and Can funtion stand-alone as it has a CPU
relies on external components. core, peripherals and timers as required.

It has higher processing power It has limited processing power


COMPUTER
ARCHITECTURE
DIGITAL SIGNAL
AND
ANALOG SIGNAL
DIGITAL SIGNAL ANALOG SIGNAL
A signal that is discrete function of A signal which is a continuous function
time, i.e. which is not a continuous of time.
signal.
Arduino is an open-source electronics
platform based on easy-to-use hardware
and software.

Arduino consists of a microcontroller and


an IDE (Integrated Development What is an
Arduino?
Environment) that runs on your computer,
used to write and upload computer code to
the physical board.

Arduino uses a simplified version of C++.


The code can be uploaded onto the board by
simply using a USB cable.
TYPES OF
ARDUINO
The Arduino Nano is Arduino's classic
breadboard-friendly designed board with
the smallest dimensions.

Arduino
The board offers 20 digital input/output
pins (including 6 PWM output pins) and 8
analog input pins.

The board can be powered through a type-B


NANO
mini-USB cable or from a 9 V battery.
ARDUINO NANO
PIN DESCRIPTION
Digital Pins (D0-D13): The pins 0 to 13 are used as a digital input or output for the
Arduino board. Out of these, 6 pins support PWM output. D13 I/0 pin is connected
directly to the built-in LED (and resistor) of the board.
Analog Pins (A0-A7): Used to read analog input from components like sensors.
The pins A0-A5 can be used as digital input/output pins.
RST: To reset the microcontroller.
TX(D1) & RXD(D0): Used for serial data transmission i.e. receiving and
transmission of data respectively.
AREF: Analog Reference pin can be used to provide an external reference voltage
for the analog-to-digital conversion of inputs to the analog pins. The reference
voltage essentially specifies the value for the top of the input range, and
consequently each discrete step in the converted output.
PIN DESCRIPTION
ICSP( In-Circuit Serial Programming ) Pins: These pins are used to code and boot
an Arduino from an external source:
MISO (Master In Slave Out) - The Slave line for sending data to the master,
MOSI (Master Out Slave In) - The Master line for sending data to the peripherals.
SCK (Serial Clock) - The clock pulses which synchronize data transmission
generated by the master.
PIN DESCRIPTION
VIN: This is an input voltage to the Arduino board when using an external power
source (7-12V)
5V: Used to power the Arduino or other modules connected to Arduino
3V: Used to power modules connected to Arduino
GND: Sets the zero voltage reference.
LEDs
RX & TX: The RX and TX lights are connected to the lines that connect both
the USB interface and the ATMega628P. They connect to TX0 and RX0.
Their blinking shows that communication is taking place during an upload.

PWR: Refers to a direct connection to the voltage-regulated 5v line i.e.


board has the power either from Vin or USB.

D13 LED: A built-in LED connected to pin 13 on the board. Can be used for
debugging.
OTHER COMPONENTS
RESET button: To reset the microcontroller. It restarts your program from the
beginning.

Mini B USB: To connect your Arduino Board to the Laptop/PC, use the cable.

ATMEGA 328P MCU: The Atmel® ATmega328P is a low-power CMOS 8-bit


microcontroller based on the AVR® enhanced RISC architecture, which is
capable of executing powerful instructions in a single clock cycle
The Arduino programming language is almost similar to C++.

setup( ) function runs only once after the board is powered up


or when the reset button is pressed.

loop( ) function runs over and over again forever.


Digital GPIO Pins
General Purpose Input Output (GPIO) pins are used as input or output for
interfacing devices.
Configuration:
Input to read the switch’s state, sensor data, etc.
Output to control the LED brightness, motor rotation, show text on
display, etc.
Some Basic functions:
pinMode(pin, Mode): This function is used to configure GPIO pin as
INPUT or OUTPUT.
digitalRead(pin): It is used to read data from specified GPIO pin
digitalWrite(pin, Output value): This function is used to set output
as HIGH (5 V) or LOW (0 V)
LET’S
CREATE
Objective: Make the built-in LED blink
YOUR
File ->Examples -> Basic ->Blink
FIRST
PROGRAM Simulation:
https://wokwi.com/projects/394486656308973569
READY
FOR Objective: Wiring up an External LED

ANOTHER
TASK?
Simulation:
https://wokwi.com/projects/394487274755006465
V/S
Pulse-width modulation (PWM) is a method of

Pulse Width
controlling the average power delivered by an
electrical signal.

The width of a pulse is varied while keeping


the frequency of the wave constant.
Modulation
A PWM signal consists of two main (PWM)
components that define its behavior: a duty
cycle and a frequency.

The percentage duty cycle describes the


percentage of time a digital signal is on over
an interval or period of time.
Objective: Make the LED glow as shown in the previous
slide

NEXT
CHALLENGE
Simulation:

https://wokwi.com/projects/394489025452357633
https://www.tinkercad.com/things/036JrGmW2Kf
Hint

Use Pulse Width Modulation (PWM)

analogWrite(pin,val);

pin = output pin number

val = duty cycle * 255


SERIAL AND PARALLEL
COMMUNICATION
Serial and Parallel Communication

Serial communication transmits one bit at a time using a single (logical) data
line.
Parallel transmission can shift multiple bits simultaneously, increasing the
throughput of data that can be transferred.
‘Sender’ sends pulses that represent data while the receiver receives it.
For 2 devices to communicate serially, digital pulses sent back and forth
between devices must agree on a rate.
Baud Rate: Specifies how fast data is sent over a serial line. It's usually
expressed in units of bits-per-second (bps).
What is Serial Monitor?
The Serial Monitor is an essential
tool when creating projects with
Arduino.
It can be used as a debugging
tool, testing out concepts or to
communicate directly with the
Arduino board.
To open it, simply click the Serial
Monitor icon. The icon is located
to the right of the other icons in
Arduino ide.
Serial Communication Functions
a) Serial.begin(baud_rate)
baud_rate : Used to define the baud rate that will be used for serial communication.
Can be 4800, 9600, 14400, 19200, etc.
For communicating with specific devices, the device baud rate needs to be used.
Example: Serial.begin(9600) defines 9600 baud rate for communication.

b) Serial.available()
This function is used to get the number of bytes available for reading from the
serial port.
It gives the number of bytes of data that has arrived and is stored in the serial
receive buffer.
Example: if(Serial.available()) --> If data available at serial port, take action.
Serial Communication Functions
c) Serial.print(value)
value : character, string, number to be printed.
This function is used to print data to a serial port in a form that is human
readable (character, strings, numbers).
Example Serial.print(“Hi 1234”) ---> Prints Hi 1234 on the serial monitor.

d) Serial.println(value)
value : character, string, number to be printed.
This function is used to print data to a serial port in a form that is human
readable (character, strings, numbers) followed by a carriage return (\r) and a
new line character (\n).
Serial Communication Functions
e) Serial.read()
This function returns a character that was received on the Rx pin of Arduino.
E.g.: char read_byte
read_byte = Serial.read() --->Byte of data read is stored in read_byte.

f) Serial.write(value), Serial.write(string), Serial.write(buff, length)


value: value to be sent as a single byte.
string: string to be sent as a series of bytes.
buff: array of data to be sent as bytes.
length: number of bytes to be sent.
This function writes data in binary form to the serial port.
Data is sent in the form of bytes or series of bytes.
Example : Serial.write(100), Serial.write(“Hello”)
Task: Reading a Button

Wokwi Simulation:
https://wokwi.com/projects/394684839679597569
Reading Analog Inputs
Real world is dominated by analog quantities.

So, for designing a real-life project, we need to get analog inputs


and give analog outputs at one point or another, but Computers &
Microcontrollers can understand digital signals alone.

So, we will be using methods like PWM & ADC to give analog
output & analog input to the microcontroller
Analog to Digital Converters (ADCs)
Used for converting analog signals to
digital signals.
Arduino Nano has 8 0n-board ADC
channels which can be used to read analog
signal in the range 0-5V.
It has 10-bit ADC means it will give digital
value in the range of 0 – 1023 (2^10).
This is called as resolution which indicates
the number of discrete values it can
produce over the range of analog values.
ADC Functions
analogRead (pin)

This function is used to read analog value from specified analog pin.
pin - number of analog pin which we want to read
returns - digital value 0 – 1023
Example: analogRead(A0) //read analog value at A0 channel
analogReference (type)
This function is used for configuring the reference voltage used for analog
input.
Task: Reading a Potentiometer
Interface LED and code to control the
brightness of the LED by adjusting the
Potentiometer.
Hint: Remember the PWM LED Fading
example

Solution Link

You might also like