Advertisement
microrobotics

Single Line ITR1502SR40A Line Sensor

Jul 24th, 2023
1,091
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The ITR1502SR40A is an infrared reflective sensor. It can be used as a line sensor in many applications, including line-following robots.
  3.  
  4. This script will continuously read the analog value from the sensor and print it to the Serial Monitor. A low value indicates a reflection (line detected), while a high value indicates no reflection (no line).
  5.  
  6. Adjust the sensorPin variable to match the actual Arduino pin the sensor is connected to. Connect the sensor's VCC to Arduino 5V, GND to Arduino GND, and OUT to the specified Arduino analog pin.
  7.  
  8. Remember that the sensor readings may need to be calibrated or thresholded to work best in your particular environment.
  9.  
  10. Here's an example of using this sensor with an Arduino:
  11. */
  12.  
  13. const int sensorPin = A0; // Sensor connected to analog pin A0
  14.  
  15. void setup() {
  16.   Serial.begin(9600); // Set up serial communication at 9600 bps
  17. }
  18.  
  19. void loop() {
  20.   int sensorValue = analogRead(sensorPin); // Read the sensor
  21.   Serial.println(sensorValue); // Print the sensor value to the serial monitor
  22.   delay(100); // Short delay before next read
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement