1 軟體 : Arduino ( v1.8.12 ) 會隨版本更新

2 元件及材料 :

ESP 32 、 超音波 、蜂鳴器 、 杜邦線x6、

Micro USB線x1

Arduino

教學 : https://zanrobot.com/uncategorized/3699

下載 : tps://www.arduino.cc/zh/main/software?setlang =cn

超音波蜂鳴器接線圖接

BZ(+) 接P12,
BZ ( – ) 接GND
trigPin 接 5 (GPIO5)
echoPin 接 4 (GPIO4)
Vcc 接 3.3 V

ESP 32 前置

教學 : https://zanrobot.com/uncategorized/3699

程式編碼

const int trigPin = 5;

const int echoPin = 4;

const int ledPin = 12;

const int freq = 2000;

const int ledChannel = 0;

const int resolution = 8;

long duration; int distance;

int safetyDistance;

void setup() { pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

Serial.begin(115200);

ledcSetup(ledChannel, freq, resolution);

ledcAttachPin(ledPin, ledChannel);

ledcWriteTone(ledChannel, 0);

}

void loop()

{ digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

{ distance= duration*0.034/2;

safetyDistance = distance; if (safetyDistance <= 30){ ledcWriteTone(ledChannel,0);

delay(100);

}

if (safetyDistance < 5){ ledcWriteTone(ledChannel,1730);

delay(100);

}

if (safetyDistance < 20){ ledcWriteTone(ledChannel,1046);

delay(100); }

}

Serial.print(“Distance: “);

Serial.println(distance);

}

影片

142 thoughts on “Arduino(ESP 32)快速上手 : 超音波應用(隔空彈奏)教學

  1. Hey There. I found your blog using msn. This is an extremely well written article.
    I will make sure to bookmark it and return to read more of your useful
    info. Thanks for the post. I’ll definitely return.

  2. Oh my goodness! Amazing article dude! Thanks, However I am encountering troubles with your RSS. I donít know why I can’t join it. Is there anybody getting the same RSS issues? Anyone that knows the solution will you kindly respond? Thanks!!

  3. Hoje é um dia triste Mas o que importa é que sábado eu vou ta com os meus vendoshow do QUAVO, djonga, sidoka, recayd, jovem dex, fbc, hot e oreia,bk, clara lima, caveirinha e etc

  4. Heya i am for the first time here. I came across this board andI find It truly useful & it helped me out a lot. I hope to give something back and aid others like you helped me.

  5. Good day! I could have sworn Iíve been to your blog before but after browsing through some of the articles I realized itís new to me. Regardless, Iím definitely pleased I discovered it and Iíll be bookmarking it and checking back often!

  6. An intriguing discussion is worth comment. There’s no doubt that that you ought to publish more about this issue, it may not be a taboo subject but usually folks don’t speak about such topics. To the next! Best wishes!!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>