ESP32 Starter Kit
3. Wiring Diagram
4. Test Code
It is interesting that the played tones vary from distance of human’s body.
/*
keyestudio ESP32 Inventor Learning Kit
Project 26 Human Body Piano
http://www.keyestudio.com
*/
int distance = 0; //Define a variable to receive the distance
int EchoPin = 14; //Connect Echo pin to io14
int TrigPin = 13; //Connect Trig pin to io13
int beeppin = 5;
float checkdistance() { //Acquire distance
// preserve a short low level to ensure a clear high pulse:
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
// Trigger the sensor by a high pulse of 10um or longer
digitalWrite(TrigPin, HIGH);
(continues on next page)
142 Chapter 8. Arduino Tutorial