1) 利用 Arduino 的数字引脚给超声波传感器的 Trig 引脚至少 10 微秒的高电平信号,这会让HC-SR04 超声波测距模块发射出8个40K赫兹的超声波脉冲(ultrasonic burst)。 2) 8个超声波脉冲发出后,echo引脚会输出高电平。假如没有声波返回,echo引脚会在38微秒后输出低电平。假如有声波返回,echo引脚会进入低电平状态。
按照电路图进行连接,如下图所示。 草图(Sketch) 在您的计算机上打开Arduino IDE软件。 用Arduino语言编码将控制你的电路。 单击“新建”打开新的草图文件。 Arduino代码 (Arduino Code) const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor const int echoPin = 6; // Echo Pin of Ultrasonic Sensor...
The Ultrasonic sensor has four terminals - +5V, Trigger, Echo, and GND connected as follows − Connect the +5V pin to +5v on your Arduino board. Connect Trigger to digital pin 7 on your Arduino board. Connect Echo to digital pin 6 on your Arduino board. ...
Once you’ve compiled and uploaded this sketch to your Arduino, you should see the following in action. Move an object closer or farther away from your HC-SR04 ultrasonic sensor and you’ll see the centimeters and inches incremented and decremented (rounded to the closest full unit). HC-SR04...
// # Product name:ultrasonic scanner // # Product SKU:SEN0001 // # Version : 0.2 // # Description: // # The Sketch for scanning 180 degree area 4-500cm detecting range // # Connection: // # Pin 1 VCC (URM V3.2) -> VCC (Arduino) ...
// # Product name: URM V4.0 ultrasonic sensor // # Product SKU : SEN0001 // # Version : 1.0 // # Description: // # The sketch for using the URM37 Serial mode from DFRobot // # and writes the values to the serialport
You can choose any digital pins on the microcontroller for connecting Trig and Echo of the ultrasonic sensor. Step 5: Arduino Software Program (Sketch) The Arduino program basically will do the following steps: Turn on Trig pin Send out a 10 microsecond width pulse ...
// # Editor :Jiang from DFRobot // # Data :18.09.2012 //#PWM output mode Arduino sample code // # Product name:ultrasonic scanner // # Product SKU:SEN0001 // # Version : 0.2 // # Description: // # The Sketch for scanning 180 degree area 4-500cm detecting range // # Connectio...
You can use this example sketch to control the sensor with a trigger. In this case, the sensor will take a reading when you press the button and display the distance measurement on the Serial Monitor. You can also just call the read_sensor function when you want to take a reading. /*...
HC-SR04 Ultrasonic Sensor Pinout Here’s the pinout of the sensor: The sensor has 4 pins.VCCandGNDgo to5VandGNDpins on the Arduino, and theTrigandEchogo to any digital Arduino pin. Using theTrigpin we send the ultrasound wave from the transmitter, and with theEchopin we listen for the...