What's new
  • Happy Birthday ICMag! Been 20 years since Gypsy Nirvana created the forum! We are celebrating with a 4/20 Giveaway and by launching a new Patreon tier called "420club". You can read more here.
  • Important notice: ICMag's T.O.U. has been updated. Please review it here. For your convenience, it is also available in the main forum menu, under 'Quick Links"!

Programming the Raspberry Pi for a Grow Room Monitor

Ringodoggie

Well-known member
Premium user
420giveaway
I am playing with the RPi and setting up some monitors. I have the DHT22 running fine and reporting the values properly to the SQL database.

I am setting up a light/LUX sensor and I need a little help with the coding.

I have the code that reads the DHT22 and writes the output to the database.

I also have code that reads the light sensor and prints the output value to the screen every 1.0 seconds.

Both are working properly

What I need, is code that will read the light sensor and write the value to the database instead of printing it to the screen.

Here is the working code that reads the DHT22 and writes the output to the database...

<php>
<?php function readSensor($sensor) { $output = array(); $return_var = 0; $i=1; exec('sudo /usr/local/bin/loldht '.$sensor, $output, $return_var); while (substr($output[$i],0,1)!="H") { $i++; } $humid=substr($output[$i],11,5); $temp=substr($output[$i],33,5); $db = mysql_connect("localhost","datalogger","datalogger") or die("DB Connect error"); mysql_select_db("datalogger"); $q = "INSERT INTO datalogger VALUES (now(), $sensor, '$temp', '$humid',0)"; mysql_query($q); mysql_close($db); return; } readSensor(9); readSensor(8); readSensor(7); ?>
</php>

Here is the code that reads the light sensor and prints to screen..

<code>

#!/usr/local/bin/python import RPi.GPIO as GPIO import time __author__ = 'Gus (Adapted from Adafruit)' __license__ = "GPL" __maintainer__ = "pimylifeup.com" GPIO.setmode(GPIO.BOARD) #define the pin that goes to the circuit---CHANGE THIS TO 11 pin_to_circuit = 7 def rc_time (pin_to_circuit): count = 0 #Output on the pin for GPIO.setup(pin_to_circuit, GPIO.OUT) GPIo_Output(pin_to_circuit, GPIO.LOW) time.sleep(0.1) #Change the pin back to input GPIO.setup(pin_to_circuit, GPIO.IN) #Count until the pin goes high while (GPIO.input(pin_to_circuit) == GPIO.LOW): count += 1 return count #Catch when script is interupted, cleanup correctly try: # Main loop while True: print rc_time(pin_to_circuit) except KeyboardInterrupt: pass finally: GPIO.cleanup()</code>

Can someone merge the applicable parts of these together to read the light sensor and write the output to the database?

Thanks for any assistance. :)


EDIT:::: Hmmmm code tags aren't working. Only attachments are images. I attached images of the code LOL Sorry.
 

Attachments

  • temp.jpg
    temp.jpg
    26.4 KB · Views: 17
  • light.jpg
    light.jpg
    45.6 KB · Views: 11

Dr_Parvo

New member
I've been using a Pi for a few years to automate things like water pumps, drains, and fans. Give me a few days I'll do some digging around for the code. There's a guy online who did this same thing with a DHT22 but for growing something else. It's on github, I'll try to find it.

I've actually ended up just placing cheap analog temp/hum thermostats at different parts of the rooms, and then adjusting my fans/AC units to that. If the room is well controllable, I find you can dial in settings that shouldn't change much day to day. Since someone is in the room every day, it works for us to have people checking temps continuously and adjusting for unusual situations.

But I'm also working on a master unit that will have multiple DHT sensors to control A/C, which would seem to be right up your alley. I'll post some stuff as soon as I can. Cheers!
 

Ringodoggie

Well-known member
Premium user
420giveaway
Thanks. I took a bunch of code from Raspiviv. I have the Temp, Humidity, LUX all working. Tomorrow I start on the moisture sensors and then the CO2 sensor.

Pretty neat stuff.
 

majorana

Member
You have no idea how much I wish I had internet access where my grow is. Beyond all controllers what I really want is in-tent camera so I can check on my babies without physically going there. That way I can go there less when all is good, and go there ASAP when something stupid happens (like today, when for whatever reason one of the Blumat drippers decided it's a good idea to remain open and floor the tent with 70 liters.) That and another security camera connected to a motion sensor, to send me a picture whenever somebody comes through the door. My life would be so much calmer if I had these two cameras on-line.
 

Ringodoggie

Well-known member
Premium user
420giveaway
If you don't have wifi or internet at your grow location, you can always use a cell sim hot spot. They are about $7 a month so it's not free but $7 is not a lot of money. A couple beers a month.

Then, use IP cams. I have 3 setup in my room(s) and I can check on then anytime from anywhere. With the addition of the Pi and an Arduino, I should actually be able to do certain things like (turn off the water when you see a flood happening LOL).

As for posting code here, it doesn't look like this forum is very post friendly. LOL It doesn't accept
Code:
 code tags
and you can't attach anything except pictures. Once I get it all together, I do a git-hub or something so I can share the code and schematics.
 

majorana

Member
If you don't have wifi or internet at your grow location, you can always use a cell sim hot spot. They are about $7 a month so it's not free but $7 is not a lot of money. A couple beers a month.

Where I'm at it's more like €12, but I'd happily pay twice as that if there was cellular reception where my grow is at. Walls and whatnot simply block the outer world. Perhaps with three wifi repeaters, or a strategically located hotspot and a single repeater. IDK. A tinkering project for May. Ironically enough I have an internet fiberoptic box super close, but I don't dare trying to hack into that.
 

Hookah79

Active member
Where I'm at it's more like €12, but I'd happily pay twice as that if there was cellular reception where my grow is at. Walls and whatnot simply block the outer world. Perhaps with three wifi repeaters, or a strategically located hotspot and a single repeater. IDK. A tinkering project for May. Ironically enough I have an internet fiberoptic box super close, but I don't dare trying to hack into that.
You must be growing in a bunker :biggrin:.
 
I am playing with the RPi and setting up some monitors. I have the DHT22 running fine and reporting the values properly to the SQL database.

I am setting up a light/LUX sensor and I need a little help with the coding.

I have the code that reads the DHT22 and writes the output to the database.

I also have code that reads the light sensor and prints the output value to the screen every 1.0 seconds.

Both are working properly

What I need, is code that will read the light sensor and write the value to the database instead of printing it to the screen.

Here is the working code that reads the DHT22 and writes the output to the database...

<php>
<?php function readSensor($sensor) { $output = array(); $return_var = 0; $i=1; exec('sudo /usr/local/bin/loldht '.$sensor, $output, $return_var); while (substr($output[$i],0,1)!="H") { $i++; } $humid=substr($output[$i],11,5); $temp=substr($output[$i],33,5); $db = mysql_connect("localhost","datalogger","datalogger") or die("DB Connect error"); mysql_select_db("datalogger"); $q = "INSERT INTO datalogger VALUES (now(), $sensor, '$temp', '$humid',0)"; mysql_query($q); mysql_close($db); return; } readSensor(9); readSensor(8); readSensor(7); ?>
</php>

Here is the code that reads the light sensor and prints to screen..

<code>

#!/usr/local/bin/python import RPi.GPIO as GPIO import time __author__ = 'Gus (Adapted from Adafruit)' __license__ = "GPL" __maintainer__ = "pimylifeup.com" GPIO.setmode(GPIO.BOARD) #define the pin that goes to the circuit---CHANGE THIS TO 11 pin_to_circuit = 7 def rc_time (pin_to_circuit): count = 0 #Output on the pin for GPIO.setup(pin_to_circuit, GPIO.OUT) GPIo_Output(pin_to_circuit, GPIO.LOW) time.sleep(0.1) #Change the pin back to input GPIO.setup(pin_to_circuit, GPIO.IN) #Count until the pin goes high while (GPIO.input(pin_to_circuit) == GPIO.LOW): count += 1 return count #Catch when script is interupted, cleanup correctly try: # Main loop while True: print rc_time(pin_to_circuit) except KeyboardInterrupt: pass finally: GPIO.cleanup()</code>

Can someone merge the applicable parts of these together to read the light sensor and write the output to the database?

Thanks for any assistance. :)


EDIT:::: Hmmmm code tags aren't working. Only attachments are images. I attached images of the code LOL Sorry.

Have you tried using node-red for your control. MQTT can be used to gather temperature data and report it to whatever you design.
here is a quick example using a potentiometer-> https://youtu.be/cklpn4pOrEI
another tutorial I like here ->https://youtu.be/fV78MQks6BI
 

Ringodoggie

Well-known member
Premium user
420giveaway
Pretty neat stuff. I saw something else similar called Cayenne. Drag and drop programming. Sure makes all those years of learning to code look like a waste. LOL
 

Ringodoggie

Well-known member
Premium user
420giveaway
Bump for Speed of Green


HTU21D: Temperature and Humidity
TSL2561: Light and LUX
MP115A2: Barometric Pressure
MHZ19: CO2
YL-69: Moisture Sensors
Pi Camera Version 2: Camera

Let me know when you get your stuff and get started.



MG811
SI7021
 

IrieHigh

New member
Wow that is really cool! I really would like to do something like this myself, but I have really no clue of programming.

The electronic side like soldering things together would be no problem.





@Ringodoggie

You think you could help me with the programming? W be really nice from you))

Thanks
 

Ringodoggie

Well-known member
Premium user
420giveaway
There are a ton of these type of monitors already programmed right out of the box. Search "Grow room automation" and you'll find a ton of options. Most of them, better than what we could program ourselves.
 

Latest posts

Latest posts

Top