Proximity and Fill Sensors

When I was assigned to handle the proximity sensor part, I was reluctant at first as I’ve only touched programming for the CY160x modules before and nothing before or after. But the rest of my group members assured me that it was going to be fine as there were a lot of tutorials and examples on the internet to refer, in terms of both the hardware and software.

What is a Proximity Sensor?

The proximity sensor we went for is the ultrasonic sensor. An ultrasonic sensor measures the distance of an obstacle by emitting sound waves in the ultrasonic range which is inaudible to the average human and converts the reflected sound off that object into an electrical signal.

Calculation of Distance

The calculation of distance is done by measuring the time taken between the emission of the sound by the transmitter and the receiver receiving back the sound. The formula is a simple D = (0.5)*TxV where T is the time taken and V is the speed of sound. The formula is not entirely accurate as you can tell from the diagram, but it’s a good estimate of how far the object is and serves our purpose well enough.

What Are We Using It For?

The primary purpose of the ultrasonic sensor in Binmax is to be a forward-facing detector for humans. Our idea is to put Binmax in a ‘screensaver’ mode when no one is around and then ‘wake him up’ when someone approaches and it will even greet the ‘person’ upon detection.

For this, we set the criteria of Binmax being able to detect an obstacle around 50cm in front of it for a period of 1.5 seconds or longer.

Hardware Setup

As one can see from the first image in this post, the ultrasonic sensor is a standalone thing with 4 pins to connect to other devices. In our case, we will be connecting it to the Jetson Nano. The great thing about the Jetson Nano is that it uses the same GPIO library as the Raspberry Pi.

A GPIO library refers to the ‘general-purpose input/output’ library which helps to handle the usage of the pins that are unused on boards such as the Raspberry Pi or Arduino or Jetson Nano in this case. We are able to define whether the pin should act as an input or output according to our needs. In our case, we would be making use of two digital pins, a ground pin and a 5V pin, to form a proper electrical circuit. Prior knowledge from CY1308 and secondary school physics helped me make sense of this.

There was already a circuit diagram to follow for interfacing the sensor with the Raspberry Pi, and since the Jetson Nano is using the same library and pins, I just had to follow the same connections. The main tricky part about this was to avoid parallax error when connecting the pins or else there might be unintentional short circuits

 

Software Setup

At first, the code provided online seemed to work well, but it can randomly start giving negative values or values above 3000cm which are quite impossible given the environment we are in. Sometimes the entire thing just stops outputting distance.

After googling for a bit like a true programmer, I realised that the code was expecting a 100% success rate for transmission and reception but this would not be the case all the time. Sometimes sounds might get absorbed by certain objects or just go astray into other directions or have random sounds coming from other places. This was the cause of a lot of the errors, and so I added some extra buffer time and maximum time for the transmitter and receiver respectively and this seemed to have solved the problems face previously.

This was the final version of the code for the standalone sensor.

Integration With Web App

The next step was to integrate the sensor with the web application and I worked with Kyaw on this one. We changed the code so that it will start when the web application is at the screensaver page and it will record up to three historical readings 0.5 seconds apart. These readings are also verified to not be negative or extremely large values. If the average of the three historical readings is less than or equal to 50cm, then the page would change to the welcome page.

Author: Evelyn Lim

Leave a Reply

Your email address will not be published. Required fields are marked *