hi frinds, i am ne bee in this world. i have some idea about programing in arduino. but i have encounter some problem in programing it. i have use sonic sensor it has 3 port. name of sensor GH-311RT. but i have found in discution it should not be use to distance measurement. but it should sense the value high withine 25cm and low beyound 25cm when i use control pin to analog input 'A0'. so i have plane to drive two motor with this sensor logic as explane above. so i have write program for it. but problem is that, it does not function according to sensor. the motors are move forward back left right without sensor value.
i have programe when any object is within 25cm both motor stop, get reverse take right/left turn. i have past my program if any mistak by me plz correct it.
data sheet is here any one find http://www.sure-electronics.net/download/DC-SS014_Ver1.0_EN.pdf
const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; // H-bridge enable pin
const int analogInPin = A0;// define analog pin
int sensorValue; // Value for sensor output
void setup() {
// set all the other pins you're using as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
// set enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);
pinMode(analogInPin,INPUT);
}
void loop() {
sensorValue = analogRead(analogInPin);
if (sensorValue==LOW)
{
driveforward();
}
else
{
stopmoto();
delay(1000);
reverse();
delay(3000);
left();
delay(2000);
}
}
void driveforward()
{
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, HIGH);
}
void stopmoto()
{
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, LOW);
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, LOW);
}
void reverse()
{
digitalWrite(motor1Pin, HIGH);
digitalWrite(motor2Pin, LOW);
digitalWrite(motor3Pin, HIGH);
digitalWrite(motor4Pin, LOW);
}
i think my" if " statment is confusing may be. but your suggetion is more importent.
thanx for feedback