0% found this document useful (0 votes)
25 views3 pages

Code Print

The code initializes serial communication and sets up a trigger pin as an output and input. It then pulses the trigger pin high and low to take an ultrasonic distance measurement. The duration of the pulse is used to calculate the distance in centimeters and inches, which are printed along with a message if the distance is out of range. This process repeats every 1000 milliseconds.

Uploaded by

Mahdye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Code Print

The code initializes serial communication and sets up a trigger pin as an output and input. It then pulses the trigger pin high and low to take an ultrasonic distance measurement. The duration of the pulse is used to calculate the distance in centimeters and inches, which are printed along with a message if the distance is out of range. This process repeats every 1000 milliseconds.

Uploaded by

Mahdye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*

*/

void setup() {

//initilize serial communication:

serial.begin(9600);

pinMode(TRIG_PIN,OUTPUT);

pinMode(TRIG_PIN,INPUT);

void loop()

long duration, diastanceCm, distanceIn;

//Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

digitalWrite(TRIG_PIN, LOW);

delayMicroseconds(2);

digitalWrite(TRIG_PIN, HIGH);

//convert the time into a distance

distanceCm = duration / 29.1 / 2 ;

distanceIn = duration / 74 / 2;

if (distanceCm <= 0) {

serial.printIn("Out of range");

else {

serial.print(distanceIn);

serial.print("in, ");

serial.print(distanceCm);

serial.print("cm");

serial.printIn();
}

delay(1000);

/*

*/

void setup() {

//initilize serial communication:

serial.begin(9600);

pinMode(TRIG_PIN,OUTPUT);

pinMode(TRIG_PIN,INPUT);

void loop()

long duration, diastanceCm, distanceIn;

//Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

digitalWrite(TRIG_PIN, LOW);

delayMicroseconds(2);

digitalWrite(TRIG_PIN, HIGH);

//convert the time into a distance

distanceCm = duration / 29.1 / 2 ;

distanceIn = duration / 74 / 2;

if (distanceCm <= 0) {

serial.printIn("Out of range");

else {

serial.print(distanceIn);

serial.print("in, ");
serial.print(distanceCm);

serial.print("cm");

serial.printIn();

delay(1000);

You might also like