top of page
View Robot Logic

Project Name :ROBOT and ROBOT Logic

 

Project description:

The Robot have (for the moment) the ability to detect obstacles across his move. When detecting such, the Robot check which way best for next move by checking open space to his left and right.In the logic video, I attached a LCD to show the parameters the robot checks.

First line : distance from obstacle in FRont.(FR=XX). When this value is 60 cm or less the logic went to a checking  loop. In second line R=XX- free space on right side, L=XX-free space on leftside. the robot will move to the side with  greatest value between the two values.The IN=XX value is for debugging purpose.

 

Components:

  • 2 DC 5V motors 100 rpm + two  2" wheels.

  • L293D  IC  - 2 motors Driver (wired by myself).

  • Sensor Shield for Arduino.

  • Micro Servo motor with holder.

  • Ultrasonis distance sensor HC-SR04 with holder.

  • StainlessSteel plate with universal swivel wheel.

 

 

 contact to                                                    yohizu@gmail.com

 

Code for Arduino

 

/*

 ROBOT NOVEMENT
 This example code is in the public domain.
Create 09 February 2015
  by Yohi Zucker
 
ROBOT NOVEMENT
Motors controlled with L293D  IC
One motor connect to pins 2 & 4 to control direction
The other motor connects to pins 8 & 10 for controlling direction.
pins 1 & 9 on the L293D connect to +5V means -allways enable
pin 16 on L293D connect to 5V
The unit run on 5V batteries connected to the Aurdino socket.
A 9.6V or 3.7x2V connected to pin 8 on the L293D to feed the motors.
The Aurdino GND used for the 9.6V or the 3.7x2V batteries.
In the loop section calculating the distanse in cm
should wait between pings at least 30 ms
need 3 veriables to save the distance 1-forward. 2- right. 3- left.
*/

#include <Servo.h>  // servo library
#include <NewPing.h>

    #define TRIGGER_PIN  12
    #define ECHO_PIN     11
    #define MAX_DISTANCE 600
 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int motor1=2; //declares the first pin for the motor1
int motor2=4; //declares the other pin for the motor1
int motor3=8;  //declares the first pin for the motor2
int motor4=10;//declares the other pin for the motor2
Servo servo1;  // servo control object
int dis,disright,disleft;//veraiables for distance in front, right side and left side.


void setup()
{
pinMode(motor1, OUTPUT); //
pinMode(motor2, OUTPUT); // these simply are declaring them as outputs
pinMode(motor3, OUTPUT); //
pinMode(motor4, OUTPUT);
 servo1.attach(9);
 
}

void loop()
{
  servo1.write(90);
   foreward();
   delay(\(\(\(\(\(\(\(\(\(\(\(\(250);         // Pause to let the servo to complete move
dis=sonar.ping()/57;
if (dis<60){
  stoop();
 sensor_movement();

   delay(\(\(\(\(\(\(\(\(\(\(\(\(100);
  if(disright>disleft){
     backleft();
       }
      else{
        backright();
      }
}                                            //end of top top  if



}                                                         //end of void loop

void stoop(){
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
digitalWrite(motor3, LOW);
digitalWrite(motor4, LOW);
}

void back(){
digitalWrite(motor1, LOW);
digitalWrite(motor2,HIGH);
digitalWrite(motor3,LOW);
digitalWrite(motor4,HIGH);
delay(\(\(\(\(\(\(\(\(\(\(\(\(250);
}
void backleft(){
//digitalWrite(motor1, LOW);//I cancel the back part
//digitalWrite(motor2,HIGH);
//digitalWrite(motor3,LOW);
//digitalWrite(motor4,HIGH);
delay(\(\(\(\(\(\(\(\(\(\(\(\(500);
digitalWrite(motor1, HIGH);//left motor foreward right motor backward
digitalWrite(motor2,LOW);
digitalWrite(motor3,LOW);
digitalWrite(motor4,HIGH);
delay(\(\(\(\(\(\(\(\(\(\(\(\(250);
}
void backright(){
//digitalWrite(motor1, LOW);//I cancel the back part
//digitalWrite(motor2,HIGH);
//digitalWrite(motor3,LOW);
//digitalWrite(motor4,HIGH);
delay(\(\(\(\(\(\(\(\(\(\(\(\(1000);
digitalWrite(motor1, LOW);//left motor backward  right motor foreward
digitalWrite(motor2,HIGH);
digitalWrite(motor3,HIGH);
digitalWrite(motor4,LOW);
delay(\(\(\(\(\(\(\(\(\(\(\(\(350);
}

void foreward(){
digitalWrite(motor1, HIGH);
digitalWrite(motor2, LOW);
digitalWrite(motor3, HIGH);
digitalWrite(motor4, LOW);
}

void sensor_movement(){
 servo1.write(0);    // Tell servo to go to  0 degrees- to the right
delay(\(\(\(\(\(\(\(\(\(\(\(\(750);         // Pause to get it time to move
disright=sonar.ping()/57;
delay(\(\(\(\(\(\(\(\(\(\(\(\(250);
servo1.write(90);    // Tell servo to go to 90 degrees-looking foreward
delay(\(\(\(\(\(\(\(\(\(\(\(\(1000);
servo1.write(180);    // Tell servo to go to 90 degrees
delay(\(\(\(\(\(\(\(\(\(\(\(\(750);
disleft=sonar.ping()/57;
delay(\(\(\(\(\(\(\(\(\(\(\(\(250);
servo1.write(90);    // Tell servo to go to 90 degrees-looking foreward
delay(\(\(\(\(\(\(\(\(\(\(\(\(1000);
}

bottom of page