cmccr95148086
Posts: 6
Joined: Fri Jun 11, 2021 4:15 pm

Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 4:28 pm

Hello,
I am trying to run an ultrasonic sensor, it is the RPS-401A, using the Raspberry Pi 4. I am also using the MCP3008 to convert the signal from analog to digital. I am currently using an external power source to power the sensor because it requires 24V. The data that I am receiving does not seem to correlate at all with the distances I have set for the ultrasonic sensor. I have included some readouts from the sensor.
Code 1.PNG
Code 1.PNG (19.51 KiB) Viewed 550 times
Code 2.PNG
Code 2.PNG (19.56 KiB) Viewed 550 times
I am currently running Python 4 on Ubuntu 20.04 but am pretty new to programming and using a RP4 in general, so any help would be greatly appreciated!

ghp
Posts: 1998
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 5:20 pm

How do you connect the sensor to the ADC chip ? Sketch and photo is helpful.
How do you scale down the Sensor voltage output (0..10V) to (0..3.3V) for the ADC ?
Does the voltage across the sensor (0..10V, load resistor 500Ohm or more) correlate with distance ? In the datasheet there is a remark about a signal strength LED, is this in "bright red indicates a strong signal".

cmccr95148086
Posts: 6
Joined: Fri Jun 11, 2021 4:15 pm

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 7:24 pm

The connection between the sensor and the ADC chip is pictured below. The white wire running out of the picture on the left is the so called "data" wire which is the 0-10V wire. The data wire is then connected to a voltage divider using a 22 ohm resistor and a 10 ohm resistor to reduce the voltage below the 3.3 volts to which I believe the MCP3008 can handle. Everything on the right side of the ADC is exactly the same as what is posted on the Raspberry Pi website and the diagram is also pictured below.

I also am running power to the sensor using a switching regulator which may be the reason I am struggling getting good results. I am fairly certain that my problem has something to do with my circuit setup, but my experience with breadboards and such is very minimal so I am a little stuck.

As for the voltage on the sensor, it is to my understanding that the voltage is supposed to decrease and increase as the distance changes. The sensor only came with two sheets of instructions and they are very vague, so trying to understand the details of the sensor is fairly difficult. I do know though that the LED on the sensor Green to Red as the sensor is receiving a stronger and stronger sound wave back.
BBoard.PNG
BBoard.PNG (132.82 KiB) Viewed 509 times
Wiring 1.PNG
Wiring 1.PNG (209.04 KiB) Viewed 509 times
Really appreciate the help!

User avatar
joan
Posts: 15648
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 7:30 pm

There is no indication or sign of a ground connection between the sensor and the ADC/Pi.

ghp
Posts: 1998
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 7:43 pm

The values of 22, 10 Ohm are far too low. The datasheet says min 500 Ohm (meaning more is possible) for the total load. In the sketch a proposal.
And I think you missed the GND connection. The voltage divider, ADC and PI have a common GND line.
Double check the voltage divider resistors that GND is connected before connecting the sensor. If this is missing, you will fry the ADC...
divider.png
divider.png (27.42 KiB) Viewed 487 times

cmccr95148086
Posts: 6
Joined: Fri Jun 11, 2021 4:15 pm

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 7:45 pm

joan wrote:
Fri Jun 11, 2021 7:30 pm
There is no indication or sign of a ground connection between the sensor and the ADC/Pi.
Thanks for the reply. The sensor is grounded to the pi by the black wire in the bottom right of the picture. The sensor also has a ground wire, which is connected to the external power source. Do I need another ground between the sensor and the pi?

Thanks

cmccr95148086
Posts: 6
Joined: Fri Jun 11, 2021 4:15 pm

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 8:03 pm

ghp wrote:
Fri Jun 11, 2021 7:43 pm
The values of 22, 10 Ohm are far too low. The datasheet says min 500 Ohm (meaning more is possible) for the total load. In the sketch a proposal.
And I think you missed the GND connection. The voltage divider, ADC and PI have a common GND line.
Double check the voltage divider resistors that GND is connected before connecting the sensor. If this is missing, you will fry the ADC...
divider.png
Hi, I now understand the voltage divider, but am still confused what needs to be connected to ground. The RPS-401A sensor has a ground input that I have connected to my power source, and I believe the MCP3008 has two ground outputs at pins 9 and 14 which I have running to the pi. Do I need another ground connection or do I need to move the ground I have connected to the sensor onto the breadboard

Your help is greatly appreciated!

User avatar
joan
Posts: 15648
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 9:04 pm

Have you connected a ground between the sensor and the Pi/ADC? A common ground is needed so that there is a common voltage reference.

ghp
Posts: 1998
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Fri Jun 11, 2021 9:50 pm

Connect all GND together:
GND-Sensor (from the 24V) ------ GND Voltage divider ------ AGND ADC pin 14 ------- DGND ADC pin 9 ------- GND Pi
First approach is: just connect them together. Second approach: when you worry about sub-millivolt, the ultimate bit of performance, noise, thermal effects, drift, ground loops, then look into star connection, ground plane, shielding (where electronics meets fun).

cmccr95148086
Posts: 6
Joined: Fri Jun 11, 2021 4:15 pm

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Mon Jun 14, 2021 3:57 pm

Hello all,

I have made some adjustments based on the suggestions provided. I have switched out the original resistors for a 1K and 470 Ohm resistors and have connected the power source, the sensor, and the ADC grounds to the same breadboard, which is then connected to the ground on the Raspberry Pi. I am now seeing that I am able to set a max and minimum distance on the sensor in which the maximum distance reads 3.29V and the minimum distance reads 0V.
The problem I am facing now is that I an unable to read any distances in between the minimum and maximum. How I understand the sensor should work is that the voltage being read should decrease as the distance from the object decreases and vice versa. Could this be due to some sort of interference or the ultrasonic signal not being read correctly? Any suggestions are greatly appreciated!

Thanks for all the help.

ghp
Posts: 1998
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Mon Jun 14, 2021 5:40 pm

The sensor supports a min and max set potentiometer. Try to change their settings. Perhaps the current set range is too narrow.
There is also a remark in the datasheet "Mounting Consideration:The performance of this sensor can be influenced by direct metal contact.This zone is12mm/.50"measured from the sensor face. See Fig.G"

cmccr95148086
Posts: 6
Joined: Fri Jun 11, 2021 4:15 pm

Re: Running Ultrasonic Sensor on RP4 with MCP3008

Mon Jun 14, 2021 7:38 pm

Hello all,

After hours of no results, I decided to remove all the wiring and start over. Upon rewiring and implementing the changes described above, I have finally been able to obtain the results I am looking for. I am very thankful for all the help everyone on this discussion board and hope that this may someday be beneficial to others who are trying to use the same products.

Thanks again.

Return to “Automation, sensing and robotics”