Uploaded by Ojas Suras [Student]

Arduino Sensors

advertisement
Arduino 7 - Sensors
Mr. McBrien
TEJ2O
Yesterday

Motors
Today

Sensors

Measuring distance
Sensors

There are MANY different kinds:
 Fire
 Heat
 Water
 Light
 MORE!

Sensors convert a situation into an electrical signal
It’s our job to write code that interprets the
electrical signal.
What makes a good sensor?

Cheap, lightweight, tough, waterproof, etc.

A good sensor is sensitive to a given physical input

To be useful, it has to be insensitive to other physical
inputs. (specific)
What happens if a sensor only works in low humidity?
Coping with Imperfect Sensors

What do you do when a sensor isn’t perfect?

Ans_1: enhance your design

Ans_2: use cases!

Ans_3: make lemonade.
If your oxygen sensor only works when it’s level,
maybe it’d make a better tilt sensor for a robot.
A Bit about Sound

Sound waves are a simple vibration in air

Solid objects reflect these waves – echoes

Generating sound and then detecting the reflection is
called “echolocation”.

Echolocation has been used by many different systems
Ultrasonic Distance

Sound travels at 340 m/s in air.

The time taken for a pulse to return to the detector can
give us the distance.
Activity 1 – Output Distance to
Serial Monitor

Wire the ultrasonic detector to the breadboard.

Connect to the Arduino.

Review the reference code

Output the distance, in cm, to the serial monitor.

Use a ruler to check the accuracy of the detection.
Include this report with your submitted code.
Activity 2 – Decisions Based on Distance

Add LEDs to your ultrasonic breadboard.

Light 1 LED when the object gets within 1 m.

Light 2 LEDs when the object gets within 20 cm.
Sensors and “Noise”
Key Pitfall!

Remember the specificity requirement?

All sensors give output NOT associated with the
target stimulus.

Random: “high frequency noise”

Systematic: “low frequency noise” - baseline
The ultrasonic detector is prone to random
spikes in distance.
Eliminating High Frequency Noise
P4 Need!

High frequency noise is often mathematically removed.

We can also remove the noise logically – is your backing up
car likely to move 2 meters in 0.01 seconds?

Signal averaging and spike rejection are two ways to
exclude unlikely data points from your decision-making
process.
After your device is ready for testing, you can
design an algorithm to remove HF noise.
Key Points

Like with most sensors, ultrasonic distance detection is
based on a mathematical operation on the electrical output
from the device.

Distance is particularly important to robotics.

Noise is a common problem with sensors, but can be
addressed in software.
Homework

Refine your code.

Don’t forget comments!
References

http://www.instructables.com/id/SimpleArduino-and-HC-SR04-Example/
Download