Hello excuse me I don't know arduino and I have a project to realize if you can help me and explain me.
In my program I have to make two motors turn as soon as the ultra sound sensor detects something in front of it.
Here is my program how I can make the assembly in real I do not know what is hardware used if you can help me?
// Constants
const int enableBridge1 = 2;
const int MotorGauche = 3;
const int MotorGauche2 = 5;
const int MotorDroite = 4;
const int MotorDroite2 = 6;
int trig = 8;
int echo =10;
long lecture_echo;
long cm;
// Variables
int Power = 10; //Vitesse du moteur entre 0 et 255
void setup(){
pinMode(MotorGauche,OUTPUT);
pinMode(MotorGauche2,OUTPUT);
pinMode(MotorDroite,OUTPUT);
pinMode(MotorDroite2,OUTPUT);
pinMode(enableBridge1,OUTPUT);
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
pinMode(echo, INPUT);
Serial.begin(9600);
analogWrite(MotorGauche,0);
analogWrite(MotorGauche2,0);
analogWrite(MotorDroite,0);
analogWrite(MotorDroite2,0);
}
void loop(){
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
lecture_echo = pulseIn(echo,HIGH);
cm = lecture_echo /58;
Serial.print("Distance en cm :");
Serial.println(cm);
if(cm < 60){ //Demarrer le moteur quand le capteur voit le panier
analogWrite(MotorGauche2,0);
analogWrite(MotorGauche,1);
}
else {
analogWrite(MotorGauche,0);
analogWrite(MotorGauche2,0);
}
if(cm < 60){
analogWrite(MotorDroite,1);
analogWrite(MotorDroite2,1);
}
else {
analogWrite(MotorDroite,0);
analogWrite(MotorDroite2,0);
}
}