arduino obstacle avoidance robot
TRANSCRIPT
Arduino Obstacle Avoidance RobotBuild an obstacle avoiding robot using ultrasonic and IR
sensors
By Steven Radigan
Arduino Obstacle Avoidance Robot1 - Introduction
Course Objective
Build an Arduino based obstacle avoidance robot
Arduino Obstacle Avoidance Robot
• Course Prerequisites• No previous programming or electronics experience is required• A basic understanding of electronics and Arduino programming concepts will
speed up your learning• Download latest version of Arduino IDE and experiment with some of the
Arduino example sketches using an Arduino Uno prior to starting the course
Arduino Obstacle Avoidance Robot
• Course OverviewArduino Obstacle Avoidance Robot OverviewLesson 1 – IntroductionLesson 2 – Arduino Uno Overview
Drive SystemLesson 3 – How a Diode WorksLesson 4 – How a Bipolar Junction Transistor WorksLesson 5 – H-Bridge Circuit Lesson 6 – Arduino Motor Shield Lesson 7 – DC Motor ConstructionLesson 8 – DC Motor OperationLesson 9 – DC Motor Speed ControlLesson 10 – Drive System BuildLesson 11 – Drive System Sketch / ExperimentLesson 12 – How Servos WorkLesson 13 – Servo Sketch & Experiment
Arduino Obstacle Avoidance Robot
• Course OverviewSensor SystemLesson 14 – LED & Photodiode OverviewLesson 15 – Infrared Sensor IntroductionLesson 16 – Sharp IR Sensor OverviewLesson 17 – Sharp IR Sensor AssemblyLesson 18 – IR Sensor Sketch & ExperimentLesson 19 – Ultrasonic Range Finder IntroductionLesson 20 – Parallax PING Sensor OverviewLesson 21 – PING Sensor AssemblyLesson 22 – PING Sensor Sketch & Experiment Obstacle AvoidanceLesson 23 – Obstacle Avoidance FlowchartLesson 24 – IR Sensor Obstacle Avoidance SketchLesson 25 – IR Sensor Obstacle Avoidance ExperimentLesson 26 – Ultrasonic Sensor Obstacle Avoidance SketchLesson 27 – Ultrasonic Sensor Obstacle Avoidance Experiment
Arduino Obstacle Avoidance Robot
• Sketches• Drive System Test
• Test ability of robot to move forward, reverse, turn left and right • Servo Test
• Test ability of servo to rotate left, right, and center• IR Sensor Test
• Test ability of Sharp IR sensor to detect an obstacle • PING Sensor Test
• Test ability of PING sensor to detect an obstacle• IR Obstacle Avoidance
• Test obstacle avoidance algorithm using Sharp IR sensor• Ultrasonic Obstacle Avoidance
• Test obstacle avoidance algorithm using PING ultrasonic sensor
Arduino Obstacle Avoidance Robot
• Required Materials• See Arduino OAR Materials List.pdf file located under Resources in
Section 1: Arduino Obstacle Avoidance Robot Overview• Resources
• Resources including the course materials list, build notes, flowcharts, and sketches are highlighted in blue and appear under the lecture title for a particular lecture.
• All documents have been saved as .pdf files and the sketches are saved as .zip files
Arduino Obstacle Avoidance Robot
• Course Goals• Build an Arduino based obstacle avoidance robot
• Understand how a DC motor based drive system works• Write sketches to implement a DC motor based drive system• Understand principles of ultrasonic and infrared based distance detection• Write sketches to implement obstacle detection using the Sharp IR and
Parallax PING sensors• Test your design and understand the limitations of IR and ultrasonic distance
sensors• Use your new knowledge to improve on the reference design or build your
own custom robot
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot2 – Arduino Uno Overview
• Arduino Uno Overview• At the heart of an Arduino board is a microcontroller• Our course is based on the Arduino Uno R3 which uses the Atmel ATmega328
microcontroller
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot
Atmel ATmega328
Reset Button
Power Pins 6 Analog Input Pins
16Mhz Ceramic Resonator
14 Digital I/O
In-circuit serial programmer (ICSP) header
USB
External Power Jack
• Arduino Uno Overview – Power• USB power or externally via barrel jack connector• External supply voltage:
• 7 to 12 Vdc
Arduino Obstacle Avoidance Robot
USB
Ext. Power
Gnd
Gnd
3.3V 5VIOREF
Vin
Pin Function
Vin Voltage from Ext. Power jack
5V 5V output from on-board Voltage regulator chip
3.3V 3.3V output from on-board Voltage regulator chip
Gnd 3 pins
IOREF Tied to 5V, tells Arduino shields voltage level from which Arduino board operates
Reset From Reset pin on MCU, tied to VCC through 10K resistor, pull to GND to reset
• Arduino Uno Overview – Digital Input / Output
• 14 Digital I/O• 5V logic level• Sink/source 20mA per pin• Universal Asynchronous Serial Receiver /
Transmitter (UART)• Pin 0 – Receive (RX)• Pin 1 – Transmit (TX)• MCU INT pins brought out to pins 2, 3
• 8-bit PWM• Pins 3, 5, 6, 9, 10, 11
• Serial Peripheral Interface (SPI)• Pins 10, 11, 12, 13
Arduino Obstacle Avoidance RobotTX / RXPWM ~ SPI
• Arduino Uno Overview – Analog• 6 Analog Inputs (A0 to A5)• Sampled input:
• 0 to 5V• 10 bits resolution
• AREF pin can be used to adjust upper limit of input range
• Two-wire Interface COM (TWI) • Pin A4 – SDA pin (data)• Pin A5 – SCL pin (clock)
Arduino Obstacle Avoidance Robot
Analog
• Arduino Uno Overview – Communication• Can communicate with a PC, another Arduino, shields, sensors• Asynchronous communication (No clock):
• UART TTL (5V) • Digital Pin 0 (RX) / Digital Pin 1 (TX)
• On-board ATmegaU16 programmed to function as USB to serial chip• UART => USB format and chip appears as virtual COM port to PC
• ATmegaU16 uses standard USB COM drivers, so no external drivers are needed (Windows needs .inf file)
• TX / RX LEDs flash when data is being transmitted to and from Uno via USB to serial chip
Arduino Obstacle Avoidance Robot
• Arduino Uno Overview – Communication• Synchronous communication (Clock) using:
• SPI• Pin 10 – Slave Select (SS)• Pin 11 – Master Out / Slave In (MOSI)• Pin 12 – Master In / Slave Out (MISO)• Pin 13 – Clock (SCK)
• TWI• Pin A4 – SDA pin (data)• Pin A5 – SCL pin (clock)
Arduino Obstacle Avoidance Robot
• Arduino Uno Overview – Programming• Bootloader firmware preinstalled with Uno• Allows you to upload new sketches via USB• Can also use external programmer to upload sketches via the In-circuit serial
programmer (ICSP) pins• Uno Memory
• 32KB of Flash memory (Sketches stored here)• 2KB of SRAM (variables stored until power cycled)• 1KB of EEPROM (store long term info: calibration constants, serial #, etc.)
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot3 – How a Diode Works
• How a Diode Works• In this lesson you will learn:
• How semiconductors work• How a PN junction works• Uses of diodes
Arduino Obstacle Avoidance Robot
• How a Diode Works• A bit about semiconductors:
• Materials including plastics and rubber are poor conductors of electricity and are called insulators
• Metals such as copper or gold are good conductors of electricity• Semi-conductors are normally poor conductors of electricity but by adding
substances to them, their properties can be altered to make them good conductors
• Silicon and germanium are two common semiconductor elements
Arduino Obstacle Avoidance Robot
• How a Diode Works• How Semiconductors Work:
• Silicon is normally an insulator, but by adding impurities (atoms of another element), called dopants, the properties of the silicon change making it more conductive
Arduino Obstacle Avoidance Robot
• How a Diode Works• How Semiconductors Work:
• Each silicon atom is bonded to its neighbor atom by 4 electrons in its outer shell
Arduino Obstacle Avoidance Robot
• How a Diode Works• How Semiconductors Work:
• Donor impurities• Introduce element whose atoms have
5 electrons (phosphorus) in outer shell
• 4 Phosphorus electrons bond with adj. Si atoms
• 5th electron loosely bound to dopant P atom
• This electron can break free, causing conduction
Arduino Obstacle Avoidance Robot
• How a Diode Works• How Semiconductors Work:
• Donor impurities donate electrons• A material that has donor impurities is called an n-type semiconductor
since the excess electrons in the material have negative charge
Arduino Obstacle Avoidance Robot
• How a Diode Works• How Semiconductors Work:
• Acceptor impurities• Introduce element whose atoms have
3 electrons in outer shell (boron)• Only 3 of 4 Silicon-Boron bonds
occupied• Creates a “hole” or absence of an
electron• Electron from another bond can move
in to complete bond
Arduino Obstacle Avoidance Robot
• How a Diode Works• How Semiconductors Work:
• Acceptor impurities accept electrons to complete their bond• A material that has acceptor impurities is called a p-type semiconductor
since the excess holes in the material have positive charge
Arduino Obstacle Avoidance Robot
• How a Diode Works• PN Junction
• Electrons diffuse from n-type material (excess electrons) to p-type material (excess of holes)
• Holes diffuse from p-type material to n-type material
• Electrons and holes diffuse across junction until equilibrium reached
• A depletion region depleted of mobile holes and electrons is created between n-type and p-type materials by this diffusion
Arduino Obstacle Avoidance Robot
• How a Diode Works• PN Junction
• Without external voltage applied, equilibrium quickly reached, no current flows
• In depletion region, what is left behind is positively charged phosphorus atoms and negatively boron atoms in our example
• Electric field created in depletion region that opposes any further current flow
• Voltage has to be applied in proper direction to overcome this barrier
Arduino Obstacle Avoidance Robot
• How a Diode Works• PN Junction
• If voltage is applied to the junction where p-type material is positive with respect to n-type material, depletion region shrinks, current flows
• Junction is forward biased
Arduino Obstacle Avoidance Robot
• How a Diode Works• PN Junction
• If voltage is applied to the junction where p-type material is negative with respect to n-type material, depletion region increases, no current flows
• Junction is reverse biased
Arduino Obstacle Avoidance Robot
• How a Diode Works
• Diode formed when terminals added to the ends of the P-N junction• Current only flows in one direction, from positive anode to negative cathode• Anode voltage > cathode voltage by 0.7V for conduction in Silicon
Arduino Obstacle Avoidance Robot
• How a Diode Works• Some uses of diodes
• Rectification (AC to DC)• Switching (RF applications)• Voltage regulation (Zener diodes)• LEDs • Photodiodes
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot4 – How a BJT Works
• How a BJT Works• In this lesson you will learn:
• How a Bipolar Junction Transistor (BJT) works
Arduino Obstacle Avoidance Robot
• How a BJT Works• Bipolar Junction Transistor (BJT) composed of
emitter, base, collector regions• BJT is 2 PN junctions back-back• Base region made very thin so electrons do
not recombine with holes in base• Emitter heavily doped so large number of free
electrons available for conduction• Two types: NPN and PNP• Two junctions:
• Collector-Base Junction• Base-Emitter Junction
C
B
E
NPN PNP
E
BC
Arduino Obstacle Avoidance Robot
• How a BJT Works• Cutoff mode: CBJ & BEJ reverse biased, no
current flows. • BJT = open circuit
• Active mode: CBJ is reverse biased, BEJ forward biased
• BEJ forward biased if voltage > 0.6Vdc applied to BEJ
• BEJ depletion region shrinks, electrons flow from emitter to base
• Small fraction of electrons recombine with holes in base or flow to the positive end of supply
Arduino Obstacle Avoidance Robot
• How a BJT Works• Active Mode: CBJ reverse biased, vast majority
of electrons flow through base, swept across CBJ depletion region into collector
• Vc > Vb by several volts to keep CBJ reverse biased
• BJT called a current controlled device because small base current, IB, controls much larger collector current, IC
• Current gain of BJT called beta• β= IC / IB
• BJT = amplifier in active mode
Arduino Obstacle Avoidance Robot
• How a BJT Works• Saturation: IB increases to where a change in
IB causes a very small change in collector current
• β= IC / IB is not true • In saturation, resistance decreases greatly, Ic =
max, Vce is reduced to tenths of a volt• In cutoff mode, resistance between collector
& emitter is very high so IC = 0, Vce about 12Vdc
• BJT = switch when operated cutoff / saturation modes
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot5 – H-Bridge Circuit
• H-Bridge Circuit• In this lesson you will learn:
• How an H-Bridge works• Purpose of a flyback diode
Arduino Obstacle Avoidance Robot
• H-Bridge Circuit• Enables voltage polarity reversal to load• Typical circuit: 2 NPN, 2 PNP• Driver circuit may be needed since digital
I/O pins can only source/sink 40mA. • Q1, Q2 = PNP • Q3, Q4 = NPN • BJTs operated in saturation mode so solid
state switches • NPN (ON): 5V to base• PNP (ON): 0V to base
Arduino Obstacle Avoidance Robot
VDD
M
Q1 Q2
Q3 Q4
E
C
BE
B
C
E
CB
CB
E
• H-Bridge Circuit
Arduino Obstacle Avoidance Robot
VDD
M
Q1 Q2
Q3 Q4
E
C
BE
B
C
E
CB
CB
E
Motor Direction BJT state
Clockwise Q1 = 0V, Q4 = 5V
Counterclockwise Q2 = 0V, Q3 = 5V
Off Q1 = 5V, Q2 = 5VQ3 = 0V, Q4 = 0V
Arduino Obstacle Avoidance Robot
• H-Bridge Circuit
Clockwise Rotation Counterclockwise Rotation
Arduino Obstacle Avoidance Robot
• H-Bridge Circuit• Flyback diode: Motor acts
like an inductor • Inductor stores energy in the
form of a magnetic field, resists change in current flow
• If circuit opened, stored energy needs path to discharge.
• No path: high voltage (back EMF voltage) builds up in opposite direction to current flow across the transistors, can cause damage
• Back EMF voltage given by Lenz’s Law:
- ++ --+
-+
Arduino Obstacle Avoidance Robot
• H-Bridge Circuit• Flyback diode
• Flyback diodes provide low impedance path for stored energy in the inductor, energy dissipated as heat
- +
Arduino Obstacle Avoidance Robot6 – Arduino Motor Shield
• Arduino Motor Shield• In this lesson you will learn:
• How the Arduino motor shield works• Purpose of bypass capacitors
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield
Arduino Obstacle Avoidance Robot
L298P Full Bridge Driver
Motor B
Motor A
Vin
Gnd
Direction Motor A
Direction Motor B PWM Motor A
PWM Motor B
Current SenseMotor A
Current SenseMotor B
Brake Motor A(Pin 9) / Motor B(Pin 8)
**Separate 6V battery pack supplies motor power for our robot
Compatible with TinkerKit modulesMotor Direction
LEDS
• Arduino Motor Shield
Arduino Obstacle Avoidance Robot
Vin Connect(**Cut this trace)Separates motor supply voltage from Arduino Vin pin
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield• Supply voltage: 5 to 12Vdc• Motors powered via Uno Vin pin or from external supply • Can drive 2 DC motors or 1 stepper motor• Can handle 2A per motor channel• Current sensing capability: 1.65V per amp
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield
Motor A Motor B
L298P IC
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield• L298P
In1 In2 EnA Motor Output
High Low High CCW
Low High High CW
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield• Shield Schematic
Arduino Obstacle Avoidance RobotFlyback diodes
Pin 12 – DIR A
Pin 13 – DIR B
6V battery pack
Pin 3 – PWM A
Pin 11 – PWM B
Pin 9 – BRAKEA
Pin 8 – BRAKE B
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield• Motor Shield Logic Table
PWM A DIR A BRAKE A PWM B DIR B BRAKE B Motor A Output
Motor B Output
Robot Direction
128 High Low 128 Low Low CCW CW Forward128 Low Low 128 High Low CW CCW Reverse128 Low Low 128 Low Low CW CW Turn Left
128 High Low 128 High Low CCW CCW Turn Right
Arduino Obstacle Avoidance RobotVin Connect (**Cut this trace)• Separates motor supply voltage from Arduino Vin pin• We are powering the motors from a separate 6 Vdc battery pack. • If we did not cut trace, the 9V battery powering the Uno would also be powering motors.
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield• Motor Current Sensing
Arduino Obstacle Avoidance Robot
• Arduino Motor Shield• Bypass Capacitors
• Can be used to shunt AC noise from surrounding circuit
• Power supply ripple• Logic switching
• The higher the frequency, thesmaller the capacitor required
• Can act as a reservoir preventing voltage dips (electrolytic)
Arduino Obstacle Avoidance Robot7 – DC Motor Construction
• DC Motor Construction• In this lesson you will learn:
• The components of a DC motor
Arduino Obstacle Avoidance Robot
• DC Motor Construction• A DC motor is composed of:
• Frame (Yoke)• Field Poles• Field Windings • Rotor (Armature)• Commutator• Brushes• Motor shaft
Arduino Obstacle Avoidance Robot
• DC Motor Construction• Frame (Yoke) – Provides structural support for
poles• Provides low reluctance path for magnetic flux
to flow between poles• Made of steel or cast iron
Arduino Obstacle Avoidance Robot
Frame
• DC Motor Construction• Field Poles – Each pole generates magnetic
flux when corresponding winding is energized• Composed of pole core & pole shoe• Pole built from thin laminations of steel• Semi-circular pole shoe extends out from pole
core & increases surface area of pole. • Ensures max flux available to interact with
large surface area of rotor as it spins.
Arduino Obstacle Avoidance Robot
Pole CorePole Core
Pole Shoe Pole Shoe
• DC Motor Construction• Field Pole Winding – Wire looped around each
pole core to form a winding using special laminated copper wire
• Field winding produces magnetic flux when energized by an external source
• Small DC motors commonly use permanent magnets instead of coils
Arduino Obstacle Avoidance Robot
Pole WindingPole Winding
North South
Permanent Magnets
• DC Motor Construction• Rotor (Armature) – Cylindrical shaped and
mounted around the motor shaft• Composed of thin laminate discs of steel.• Wedge shaped slots are punched into each
disc forming rotor teeth and slots• Discs combined to form rotor and windings
laid into slots• Rotor windings generate magnetic flux when
energized, easily flows through rotor due to its high permeability
Arduino Obstacle Avoidance Robot
Laminate discs
Rotor Windings
Rotor Tooth
Rotor Slot
• DC Motor Construction• Commutator – Constructed of copper
bars called commutator segments built onto motor shaft
• Each bar insulated from another by insulating material such as mica
• The commutator and brush set allow electrical power to continuously be provided to rotor windings as motor rotates.
Arduino Obstacle Avoidance Robot
Commutator Segment
• DC Motor Construction• Brushes – Typically made of carbon or
graphite• Provides path for current to travel from
external power source to commutator segments as motor rotates
• Brushes are spring-loaded to apply correct pressure to commutator segments
Arduino Obstacle Avoidance Robot
• DC Motor Construction• Motor Shaft – Machined steel cylinder that
rotor & commutator are built around• Shaft rides on ball bearings allowing it to
rotate freely with little friction• One end of shaft connects motor to a
mechanical load
Arduino Obstacle Avoidance Robot
Motor Shaft
Ball bearings
Ball bearings
Arduino Obstacle Avoidance Robot8 – DC Motor Operation
• DC Motor Operation• In this lesson you will learn:
• Basic principles of magnetic fields• The principle of operation of a single loop permanent magnet DC motor
Arduino Obstacle Avoidance Robot
• DC Motor Operation• Magnetic field
• Created when electrical charge carriers move through space or within a material such as a conductor
• Can be represented as a vector field comprised of individual vectors each having magnitude and direction
• Combine vectors to form magnetic lines of force (magnetic flux SI unit: weber (Wb))
Arduino Obstacle Avoidance Robot
By Geek3 - Own workThis vector graphics image was created with VectorFieldPlot., CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=10587119
S N
• DC Motor Operation• Magnetic field
• Magnetic field intensity, H • Indicates how much effort a current is
putting into establishing field• SI unit: ampere-turns per meter
• Magnetic Flux density, B• B = µH
• µ is magnetic permeability of material
• SI unit: Wb / m2 or tesla (T)
Arduino Obstacle Avoidance Robot
BA
By BillC at the English language Wikipedia, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=27407689
V = IRℱ = NIℱ = ΦR
φ = BA for case when B normal to A
• DC Motor Operation• Magnetic field
• Induced force on a wire• B field induces a force on a current
carrying wire within the field• F=i(lxB), rewrite as F = ilBsinθ
• i = current in wire• l = length of wire • B = Magnetic flux density
Arduino Obstacle Avoidance Robot
• DC Motor Operation• Units
• Force – SI unit: newton (N)• Torque – SI unit: newton-metre (N m) / Imperial unit: pound-foot (lb ft)∙ ∙
Arduino Obstacle Avoidance Robot
• DC Motor Operation• Figure shows a simple single loop DC motor
connected to a battery via a set of brushes & 2 commutator segments
• B field exists between the north and south field poles
• Current flows from positive terminal of battery through motor current loop and returns to negative terminal of battery
• We use the equation: Force = i*(l x B) to determine the direction of force on a side of the loop
• i : current• l: length of wire segment• B: Magnetic flux
Arduino Obstacle Avoidance Robot
i N S
+ -
i
B
a
bc
d
• DC Motor Operation• F = ilBsinθ
• i = current in segment• l = length of segment • B = Magnetic flux density
• Determining Force Direction• (1) Fingers point in direction of current, i• (2) Curl fingers into direction of magnetic
flux density, B• (3) Thumb points in direction of force, F
Arduino Obstacle Avoidance Robot
x *
BF,ab
F,cdSide View
N S
i N S
+ -
B
F,cd
F,ab
a
bc
d
ω
r
i
• DC Motor Operation• No rotation without commutation
Arduino Obstacle Avoidance Robot
i N S
- +
BF,ab
F,cdd
cb
a
ω
t = 180°
ii N S
B
F,cd
F,ab
a
bc
d
ω
t = 0°
i
+ -
x *
BF,ab
F,cd
N S
r
* X
B
F,cd
F,ab
N S
r
• DC Motor Operation• At t = 0°, using F = ilBsinθ• θ = angle between r & F• r = radius from axis of rotation to edge of loop• Fab = ilB upward• Fcd = ilB downward• Fbc & Fda = 0 since l is parallel to B
Arduino Obstacle Avoidance Robot
x *
BF,ab
F,cdSide View
N S
i N S
+ -
B
F,cd
F,ab
a
bc
d
ω
t = 0°
r
i
• DC Motor Operation• Induced voltage also generated on each loop
segment as it rotates• Brushes short commutator segments at point
where the loop has rotated into the gap between the poles to minimize arcing
• Commutation is the process of switching electrical connections to rotor loop to maintain constant dc output voltage (generator) or constant induced torque (motor)
Arduino Obstacle Avoidance Robot
B
Side View
N S
N S
+ -
B
d
c
b
a
t = 90°
ω
• DC Motor Operation• DC Motor Operation
• At t = 180°, F = ilBsinθ• Fab = ilB downward• Fcd = ilB upward• Fbc & Fda = 0 since l is parallel to B, where
sin(0°) = 0• τ = rFsinθ• τab = rilB• τbc = 0• τcd = rilB• τda = 0;• Net torque on loop =>
τ = 2rilB under the pole faces
Arduino Obstacle Avoidance Robot
x *
B
F,cd
F,abSide View
N S
iN S
+ -
i
BF,cd
F,abd
cb
a
t = 180°
ω
• DC Motor Operation• DF Robot miniQ DC motor specs:
• 13000 rpm @ No load• 50:1 Gear ratio• 260 rpm geared down @ 6V• 30mA no load current @ 6V• 350mA stall current @ 6V• 0.39kg-cm @ 6V
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot9 – DC Motor Speed Control
• DC Motor Speed Control • In this lesson you will learn:
• How pulse width modulation (PWM) works• How the analogWrite() function works
Arduino Obstacle Avoidance Robot
• DC Motor Speed Control • Pulse Width Modulation (PWM) - Simulates analog control digitally• Digital I/O pins pulsed on/off• The duration of time the I/O pin is high in one period is called the pulse width• Vary pulse width, can control “average” voltage level from a digital I/O pin
Arduino Obstacle Avoidance Robot
• DC Motor Speed Control • Pulse Width Modulation (PWM) - Period is
inverse of frequency of a signal• 1000 Hz = 1ms period• Pulse width: zero to full period• If pulse width = 0.5 ms, then duty cycle is
50%• Duty cycle is percentage of time square
wave high in one period• Digital pin with 5V amplitude with a duty
cycle of 50 % appears as 2.5V
Arduino Obstacle Avoidance Robot
25% Duty Cycle
50% Duty Cycle
75% Duty Cycle
1 period
t
t
t
V
V
V
• DC Motor Speed Control • Pulse Width Modulation (PWM)
• On the Arduino Uno, pins 3, 5, 6, 9, 10, 11 have PWM capability• Pins 3, 9, 10, 11 operate at a PWM frequency of 490 Hz• Pins 5, 6 operate at a PWM frequency of 980 Hz
Arduino Obstacle Avoidance Robot
• DC Motor Speed Control • analogWrite(pin, value)
• Writes an analog value to a pin using PWM• Parameters:• pin – number of digital pin• value – digital count value between 0 and 255
• 0 = always off• 255 = always on
Arduino Obstacle Avoidance Robot
• DC Motor Speed Control • PWM Resolution
• analogWrite() uses a timer circuit built into ATmega 328 microcontroller on Uno board
• Timer is 8 bits• In binary math, a value can either be 0 or 1, so values can range from
00000000b to 11111111b providing (28) 256 possible PWM values• 256 voltage steps between 0 and 5Vdc• Single step rounded is 0.0195 or 19.5mVdc
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot10 – Drive System Build
Arduino Obstacle Avoidance Robot11 – Drive System Sketch / Experiment
Arduino Obstacle Avoidance Robot12 – How Servos Work
• How Servos Work• In this lesson you will learn:
• Servo components and operation• Servo control• Types of servos • Servo applications• Arduino Servo Library functions
Arduino Obstacle Avoidance Robot
• How Servos Work• Components:
• DC motor• Set of reduction gears• Potentiometer• Control circuitry
• Operation• Input command sent to servo• Commanded angle vs. feedback angle• Input angle – feedback angle = Error signal• Servo control circuit applies power to
motor until error signal is zero
Arduino Obstacle Avoidance Robot
• How Servos Work• Control signal generated by an external
hardware circuit or microcontroller (Uno)• Command output shaft to rotate 90-180°• 3 wires:
• Red = Power• Black = Ground• White = Command signal
Arduino Obstacle Avoidance Robot
• How Servos Work• Control signal is typically 5V square wave
pulse• Control pulse duration determines how many
degrees of servo shaft rotation• Pulse period = 20ms• Pulse duration = 1 to 2ms
• 1 ms = -90 degrees• 1.5 ms (neutral) = 0 degrees• 2 ms = 90 degrees
t
V
20 ms
2 ms = 90°
t
V1.5 ms = 0°
t
20 ms
1ms = -90°
20 msV
Arduino Obstacle Avoidance Robot
• How Servos Work• Control pulse must be applied at least every
20ms for servo to hold position when load applied
• Control pulse range may differ slightly between any 2 servos.
t
V
20 ms
2 ms = 90°
t
V1.5 ms = 0°
t
20 ms
1ms = -90°
20 msV
Arduino Obstacle Avoidance Robot
• How Servos Work• Tower Pro SG90 Micro Servo
• Weighs just 9 grams• Servo Stall Torque Rating
• Maximum torque servo can apply to load• SG90 rating: 1.8kgf-cm
• Servo Stall Current Rating• Maximum current servo can apply to load
• Servo Operating Speed• Maximum rate servo shaft can turn• SG90 servo rating: - 0.1 sec / 60° at no load
• Servo Dead Bandwidth• Minimum pulse width required for servo
response• SG90 dead-bandwidth: - 10µs• Stops servo “dancing” at a set point
Arduino Obstacle Avoidance Robot
• How Servos Work• Servo Sizes
• Nano (stall torque = 11 oz-in / 0.07 kgf-cm)
• Giant scale (stall torque = 343 oz-in / 24.7 kgf-cm) for Hitech brand models
• Nano servos (ex: HS-35HD) used for fine motor movements in robotics
• Giant servos (ex: HS-815BB) used to control sail on RC boat
Arduino Obstacle Avoidance Robot
• How Servos Work• Positional Rotation Servo
• Stepwise rotation of 180 degrees• Control signal sets angle & direction
• Continuous Rotation Servo• Allows continuous rotation in CW / CCW
direction• Control signal sets direction and speed of
rotation
Arduino Obstacle Avoidance Robot
• How Servos Work• Servo Gears• Nylon
• Gears strip if overloaded• Lightweight• Inexpensive
• Karbonite• Stronger, more wear resistant than nylon
gears• Metal
• High strength / expensive• Heavier than nylon & Karbonite• Gears wear faster than Nylon & Karbonite
causing servo slop
Arduino Obstacle Avoidance Robot
• How Servos Work• Servo Horns
• Fit onto output shaft of servo• Servos come with an assortment of horns
HS-311 Servo Horns
Arduino Obstacle Avoidance Robot
• How Servos Work• Analog Servo
• Control board electronics are analog• Motor receives a pulse 50 times per second (every 20 ms)• Infrequent pulses reduce motor torque / ability to respond quickly• Inexpensive
• Digital Servo• Microcontroller based control board but still has same gear train / feedback
mechanism (pot) as analog servo• Motor receives a pulse 300 times per second (every 3 ms)• Pulse length decreased but greater torque / quicker response since pulses applied
more frequently• Consumes more power• More expensive
Arduino Obstacle Avoidance Robot
• How Servos Work• Servo Applications
• RC controlled vehicles• Robot joints /grippers• Conveyor belts• Camera auto focus• Robot vehicles• Solar tracking system• Antenna positioning system• CNC machine• Automatic door opener• Printers
Arduino Obstacle Avoidance Robot
• How Servos Work• Arduino Servo Library
• Supports up to 12 servos on most Arduino boards / 48 on Arduino Mega• Using library disables PWM functionality on pins 9 & 10, regardless of
whether there is servo on pins• The following Servo Library functions will be used:
• attach()• write()
Arduino Obstacle Avoidance Robot
• How Servos Work• attach(pin)
• Servo library function that attaches servo variable to pin• Parameters:
• pin – number of pin that servo is attached
Arduino Obstacle Avoidance Robot
• How Servos Work• write(angle)
• Servo library function sets angle of servo shaft • 0 to 180 degrees
• Parameters• angle – value to write to servo from 0 to 180 degrees
Arduino Obstacle Avoidance Robot
• How Servos Work• #include <Servo.h>
• Preprocessor directive required to use Servo Library• Servo myservo1;
• Create Servo object for each servo• void setup()
• myservo1.attach(2);• Attach digital pin 2 to myservo1 object
• void loop()• myservo1.write(90);
• Sets servo angular position according to scaled value
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot13 – Servo Sketch / Experiment
Arduino Obstacle Avoidance Robot
Tower SG-90 Servo cable
Swap power and signal wires. The picture shows the end state for the cable(Flip the plug over before inserting into motor shield so the power wire is closest to the Digital I/O header)
Arduino Obstacle Avoidance Robot14 – LED & Photodiode Overview
• LED & Photodiode Overview• In this lesson you will learn:
• How an LED works• How a Photodiode works
Arduino Obstacle Avoidance Robot
• LED & Photodiode Overview• LED stands for Light Emitting Diode
• Positive lead = Anode / Negative lead = Cathode
Arduino Made Easy
• LED & Photodiode Overview• Forward bias operation• Electrons flow from n-type to p-type
material • Some electrons fill holes or
“recombine” with holes in p-type material
• Electrons that recombine with holes move from the conduction band to the valence band
• Electron loses energy in the form of a photon of light
Arduino Made Easy
By S-kei, CC BY-SA 2.5, https://commons.wikimedia.org/wiki/File:PnJunction-LED-E.svg
• LED & Photodiode Overview• In materials such as silicon and germanium, recombination results in non-
radiative transitions where vibrational energy increases but no light is given off• LEDs are manufactured with semiconductor materials with characteristics so
that photons are emitted when recombination occurs
Arduino Made Easy
Color Wavelength Semiconductor Material
Infrared > 760 nm Gallium Arsenide (GaAs)
Red 610 to 760 nm Gallium Arsenide Phosphide (GaAsP)
Violet 400 to 450 nm Indium Gallium Nitride (InGaN)
• LED & Photodiode Overview• LED Parameters
• Forward voltage, VF, specified at a certain forward current, IF. • Irradiance (Ee) – average power density incident onto a surface of diameter,
D, and at a distance, d. Measured in mW/cm2. Value specified at a set forward current, IF.
Arduino Obstacle Avoidance Robot
• LED & Photodiode Overview• Photodiode
• Converts incident light into photocurrent• Can operate in 2 modes:
• Photovoltaic (solar cells)• Photoconductive
• Photoconductive mode• Diode is reverse biased• Light of sufficient energy strikes
depletion region, creates electron-hole pairs
• Electrons swept into N region while holes swept into P region generating photo current
Arduino Obstacle Avoidance Robot
• LED & Photodiode Overview• Photodiode
• In photoconductive mode, operate under reverse bias to increase size of depletion region which is photosensitive
• The photocurrent varies almost linearly with incident light flux and is almost independent of applied reverse biased voltage
• Silicon photodiodes are sensitive to light from 400nm (near UV) to about 1100nm (near infrared)
Arduino Obstacle Avoidance Robot
• LED & Photodiode Overview• Photodiode
• Performance Parameters• Quantum Efficiency – Number of electron-hole pairs collected per
second to the number of incident photons per second (%)• Responsivity – Ratio of generated photocurrent to incident light (A/W)• Bandwidth – Defines range of operating frequencies of the device,
determined by rise and fall time of device (Hz)
Arduino Obstacle Avoidance Robot
• LED & Photodiode Overview• PIN Photodiode
• P / N regions highly doped• Add undoped or intrinsic region to
device• Device still reverse biased for
photoconductive mode• Larger depletion region formed
enhancing ability of device to absorb light
• Enables quicker device response when used as a photodetector
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot15 – Infrared Sensor Introduction
• Infrared Sensor Introduction• In this lesson you will learn:
• What wavelengths define the Infrared region • Two methods of using infrared (IR) sensors• Applications of IR sensors
Arduino Obstacle Avoidance Robot
• Infrared Sensor Introduction• Infrared region of electromagnetic spectrum spans from about 0.75μm to
1000μm
• Infrared sensors typically consist of photo-emitter such as an IR LED and photodetector circuit
Arduino Obstacle Avoidance Robot
Band Wavelength
Near-Infrared 0.78–3 µm
Mid-Infrared 3–50 µm
Far-Infrared 50–1000 µm
• Infrared Sensor Introduction• Two methods for using the IR sensor:
• Direct Incidence• The IR LED placed across from
photodetector• Lenses pointed directly at each
other• Photodetector receives full
emitted IR radiation from IR LED
Arduino Obstacle Avoidance Robot
IR LED IR Photodetector
• Infrared Sensor Introduction• Indirect Incidence
• IR LED / photodetector placed next to one another
• IR LED points into space so IR radiation does not hit photodetector
• Photodetector also points into space
• IR LED shines on a reflective surface and portion of light beam reflected onto photodetector
• Photodetector may use optical shielding to block unwanted portions of light spectrum
Arduino Obstacle Avoidance Robot
IR LED
IR Photodetector
• Infrared Sensor Introduction• Direct Incidence Application
• Intruder alarm• IR LED fitted into door frame
and IR photodetector fitted into door
• IR light beam interrupted, alarm is triggered
Arduino Obstacle Avoidance Robot
• Infrared Sensor Introduction• Indirect Incidence Application
• Line follower robot• IR LED shines onto black line or
white surface• Photodetector receives
reflected IR light• Black line reflects little light
compared to white surface• Algorithm written to control
robot based on this concept
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot16 – Sharp IR Sensor Overview
• Sharp IR Sensor Overview• In this lesson you will learn:
• Sharp GP2Y0A21YK0F Distance Measuring Sensor Unit Components• How a position sensing detector (PSD works)• How PSD sensor triangulation works• Measuring considerations for the Sharp IR sensor
Arduino Obstacle Avoidance Robot
• Sharp IR Sensor Overview• Sharp GP2Y0A21YK0F Distance
Measuring Sensor Unit• Composed of:
• Position Sensitive Detector (PSD) • Infrared Light Emitting Diode• Signal Processing Circuit
• Sensor uses triangulation method to calculate distance to object, outputs voltage proportional to distance
Arduino Obstacle Avoidance Robot
• Sharp IR Sensor Overview• Parameters
• Range: 10 to 80 cm (3.9 in to 31.5 in)• Input voltage range: 4.5 to 5.5 Vdc
Arduino Obstacle Avoidance Robot
• Sharp IR Sensor Overview• Sharp GP2Y0A21YK0F Distance Measuring Sensor Unit
• Pinout
Arduino Obstacle Avoidance Robot
5VGNDSignal Out
• Sharp IR Sensor Overview
Arduino Obstacle Avoidance Robot
Output Voltage vs. Distance
• Sharp IR Sensor Overview• Position Sensing Detector (PSD)
• P-type layer doped to provide uniform resistivity
• EH pairs generated in P-type layer creating photocurrent
• Current at each electrode is inversely proportional to distance from incident light beam
• Spot in center – equal current from each electrode
• Spot shifted – Current from each electrode differs
Arduino Obstacle Avoidance Robot
• Sharp IR Sensor Overview• Position Sensing Detector (PSD)
• Single-axis type – tracks light beam from left to right
• Spot location determined by using equation: X = [(Ix2-Ix1 / Ix2+Ix1)] / (Lx/2)
• Lx = distance between electrodes on P-type resistive layer
• X = location of centroid (weighted center) of beam spot
• Benefits: high resolution, highly linear
• Drawbacks: Cannot distinguish if multiple reflections present on surface
Arduino Obstacle Avoidance Robot
• Sharp IR Sensor Overview• Position Sensing Detector (PSD)
• PSD Output Circuit
Arduino Obstacle Avoidance Robot
Example Circuit from On-Trak Photonics, Inc.
• Sharp IR Sensor Overview• Triangulation Distance Measurement
• Using similar triangles concept• D = distance from IR LED lens to
object• E = distance from IR LED to PSD
lens• F = distance from PSD lens to
sensor• X = distance from PSD center to
incident light location
Arduino Obstacle Avoidance Robot
Object
D
E
PSD
LED
FX
D/E = F/XD = E*F/X
• Sharp IR Sensor Overview• Measurement Considerations
• Avoid operating sensor where exposed to direct sunlight or bright light source such as a tungsten lamp
• Insert a bypass capacitor of 10µF or more between Vcc and GND near the unit
• Avoid operating sensor outside where lenses exposed to dust, water, or oils
Arduino Obstacle Avoidance Robot
• Sharp IR Sensor Overview
Arduino Obstacle Avoidance Robot
Sharp Sensor Timing Diagram
Arduino Obstacle Avoidance Robot17 – IR Sensor Assembly
Arduino Obstacle Avoidance Robot
Micro-JST Male to Standard Male servo cable / 8” length (28 AWG Light)
Swap power and signal wires. The picture shows the end state for the cable
Arduino Obstacle Avoidance Robot18 – IR Sensor Sketch / Experiment
Arduino Obstacle Avoidance Robot19 – Ultrasonic Range Finder Introduction
• Ultrasonic Range Finder Introduction• In this lesson you will learn:
• What sound is and how sound pressure is detected• What frequencies comprise the ultrasonic frequency range• Components of an ultrasonic range finder• How a piezoelectric transducer works• Overview of ultrasonic sensor electronics • Applications of ultrasonic range finders
Arduino Obstacle Avoidance Robot
• Ultrasonic Range Finder Introduction• Sound = mechanical wave resulting from back
& forth motion of particles of medium through which sound wave is moving
• Sound propagates as a longitudinal wave in a fluid such as air
• Particles in longitudinal wave oscillate back & forth in a direction parallel to direction the wave is moving
• Particles always return to their original position, only energy transferred
Arduino Obstacle Avoidance Robot
• Ultrasonic Range Finder Introduction• Vibrating source creates regions in medium
where particles are squeezed (compressions) & regions where particles spread apart (rarefactions)
• Compression regions • High pressure areas
• Rarefaction regions• Low pressure areas
• Detector such as microphone detects fluctuations in air pressure
• Fluctuations converted into electrical signals & processed
Arduino Obstacle Avoidance Robot
Compressions
Rarefactions
• Ultrasonic Range Finder Introduction• Human ear frequency sensitivity: 20 Hz to 20 KHz • Ultrasonic refers to frequencies greater than audible range, can extend into
GHz • Bats, certain marine mammals communicate & navigate using ultrasonic
frequencies from 20KHz to 100 KHz • Medical ultrasound diagnostic equipment used for imaging operates from
about 2-15 MHz
Arduino Obstacle Avoidance Robot
• Ultrasonic Range Finder Introduction• Ultrasonic Sensor
• Composed of:• Ultrasonic transducers• Processing electronics
• Series of pulses sent from sensor. If object within the sensor’s range is in front of the sensor, fraction of the pulse will echo back from object to sensor
• Echo converted to electrical signal and processed by sensor electronics
• Sensor outputs electrical signal with pulse width that is directly proportional to distance to object
Arduino Obstacle Avoidance Robot
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
• Common technologies include:• Magnetostrictive• Piezoelectric
Arduino Obstacle Avoidance Robot
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
• Piezoelectric• Utilizes piezoelectric effect whereby positive & negative charges in a
crystalline material accumulate on electrodes on opposite sides of material in response to applied mechanical stress (stretching or compressing)
Arduino Obstacle Avoidance Robot
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
• Electric dipole created when piezoelectric material is deformed
Arduino Obstacle Avoidance Robot
-
+
+
-
+
-
Silicon +
Oxygen -
-
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+Compression
Tension
Quartz
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
• Voltage polarity measured depends on how material was manufactured
• Tension produces a negative voltage when measured as shown
• Compression produces a positive voltage when measured as shown
• Alternating compression and tension generates an alternating voltage
Arduino Obstacle Avoidance Robot
Compression
-V
Tension
+V---
+++
+++
---
Alternating Compression / Tension
VAC
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
Inverse Piezoelectric effect• Applied electric field creates mechanical
stress distorting original shape of material• Application of -V causes material to
elongate in horizontal direction• Application of a +V causes material to
compress in horizontal direction• Application of ACV causes material to
oscillate at applied frequency
Arduino Obstacle Avoidance Robot
- + + -
Vs Vs
Negative Voltage Applied Positive Voltage Applied
Vs
Alternating Voltage Applied
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
• Common piezoelectric ceramics include:• Barium Titanate • Lead Titanate• Lead-Zirconate-Titanate (PZT)
Arduino Obstacle Avoidance Robot
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
• Consists of piezoelectric element that converts applied electrical signal into mechanical vibration oscillating at a particular frequency
• Same element or second element in parallel receives reflected pulse & deforms, generating electrical signal read by sensor electronics
Arduino Obstacle Avoidance Robot
Wear Plate
Electrodes Backing Material
Epoxy Potting
Case
Piezoelectric Element
• Ultrasonic Range Finder Introduction• Ultrasonic Transducer
• Epoxy minimizes vibration, holds components in place
• Backing material used for support & to attenuate acoustic signal radiating into back of transducer
• Wear plate or protective cover protects piezoelectric element
• Device is constructed to maximize resonance at particular frequency & to minimize acoustic mismatch
Arduino Obstacle Avoidance Robot
Wear Plate
Electrodes Backing Material
Epoxy Potting
Case
Piezoelectric Element
• Ultrasonic Range Finder Introduction• Ultrasonic Sensor
• 2 configurations:• Single transducer – generates a pulse
& receives echo• 2 transducers – placed next each
other, one generates pulse, second transducer receives echo
Arduino Obstacle Avoidance Robot
Parallax PING
Maxbotix XL MaxSonar EZ‑ ‑
• Ultrasonic Range Finder Introduction• Ultrasonic Sensor Electronics
Arduino Obstacle Avoidance Robot
Amplification / Bandpass Filtering
Stages
Peak Detector / Comparator
Pulse Generator Logic Circuit (40 KHz)
Ultrasonic transmitter
Ultrasonic Receiver
Controller Circuit / Microcontroller Counter Circuit
• Ultrasonic Range Finder Introduction• Applications of ultrasonic sensors:
• Diagnostic medical imaging• Automotive parking assist systems• Robot navigation• Proximity sensing• Fluid level measurement• Bulk material level measurement• Ultrasonic cleaning systems• Flaw detection in materials• Humidifiers
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot20 – Parallax PING Sensor Overview
• Parallax PING Sensor Overview• In this lesson you will learn:
• How the Parallax PING sensor works• PING sensor considerations and limitations• How the Arduino pulseIn() function works
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• Pinout
• SIG pin acts as input receiving trigger from Uno digital pin• SIG pin acts as output sending pulse to Uno digital pin
Arduino Obstacle Avoidance Robot
GND SIG5V
• Parallax PING Sensor Overview• PING Sensor Parameters
• Range: 2cm to 3m (0.79 in to 118 in)• Max angle between sensor face & object: 45°• Input Voltage = 5Vdc
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• Parallax PING sensor sends out 40 KHz burst in response to positive 5Vdc
trigger pulse generated by Uno
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• Timing Diagram
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• Echoed ultrasonic pulse has both a minimum and maximum duration:
• Echo Return Pulse Minimum (tIN-MIN) = 115 μs• Echo Return Pulse Maximum (tIN-MAX) = 18.5 ms
• The min and max durations correspond to the min (1.96 cm) and max (3.15 m) range of Ping sensor
• Uno must insert a 200 μs delay before sending next trigger pulse to initiate another distance measurement
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• PING Sensor Limitations:
• The sensor cannot accurately measure distance to an object if:• Object > 3 meters • Too shallow of angle• Object is too small• Object surface is not reflective
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• Assumptions:
• It is assumed that you are in an indoor environment, 20°C (68°F) • The speed of sound in air is influenced by temperature and altitude • Speed of sound in air at sea level @ 20°C = 343.2 m/s (1126 ft/s)• Use following equation to calculate speed of sound for different
temperatures:• Cair (m/s) = 331.3 + (0.6*TC)
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• PING Sensor Beam Patterns
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• pulseIn(pin, value, timeout)
• Reads pulse (can be high or low) on digital pin, returns pulse duration in µs• Returns zero if no pulse returned within time period specified by ‘timeout’• Works for pulses between 10 µs to 3 min in length• Parameters:
• pin – digital pin on which pulse is to be read• value – type of pulse to be read, high or low
• Start counting when pulse goes high, stop when low• Start counting when pulse goes low, stop when high
• Timeout (if specified) – number of µs to wait for pulse to start, default: 1 sec
Arduino Obstacle Avoidance Robot
• Parallax PING Sensor Overview• echo_duration = pulseIn(trigger_pin, HIGH);
• Measure duration while PING SIG pulse is high• Calculating distance in centimeters:
• Speed of sound in air at sea level @ 20°C = 343.20 meters per second• 343.20 m/s => 34320 cm/s
• 29 µs to travel 1 cm• echo_duration / 29 => distance to object and back to sensor in cm• distance = echo_duration / 29 / 2 gives us the distance to the object
Arduino Obstacle Avoidance Robot
Arduino Obstacle Avoidance Robot21 – PING Sensor Assembly
Arduino Obstacle Avoidance Robot
Male to Male Servo Extension Lead / 20 cm length
Swap power and signal wires. The picture shows the end state for the cable
Arduino Obstacle Avoidance Robot
Receive my full course for 75% off by signing up below:
https://www.udemy.com/arduino-obstacle-avoidance-robot/?couponCode=OAR_SKILLSHARE
All sketches and build videos are included.