ចម្លើយ

ថ្ងៃទី 02 ខែកញ្ញា ឆ្នាំ 2025 - ម៉ោង 09:29 ព្រឹក
To connect and use the Velleman VMA306 HC-SR05 Ultrasonic Sensor with an Arduino board, follow these steps:
1. **ខ្សែភ្លើង៖**
- Connect the VCC pin of the sensor to the +5V pin on the Arduino.
- Connect the GND pin of the sensor to the GND pin on the Arduino.
- Connect the TRIG pin of the sensor to digital pin D4 on the Arduino.
- Connect the ECHO pin of the sensor to digital pin D2 on the Arduino.
2. **Code:**
- Use the following Arduino sketch to read distance measurements from the sensor:
```cpp
#កំណត់ trigPin 4
#កំណត់ echoPin 2
ការកំណត់ទុកជាមោឃៈ () {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
រយៈពេលវែង, ចម្ងាយ;
digitalWrite(trigPin, LOW);
ពន្យារពេលមីក្រូវិនាទី (2);
digitalWrite(trigPin, HIGH);
ពន្យារពេលមីក្រូវិនាទី (10);
digitalWrite(trigPin, LOW);
រយៈពេល = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2; // Calculate distance in cm
Serial.print("Distance: ");
Serial.print(ចម្ងាយ);
Serial.println(" cm");
delay(1000); // Delay for stability
}
```
3. ** ការធ្វើតេស្ត៖ **
- Upload the code to your Arduino board.
- Open the Serial Monitor in the Arduino IDE to view the distance measurements in centimeters.
By following these steps, you should be able to successfully connect and use the Velleman VMA306 HC-SR05 Ultrasonic Sensor with your Arduino board for distance measurement in your projects.
បន្ថែមមតិយោបល់ថ្មី។