It was so long since my last published Instructables. Actually, I tried to do very popular project but with a new tools and an easy way especially in coding. I worked on a line follower robot that track a white line and follow it but not using LDRs or commercial color sensor, I actually used my mobile phone as the color sensor and 1Sheeld that communicates between my mobile phone and Arduino to control the motion of the motors of the robot.

As well, I got some help from my friends in CAT Lab at Zewil city of Science and Technology who provide me with some tools and space to work in.

So let's begin illustrating the project.

Step 1: Components

1- Arduino Uno ($15)

2- 1Sheeld ($55)

3- Any Robot Chassis ($13)

4- Any motor driver for the motors ($9)

5- Battery to power your system

6- Your smart Android Phone

Step 2: Hardware Connection

Basically, the connection is very simple like the connection of any 2 motors with a motor diver as shown in the above schematic. We have to each channel on the motor driver a (PWM) pin to change speed of motor and (DIR) pin to change the direction (CW/ CCW).

Step 3: Software: Arduino Code

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).

#include <OneSheeld.h>

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

void setup() {
  pinMode(motor1PWM, OUTPUT);
  pinMode(motor1DIR, OUTPUT);
  pinMode(motor2PWM, OUTPUT);
  pinMode(motor2DIR, OUTPUT);
  digitalWrite(motor1DIR, LOW);
  digitalWrite(motor2DIR, HIGH);

void loop() {  

void selected()

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);

Step 4: Mobile Application

Basically, All you have to do here is to download 1Sheeld application from Play Store. This Application gets rid of the headache for developing the Android Application. Download the App and 1Sheeld library.

Actually, we will use only color shield in this project.

Step 5: Test

All we have to do in this is to put our robot on the white line and put the mobile on the robot. Then, open the 1Sheeld App and adjust it to be at the center of the white line. Finally, connect the battery of the motors and enjoy it.

About This Instructable




More by ashraf nabil:Line Follower Robot Using Camera Shield in 1Sheeld & Arduino Automated Photo Booth takes a picture and posts it on Twitter with Arduino and 1Sheeld Real-time BitCoin Price monitor using LED Matrix, Arduino and 1Sheeld 
Add instructable to: