Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

yteCake

w w w. b y t e c a ke . c om

Arduino Robotics Workshop


IISER PUNE
5th October 2019
Digital Inputs

Now we’ll be accepting


inputs into our Arduinos.

The two ends of this


button are connected
when the button is pushed
down.
Digital Input Code

The important
The important
function!
function!
Pushbutton’s Potential Piffling Problem: Debouncing

The important
The important
function!
function!
A More Advanced Input – the Distance Sensor
Most common distance
sensors work through
ultrasound.

By The
measuring
important the time it
The important
function!
takes for sound reflected
function!

from an object to come


back to the sensor, we can
calculate how far away it
must be.
Distance Sensor Caveats

The important
The important
function!
function!
Distance Sensor Method

The important
The important
function!
function!

1. Get ready, I’m about to


send the wave. I’ll wait 2
microseconds to reset you.
LOW
Distance Sensor Method

The important
The important
function!
function!

2. Send out the wave! I’ll


wait 10 microseconds for
this to complete.
HIGH
Distance Sensor Method

…just
Thetell me when you get
important
3. I’ve now set this LOW, to it The
back on this pin…
important
function!
make it clear that I’m now function!

only waiting...
LOW

LOW
Distance Sensor Method

4. OK, got it! I had to wait a


The important
whole
The 15 microseconds in total,
important
function!
both for the wave to reach the
function!
object, and for it to come back.

HIGH
Distance Sensor Method

(constant speedThe important


of sound in air) function!
distance = speed × time / 2
So, we simply use: (centimeters) (centimeters/ (microseconds)
microsecond)
(Remember, here the
≈ 340 m/s time includes outbound
≈ 0.034 cm/μs and inbound time)
Basic Implementation for Distance Sensor
Exercise: Given a new
function, delayMicroseconds,
write the code for triggering
the distance sensor, without
writing anything for
measuring the duration of the
pulse for now – we’ll get to it
in the solution.

Think about it, however: how would you


wait for any arbitrary amount of time for
the echo pin to turn HIGH?
Solution
Viewing The Results

You might also like