HTE - Ultrasonic Distance Sensor

Overview

For Fullscreen: https://www.youtube.com/watch?v=QUoJob2Nvx8

This tutorial will show you how to use an Ultrasonic Distance Sensor, connect it to the Quantum system, and create a simple demo using it.


What is an Ultrasonic Distance Sensor?

The Ultrasonics Distance Sensor emits sonic waves at a high frequencies and waits for them to be reflected back. It then calculates the distance by the time the wave travelled. The four pins of the Ultrasonic Distance Sensor are the vcc pin, the trig pin, an echo pin and the ground (gnd) pin.


Assemble the Circuit

Picture

Name

Quantity

Link

Picture

Name

Quantity

Link

 

Ultrasonic Distance Sensor

1

Included in Component Kit

Or you can purchase it here

Male to Male and Male to Female jumper wires

4

Included in Component Kit

Or you can purchase it here

Q-Client Builder Base

1

Q-Client

If you have all the parts listed above, we can go ahead and build the circuit. It should look like this:

Connect the vcc pin to the 5V of the Builder Base. We connected the trig pin and the echo pin to the GP5 and GP6 pin of the Builder Base. You can use any other GP pin if you want to. Also connect the gnd pin of the Ultrasonic Distance Sensor with the GND of the Builder Base.


Pair the Builder Base

Now we want to pair the Builder Base with our Q-Server. In order to do so, go to the Homescreen of your Q-Server.

Next click on the lift side symbol labeled “Clients”. Switch to the “Unpaired” tab at the top middle of the screen.

You should see your unpaired Builder Base. If not, check if you have plugged in the power supply for the Builder Base. Now move to the three dots below “Actions” and click “Pair”.

Once your Client is paired, click the “Setup” button.

Now you can edit your Client. Give him a Name you want and also a location where you are going to use it. Hit “Save” when you finished.


Build the Firmware

So once the Builder Base is paired and set up, we can start building our firmware. Move to the “Firmware” tab on the left side of your Q-Server interface. Hit “+ Create New”.

You will be prompted to give your new firmware a name. We named ours “Ultrasonic”.

Once you created the new firmware, hit the “+ Add Hardware” button on the top, next to the “Actions” button.

We are going to search for an ultrasonic distance sensor. You can use the search bar or scroll down till you find it. After this, you can give it a name and then click on “Add Hardware”. We named ours “Ultrasonic”. Next we need to configure the firmware. Click on the ultrasonic bar:

As the “Driver” we use HC-SR04. Choose the right pins for the “Echo Pin” and “Trigger Pin” in our case its GP6 and GP5 and the Resolution is set to 5. This means if the distance changes an update will be made to the system every 5cm.

Next we have to upload the firmware file to our Builder Base. Click on the three dots below “Actions” and click on “Upload”:

Choose the correct Builder Base and hit “Upload”. You should see a progress bar pop up at the right side of your screen.


Build the App

While the firmware is uploading, we can build the application for our Button. Move to the “Apps” tab on the left side. Click on “Create New” and give it a name you want. We named ours again “Ultrasonic”. Hit “Create”.

You will find yourself on the Canvas.

For this tutorial we will need a “Distance Ultrasonic” hardware object and a “Text” interface objects.

Connect the Distance channel of the “Distance Ultrasonic” hardware object with the “In” channel of the “Text” interface object. We named the “Distance Ultrasonic” hardware object into “Ultrasonic” and the “Text” interface object into “Distance”.

Click “Save App” on the top right. You will return to the first screen of the “Apps” tab. Now click the play button on the bar located at the right side.

Now we have to map the hardware and interface objects we have put together before to the actual hardware of the circuit. Click on the “Ultrasonic” tab and choose the Client, which is connected to the Ultrasonic Distance Sensor.

Once you done click “Save + Run”.


Run the App!

Click on the “Dashboard” icon in the top right corner.

Select the Ultrasonic app.

As you can see the sensor will now send data about the Distance in 193 cm. The distance will change if you put your hand in front of the sensor.


Changing units of measurement

To change the units of measurement you have to go back to your Q-Server. Go to the “Settings” panel on the top right corner.

Go to System Actions and change the units.

We changed the system to “Metric” as you can see in the next picture.


Compare data

The sensor also can do something with the measured data. When the measurement exceeds a certain amount or is between a defined distance it can send out a trigger. This trigger can cause some other actions to happen. In order to do so we need to go back to our app and change and add something.

We added a “Number Compare” code object and three “Debug” interface objects. For the “Number 2” we set the “Default Value” as 10. Also we need to connect the “Distance Ultrasonic” hardware object with the “Number Compare“ code object. Then we connect one of the three outputs “Greater”, “Less“ and “Equal” with one of the three inputs of the “Debug” interface objects. What will happen is that “Number 1” and “Number 2“ will be compared. If the measured number is greater than the given number the Debug of the Greater will trigger.

As you can see the measured value is 16.54 inch. Also the debug of the Greater is trigger with the “value” set to “ON”. If the measured value will change now, the different debugs will trigger.

This is how you connect and use an Ultrasonic Distance Sensor with the Quantum System. We also learned how to set different trigger values for our sensor system and the measured data.

Happy Making!