Pages: [1]   Go Down
Author Topic: Ultrasonic sensor sr b1  (Read 394 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I need help with measuring the distance so i can decide to turn left or right my car uses one servo to turn and is 4 wheel drive with one motor

I can not figure out how to measure the distance using 2 sr-04 ultrasonic sensors and i need HELP

my car has two ultrasonic sensors one on the left and the right I also am using a adafruit motor shield so will this effect my choice of ports I use for the ultrasonic sensors

Will this be a hardware or software or both please help......

* rc_car_test.ino (0.65 KB - downloaded 5 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <AFMotor.h>
#include <Servo.h>
#include <Ultrasonic.h>

Servo servoturn;
AF_DCMotor motor(2, MOTOR12_64KHZ);

void setup() {
 
  servoturn.attach(13);
  servoturn.writeMicroseconds(1500);
 
}

void loop() {
 
  motor.setSpeed(150);
  delay(3500);
  servoturn.writeMicroseconds(1500);
  motor.run(FORWARD);
 
  if (putvalueofultrasonicsensorheredistanceincm < 50){         //I need help here
   
      motor.setSpeed(100);
    servoturn.writeMicroseconds(2000);
   
  }else if (putvalueofultrasonicsensorheredistanceincm < 50){             //and here for distance in cm
   
     motor.setSpeed(100);
     servoturn.writeMicroseconds(1000);
     
  }
}
Logged

Pages: [1]   Go Up
Jump to: