Jump to content

Raspberry Pi Temperature Monitor


3potheads

Recommended Posts

Evening all,

 

I've made the below guide for anyone interested in adding some temperature probes to their grow room. It will help if you have a little bit of previous knowledge in using CMD line interface (CLI) but it's not essential. You should be able to do the work with zero previous knowledge, just know that it might take a few evenings. Patience when it comes to connecting the probes up is required though!

 

I have only provided a few links as I'm not sure on the policy for using loads of links but if I'm OK to link to all the software and parts you need then I will edit the post and add them.

 

Let me know if you find anything missing or any steps that need more/less info. Hopefully someone finds this useful!

 

Raspberry Pi Temperature Monitor (& More!)

 

So this guide is for anyone who wants to create a DIY temperature monitor device. You can probably buy something like this that is already setup, might have more features and might even be cheaper but where is the sense of accomplishment (or failure!) in doing that!

This guide will explain how to use a Raspberry Pi as a temperature monitor. There are other devices that can be used (Ardunio) but I have personally only ever used a Pi so can only offer instructions on how to do this.

This guide will be limited to only providing Temperature readings for now and you are limited to 5 probes per Pi, if you want/need more probes you will need more Pis for now.

 

Things you will NEED:

 

Raspberry Pi
    I use a mixture of models. Model 3 would be the quickest to setup/use. Pi Zero WH would be the cheapest and lowest power usage. IT NEEDS GPIO PINS!
MicroSD Card
    These are so cheap now that I would suggest spending the £10 for a 64GB but 16GB would more than suffice.
Temperature Probes
    DS18B20 for a waterproof probe with 0.5c accuracy (Can use up to 5 ONLY)
    I got probes with a 5m tail but you can get less if you wish.
4.7K Resistor
    Needed as a pull-up between live and the data cable
Power for Pi
    Standard micro USB required. You want AT LEAST 1a plug with 2a+ being suggested for adding lots of peripherals.

 

Other things you need are:

 

Case for the Pi - Doesn't have to be fancy but something to protect it is a good idea.
Way of writing to MicroSD card
Internet
WiFi name and password
K/B & Mouse & HDMI Cable and capable TV/Monitor - Not required if using headless and setup before hand.
Putty software (or another SSH terminal)


Other things that make this easier

 

Breadboard
Dupont cables
Notepad++
If using a Pi Zero you may need a micro usb to USB A adapter to connect USB devices


OK, so you've decided to embark on this journey and create a DIY temp monitor to use at an undisclosed location! I'm going to imagine you know a few bits about windows, SSH/Terminal and connecting an SD card to your computer/laptop. I'm assuming you are using Windows OS here...

1. Install Raspbian on your SD Card
    - I won't go into loads of detail here, there are many guides online how to do this
    - Download Raspbian Lite : There is not much point in getting the full version as you should be controlling the Pi from another device most of the time. - https://www.raspberrypi.org/downloads/raspbian/
    - Extract .zip file and note down location of .img file that is extracted
    - Install Raspbian Lite to the SD Card : Follow these instructions:
    Download balenaEtcher and install it.
    Connect an SD card reader with the SD card inside.
    Open balenaEtcher and select from your hard drive the Raspberry Pi .img or .zip file you wish to write to the SD card. - Location from above
    Select the SD card you wish to write your image to.
    Review your selections and click 'Flash!' to begin writing data to the SD card.
    - Make a cup of tea!
    
2. Configure installation of Raspbian for 'headless' use
    - Enable SSH for remote terminal access
        Open SD card in File Explorer
        Enable 'File Name Extensions' : In windows 10, Click 'View' (Top of File Explorer) --> tick box for 'File Name Extensions'
        Right click in blank space --> New --> Text Document
        Rename newly created file to  ssh  - this needs to have no file extension and only contain those letters! Say yes to a warning about changing the file type.
    - Add network info : This will allow the Pi to auto-magically connect to your WiFi so you can logon via ssh/terminal    
        Create a file in the root of boot called: wpa_supplicant.conf (instructions below). Then paste the following into it (adjusting for the name of your country code, network name and network password):
        Open SD card in File Explorer
        Enable 'File Name Extensisons' : In windows 10, Click 'View' (Top of File Explorer) --> tick box for 'File Name Extensions'
        Right click in blank space --> New --> Text Document
        Rename newly created file to  wpa_supplicant.conf 
        Open new text document -- READ THE BELOW -- Notepad++ suggested as text editor!
        !! If using Windows you need to make sure the text file uses Linux/Unix style line breaks. I use Notepad++ (it’s free!) and this is easy to do using “Edit” --> “EOL Conversion” --> “UNIX/OSX Format”. “UNIX” is then shown in the status bar. !!
        Copy the below into the text conf file -- Replace 'SSID GOES HERE' with your SSID (this is your WiFi name) and replace 'PASSWORD GOES HERE' with your WiFi password -- Leave the double quotes in place
        
        country=GB
        pdate_config=1
        ctrl_interface=/var/run/wpa_supplicant

        network={
        scan_ssid=1
            ssid="SSID GOES HERE"
            psk="PASSWORD GOES HERE"
        }

        Make sure the file is called wpa_supplicant.conf  and NOT wpa_supplicant.conf.txt!

 

3. Setup the Pi!

    - WHERE EVER YOU SEE #### TYPE sudo IN PLACE OF THE ####
    - Eject the card, plug card into Pi and power on Pi
    - At this point you will need to know the IP Address of the Pi. If you are using a K/B + Mouse + Monitor then once the Pi has booted you can run the following command:

        hostname -I

    If you are using the Pi headless then you will need to find the IP Address another way. This is beyond the scope of this guide by some quick pointers:

        Use your Routers DHCP table 
            Your router will give every device on your network an IP Address, you can logon to the admin function of the router and get the IP Address from the list there. Each router is different but a quick google of your router model and 'DHCP List' should get you on the right track
            Try and ping the Pi - This might work but when I tested it I had more than 1 Pi running so it picked up the first one. Open a command prompt and type: ping raspberrypi.local
            Ping or try and SSH to every Ip on your subnet. Your laptop/PC will have an IP address which can be found by opening command prompt and typing: ipconfig  Use this IP to then try and connect to each IP within that subnet. For instance, if your IP is 192.168.1.5 then you can try and ping or SSH to each IP between 192.168.1.1 & 192.168.1.250
            
    Once you have the IP Address for your Pi open Putty (or alternative SSH terminal) and type the IP address into the 'Host Name' (or IP Address) field. Leave everything else for now.
    
    If all goes well you are now connected to the Pi! Congrats! It will now ask for a username and a password, these are defaulted to:

    
    Entering these should get you onto the terminal of the Pi, my suggestion here is to read the text and you will see that it warns of the default password. Follow the instructions to change the password to a more secure password.
    
    After you have changed the password you want to run the following commands. This can sometimes take a while so feel free to make a brew while these run! Enter on the command line:
    

    #### apt-get update
    #### apt-get dist-upgrade
    
    #### apt-get update - this will update the package list.
    #### apt-get dist-upgrade - this will update the installed packages to the latest version (This is the one that can take a while. Brew time!)


    -Rename Pi

-REMOVE THE SPACE AFTER etc BELOW! CloudFlare throws an error when I don't have the space in!

    We will name the Pi now which will make it easier to see when using the software, type the following:
    #### nano /etc /hostname
    Change the line from 'raspberrypi' to whatever hostname you would like
    Type:
    #### nano /etc /hosts
    Find the line with raspberrypi and change to the same hostname
    OK, now type:
    #### reboot
    The Pi will reboot and the name will have changed. To reconnect, if you are using Putty, right click the menu bar at the top (Where is says Putty Inactive) and choose restart session.
    
    Once you have completed the above you have a Pi that is ready to be used! This concludes the setup of the Raspberry Pi, you can now use this device for anything you wish! Continue reading on how to use this as a temperature monitor...

 

4. Create the 'Circuit'
    Here we are going to plug the probes into the Pi. There are many tutorials on the internet WITH PICTURES that will do a better job at explaining this than me. I will leave this bit up to you...


    There are many guides on the internet that will do a much better job of explaining this than I will so I would use this link here https://www.google.co.uk/search?btnG=1&pws=0&q=pi+ds18b20+tutorial but I will give an overview as best as I can. I would personally follow the 'Pi Hut' link as this is quite straight forward to follow. There are steps in here that create some software to get the temperature and log to the terminal, while you can complete these steps and it will give you a better understanding about how it is working it is not required as the software we will be using later deals with most of this for us.
    
    My suggestion here is to add a single probe first and then add more once you know you have the circuit created correctly and receiving a reading when running the test commands.
    
    I'm going to assume moving forward that you have followed the instructions to create the probe circuit, have connected the probes to the Pi, added the required lines to the boot/config.txt and completed a test of the probe and received a reading back in the terminal.


5. Install Temperature Monitor Software
    So you've made it this far eh! At this point you should have a fully working Pi that is accessible from another device via SSH, have probes physically connected and be able to take readings via a command line or a python program. If you don't have all this in place you need to go back and complete the previous steps.
    
    OK, so the software we are going to use is called 'Temperature Machine' and a link to info can be found here https://temperature-machine.com/docs/index.html

    Disclaimer: I did not write this software and take no credit for the work!
    
    I'll go over the steps here that you need to do but it is also listed on the 'Installing' page of the website.
    
    STEP 1 SHOULD ALREADY BE COMPLETED IF YOU HAVE SUCCUESSFULLY TESTED THE PROBES IN STEP 4
    5a. Setup 1-wire Support by adding dtoverlay=w1-gpio to /boot/config.txt - This allows the Pi to communicate with the temperature probe. Run the following command:
    
    ### bash -c 'echo "dtoverlay=w1-gpio" >> /boot/config.txt'
    
    Reboot the Pi after by typing:
    
    ### reboot
    
    5b. Setup apt-get to recognise the temperature-machine repository. - This will allow you to download the Temperature Machine software
    
     ### bash -c 'echo "deb http://robotooling.com/debian stable temperature-machine" >> /etc/apt/sources.list'
    ### apt-key adv --keyserver pool.sks-keyservers.net --recv-keys 00258F48226612AE
    
    5c.Stop any running versions already built from source (not required for a fresh install) - We'll ingnore this section as this is fresh install
    
    5d. Install - Install the software on your Pi!
    
    ### apt-get update
    ### apt-get install temperature-machine
    
    Time for another cuppa! Depending on the Model of Pi you are using this can take up to 30 mins.
    
    
    5e. Decide if you will be running the temperature-machine as a server or client.
    
    If you have a single machine, you want a server. If you already have a server running and want to monitor more rooms with more machines, add each of these as clients.
    
    Run the following before you startup the temperature-machine for the first time:
    
    temperature-machine --init
    
    It will ask you to choose and create the configuration file as ~/.temperature/temperature-machine.cfg.
    
    If you created a server configuration file above, update the default hosts.

    The default configuration will list some default values for hosts, such as:
    
    hosts = ["garage", "lounge", "study"]
    These are the machines you will be using in your final setup. Ensure these match the host names of each machine you plan to add. The values are used to initialise the RRD database on the server. If you need to change this later, you will have to delete the ~/.temperature/temperature.rrd file, losing historic data. It’s worth adding in some spares.
    
    After setting up the configuration, you can either restart the service manually (run ### systemctl restart temperature-machine) or wait about a minute and it will restart automatically.
    
    This will allow you to configure the setup of the software. I am only covering connecting 1-5 probes to a single Pi in this guide. If you think you will be adding more Pis and using this software, 1 for flower room and 1 for veg room for instance, then make sure you name the Pis now. you can name later but the historic data will be lost. If required I can cover in more detail connecting multiple Pis together with this software.
    
    
    That's it! If you have connected all the probes up correctly then you will now have a nice interface for reading some probes!


6. View the webpage for the temperature readings
    - Open a web browser
    - Browse to the IP Address of the Pi and add the port required
    192.168.x.x:11900
    
    
The pretty much concludes our evening broadcast. Be sure to tune in next time for more fun filled episodes!

 

 

large.Capture1.JPGlarge.Capture.JPG

 

What you should end up with

 

large.Capture2.JPG

Historic Data

Edited by 3potheads
  • Like 6
Link to comment
Share on other sites

Great write up dude. Look forward to seeing when someone else gives this a go and publishes their data!

Edited by mrevolve
Link to comment
Share on other sites

Great guide, not read through it yet, but this is something I’d been considering.

Any thing that needs to change when using a Linux/OS X based system? Apart from the obvious putty > terminal?

Link to comment
Share on other sites

12 hours ago, mrevolve said:

Great write up dude. Look forward to seeing when someone else gives this a go and publishes their data!

Thanks dude! Meant to do it ages ago but life has gotten in the way and only recently managed to get logged back onto the site.

12 hours ago, MidlandGrow said:

Great guide, not read through it yet, but this is something I’d been considering.

Any thing that needs to change when using a Linux/OS X based system? Apart from the obvious putty > terminal?

I don't think much would change with the end result but you might have to mount the SD card differently and use different software to create the SD card etc. The rest should be pretty similar. To be fair if someone is using Linux (Ubuntu etc) I'd imagine that they will know what differences there are and know how to do it. I might try and create a Mac OS X guide at some point as there shouldn't be too many differences.

 

 

Does anyone think that some pics throughout the guide might help? If so I can try and take some and edit the post.

  • Like 1
Link to comment
Share on other sites

 
 
 
 
17 hours ago, 3potheads said:

Does anyone think that some pics throughout the guide might help? If so I can try and take some and edit the post.

 

Pictures always help mate.

Link to comment
Share on other sites

Oh boy, oh boy, oh boy...   I'm very excited for this thread.  I have a birthday coming up, and know exactly what I'll be asking for. @3potheads thank you for putting this together.

 

For those who haven't read the thread that was the genesis to this guide.  

 

 

is an excellent read.   Once again, very excited to get stuck in to this.  

Link to comment
Share on other sites

Thanks UK_Canadian! It's a fun little mission with nice benefits at the end. Give me a message in here if you need any help or advice.

 

@Joolz I'm not sure how to edit my original post to put some info back in and add pics (once I've taken some) I'd also like to add some more links to places but not sure on the rules of posting to external sites etc

Link to comment
Share on other sites

  • 4 months later...

Awesome topic, have you thought to expand a bit further you could as an example using relays to flip lighting contactors controlling lighting, growth medium moisture levels, fan speed controlling.. yada yada yada I'm sure you've had some thoughts to what else you could experiment with :)

Link to comment
Share on other sites

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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use