Go Down

Topic: Ultrasonic sensor sr b1 (Read 465 times) previous topic - next topic

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

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy