Code not working.help

i have 3 ultrasonic sensor that interfacing with 2 motor.
The serial monitor is able to respond but the motor does not react base on that distance.
#include <Ultrasonic.h>
Ultrasonic ultrafront(12,11); // (Trig PIN,Echo PIN)
Ultrasonic ultraleft(10,9); // (Trig PIN,Echo PIN)
Ultrasonic ultraright(7,6); // (Trig PIN,Echo PIN)

//motor one
const int DIR1 = 4;
const int EN1 = 5;
//motor two
const int DIR2 = 7;
const int EN2 = 6;

void setup() {

Serial.begin(9600);

pinMode (DIR2,OUTPUT);
pinMode (DIR1,OUTPUT);
pinMode (EN1,OUTPUT);
pinMode (EN2,OUTPUT);

}

void loop(){

Serial.print("Front: “);
Serial.print(ultrafront.Ranging(CM)); // CM or INC
Serial.print(” cm " );
delay(100);
Serial.print("Left: “);
Serial.print(ultraleft.Ranging(CM)); // CM or INC
Serial.print(” cm " );
delay(100);
Serial.print("Right: “);
Serial.print(ultraright.Ranging(CM)); // CM or INC
Serial.print(” cm " );
delay(100);

int cm_L = ultraleft.Ranging(CM);
int cm_F = ultrafront.Ranging(CM);
int cm_R = ultraright.Ranging(CM);

//middle sensor (turning right)

if(cm_L >=45,cm_F >=45,cm_R >=45) {
digitalWrite(DIR2, LOW);
analogWrite(EN2, 100);
digitalWrite(DIR1, LOW);
analogWrite(EN1, 100);
}
else if (cm_L <45,cm_F >=45,cm_R >=45){
digitalWrite(DIR2, HIGH);
analogWrite(EN2, 100);
digitalWrite(DIR1, LOW);
analogWrite(EN1, 0);
}
else if (cm_L <45,cm_F <45,cm_R >=45){
digitalWrite(DIR2, HIGH);
analogWrite(EN2, 100);
digitalWrite(DIR1, LOW);
analogWrite(EN1, 100);
}
else if (cm_L>=45,cm_F >=45,cm_R <45){
digitalWrite(DIR2, HIGH);
analogWrite(EN2, 0);
digitalWrite(DIR1, LOW);
analogWrite(EN1, 100);
}
else if (cm_L >=45,cm_F<45,cm_R <45){
digitalWrite(DIR2, LOW);
analogWrite(EN2, 100);
digitalWrite(DIR1, HIGH);
analogWrite(EN1, 100);
}
else if (cm_L >=45,cm_F<45,cm_R <45){
digitalWrite(DIR2, LOW);
analogWrite(EN2, 100);
digitalWrite(DIR1, HIGH);
analogWrite(EN1, 100);
}
else if(cm_L <45,cm_F <45,cm_R <45){
digitalWrite(DIR2, LOW);
analogWrite(EN2, 0);
digitalWrite(DIR1, LOW);
analogWrite(EN1, 0);
}
else if (cm_L>=45,cm_F <45,cm_R >=45){
digitalWrite(DIR2, HIGH);
analogWrite(EN2, 0);
digitalWrite(DIR1, LOW);
analogWrite(EN1, 100);
}

delay(100);

}

  if(cm_L >=45,cm_F >=45,cm_R >=45) {

Check the syntax used when more than one value is tested. The commas between the parameters are not doing what you think. You need some logical operators in there, either || (or) or && (and) or both.

Ok. I will try it out. Thanks.

also, digitalWrite(PIN, state); is correct while it takes some 40 instructions to complete, direct port manipulation will be much more responsive later on.

-side note, most arduino pins are only capable of 40mA or so and back EMF is very bad for arduino pins and transistors. Hope your using either a tiny motor or some interfacing circuit with those motors.

good luck with it.

rinkrides: also, digitalWrite(PIN, state); is correct while it takes some 40 instructions to complete, direct port manipulation will be much more responsive later on.

Responsive? How fast do you think a motor responds? Not microseconds.

oops, sorry, but might be relevant for troubleshooting feedback loop problems on self-balancing bots for example… just sayin is all.
Very annoying caveats NOT mentioned in any of the documentation of the Arduino language reference if I’m asked. </end Rant>

No HW divide on MCU’s?! Fair enough! – made me nuts though and took a week+ of googling to find the cause because I had no idea divide was emulated causing my programs to grind to a crawl!

DigitalWrite() takes ~40 instructions just to XOR a PIN! WILL also disable PWM on a pin

digitalRead() also takes ~40 instructions BUT, WILL also disable PWM on a pin IF you try to read from that pin enabling a while loop to read from a sensor WHILE the PWM pin is HIGH… --That drove me nuts for over a week!!