ULTRASONIC SENSOR

CODE:

#include<maker_ulstrasonic.h>

uint8_t Trig = 13;
uint8_t Echo = 10;

uint8_t Distance;


int main()
{


init();
Serial.begin(9600);
maker_setUltrasonic( Trig, Echo );

while(1)
{

Distance = maker_ultrasonicDistance_cm();
Serial.print(Distance);
Serial.println(“cm”);
Distance maker_ultrasonicDistance_m();
Serial.print(Distance);
Serial.println(“m”);
Distance maker_ultrasonicDistance_mm();
Serial.print(Distance);
Serial.println(“mm”);
Distance = maker_ultrasonicDistance_inch();
Serial.print(Distance);
Serial.println(“inch”);
delay(1000);

}
return 0;

}

Ultrasonic sensor emits an ultrasound that travels through the air, but when the sound comes to the object, it bounces back to the module. Knowing the speed of ultrasound and time needed for sound to come back, we can calculate the distance.

VCC – power supply pin (5V)

GND – ground pin (0V)

ECHO – input pin that receives ultrasound waves

TRIG – output pin that sends ultrasound waves

Coded by: