Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 9 months ago.
Polulu QTRA reflectance sensor
Does any body have the QTRA library for mBed? I really need it
5 Answers
11 years, 9 months ago.
Hello,
I have used a Pololu QTRA reflectance sensor for a project and I still have the code if you need it. It depends though what do you need the sensor for. The way that I used it was for calculating wheel speed. SO i was using it to count wheel rotations and then calculate wheel speed for a traction control system.
Anyway if my code would be help to you just let me know and I will pass it to you!
Regards, Georgios
Actually now that I think about it why do that? Pololu QTRA does not a library as is a very easy sensor. My opinion is :
Connect the output from the sensor to an oscilloscope or voltmeter, Record the output voltage for Black and the output voltage for White. Then use the Analogin or Digitalin, depenting on your sensor, library And then with a simple A-D or D-A converter and some if statements you can read the voltage on the pin.
There are several other ways to do it, see interrupts and negative/positive edge triggered interrups, but this is the easier way.
eg.
Analogin sensorin (p16);
. . .
Vin=sensorin.read()*3.3; Converter
if (Vin<2)
{
counter++;
}
if (Vin>2)
{
counter;
}
In the example above I used a threshold voltage of 2V. If output voltage for black is 3V and for white is 0.3V, you can use 1.5V threshold.
I hope this helps!!
posted by 20 Mar 2013Sorry, I keep on forgetting thinks I want to say! Be careful though with this easy solution because the program will read the voltage every fraction of a second. So you will need to limit the reading of voltage to 1 time per edge. A bit of challenge for you there. Think of using a state variable for limiting it.
Best regards.
posted by 20 Mar 20137 years, 7 months ago.
No code is served,
How can you apply the pololu library of the QTR 8A it is good to be able to thank me thanks...
11 years, 9 months ago.
Hi, Mejrissi, in this post:
http://mbed.org/forum/mbed/topic/2420/?page=1#comment-20717
Is a suggest code for what you want. Maybe this will help you
Greetings
11 years, 9 months ago.
it does not work properly. have you tested it ?
No, i did not test it, because i dont have a qtra sensor right now. What is the problem with the code?
posted by 19 Mar 2013it does not work properly. it does not differentiate black from white as it should.
posted by 19 Mar 2013Ok, please give some time to try to help you making a code for my own.
Greetings
posted by 19 Mar 2013hi, try this code, i am assuming this QTRA sensor:
- QTR-8RC Reflectance Sensor Array http://www.pololu.com/catalog/product/961
#include "mbed.h" #define WHITE 1 #define BLACK 0 DigitalInOut sensors[]={(p5),(p6),(p7),(p8),(p9),(p10),(p11),(p12)}; InterruptIn sensorsEvent[]={(p5),(p6),(p7),(p8),(p9),(p10),(p11),(p12)}; Timer timer; //p5 = sensor1 //p6 = sensor2 //p7 = sensor3 //p8 = sensor4 //p9 = sensor5 //p10 = sensor6 //p11 = sensor7 //p12 = sensor8 //1 ms=0.001 //1 us=0.000001 const int sensorsSize=8; int sensorTimeus; void lowPulseDetected() { timer.stop(); sensorTimeus=timer.read_us(); timer.reset(); } int main() { int lineColor; for(int i=0;i<sensorsSize;i++) { sensors[i].output(); sensors[i]=0; } sensorsEvent[0].fall(&lowPulseDetected); //try to read from sensor 1 sensors[0].output(); //setting as DigitalOutput sensors[0]=1; //high pulse wait_us(10); //delay according to manual sensors[0].input(); timer.start(); if(sensorTimeus<=780) { lineColor=WHITE; } if(sensorTimeus>780 && sensorTimeus <=10000) { lineColor=BLACK; } }
I cant probe the code for my own because i dont have this sensors
Please try and tell me if it works
posted by 22 Mar 2013