Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 152 - 2615_KEC
P. 152

    Their ability  to  work in various  lighting  conditions makes  them  ideal  for detecting  objects  in
                      challenging environments.

                      HOW DO THEY MEASURE DISTANCE USING SOUND WAVES?
                      Ultrasonic  sensors use  sound  waves to  determine  the  distance  to  an object.  They work like

                      echolocation, just like how bats and dolphins detect objects.
                      Here’s how ultrasonic sensors work to measure distance:

                         ∑  Sending Sound Waves: The sensor sends out a quick sound wave that humans cannot hear.

                         ∑  Hitting an Object: The sound wave travels through the air until it hits an object.

                         ∑  Echo Returning: The sound bounces back to the sensor, like an echo.

                         ∑  Measuring Time: The sensor measures how long it takes for the sound to travel to the object
                          and return.

                         ∑  Calculating Distance: Since we know how fast sound travels, the sensor can calculate the
                          distance to the object.

                      CONNECTING ULTRASONIC SENSOR TO SERVO MOTOR
                      To create an interactive system where the ultrasonic sensor triggers the servo motor based on the
                      object’s distance, follow these steps:

                      Step  1   Connect the Ultrasonic Sensor to the Micro:bit

                                   ∑  VCC pin of the ultrasonic sensor   3V on the Micro:bit.

                                   ∑  GND pin of the ultrasonic sensor   GND on the Micro:bit.

                                   ∑  Trig pin of the ultrasonic sensor   P0 on the Micro:bit.

                                   ∑  Echo pin of the ultrasonic sensor   P1 on the Micro:bit.

                      Step  2   Connect the Servo Motor to the Micro:bit
                                   ∑  VCC pin of the servo motor   3V on the Micro:bit.

                                   ∑  GND pin of the servo motor   GND on the Micro:bit.

                                   ∑  Signal pin of the servo motor   P2 on the Micro:bit (for the 180° servo).

                                    For a 360° continuous servo:

                                    o   The wiring remains the same, but the motor will rotate continuously based on
                                        the value provided to it via the servo write speed block.

                      Step  3   Programming Logic in MakeCode
                                Now, in MakeCode for Micro:bit, you will need to create the logic to make the servo
                                motor rotate based on the ultrasonic sensor’s detection of an object.

                      150   Premium Edition-VI

| 147 148 149 150 151 152 153 154 155 156 157 |