We'll be using the QTR-3RC from pololu to create a line following robot.
In this lesson we will be looking at the reference document to figure out how it this sensor works, and then you will be building a rudimentary line following robot
Take a look at the specifications on the product page
These are the most useful bits of information to pay attention to when mounting your sensor
There is a nice in depth description of how each individual sensor works here on the product page for a single sensor.
The gist of it is that it works like this:
1. A capacitor is attached to ground through a phototransistor- a device which lets current flow when it receives light.
Your code will need some way to record the data your sensor is reading.
For this you should use an array, otherwise you'll need to give each sensor it's own variable.
(using arrays will make your code much simpler in the coming lessons)
For help using arrays, check out these exercises Introduction to Arrays .
Now is a good time to reread the information step images which explain how the reflectance sensor physically works.
Next you should look at the sensor instructions. There are four steps to take a sensor reading, and your function should perform them for each sensor
Additional hints are available in the following steps
Part of reading a sensor value is timing how long it takes for the capacitor to discharge.
Imagine using a stop watch to time this.
What we are looking for then is a way to measure elapsed time of the capacitor discharging.
Imagine looking at a clock on your wall.
How would you use this to record the length of an event, say, getting ready for school?
If you woke up at 7am and were ready at 7:45am, what formula would you use to calculate how long it took you to get ready?
Using this formula:
startTime we can calculate
Create two variables:
These should be of type unsigned long
The current time can be found using the built-in function
micros() which tells us how long the program has been running since the Arduino began.
Think of the value of
micros() as the clock on the wall.
You should have a while loop that continuously checks the value of each sensorPin.
The while loop should repeat until either:
HINT: What value will you get with
digitalRead() from the sensorPin once the capacitor has fully discharged?