|
Raspberry Pi |
x 1 | |
|
Ultrasonic Sensor |
x 1 | |
|
Servo Motor |
x 1 | |
|
PWM Driver |
x 1 |
![]() |
Thonny IDE |
|
|
Raspbian OS |
|
![]() |
Python |
Raspberry Pi + Servo Motor + Ultrasonic Sensor
Hello!
We have prepared a small tutorial with Raspberry Pi + Ultrasonic
Sensor + Servo Motor. I would try another Raspberry Pi application for
beginners; I looked among the pieces I had at my disposal, and found something
interesting; I searched the internet for information about the parts I have,
how to control them individually, and now I will try to combine them to make an
application for learning purposes.
Components used in this project:
- Raspberry Pi;
- Ultrasonic Sensor HC SR-04;
- Servo Motor SG90;
- PCA9685 PWM Driver.
The first step is to install a library, which will help us use
the PWM driver PCA9685 (Figure 1), useful to control a servomotor, an LED or a
dc motor. Information can be found at this link:
https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/using-the-adafruit-library.
Figure 1
We start by opening Terminal Window and writing the command:
sudo pip3 install
adafruit-circuitpython-servokit
We are waiting for the package installation to be completed.
The control of the SG 90 servomotor (Figure 2) is easy, we only
need a few program lines written in Thonny IDE:
from
adafruit_servokit import ServoKit
kit = ServoKit
(channels = 16)
We import and initialize the ServoKit class.
Then, to move the actuator to an angle we want, we add the
command:
kit.servo [0] .angle
= 0
Figure 2
The HC SR-04 ultrasonic sensor (Figure 3) is affordable, easy to
use at 5V.
Figure 3
The electronic scheme according to which the connections are
made is the following:
Figure 4
The servomotor is connected to channel 0 of PCA9685; a supply
voltage of 5V is required for the servomotor and the ultrasonic sensor, and a
3.3V for the logic circuit of the PCA9685; PCA9685 driver, SDA and SCL pins
connect SDA and SCL pins on the Raspberry Pi (physical pins 3 and 5); for the
ultrasonic sensor, the Trig pin -> GPIO23 (physical pin 16) and Echo ->
GPIO24 (physical pin 18).
Practical realization of the project (Figure 5):
Figure 5
The distance is displayed in centimeters, with two decimals, the
program is run in Thonny Python (Figure 6):
Figure 6
Thanks to the PCBWay team for this activity!
We expect as much from you!
Success!

Raspberry Pi + Servo Motor + Ultrasonic Sensor
- Comments(0)
- Likes(0)
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Pitigoi
-
Adjustable voltage power supply Among the most important electronic devices in the electronics laboratory is the voltage source. Thi...
-
Digital Clock with AT89C2051 Circuit OperationShort SW2 presses cycle through displaying the current time in HH:MM and MM:SS form...
-
Switch based light sensor Hi!The circuit shown can be used to turn on the light in the garden, or some light panels / advertis...
-
LM3909 flashing indicator I present to you a circuit which is a little outdated, but quite pleasant for some, I saw that this ...
-
LED Panel with 5x8 LED Matrix This is a light panel made of 5x8 type LED matrices, which can be used together with an Arduino plat...
-
4 Digits 7 Segments CC Display Module with 74HC595 Hello! This time I want to present an 7-segment four digit display controlled by two 74HC595.The LED...
-
Adjustable voltage power supply Adjustable voltage power supplyAmong the most important electronic devices in the electronics labora...
-
ARDUINO LCD 1602 SHIELD + KEYBOARD ARDUINO LCD 1602 SHIELD + KEYBOARDThe LCD1602 shield can be mounted together with an Arduino Nano de...
-
Double voltage source Circuit presentationDouble voltage source + 15V / -15V and + 5V / -5V stabilizedThis circuit offers ...
-
Monitor for 12V batteries Monitor for equal voltage at the terminals of two 12V batteries.Circuit presentation Most 24V back-u...
-
Variable stabilizer for low voltages Variable stabilizer for low voltagesThe presented circuit allows to obtain stabilized voltages betwe...
-
Simple Temperature Regulator Simple temperature regulatorCircuit descriptionThe temperature controller uses as a temperature tran...
-
Audio balance indicator Technical data: - supply voltage 12-15V; - minimum level of the audible signal applied at the input&...
-
Twilight with hysterezis Circuit OperationThe light-operated electronic switch is a common electronic device in automation eq...
-
Car Battery Monitor Circuit presentationThe electronic circuit presented indicates the value of the voltage with eight L...
-
Differential voltage source Circuit working principleThe application schemes of the already integrated classics LM317 and LM337 ...
-
Battery Cell Charger Circuit Operation?The assembly ensures the charging phase with limited current and constant voltage....
-
Programmable Board with ATMega Hello! I made this platform for me, you can use it with an ATMega8 or ATMega328 microcontroller, or ...
-
-
-
-
-
-
-
-
-
-
ESP32-S Development Board, in "Arduino Uno" form factor
4143 4 16