Welcome to UK420

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more!

This message will be removed once you have signed in.


Sign in to follow this  
Followers 0
dboi88

Raspberry Pi Grow Controller

86 posts in this topic

Hi guys, i just wanted to introduce myself and my ongoing project. I know a lot of people will want to follow my progress with this and i’m pretty sure i’ll need some contributors before the end of this project. I’ve read a few other threads here and there but not seen any that have actually gone somewhere and produced any results although some are ongoing and look rather promising. So i’m going to take the time to let you all know what I’m up to and what i want to achieve so that anyone else who is interested can join in and reap the benefits. This project was born out of a frustrating lack of control systems that operate on a day and night basis as well as controlling heaters and extraction fans. I’m not even aware of a commercially produced system that performs this job under £1000. I know how important it is to have a controlled night time drop in temperatures so why doesn't anyone cater for this?

I plan to use a raspberry pi as my main controller.

The basic requirements i’m looking to achieve with my project are;

  • Lighting control

  • Separate night and day temperature settings

  • Separate night and day humidity settings

  • Must have full and independent and automatic control over extraction, heaters and humidity foggers

  • All data must be fully logged

  • Full web interface for controls and monitors

  • LCD screen readouts and basic settings control on the unit itself

At the minute i’m in the ‘proof of concept stage’. I’m buying components bit by bit and proving to myself that what i have in my head will transfer to practice. For example how do you get a raspberry pi to record a temperature? Or how do i measure the moisture level of the soil? These are the questions that need answers before even thinking about putting the whole thing together. Then when each of these all work i can start to buy everything i need to build the system and start on the main code.

The next few posts will explain the steps I've been through already.

raspberry-pi-800x800.jpg
Edited by dboi88
8 people like this

Share this post


Link to post


The first thing i worked on was the temperature sensing. For these i decided to go with a TMP36 sensor. This is a 3 pin sensor that works by passing a voltage through it, the temperature can then be determined by how much the voltage drops. TMP36 are used everywhere! pretty much any digital temperature probe you’ve got will include one of these so the amount of data available is quite extensive making it the perfect sensor for our uses. The problem with using these with a raspberry pi is they give back an analogue signal. The pi only has i/o ports (i/o =in/out) that will read a digital signal i.e. on or off. We need to read the voltage being returned from 0 - 3.5v 0 being -40c and 3.5v being 125c. For this we need an adc chip (analogue to digital convertor). This will convert the analogue signal to a number that we can actually use. I chose an MCP3008 chip because they are less than £3 each and i found a guide here with all the complicated bit bashing code already worked out(it would literally take me months of work to do this myself). This chip has 4 analogue inputs.

So the basic concept i’m trying to prove is that the pi is capable of being set up to take an accurate temperature reading of the room. This should produce a value that we can later use to determine fan and heater states. This data should also be logged in a database that can be used to produce graphs.

This is the guide i found to setup the circuit.http://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi/overview This guide is actually to make a volume control for a music player but hey the concept is the same.

This is my circuit:

DSC_0209.JPG

This is the code used to get the value from the adc chip, convert it to a temperature reading we can understand and use later then log it to a database. I’ve not included the bit bashing code as it would make little sense to even a seasoned programmer and can be found in full in the guide above.

# this creates a function called UpdateDB that when run will update the database with the latest value

def UpdateDB(sensor_id, temperature_reading):

# this connects to the database and provides log in values obviously removed

db = mdb.connect(host="localhost", port=****, user="****", passwd="*****

cursor = db.cursor()

#this provides the values to be inputted to the database

querystring = "INSERT INTO temperature (sensor_id, log_date, log_time, $

print(querystring)

# this provides the commands to create and finish the database insertion

cursor.execute(querystring)

db.commit()

db.close()

#this creates and empty list

templist = []

# this defines the last time as the current time

lasttime = int(time.strftime("%H%M"))

#this is the code that runs continuously

while True:

#this defines this time as the current time

thistime = int(time.strftime("%H%M"))

#this checks if this time is not the same as last time and runs the indented code if the time has changed this means the code runs every 1 minute as this is how often this time will change

if(thistime != lasttime):

#this defines average temperature average of templist

avgtemp = (sum(templist) / len(templist))

# this runs the UpdateDB command with the average temperature for the last minute

UpdateDB(1, avgtemp)

# this prints the values sent to the database

print("----- DB Updated: " + str(avgtemp) + " (" + str(sum(temp$

# this deletes the templist and creates a new empty list to start again

del templist

templist = []

#this is the code that runs if we have not yet got to the next minute

# this defines which channel to take the reading from in this case channel 0

potentiometer_adc = 0;

# this defines trim_pot and calls the bit bash code that i’ve excluded that will give back the reading

trim_pot = readadc(potentiometer_adc, SPICLK, SPIMOSI, SPIMISO, SPICS)

# this takes the reading from above and converts it to a temperature

temperature = ((float(trim_pot) * 3300/1024) -500) / 10.

‘’’ this code runs every second, it takes the temperature read out and adds each one to the templist to then take an average on the entire list when the minute changes

tempc = temperature # put temperature variable here

print ("Temp: (" + str(thistime) + ") " + str(tempc))

templist.append(tempc)

lasttime = thistime

time.sleep(1)

It works! i’m getting a solid accurate reading with no fluctuations. There is a graph below.

tn_gallery_54545_7768_16797.jpg

9 people like this

Share this post


Link to post

Looks interesting,I hope you achieve all your goals with this project mate.

I doubt I'll have any useful input as i have no experience playing with a pi yet but it is on my to do list and I hope to pick up a few pointers from you :oldtoker:

1 person likes this

Share this post


Link to post

Why not use the dht11 or 22 combined thermo/humidity sensor?

2 people like this

Share this post


Link to post

Looks interesting,I hope you achieve all your goals with this project mate.

I doubt I'll have any useful input as i have no experience playing with a pi yet but it is on my to do list and I hope to pick up a few pointers from you :oldtoker:

thanks mate, hopefully you will. If you ever do get started with the pi drop me a pm i'd be interested in what project you get into

Why not use the dht11 or 22 combined thermo/humidity sensor?

i considered them but i decided i'd prefer to go with the tmp36 as they're easy'll waterproofed and turned into probes without losing any sensitivity, cheap, small and i'm planning on using a lot more temperature sensors than humidity sensors in my final build so i'll probably end up using two or three seperate humidity sensors

Share this post


Link to post

Looks interesting ;) will be following this with enthusiasm, though I've got all the stuff for an ATC800+ twin variac build. Like it though :yep:

1 person likes this

Share this post


Link to post

Hi it's always good to see a stoner geek

I am an electrical engineer and I work in and love embedded real time control and I have quite a bit of experience in a lot of aspects of programming and electronics and I am always playing with something

I have used a few micro controllers I program in c but my raspberry pi is left unused, because as you have found it doesn't have an adc which is a big let down IMO it's just a unnecessary hassle building an external one

I have built a fan controller and to do that sort of DSP stuff you need a 32 bit processor like an stm32 or a pic32mx but for standard stuff like logging temps an 8 bit processor is quite sufficient if I were you I would not use a pi but use an atmega328 like an arduino uses its nice and easy stacks of support the pi is aimed at multi media applications not real time control

You could use an arduino but its best to learn c programming properley and the avr is a really good platform for tat

I could talk all day about electronics and there are many ways to measure temperature depending on the range and accuracy but the tmp36 is an old one now and there are better available check out the mcp9701a iirc it has 28mv/c resolution that's nearly three times better than the tmp and there are even better ways than the old analogue techniques now that don't need calibrating and don't drift etc

I am interested to hear how you plan on controlling your fans?

Nice project though I will watch this thread

Edited by Davey Jones
7 people like this

Share this post


Link to post

I am an electrical engineer and I work in and love embedded real time control and I have quite a bit of experience in a lot of aspects of programming and electronics and I am always playing with something

Then i might have a few questions for you soon. I've been struggling recently with the best optocoupler/relay/transistor set up to turn on a mains circuit with the 3.3v supplied by the pi's GIPO pins. If you have any thoughts on that i'd love to hear them.

I agree the ADC chip is a glaring omission from the Pi but 'a hassle' to add it is not. literally just 4 wires to connect with 30 lines of bit bashing code to include in your code.

I prefer the Pi to the arduino for a few reasons. You can't have an SQL server on an arduino and updating one on an other computer would be very difficult to achieve. I see it like this. There isn't anything i'm aware of that the arduino can do that can't be achieved with the Pi but there is a lot that i know you can't do with the arduino. I've also already dealt with webservers, SQL databases and learned python before so i didn't fancy learning a whole new language for this project. I know a good few people who have ongoing Pi/python projects that i can collaborate with as well as the past projects I've done.

For the fans i was thinking something along the lines of just a few separate circuits with a different resistor on each so i could have 3 or 4 fan speeds and i'd just turn one on at a time. I'd be interested to know how you would do it though.

I'll take a look at the mcp9701a they could certainly be an option.

1 person likes this

Share this post


Link to post

Wow a rather glaring omission from my first post, soil moisture readings! I want this system to not only monitor the moisture readings in each pot i also want each pot to be watered independently. I did a lot of research on soil moisture sensors and there are lots out there but i couldn't find anything to purchase that would take a moisture reading at anything more than an inch or two depth, and then waterproofing them wouldn't be the easiest task. I came across diagrams for diy probes but all seemed to rely on calibration after being built so building loads of these and then calibrating them all would have been an impossible task.

This is what i came up with in the end. A 6.35mm jack. As it has 3 connections on the jack i can use two of these as the two probes. This means i can buy as many of these as i want and everyone will be perfectly calibrated as the distance between these two points will always remain the same.

med_gallery_54545_7768_372104.jpg

I then waterproofed this to make a probe that could be inserted to any depth within the pot. If you've never used this stuff before your missing a trick! it’s called poly-morph and you can buy it at maplin. It’s plastic granules that melt at 60c and you can mold it into whatever shape you want and it then hardens back into solid plastic. Really hard plastic!!

med_gallery_54545_7768_53785.jpg

This is the wiring diagram and the readings are taken in the same way as the temperature readings were taken using the same code.

med_gallery_54545_7768_225063.jpg

med_gallery_54545_7768_7130.jpg

Unfortunately the readings aren't always accurate, sometimes i get some great readings, other times they get all sporadic and i’m not sure exactly why. Some playing around is in order i think. I've included a graph below showing some of the readings I've been getting. It seems the readings get sporadic as the soil dries out.

gallery_54545_7768_66857.gif

This is the diagram for a diy moisture sensor that i considered would have too many variables to be able to accurately calibrate.
gallery_54545_7768_11381.png
1 person likes this

Share this post


Link to post

Then i might have a few questions for you soon. I've been struggling recently with the best optocoupler/relay/transistor set up to turn on a mains circuit with the 3.3v supplied by the pi's GIPO pins. If you have any thoughts on that i'd love to hear them.

I agree the ADC chip is a glaring omission from the Pi but 'a hassle' to add it is not. literally just 4 wires to connect with 30 lines of bit bashing code to include in your code.

I prefer the Pi to the arduino for a few reasons. You can't have an SQL server on an arduino and updating one on an other computer would be very difficult to achieve. I see it like this. There isn't anything i'm aware of that the arduino can do that can't be achieved with the Pi but there is a lot that i know you can't do with the arduino. I've also already dealt with webservers, SQL databases and learned python before so i didn't fancy learning a whole new language for this project. I know a good few people who have ongoing Pi/python projects that i can collaborate with as well as the past projects I've done.

For the fans i was thinking something along the lines of just a few separate circuits with a different resistor on each so i could have 3 or 4 fan speeds and i'd just turn one on at a time. I'd be interested to know how you would do it though.

I'll take a look at the mcp9701a they could certainly be an option.

There's a few ways to switch ac mains from a microprocessor it depends on what you require and how much you want to spend optocoupler for isolation and a relay is common, solid state relays are another but the opto coupler and relay is probably the way I would do it but its impossible to say what's the best one, you just get a suitable relay and size the opto couplers current so it can handle the relay coil load its not difficult at all it all depends on your setup as to what currents you are switching and what voltages are available

Anything that adds work can be considered a hassle! When it's hardware and software it's ad,ded expense added work and added opportunity for it to fuk up! But it is all fun to me and the learning curve can make lots of these hassles fun

I would prefer the pi over the arduino as the arduino is aimed at none programmers given your experience I was thinking of the atmega328 processor as it is extremely versatile and capable of achieving all the things you mention in your op comparing them is not useful as the pi uses a new age 32 bit arm and the atmega is an 8 bit avr

We can't compare 32 bit processors to 8 bit as they can obviously do more the pi is aimed at multimedia PC applications SQL and all that sort of stuff is not my thing I know nothing about it and don't plan on learning so if that's what floats ya boat the maybe the pi is for you for me if I want pi performance I just use another arm based chip that has all the peripherals onboard and I can do all things DSP cheaper and better for me

But your requirements in the op doesn't require 32bit processing if you have support and other reasons then that's how it is no one way is ever the right way

You can't control fans by placing series resistors inline to drop the voltage it's just too inefficient for a start, how I do it these days is I built a home made inverter drive but that is quite difficult to do its an ongoing project that has kept me busy for a few years now I love it unless you have equipment and lots of electronics experience it's not really advisable to start its certainly not something that could be done in a DIY thread so you might have to use other methods like variacs or whatever your happy with

The mcp9701 is one of a range of thermistor IC's there's lots going on inside the can that means less hassle for the hardware stage

Good luck

2 people like this

Share this post


Link to post

So i have a moisture sensor that at least gives me some readings and a temperature sensor that gives me some great readings so i decided to box this up and turn the temperature sensor into a probe. I’ve then put this in the room and left if for a while to see what kind of readings i get in the long terms.

Pictures of the probe’s and a nice sandwich box to make sure i don’t spill any water over the pi.

gallery_54545_7768_328385.jpg

These are the two graphs for the last few days of readings. Obviously at this stage the heaters and extraction fans are being controlled separately and watering is done manually, the pi is only monitoring the levels.

gallery_54545_7768_29114.gif

gallery_54545_7768_66857.gif

If you’re interested in how i’ve achieved the night time drop and control over both the heaters and extraction take a look at this thread. I’ve included pictures and circuit diagrams if anyone considers making one themselves..

http://www.uk420.com/boards/index.php?showtopic=334119

6 people like this

Share this post


Link to post

:smartass:

That's crazy dude, very interesting, I'll be watching :)

Good luck.

:yingang:

2 people like this

Share this post


Link to post

The soil probe looks like some good innovation!

Have you tried a capacitor to smooth the output?

The sporadic readings are because it goes open circuit when dry and grounds the adc input there are proper capacitive moisture sensors available commercially dirt cheap try one

Or you can try and rework the probe to have a bigger surface area, be careful when thinking things don't need calibrating no two items are the same and almost everything needs calibrating in reality

You should be looking at all these digital spi and i2c sensors they are much better

1 person likes this

Share this post


Link to post

No i haven't tried the capacitor yet, I've picked up a bag from maplin so it's on the list. I've not brought the pi down in a little while as I've been fine tuning the settings on my thermostats in the room, the numbers on them are a load of rubbish! ;) So i've got a few new things to try when it comes back down.

The problem I've encounter with the spi and i2c sensors is the low number of programmable address, normally between 4 and 8. I'm going to want i lot more than that. They also don't lend themselves well to my application, I've only seen them come as a chip and i want most of mine to be probes.

1 person likes this

Share this post


Link to post

You can't control fans by placing series resistors inline to drop the voltage it's just too inefficient for a start, how I do it these days is I built a home made inverter drive but that is quite difficult to do its an ongoing project that has kept me busy for a few years now I love it unless you have equipment and lots of electronics experience it's not really advisable to start its certainly not something that could be done in a DIY thread so you might have to use other methods like variacs or whatever your happy with

I always assumed a variac was another name for a variable resistor but had never actually read up on them at all. So thanks for that, i guess i'll be going with 2 or 3 variacs then. I'm not too bad with DC but AC melts my mind sometimes :fear:

1 person likes this

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0