Hi, can you help me. I have a code
#define trigPin1 3
#define echoPin1 2
#define trigPin2 4
#define echoPin2 5
long duration, distance;
void setup()
{
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
}
void loop() {
unsigned char m;
if ( Serial.available() ) {
m = Serial.read();
if ( m == '1' ) {
SonarSensor(trigPin1, echoPin1);
if ( distance < 30 ) {
Serial.print("1"); // parking slot filled
}
else {
Serial.print("0"); // parking slot empty
}
}
else if ( m == '2' ) {
SonarSensor(trigPin2, echoPin2);
if ( distance < 30 ) {
Serial.print("1");
}
else {
Serial.print("0");
}
}
}
}
void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
delay(500);
}
but when I upload it in serial monitor blank
. Is there something wrong with A code?