Ashraf Nabil
Published © GPL3+

Line Follower Robot Using Arduino & 1Sheeld

I worked on a line follower robot that track white line and follow it but not using LDRs or color sensor, but using my Smart Phone.

IntermediateFull instructions provided3 hours5,286
Line Follower Robot Using Arduino & 1Sheeld

Things used in this project

Story

Read more

Schematics

Dual_10A_driver.jpg

IMG_20160511_171259.jpg

IMG_20160511_171228.jpg

Code

Arduino Code

Arduino
This part is the best and describe the core part in the project. Basically, we will use the camera in the mobile phone to get the most dominant colors , function "setCalculationMode", in the view and by using "setPalette" function, it make the screen as a grid (for example 3 x 3) with a color in each cell corresponding to the most dominant color in that cell.

So we are concerned only with the first and third cells which are the left upper cell and right upper cell that indicates the boundaries of the camera view. So, if any of the third or first cells gets a color in stead of white so it means that the robot has to drift in that direction to maintain the robot to be in the center of the white color which is by the way has a hex value (0xFFFFFF
#define CUSTOM_SETTINGS
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_COLOR_DETECTOR_SHIELD
#include <OneSheeld.h>

unsigned long white = 0xFFFFFF;
int motor1PWM = 3;
int motor1DIR = 4;
int motor2PWM = 6;
int motor2DIR = 7;

void setup() {
  OneSheeld.begin();
  ColorDetector.setOnSelected(&selected);
  pinMode(motor1PWM, OUTPUT);
  pinMode(motor1DIR, OUTPUT);
  pinMode(motor2PWM, OUTPUT);
  pinMode(motor2DIR, OUTPUT);
  
  digitalWrite(motor1DIR, LOW);
  digitalWrite(motor2DIR, HIGH);
}

void loop() {  
}

void selected()
{
  ColorDetector.setPalette(_3_BIT_RGB_PALETTE);
  ColorDetector.enableFullOperation();
  ColorDetector.setCalculationMode(MOST_DOMINANT_COLOR);
  ColorDetector.setOnNewColor(&newColor);
}

void newColor(Color one,Color two,Color three,Color four,Color five,Color six,Color seven,Color eight,Color nine)
{
  if (three == white && one == white)
  { moveForward(); }
  else if (three == white && one != white)
  { moveLeft(); }
  else if (one == white && three != white)
  { moveRight(); }
}

void moveForward()
{
  analogWrite(motor1PWM, 25);
  analogWrite(motor2PWM, 25);
  }

void moveRight()
{
  analogWrite(motor1PWM, 20);
  analogWrite(motor2PWM, 12);
  }

void moveLeft()
{
  analogWrite(motor1PWM, 12);
  analogWrite(motor2PWM, 20);
  }

Credits

Ashraf Nabil

Ashraf Nabil

8 projects • 102 followers

Comments