haylermoon
Posts: 1
Joined: Fri May 25, 2018 9:36 pm

Pulse Counter

Fri May 25, 2018 9:48 pm

Hi there, I'm brand new to Raspberry Pi and electronics so I would really appreciate some help! :shock:

I was wondering how to approach building a system that can measure the number of electronic pulses produced by a gas volume sensor used in an aquarium. The sensor is connected to a standard 3.5 mm stereo jack and sends a small signal through the jack's third contact every time it measures a bubble (https://www.ritter.de/en/data-sheets/pu ... d-contact/). I was hoping to find a way to record the number of signals sent each hour separately for four separate gas sensors connected to one Pi.

I just have a basic Raspberry Pi right now and was wondering if someone could point me in the right direction re: materials and programming. Thank you for your help!! :D

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 319
Joined: Fri Jan 06, 2012 7:46 pm

Re: Pulse Counter

Sat May 26, 2018 1:11 pm

The most simple, albeit a bit hacky, method would be to just thing of it as a switch. It only uses 2 contacts, Ground & Signal.

If you are new to all this, I suggest that you have a look at the documentation for the Python3 gpiozero library. This library is already installed on the Pi. Read through (or even better, try them out), the first few 'recipes' from here:https://gpiozero.readthedocs.io/en/stable/recipes.html#

If you look at recipe 2.5 - Button, that would be a good way to start with your sensor. Just connect the Ground from the sensor to any of the Pi's Ground pins, and the Signal to any available gpio pin. Every time the sensor sends a signal, it would look to the Pi just like a button press.

You could modify the code in the Button recipe to keep track of the number of pulses, like this;

Code: Select all

from gpiozero import Button

sensor = Button(21)
count = 0

while True:
	if sensor.is_pressed:
		count += 1
		print(count)
We did something very similar at primary school this term with a project involving water-flow sensors.

jbudd
Posts: 1641
Joined: Mon Dec 16, 2013 10:23 am

Re: Pulse Counter

Sat May 26, 2018 2:07 pm

Just connect the Ground from the sensor to any of the Pi's Ground pins, and the Signal to any available gpio pin.
Make sure the signal voltage doesn't exceed 3.3V or you will fry the Pi!

It might be wise to use an optocoupler to protect the Pi's GPIO pins.
Last edited by jbudd on Sat May 26, 2018 2:15 pm, edited 1 time in total.

pcmanbob
Posts: 10659
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pulse Counter

Sat May 26, 2018 2:12 pm

The sensor is connected to a standard 3.5 mm stereo jack and sends a small signal through the jack's third contact every time it measures a bubble
This statement suggests to me that you have the sensor connected to some other device or display.

just be aware you cant use the switch contact if it is being used in an existing circuit without knowing what voltages are being switched by the contact.

you will also not be able to use it as just a switch and apply your own voltages to it without risk of damaging any connected device.

there may be a away of getting a pulse from the switch if its already connected to some other device or display but it would involve knowing a lot more about the existing setup.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 319
Joined: Fri Jan 06, 2012 7:46 pm

Re: Pulse Counter

Sun May 27, 2018 7:26 am

jbudd wrote:
Sat May 26, 2018 2:07 pm
Just connect the Ground from the sensor to any of the Pi's Ground pins, and the Signal to any available gpio pin.
Make sure the signal voltage doesn't exceed 3.3V or you will fry the Pi!

It might be wise to use an optocoupler to protect the Pi's GPIO pins.
The 'signal' voltage will be 3v3 as it is just acting as a switch, attached to the gpio of the Pi. It's no different to using a simple pushbutton.

jbudd
Posts: 1641
Joined: Mon Dec 16, 2013 10:23 am

Re: Pulse Counter

Sun May 27, 2018 7:41 am

The 'signal' voltage will be 3v3 as it is just acting as a switch, attached to the gpio of the Pi. It's no different to using a simple pushbutton.
If the sensor simply opens and closes a reed switch that carries a Pi GPIO voltage that's all OK.
But it isn't clear from a cursory reading of the device manual that it works like that.
The second reed contact works as a pulse generator (V6.0) and can be used as signal output from the MilliGascounter to an external data acquisition system.
And the connections at the jack socket are Signal and Gnd, not Vin, Gnd and Signal. A 6V pulse would fry the GPIO.

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 319
Joined: Fri Jan 06, 2012 7:46 pm

Re: Pulse Counter

Sun May 27, 2018 5:45 pm

jbudd wrote:
Sun May 27, 2018 7:41 am
The 'signal' voltage will be 3v3 as it is just acting as a switch, attached to the gpio of the Pi. It's no different to using a simple pushbutton.
If the sensor simply opens and closes a reed switch that carries a Pi GPIO voltage that's all OK.
But it isn't clear from a cursory reading of the device manual that it works like that.
The second reed contact works as a pulse generator (V6.0) and can be used as signal output from the MilliGascounter to an external data acquisition system.
And the connections at the jack socket are Signal and Gnd, not Vin, Gnd and Signal. A 6V pulse would fry the GPIO.
Yep, I see what you're saying. My feeling is that as the datasheet does not state any specific voltage for the 'signal' output, that there is none, and it relies solely on power from the connected device.

Whichever way, it is easily checked by measurement while the sensor is running.

Return to “Beginners”