yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
9G Servo PTZ📖
1.Drive servo
  • For Arduino
  • For Microbit
  • For Raspberry Pi Pico
  • For Raspberry Pi
  • For MSPM0G3507new
  • For MSPM0G3519new
2.Drive ultrasonic module
  • For Arduino
  • For Microbit
3.Drive servo platform
  • For Arduino-without servo
  • For Arduino-with servo
  • For Microbit
Download ZIP

Welcome to 9G Servo PTZ repository

For Arduino

The purpose of the experiment

In this course we mainly study the use of Ultrasonic sensor.

Introduction of Dual axis XY rocker module:

The ultrasonic module is a sensor that uses ultrasonic characteristics to detect the distance. It has two ultrasonic probes for transmitting and receiving ultrasonic waves. The range of measurement is 3-450 cm.

image.png 

3-1 Ultrasonic emission and reception schematic

(1) You need to input a high level signal of at least 10us to the Trig pin to trigger the ranging function of the ultrasonic module.                     

image.png

3-2  Ultrasonic module sends trigger signal

(2) After the ranging function is triggered, the module will automatically send out 8 ultrasonic pulses with 40 kHz and automatically detect whether there is a signal return. This step is done internally by the module.


image.png 

(3) When the module detects an echo signal, the ECHO pin will output a high level. The high level duration is the time from when the ultrasonic wave is sent to when it returns. You can calculate the distance by using the time function to calculate the high level duration. Formula: Distance = High level duration * Speed of sound(340M/S)/2.

The actual object is shown below.

image.png 

List of components required for the experiment

Arduino UNO board *1

USB cable *1

Ultrasonic sensor *1

Dupont line *1 bunch

Actual object connection diagram:

We need to connect the circuit as shown in the figure below.

image.png 

Experimental code analysis:

int Echo = A5;  
int Trig =A4; 
int Distance = 0;
void setup()
{
  Serial.begin(9600);     //Initialize the serial ports
  pinMode(Echo, INPUT);    
  pinMode(Trig, OUTPUT);  
}
void Distance_test()  
{
  digitalWrite(Trig, LOW);   //Give the trigger pin 2μs low level
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);  //Give the trigger pin 10μs high level,at least 10μs
  delayMicroseconds(10);
  digitalWrite(Trig, LOW);    
  float Fdistance = pulseIn(Echo, HIGH);  //(unit:us)
  Fdistance= Fdistance/58;       
  // X second=( 2 * Y meter)/344 ==》X second = 0.0058 * Y meter ==》cm = us / 58
  Distance = Fdistance;
}  
void loop()
{
  Distance_test();
  if((2


Experimental steps

1. We need to open the program for this experiment: code_Ultrasonic_sensor.ino, click “√”under the menu bar,compile the program, and wait for the words of Done compiling in the lower left corner, as shown in the following figure.

image.png 

2. In the menu bar of Arduino IDE,you need to select the 【Tools】---【Port】--- select the port that the serial number displayed by the device manager just now.for example:COM6,as shown in the following figure.

image.png 

image.png 

3. After the selection is completed, you need to click “→”under the menu bar,and upload the program to the Arduino UNO board, when appears to Done uploading on the lower left corner , that means that the program has been successfully uploaded to the Arduino  UNO  board, as shown in the following figure.

image.png 

4. After the program upload is completed. You need to open the serial monitor of the Arduino IDE and you can see the current distance measured by the ultrasonic sensor. If the measured distance is larger than the range of the sensor, it will output “!!! Out of range”.  As shown in the following figure.

image.png image.png

image.png image.png


For MSPM0G3519
For Microbit

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文