NodeMCU ESP8266 สัปดาห์ที่ 5
ESP8266 GY-530 VL53L0X Laser ranging and gesture เลเซอร์วัดระยะทางและตรวจจับท่าทาง
GY-530 โมดูลวัดระยะทางและตรวจจับท่าทางด้วยแสงเลเซอร์ ใช้ชิฟ VL53L0X วัดได้ระยะสูงสุด 2 เมตร ความคลาดเคลื่อน 1mm โมดูลมีขนาดเล็กมาก ก่อนใช้งานครั้งแรก อย่าลืมดึงสติกเกอร์ที่เซนเซอร์เลเซอร์ออกด้วยก่อนใช้งาน
โค๊ด
| #include <Wire.h> | |
| #include <VL53L0X.h> | |
| int led = 14; //D5 | |
| int buzzer = 0; //D3 | |
| VL53L0X sensor; | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| Wire.begin(); | |
| pinMode (led, OUTPUT); | |
| pinMode (buzzer, OUTPUT); | |
| sensor.init(); | |
| sensor.setTimeout(500); | |
| sensor.startContinuous(); | |
| } | |
| void loop() { | |
| Serial.print(sensor.readRangeContinuousMillimeters()); | |
| if (sensor.timeoutOccurred()) { | |
| Serial.print(" TIMEOUT"); | |
| } | |
| if (sensor.readRangeContinuousMillimeters()< 50) { | |
| digitalWrite(led, HIGH); | |
| digitalWrite(buzzer, LOW); | |
| } | |
| if (sensor.readRangeContinuousMillimeters()> 50) { | |
| digitalWrite(led,LOW); | |
| digitalWrite(buzzer, HIGH); | |
| } | |
| Serial.println(); | |
| } |
ลิ้งhttps://www.myarduino.net/article/322/%E0%B8%AA%E0%B8%AD%E0%B8%99%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-esp8266-gy-530-vl53l0x-laser-ranging-and-gesture-%E0%B9%80%E0%B8%A5%E0%B9%80%E0%B8%8B%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B8%A7%E0%B8%B1%E0%B8%94%E0%B8%A3%E0%B8%B0%E0%B8%A2%E0%B8%B0%E0%B8%97%E0%B8%B2%E0%B8%87%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%95%E0%B8%A3%E0%B8%A7%E0%B8%88%E0%B8%88%E0%B8%B1%E0%B8%9A%E0%B8%97%E0%B9%88%E0%B8%B2%E0%B8%97%E0%B8%B2%E0%B8%87
ความคิดเห็น
แสดงความคิดเห็น