tbd.pi
Posts: 34
Joined: Sat Aug 11, 2012 11:21 am
Location: NJ,USA
Contact: Website

EZ0 distance sensor measurement

Sun Sep 20, 2015 3:06 am

I have an EZ0 sonar distance sensor hooked up to the pi. Most of the tutorials I find on using it involve the Arduino but I want to use this with the Pi. I have followed a tutorial on Analog Sensors and hooked up the EZ0 on 5v from the pi, the ground and the analog to channel 0 on the mcp3008.

I do get a reading, and the sensor does adjust to an object placed infront of it. However, I get values that jump all over the place.

I looked up connecting ADC to a pi and foundAnalog Inputs for Raspberry PI with MCP3008 which doesn't send me down the same path, it has me hooking up the MCP3008 to the regular GPIO pins.

The code I'm using for the measurements;

Code: Select all

    
while True:
        distsensor = 0

        for i in range(0, 8):
            distsensor += ReadChannel(0)

            time.sleep(0.05)

        distsensor = distsensor / 8

        print("{0}".format(distsensor))

User avatar
mikronauts
Posts: 2732
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: EZ0 distance sensor measurement

Sun Sep 20, 2015 3:31 am

Be careful how you hook up the MCP3008

If you are powering the MCP3008 from 5V, you must put a voltage divider on DO before feeding it to MISO on the Pi header.

If you don't, you will likely fry the Pi MISO pin.

You can see how I divided the voltage for MCP3208's at

http://www.mikronauts.com/raspberry-pi/ ... and-howto/
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

tbd.pi
Posts: 34
Joined: Sat Aug 11, 2012 11:21 am
Location: NJ,USA
Contact: Website

Re: EZ0 distance sensor measurement

Sun Sep 20, 2015 4:34 am

Thanks for the heads up.

Re-reading my post, it seems like I didn't really ask a question. The question being, is either method more accurate when it comes to hooking up the MCP3008? Or is either way acceptable?

I have the pi's 3.3v hooked up to the IC, and the 5v of the pi hooked up to the EZ0 in this specific case.

Return to “Automation, sensing and robotics”