US-XXX

อ่านค่าจากอัลตร้าโซนิค
โมดูลอัลตราโซนิก ใช้วัดระยะทาง ตรวจจับสิ่งกีดขวาง วัดได้แม่นยำในระยะทาง โดยใช้หลักการคำนวนระยะทางจากสะท้อนกลับของคลื่นเสียงในอากาศ การจับเวลาในการเดินทางของคลื่นเสียงจากจากตัวส่ง ตกกระทบยังวัตถุ แล้วสะท้อนกลับมายังตัวรับ แล้วนำมาคำนวณออกมาเป็นระยะทาง ใช้ไฟ 5 โวลต์

US-015 Ultrasonic Module
Features:
• US-015 Ultrasonic Module
• Working voltage: DC 5 V
• Working current: 2.2 mA
• Working temperature: 0 ~ + 70°
• Output way: GPIO
• Induction Angle: Less than 15°
• Detection range: 2 cm to 400 cm
• Detecting precision: 0.3 cm + 1%
• Resolution:1mm
• The module size: 45mm x 20mm x 1.6mm

US-016 Ultrasonic Module
Features:
• US-016 Ultrasonic Module
• Working voltage: DC 5 V
• Working current: 3.8mA
• Working temperature: 0 ~ + 70°
• Output way: Analog voltage: (0 ~ Vcc)
• Induction Angle: Less than 15°
• Detection distance: 2 cm to 300 cm
• Detection accuracy: 0.3 cm + 1%
• Resolution:1mm
• The module size : 45mm x 20mm x 1.2mm

US-100 Ultrasonic Sensor Module
Feature:
• US-100 Ultrasonic Module
• Working voltage: DC 5 V
• Working current: 2 mA
• Output way: GPIO
• Output way: Analog voltage: (0 ~ Vcc)
• Induction Angle: Less than 15°
• Detection distance: 2 cm to 450 cm
• Resolution:1mm
• The module size : 45mm x 20mm x 1.2mm

การทดสอบ US-016
การทดสอบผมทดสอบจาก Module US-016 และ Arduino UNO,Arduino MEGA โดยผมจะใช้ Code ต่อไปนี้
ตัวอย่าง

const int pingPin = 13;    //ประกาศตัวแปรค่าคงที่ pingPin เท่ากับ Pin13
    int inPin = 12;    //ประกาศตัวแปรค่าคงที่ inPin เท่ากับ Pin12

    void setup() {    //เข้าฟังชั่น Setup (ทำงานครั้งเดียว)
      Serial.begin(9600);    //คำสั่ง Debug การแสดงผลออกทางมอนิเตอร์
    }    //ออกจากฟังชั่น Setup
   
    void loop()  
    {    //เข้าฟังชั่น Loop (ทำงานวนซ้ำ)
      long duration, cm;
   
      pinMode(pingPin, OUTPUT);    //ใช้คำสั่ง pinMode กำหนดให้ pin pingPin เป็น mode OUTPUT
      digitalWrite(pingPin, LOW);    //ใช้คำสั่ง digitalWrite กำหนดให้  pin pingPin มีสถานะเป็น LOW
      delayMicroseconds(2);    //delay 2 Microseconds
      digitalWrite(pingPin, HIGH);    //ใช้คำสั่ง digitalWrite กำหนดให้  pin pingPin มีสถานะเป็น HIGH
      delayMicroseconds(5);    //delay 5 Microseconds
      digitalWrite(pingPin, LOW);    //ใช้คำสั่ง digitalWrite กำหนดให้  pin pingPin มีสถานะเป็น LOW
      pinMode(inPin, INPUT);    //ใช้คำสั่ง pinMode กำหนดให้ pin inPin เป็น mode INPUT
      duration = pulseIn(inPin, HIGH);

      cm = microsecondsToCentimeters(duration);    //ใช้ฟังชั่นคำนวนผลระยะเวลาสะท้อนกลับเป็นระยะทาง

      Serial.print(cm);    //ใช้คำสั่ง print ผลการคำนวนออกเป็น cm
      Serial.print("cm");    //ใช้คำสั่ง print ผลการคำนวนออกเป็น cm
      Serial.println();     //ใช้คำสั่ง print ผลการคำนวนออกเป็น cm
      delay(100);    //delay 1 วินาที
    }
   
    long microsecondsToCentimeters(long microseconds)
    {
      // The speed of sound is 340 m/s or 29 microseconds per centimeter.
      // The ping travels out and back, so to find the distance of the
      // object we take half of the distance travelled.
      return microseconds / 29 / 2;
    }

วิธีการต่อขา ใช้งาน โมดูลวัดระยะทาง Ultrasonic Module กับ Arduino
- Vcc - 5v
- Gnd - Gnd
- Trig - 13
- Echo - 12

ความคิดเห็น

บทความที่ได้รับความนิยม