bat-sensor

What is an ultrasound sensor?

ultrasonido Ultrasound sensors are devices that use ultrasound waves to determine how far away an object is. They are easy to operate. An ultrasound wave is emitted by something similar to a speaker which is known as a transmitter. This wave travels until it reaches an obstacle and then it bounces back. They are used in many robots in order to detect obstructions and avoid crashing into them.

The ultrasound sensors enable the distance to the objects ahead to be measured. As you can see, the ZUM Kit ultrasound sensor has two parts, one is the transmitter and the other is the receiver. Each of them emits an ultrasound wave (which cannot be heard) and it  travels through the air until it hits any object in front of it. Then it bounces back to the robot and the receiver detects it. As we already know the speed of sound (343.2 metres/second), by measuring the time the wave takes to reach the object and bounce back again, we can calculate how far away it is. You can use the ultrasound sensors in projects that require you to know the distance to an object. For example, your robot will know the distance to any objects in its path in order to avoid it.

  1. 1 x Zumbloq  buzzer
  2. 1 x Zumbloq ultrasound sensor
  3. A ZUM BT 328 controller board or one compatible with Arduino UNO
  4. A USB cable

Got everything? Let´s get started then. We´re going to make an alert system similar to the ones used in cars to make it easier to park by emitting warning sounds as you get closer to another car.

Exercise 1. Programming the controller board to make the buzzer sound as it gets closer to an object.

In this example, we will create a program to make the ultrasound sensor react as follows:

When it gets within 40 centimetres of an object, it beeps intermittently. The time between one beep and the next will depend on the distance (the closer it gets to the object, the faster the alternating beeps will be).

It works in exactly the same way as the car sensors used in assisted parking systems. As we get nearer to another car or the wall, it makes a beeping noise, which gets faster and faster.

Let´s do it one step at a time:

1) Connect the buzzer to digital pin 10 and the ultrasound sensor as shown in the diagram.

Make sure you connect the cables correctly – it´s super important! The echo and the trigger pins, which are called ECH (red cable) and TRI (blue cable) on the sensor, must be connected to a signal pin (which are yellow on your bq ZUM BT-328), whereas the other two cables are connected as follows:

  • Black cable to any black pin
  • Orange cable to any red pin

ZUM-ULTRASNIC-6

The trigger pin is the one that gives the commands to that the ultrasound sensor that launches the wave. The echo pin is activated when the wave comes back. As a result, the distance in metres will be the time from activating the trigger pin until the wave is received by the echo pin, divided by 343 and then divided by 2 (the speed of sound is 343 metres per second, and x 2 as the wave travels there and back again).

2) Let´s make the code using bitbloq.

As we can see, we only need to indicate which pins we have connected the echo (ECH) and the trigger (TRI) to on the ultrasound sensor block.

Have a go at programming it using bitbloq and you will see that it works as we would expect it to. Do you dare to have a go at tweaking the program yourself to execute the next action?

  • When it gets within 10 inches of an object, it beeps for 500 milliseconds (so just before it´s about to hit an obstacle, it makes a long error beep)…
  • When it gets within 40 centimetres of an object, it beeps intermittently. The time between one beep and the next will depend on the distance (the closer it gets to the object, the faster the alternating beeps will be).