It Follows

TLROB007

Shruti wants to gift a robo pet to her sister. Robo pet should follow the path that her sister draw. Can you help Shruti to make robo pet?
Robo Car chassis Kit
  1. Attach 2 motors and caster wheel to the chassis.
  2. Create a system of motor driver IC and arduino UNO.
  3. Attach IR sensor in front of the cart and connect it with Arduino.
  4. Code on arduino IDE. (for connection and code take help of let's tinker app)

    

int LS=2; // left sensor

int RS=3; // right sensor



int LM1=7; // left motor

int LM2=8; // left motor

int RM1=6; // right motor

int RM2=5; // right motor

void setup()

{

pinMode(LS, INPUT);

pinMode(RS, INPUT);

pinMode(LM1, OUTPUT);

pinMode(LM2, OUTPUT);

pinMode(RM1, OUTPUT);

pinMode(RM2, OUTPUT);

Serial.begin(9600);

}

void loop()

{if(!(digitalRead(LS)) && !(digitalRead(RS))) 

// Move Forward

{

digitalWrite(LM1, LOW);

digitalWrite(LM2, HIGH);

digitalWrite(RM1, LOW);

digitalWrite(RM2, HIGH);

Serial.println(LS);

Serial.println(RS);

}

if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right

{

digitalWrite(LM1, LOW);

digitalWrite(LM2, LOW);

digitalWrite(RM1, LOW);

digitalWrite(RM2, HIGH);

}

if(digitalRead(LS) && !(digitalRead(RS))) // turn left

{

digitalWrite(LM1, LOW);

digitalWrite(LM2, HIGH);

digitalWrite(RM1, LOW);

digitalWrite(RM2, LOW);

}

if(digitalRead(LS) && digitalRead(RS)) // stop

{

digitalWrite(LM1, LOW);

digitalWrite(LM2, LOW);

digitalWrite(RM1, LOW);

digitalWrite(RM2, LOW);

Serial.println(LS);

Serial.println(RS);

}

}