You are on page 1of 2

//#define bTrigPin 9 // attach pin D9 Arduino to pin Echo of HC-SR04 Back sensor

//#define bEchoPin 8 // attach pin D8 Arduino to pin Echo of HC-SR04 Back Sensor

#define fTrigPin 10 // attach pin D10 Arduino to pin Echo of HC-SR04 Front Sensor
#define fEchoPin 11 // attach pin D11 Arduino to pin Echo of HC-SR04 Front Sensor

void setup()
{
Serial.begin(9600);

pinMode(fTrigPin, OUTPUT);
pinMode(fEchoPin, INPUT);

}
/*///////////////////////////////////////////////////////////////////////////
Students need to update the void main function from here… */

/* define and initialize variables for storing


the distance vales in ultrasonic sensor front and rear */
int dist = 0, dist1 = 0;
void loop()
{
digitalWrite(fTrigPin, HIGH);
delayMicroseconds(5);
digitalWrite(fTrigPin, LOW);
dist1 = (pulseIn(fEchoPin, HIGH)) * 0.034 / 2;

Serial.print("front sensor= ");


Serial.print(dist1);
Serial.print("cm\n");

delay(500);
}

You might also like