GPIO output to switch relay at high C02?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

GPIO output to switch relay at high C02?

Waggotamp
Hello Alfred

It's been a while! All of our LivPis are working awesome!

Can I get your thoughts on this project? GPIO output to switch relay at high C02

How would I go about this?

Regards

Tony
Reply | Threaded
Open this post in threaded view
|

Re: GPIO output to switch relay at high C02?

AlfredC
Administrator
Hello Tony,

Glad to hear your LiV units are working OK.

There are 2 DHT22 connectors on LIV (GPIO 17 and GPIO 27). You can use the free one to control a relay module. RPi GPIOs operate at 3.3V, so your relay module should accept a 3.3 V input. (something like this:
https://www.aliexpress.com/item/3-Channel-Relay-Module-With-Optocoupler-Isolation-Fully-Compatible-3-3V-5V-Signal-High-Voltage-Relay/32773136518.html?spm=2114.40010308.4.2.rc2fWS
Most relay modules operate on 5V input, if you use one of those, you will need to use a transistor to adapt levels, like this:  
http://www.reuk.co.uk/wordpress/raspberry-pi/simple-raspberry-pi-relay-control-over-the-internet/">http://www.reuk.co.uk/wordpress/raspberry-pi/simple-raspberry-pi-relay-control-over-the-internet/
LiV schematics are here: http://www.livpi.com/liv-schematics.html


You can write a small Python program that reads the most recent value of CO2 from the DB (use function "getMeasurements" at line 125 as a reference.) https://github.com/FirstCypress/LiV/blob/S_development/software/liv/livXMPP/livXMPP.py
If the value exceeds your defined threshold limit, you can use the function "GPIO.output" to write GPIO.HIGH to the GPIO pin you are using. When the value goes under the limit, you will write GPIO.LOW to the GPIO pin. The RPI.GPIO python library is already installed on LIV, so you only need to import it into your code. https://learn.sparkfun.com/tutorials/raspberry-gpio/python-rpigpio-example
Your Python program will run in a forever loop, with some time sleep period (a couple of minutes or more will be OK.)
Once your Python program works, you can add its name to the process starting script, so your program will automatically start running when LiV is powered.

Good luck with your project.

-Alfred