Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
code from the paper Project AWAAZ.pdf
const int trigPin = 3;
const int echoPin = 2;
void setup()
// initialize serial communication:
void loop()
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
if( duration>10000)
goto repeat;
Serial.print(" ");
int OutputPin=9;
unsigned int thisPitch = map(cm, 2, 400, 150, 15000);
// play the pitch:
tone(OutputPin, thisPitch, 10);
// delay in between reads for stability
Serial.print(" ");
long microsecondsToCentimeters(long microseconds)
return microseconds / 29 / 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.