hc-sr04 rc car issue steering

ok so heres the beef, all my sensors are reading correctly, but on my left front when the sensor detects an object within range, the wheel just twitches, while right sensor steers away as it should, my ESC values are currently disabled for steering debugging

can anyone point out where it i am screwing up the steering on the left side?

#include <Servo.h>
#include "ESC.h"
#define trigPin 13
#define echoPin 12
#define trigPin1 11
#define echoPin1 10
#define trigPin2 9
#define echoPin2 8

Servo myservo;
ESC myESC (6, 1000, 2000, 500);
int val;
int val_rev;

void setup() {
Serial.begin (9600);
myESC.arm();
myservo.attach(3);
myservo.write(100);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);

pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
val = 0;
val = map(val, 0, 1023, 1000, 2000);

val_rev = 0;
val_rev = map(val_rev, 0, 1023, 1000, 2000);

delay(5000);
}

void loop() {
long duration1, distance1;
long duration2, distance2;
long duration, distance;

//center
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);

delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
delay(50);

//right
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);

delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
delay(50);

//left
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);

delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;
delay(50);

Serial.print(distance);
Serial.println(" cm");
Serial.print(distance1);
Serial.println(" cm");
Serial.print(distance2);
Serial.println(" cm");

delay(500);

if (distance >= 10){

myESC.speed(val);
delay(15);
}

if (distance < 10){
myESC.speed(val_rev);
delay(15);

}

if (distance1 >= 10){

myservo.write(100);
delay(15);
}

if ((distance1 < 15) && (distance2 > 15)){
myservo.write(10);
delay(15);

}

if (distance2 >= 15){

myservo.write(100);
delay(15);
}

if ((distance2 < 15)&&(distance1>15)){
myservo.write(170);
delay(15);

}

}

Is this the incorrect forum to seek this type of guidance?

figured out the steering issue, removed the If statement to recenter steering, just after setting angle, a new issue has come up

and i was wondering can the Servo lib, and A wrapper Lib Like Robotshops ESC lib be used in conjunction? I can use the Libs separately from one another but when they are both used in the same sketch, the ESC fails to activate

if its a lib Conflict will load order fix it? or are they simply conflicting and i need to come up with alternate means?

Morecrabs:
and i was wondering can the Servo lib, and A wrapper Lib Like Robotshops ESC lib be used in conjunction? I can use the Libs separately from one another but when they are both used in the same sketch, the ESC fails to activate

If one is just a wrapper for the other, they both use the same resources (pins, timers, interrupts, etc.) and don't play well together.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

figured out the code problem for the steering as i posted earlier, and thank you for the insight on the wrapper using identical interrupts and resources, thus leading to my issue using both libs, at the same time will have to come up with alternate code, for running the ESC.. so thank blh64 for the info I can make both pieces work independently while still being assembled as a whole when coded separately, the Circuit is sound.