Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- To use the Pololu QTR-31RC Reflective Array with an Arduino, you will first need to install the "QTRSensors" library. Open the Arduino IDE, navigate to "Tools" > "Manage Libraries..." and search for "QTRSensors" by Pololu. Install the library and restart the Arduino IDE.
- Next, connect the Pololu QTR-31RC Reflective Array to your Arduino as follows:
- Connect the sensor's VCC pin to the Arduino 5V pin.
- Connect the sensor's GND pin to the Arduino GND pin.
- Connect the 31 sensor outputs (OUT0 to OUT30) to 31 digital input pins on your Arduino. Note that most Arduino boards do not have 31 available digital input pins. You might need to use an Arduino Mega or a similar board with more digital input/output pins.
- Now, upload the following code to your Arduino:
- This code initializes the QTR-31RC Reflective Array using the QTRSensors library and calibrates the sensors in the setup() function. In the loop(), the calibrated sensor readings are obtained using the readCalibrated() function, and the sensor values are printed to the serial monitor every 500 milliseconds.
- After uploading the code to your Arduino and opening the serial monitor, you should see the calibrated sensor values being printed.
- You can modify the code to control other devices or make decisions based on the sensor readings according to your project requirements, such as line following or detecting objects on a conveyor belt.
- */
- #include <QTRSensors.h>
- const uint8_t sensorCount = 31;
- uint8_t sensorPins[sensorCount] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52};
- QTRSensorsRC qtr(sensorPins, sensorCount, 2000, QTR_NO_EMITTER_PIN);
- unsigned int sensorValues[sensorCount];
- void setup() {
- Serial.begin(9600);
- // Calibrate the sensors by placing the array over a white surface and a black surface
- Serial.println("Calibrating...");
- for (uint16_t i = 0; i < 400; i++) {
- qtr.calibrate();
- delay(20);
- }
- Serial.println("Calibration complete.");
- }
- void loop() {
- qtr.readCalibrated(sensorValues);
- Serial.print("Sensor values: ");
- for (uint8_t i = 0; i < sensorCount; i++) {
- Serial.print(sensorValues[i]);
- Serial.print(i < sensorCount - 1 ? ", " : "");
- }
- Serial.println();
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement