This is going to be one complex connection with four pins and three resistors, so brace yourselves!

Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео
- #842
- 20 Apr 2018
TL:DR.
You better read the whole section, we are about to create voltage divider!
- Power off the Raspberry.
- Connect the VCC pin of the sensor to a 5V pin on the Raspberry (pin 2 or pin 4).
- Connect the TRIG pin of the sensor to GPIO 5.
- Connect the GND pin of the sensor to a ground pin on the Pi (pin 39).
- Connect one end of a 220Ω resistor to GPIO 6.
- Connect two 220Ω resistors one after the other and both of them to GND pin of the Raspberry (pin 34 or pin 30);
- Use heat shrink tube to connect the single resistor, with the pair of resistors and an F-cable to the ECHO pin of the sensor.
This is a distance sensor
That sensor is an ultrasonic distance sensor model HS-SR04. It can measure from 2cm up to 4m. The sensor works like a bat from the animal kingdom - it sends 40MHz sound impulse and receives reflections of that sound. The shorter the time between the transmission and the receiving, the closer the object is.
We will use the sensor so that our car avoids obstacles.
Basic connection of the first three ports of the sensor
Connect Vcc of the sensor to +5V of the Raspberry, the red cable on the picture. There are at least two pins with +5V - pin 2 or pin 5.
A reference image with the pin layout is attached in the end of the lesson.
Connect TRIG to GPIO 5, the yellow cable on the picture.
Connect GND of the sensor to some GND pin of the Raspberry, pin 39 for example with the gray cable on the picture.
Creating a voltage divider step by step
Purpose of voltage devider
The sensor receives 5V as input and returns 5V output to the GPIO pins of the Raspberry. But the GPIOs are designed to receive up to 3.3 Volts. In order to lower that voltage we will create a voltage divider.
What is our target
We will connect the ECHO pin between two resistors. One is 220Ω, and the second is 440Ω. Because we don't have a 440Ω resistor, we will create one by connecting two 220Ω resistors one after the other.
In the end we connect 220Ω resistor to GPIO 6 and 440Ω resistor to GND.
Connect two resistors one after the other and both to GND
Connect a 220Ω resistor to an F-F cable and GPIO 6
[no image here]
Connect the ECHO pin between two of the resistors
That is the complex part. We must create three endings at once. We will use heat shrink tube again to connect them.
Cut a cable by half and use the F-ending to connect it to the ECHO pin. The loose end goes between two resistors ending and in a heat shrink tube.
Heat up the tube
End result
Let'e repeat all the connections
- Connect the VCC pin of the sensor to a 5V pin on the Raspberry (pin 2 or pin 4).
- Connect the TRIG pin of the sensor to GPIO 5.
- Connect the GND pin of the sensor to a GND pin on the Pi (pin 39).
- Connect ECHO via 220Ω resistor to GPIO 6.
- Connect ECHO via two 220Ω resistors to GND pin of the Raspberry (pin 34 or pin 30);
Reminder of the pin layout of the Raspberry Pi
Python demo program to use Distance sensor and control car motors.
Part of the Perfect STEM course, you should have a Raspberry Pi and a HC-SR04 distance sensor connected to 5V, GPIO 5, GPIO 6 and GND.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.

Perfect STEM course. Module 1 - Smart Car with Raspberry PI
Disassemble a remote control car. Change the brain of the car with a smart computer like Raspberry Pi. Build a smart device with artificial intelligence that you could control from your phone and that could freely navigate itself in the real world and on the Internet. Use your hands. Develop programs for your robot and your phone. Be curious and invent.
The perfect course lives up to its name. You move through the content, we check it and return feedback to you.
In the end, you should be able to better understand how to program and design smart devices that would make the world a better place. For everybody age 12+, 16+, 21+, 35+, etc. The hardware costs about 150$. It changes through the years so it might take some time for you to find it as Raspberry PI, motor drivers, power banks and h-bridges.. they change. Note that the course was designed to be led by a teacher with a decent knowledge in embedded hardware and software. This, on the other hand should not stop you, if you are curious.
- 118
- 42:47
- 136

Execute Python program about car distance sensor from the computer
This is going to be one complex connection with four pins and three resistors, so brace yourselves!
- 3
- 0
- 1
- 3d_rotation 0