Introduction To Arduino
Introduction To Arduino
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.
Arduino
The board offers 20 digital input/output
pins (including 6 PWM output pins) and 8
analog input pins.
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.
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.
NEXT
CHALLENGE
Simulation:
https://wokwi.com/projects/394489025452357633
https://www.tinkercad.com/things/036JrGmW2Kf
Hint
analogWrite(pin,val);
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.
Wokwi Simulation:
https://wokwi.com/projects/394684839679597569
Reading Analog Inputs
Real world is dominated by analog quantities.
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