Advertisement
microrobotics

Maker Line 5 channel line sensor

Jul 24th, 2023
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's an example of how you can use the Maker Line 5 channel line sensor with an Arduino. This example uses the digital outputs from the sensor to detect a line.
  3.  
  4. This code will continuously read the digital output of each sensor channel and print the results to the Serial Monitor. This way you can see the output from each sensor in real time.
  5.  
  6. This example assumes that the sensor channels are connected to Arduino digital pins 2 to 6. You'll need to adjust the pin numbers according to your exact setup. Also, remember to connect the GND of the sensor to the GND of the Arduino, and to supply the sensor with an appropriate power source on VCC.
  7. */
  8.  
  9. // Define sensor pins
  10. const int Sensor1 = 2;
  11. const int Sensor2 = 3;
  12. const int Sensor3 = 4;
  13. const int Sensor4 = 5;
  14. const int Sensor5 = 6;
  15.  
  16. void setup() {
  17.   // Initialize the sensor input pins as input
  18.   pinMode(Sensor1, INPUT);
  19.   pinMode(Sensor2, INPUT);
  20.   pinMode(Sensor3, INPUT);
  21.   pinMode(Sensor4, INPUT);
  22.   pinMode(Sensor5, INPUT);
  23.  
  24.   // Start serial communication at 9600 baud
  25.   Serial.begin(9600);
  26. }
  27.  
  28. void loop() {
  29.   // Read the value from the sensors
  30.   int S1 = digitalRead(Sensor1);
  31.   int S2 = digitalRead(Sensor2);
  32.   int S3 = digitalRead(Sensor3);
  33.   int S4 = digitalRead(Sensor4);
  34.   int S5 = digitalRead(Sensor5);
  35.  
  36.   // Print the sensor values to the serial monitor
  37.   Serial.print("S1: ");
  38.   Serial.print(S1);
  39.   Serial.print(" S2: ");
  40.   Serial.print(S2);
  41.   Serial.print(" S3: ");
  42.   Serial.print(S3);
  43.   Serial.print(" S4: ");
  44.   Serial.print(S4);
  45.   Serial.print(" S5: ");
  46.   Serial.println(S5);
  47.  
  48.   delay(200);
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement