You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: distance.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,20 @@
1
1
# Ultrasonic distance sensor
2
2
3
-
In air, sound travels at a speed of 343 meters per second. An ultrasonic distance sensor sends out pulses of ultrasound (inaudible to humans) and detects the echo that is sent back when the sound bounces off a nearby object. It then uses the speed of sound to calculate the distance from the object.
3
+
In air, sound travels at a speed of 343 metres per second. An ultrasonic distance sensor sends out pulses of ultrasound which are inaudible to humans, and detects the echo that is sent back when the sound bounces off a nearby object. It then uses the speed of sound to calculate the distance from the object.
The circuit connects to two GPIO pins (one for echo, one for trigger), the ground pin and a 5V pin. You'll need to use a pair of resistors (330Ω and 470Ω) as a potential divider:
9
+
The circuit connects to two GPIO pins (one for echo, one for trigger), the ground pin, and a 5V pin. You'll need to use a pair of resistors (330Ω and 470Ω) as a potential divider:
10
10
11
11

12
12
13
13
## Code
14
14
15
15
To use the ultrasonic distance sensor in Python, you need to know which GPIO pins the echo and trigger are connected to.
16
16
17
-
1. Open Python 3
17
+
1. Open Python 3.
18
18
19
19
1. In the shell, enter the following line to import `DistanceSensor` from the GPIO Zero library:
20
20
@@ -36,7 +36,7 @@ To use the ultrasonic distance sensor in Python, you need to know which GPIO pin
36
36
ultrasonic.distance
37
37
```
38
38
39
-
You should see a number: this is the distance to the nearest object, inmeters.
39
+
You should see a number: this is the distance to the nearest object, inmetres.
40
40
41
41
1. Try using a loop to print the distance continuously, while waving your hand in front of the sensor to alter the distance reading:
42
42
@@ -61,7 +61,7 @@ As well as being able to see the distance value, you can also get the sensor to
61
61
print("Out of range")
62
62
```
63
63
64
-
Now wave your hand in front of the sensorandit should rotate between showing the message "In range"and"Out of range"as your hand gets closer and further away from the sensor. See if you can work out the point at which it changes.
64
+
Now wave your hand in front of the sensor; it should switch between showing the message "In range"and"Out of range"as your hand gets closer and further away from the sensor. See if you can work out the point at which it changes.
65
65
66
66
1. The default range threshold is0.3m. This can be configured when the sensor is initiated:
0 commit comments