-
1Setup
The working voltage of HC-SR04 is 5V. When we pull high the ECHO pin to 5V, the voltage might cause damage to the GPIO pin of Ameba. To avoid this situation, we need to drop the voltage as follows:
We pick the resistors with resistance 1:2, in the example we use 10kΩ and 20kΩ. If you do not have resistors in hand, you can use level converter instead. The TXB0108 8 channel level converter is a suitable example:
-
2Programming
The programming of the Ameba RTL8722DM can be done using Arduino IDE which makes it very easy to write code and upload code to the Ameba Board.
Open the sample code in “File” -> “Examples” -> “AmebaGPIO” -> “HCSR04_Ultrasonic”
-
3Final Results!
Verify and upload the code. Press the reset button on Ameba once the uploading is complete. Open the Serial Monitor, the calculated result is output to serial monitor every 2 seconds.
Note that the HCSR04 module uses the reflection of sound wave to calculate the distance, thus the result can be affected by the surface material of the object (e.g., harsh surface tends to cause scattering of sound wave, and soft surface may cause the sound wave to be absorbed).
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.