Transcript Sensors
Sensors
Material taken from Robotics with the
Boe-Bot
Where Are We Going?
Sumo-Bot competitions
Devices that Contain Sensors
The boebot uses sensors to interact with its
environment.
There are a variety of sensors used for a variety
of purposes: smoke, sound, rotation/tilt,
vibration, orientation, temperature,
humidity, pressure, proximity, distance,
light, and so on.
Ultrasonic Distance Sensor
PING Ultrasonic Range Finder
Parallax Tutorial
•PING ultrasonic distance sensor provides precise distance measurements
from about 2 cm (0.8 inches) to 3 meters (3.3 yards).
•It works by transmitting an ultrasonic burst and providing an output
pulse that corresponds to the time required for the burst echo to return to
the sensor.
•By measuring the echo pulse width the distance to target can easily be
calculated.
Theory of Operation
The PING sensor emits a short
ultrasonic burst and then "listens"
for the echo.
Under control of a host
microcontroller (trigger pulse), the
sensor emits a short 40 kHz
(ultrasonic) burst.
This burst travels through the air
at about 1130 feet per second,
hits an object and then bounces
back to the sensor.
The PING sensor provides an
output pulse to the host that will
terminate when the echo is
detected, hence the width of this
pulse corresponds to the distance
to the target.
Limited Detection Range
Simple to Connect
http://learn.parallax.com/
Programs
Code---Without Library Support
With the NewPing library
#include <NewPing.h>
int PingPin = 9;
int maxDistance = 5 * 12 * 2.54;
// max sonar range in cm
NewPing sonar(PingPin, PingPin, maxDistance);;
void setup() {
Serial.begin(9600);
}
void loop() {
delay(50);
int location = sonar.ping_in();
Serial.print("Ping: ");
Serial.print(location);
Serial.println(” in");
}
QTI Line Sensor
How it Works
The QTI is a reflective object sensor.
There’s an infrared LED behind its clear
window and an infrared phototransistor
behind its black window.
When the infrared light emitted by the
LED reflects off a surface and returns to
the black window, it strikes the infrared
phototransistor’s base, causing it to
conduct current.
The more infrared incident on the
phototransistor’s base, the more current
it conducts.
Like an RC Circuit
http://learn.parallax.com/
Code for Testing QTIs
int LeftQTI = 8;
int RightQTI = 2;
void setup() {
Serial.begin(9600);
}
void loop() {
long tLeft = rcTime(LeftQTI);
long tRight = rcTime(RightQTI);
Serial.print("tLeft = "); Serial.print(tLeft); Serial.println(" us");
Serial.print("tRight = "); Serial.print(tRight); Serial.println(" us");
delay(1000);
}
long rcTime(int pin) {
// ..returns decay time
pinMode(pin, OUTPUT);
// Charge capacitor
digitalWrite(pin, HIGH);
// ..by setting pin ouput-high
delay(1);
// ..for 5 ms
pinMode(pin, INPUT);
// Set pin to input
digitalWrite(pin, LOW);
// ..with no pullup
long time = micros();
// Mark the time
while(digitalRead(pin));
// Wait for voltage < threshold
time = micros() - time;
// Calculate decay time
return time;
// Return decay time
}
Code for Detecting Reflection
Customizing the code:
Assign names to the pins
Use multiple QTI sensors
More?
Simple Connections
http://learn.parallax.com/
Mount the QTI sensor close to the
ground