Line detection 4 sensors by kevindc927

Cloned from Sketch Arduino Adafruit Motor Shield Line Detector for Car by ranchc

This sketch is missing a short description

This is a line following robot car using Adafruit motor shield and 4 line detecting sensors. Motor speed ranges between 0 to 255 rpm.

Sensors are set in the following format in the front of the car: rightBackgroundDetector | rightMiddleLineDetector | leftMiddleLineDetector | leftBackgroundDetector

This code will assume you are starting on a white background with black line; then moving into black background with white line; and when it reach to the end with all white strip it will stop.

You can set the following variables:

  • MAX_SPEED 107 //Maximum speed of motor
  • MIN_SPEED 0 //Minimum speed of motor
  • TURN_SPEED 97 //Turning speed of motor

  • THRESHOLD 500 //Threshold to detect the line sensor, greater than 500 means it detected black line.

  • bg_right A5 //Port for right background detector

  • ir_right A3 //port for middle right line detector
  • ir_left A2 //port for middle left line detector
  • bg_left A0 //port for left background detector

Embed This Sketch

Use the following HTML code to embed the sketch code above in your blog or website.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:195287" frameborder="0"></iframe>

Embed The Serial Monitor

You can also embed the Serial Monitor section! Just use this HTML code.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/serialmonitor" frameborder="0"></iframe>