rulururu

post Raspberry Pi and Parallax Ping)))

January 5th, 2014

Filed under: Tech — RHH @ 3:15 am

I have had a desire to be alerted when the salt level in my water softener gets low. I have put this off and put this off. My original plan was some convoluted mechanism of springs and weighing the barrel. The main reason for that was the concern that the salt would corrode any electronics that were inside the barrel. Later I thought of a sealed magnet with a reed switch or hall affect sensor on the outside. Then I read a post somewhere that basically said that the salt shouldn’t be an issue. I like that! I went with the Parallax Ping))) sensor since I had a couple around. Originally, I had planned for this to be an Arduino project. But I become very pro-Raspberry Pi since then. It has less I/O than an Arduino, but most (all) of my projects require very few I/O pins. The other day I decided that this needed to be completed. I found an article that very simply and easily got the distance value from the Parallax Ping))). That forum post is here.  User feiry absolutely nailed it!  As feiry did, I used pin 11 on the Pi for SIG, pin 2 on the Pi for 5v and pin 6 on the Pi for GND.

PiPing

You will have to forgive that image.  I’m new to Fritzing.

The next important bit is the code that will get the distance for you.  As I said this is the code that was posted by feiry back in October.

import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)

#cleanup output
GPIO.output(11, 0)

time.sleep(0.000002)

#send signal
GPIO.output(11, 1)

time.sleep(0.000005)

GPIO.output(11, 0)

GPIO.setup(11, GPIO.IN)

while GPIO.input(11)==0:
   starttime=time.time()

while GPIO.input(11)==1:
   endtime=time.time()
   
duration=endtime-starttime
distance=duration*34000/2
print distance

I wrote a shell script (I need to learn more python) that calls that python code, then takes the value distance, populates a variable with it and inserts it into a mysql database.  Then I have a script on my database server that will check various values from the database and do things based on those values.  Mostly it will email me when a value requires attention.

There you have it.  A Raspberry Pi based water softener salt level notification tool.

Special thanks to feiry and richlish@gmail.com
Forum thread: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=7688
Fritzing part for Parallax Ping)): http://code.google.com/p/fritzing/issues/detail?id=875#c508

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

ruldrurd


Powered by WordPress, Web Design by Laurentiu Piron
Entries (RSS) and Comments (RSS)