Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The QTRX-HD-04A Reflectance Sensor Array is a 4-channel high-resolution infrared reflectance sensor designed for detecting lines and edges. It consists of four IR emitter and phototransistor pairs that can measure the amount of infrared light reflected from a surface. This array is useful in applications like line following, edge detection, or object proximity detection.
- The QTRX-HD-04A has four separate analog output pins that can be connected to the analog inputs of a microcontroller (e.g., Arduino) to read the sensor values. Each output provides a voltage proportional to the amount of IR light reflected by the surface.
- To use this code:
- Install the QTRSensors library in the Arduino IDE.
- Connect the QTRX-HD-04A Reflectance Sensor Array to your Arduino according to the product documentation: https://www.pololu.com/docs/0J13
- Upload the code to your Arduino board.
- Open the Serial Monitor to view the calibrated sensor values for each of the four channels.
- You can then use these sensor values for various applications, such as line following or object detection.
- Here is the complete code for reading sensor values from the Pololu QTRX-HD-04A Reflectance Sensor Array using an Arduino:
- */
- #include <QTRSensors.h>
- // Define the pins connected to the QTRX-HD-04A sensor array
- #define QTR_PIN_1 A0
- #define QTR_PIN_2 A1
- #define QTR_PIN_3 A2
- #define QTR_PIN_4 A3
- // Create an instance of the QTRSensorsAnalog class with the pins defined
- QTRSensorsAnalog qtr((unsigned char[]){QTR_PIN_1, QTR_PIN_2, QTR_PIN_3, QTR_PIN_4}, 4);
- // Array to store the sensor values
- unsigned int sensorValues[4];
- void setup() {
- Serial.begin(9600); // Initialize serial communication at 9600 baud rate
- delay(500); // Give the sensors some time to power up
- // Calibrate the sensors by placing them over the surface to be used
- // and sliding them across the surface for a few seconds.
- Serial.println("Calibrating...");
- for (int i = 0; i < 400; i++) {
- qtr.calibrate(QTR_EMITTERS_ON);
- delay(20);
- }
- Serial.println("Done!");
- }
- void loop() {
- // Read the sensor values and store them in the sensorValues array
- qtr.readCalibrated(sensorValues, QTR_EMITTERS_ON);
- // Print the sensor values to the serial monitor
- for (int i = 0; i < 4; i++) {
- Serial.print("Sensor ");
- Serial.print(i + 1);
- Serial.print(": ");
- Serial.println(sensorValues[i]);
- }
- Serial.println();
- delay(500); // Add a small delay to avoid flooding the serial monitor
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement