В момента ресурсът е наличен само на английски

Connecting Distance sensor to the Raspberry Pro Preview

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!

  1. Power off the Raspberry.
  2. Connect the VCC pin of the sensor to a 5V pin on the Raspberry (pin 2 or pin 4).
  3. Connect the TRIG pin of the sensor to GPIO 5.
  4. Connect the GND pin of the sensor to a ground pin on the Pi (pin 39).
  5. Connect one end of a 220Ω resistor to GPIO 6.
  6. Connect two 220Ω resistors one after the other and both of them to GND pin of the Raspberry (pin 34 or pin 30);
  7. 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

  1. Connect the VCC pin of the sensor to a 5V pin on the Raspberry (pin 2 or pin 4).
  2. Connect the TRIG pin of the sensor to GPIO 5.
  3. Connect the GND pin of the sensor to a GND pin on the Pi (pin 39).
  4. Connect ECHO via 220Ω resistor to GPIO 6.
  5. 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.

Курсове и занятия включващи този Урок

Този Урок е използван в следните курсове и занятия.

Image for Perfect STEM course. Module 1 - Smart Car with Raspberry PI
  • 118
  • 42:47
  • 136