ECE 110/Equipment/QTI

From PrattWiki
Revision as of 18:26, 6 October 2022 by AdamWDavidson (talk | contribs) (Sample Code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

As noted at https://www.parallax.com/product/qti-sensor/, "The QTI Sensor is a close-proximity infrared emitter/receiver that is able to differentiate between a dark surface) with low IR reflectivity) and a light surface (with high IR reflectivity)... What does QTI stand for?

   Q = Charge
   T = Transfer
   I = Infrared

When your microcontroller measures the time it takes for the QTI’s capacitor to decay, it’s measuring a rate of charge transfer through an infrared phototransistor. This rate indicates how much infrared is reflecting off a nearby surface."

Leads

There are three leads on a QTI; they are labeled based on the colors of the three-wire cables that are typically used to connect them to the microcontroller:

  • B: Black - Ground
  • R: Red - Sensor pin, will alternate as an output pin to start the sensory process and then as an input pin to measure the discharge voltage
  • W: White - Supply voltage, typically 5 V

Operation

The pin connected to R should be made an output pin and turned on (HIGH) for 1 ms; this will charge a capacitor in the QTI circuit to 5 V. Next, change the pin connected to R to an input pin - this will make the capacitor discharge across a resistor in the QTI circuit. Monitor the voltage on the input pin and track how long it takes for the voltage at the pin to switch to LOW. According to https://www.arduino.cc/reference/en/language/variables/constants/constants/, the pin should read LOW once the voltage goes below 1.5 V.

Sample Code

The rcTime code below is from Ch. 6, Activity 2 of Robotics with the Board of Education Shield for Arduino. This program will continuously monitor one QTI and returns the amount of time it took for the QTI's internal capacitor to discharge below a certain voltage.

//Pins for QTI connections on board
#define lineSensor1 47 

void setup() {
  Serial.begin(9600); //start the serial monitor so we can view the output
}
void loop() {
  int qti1 = rcTime(lineSensor1); 
  delay(200);
  Serial.println(qti1);  
}

//Defines funtion 'rcTime' to read value from QTI sensor
// From Ch. 6 Activity 2 of Robotics with the BOE Shield for Arduino
long rcTime(int pin)
{
  pinMode(pin, OUTPUT);    // Sets pin as OUTPUT
  digitalWrite(pin, HIGH); // Pin HIGH
  delay(1);                // Waits for 1 millisecond
  pinMode(pin, INPUT);     // Sets pin as INPUT
  digitalWrite(pin, LOW);  // Pin LOW
  long time = micros();    // Tracks starting time
  while(digitalRead(pin)); // Loops while voltage is high
  time = micros() - time;  // Calculate decay time
  return time;             // Return decay time
}

Notes

With multiple QTIs, keep in mind that the readings will be serial, not parallel - that is, you will get the reading for the first one, then the second one, etc, etc. The state of one may change while another is read.

References