loading

Please note that there's a Git repo for code at:

https://github.com/jervine/rpi-temp-humid-monitor

If you'd like the latest fixes or would like to contribute. Thanks Jonny Ervine!


I had some issues with Kingston SD Cards, but the SanDisk cards I'm using now have run for weeks without issues, so I'm changing the parts list to reflect that.

Also, after some 49 days, 16 hours, the display flatlines, as the reading routines start returning the same number over and over again. A reboot clears it, so just reboot once a month until I figure out what's up.


Over the past summer, my vacation home had a small water leak for three months, and I realized that had I been measuring the humidity in the effected area, I'd have
seen it go to 100% for a long time and I could have dispatched someone to fix the small problem before it became a big one.
And since I've been playing with Raspberry Pi computers for a while now, and saw an inexpensive temperature/humidity sensor on AdaFruit, I had all the pieces I needed
to implement an inexpensive network-connected monitor.
The Bill Of Materials (BOM):
1) Raspberry Pi Model B
2) Case
3) SD Card
4) Temperature/Humidity sensor
5 ) Power Supply (I use PoE splitters, but any 5V 1A Micro-USB supply will work)
I used the following exact parts, but obvious substitutions can be made to match local conditions and the state of your junk box. Shipping and the availability of bundles
may effect your final price.
$35.00 RPi http://www.newark.com/raspberry-pi/raspbrry-modb-...
$ 8.12 Case http://thepihut.com/products/classic-raspberry-pi... (5.99 Euros)
$ 6.99 SD Card (Sandisk, not Kingston)
$15.00 Sensor http://www.adafruit.com/products/393
$15.99 PoE Splitter http://www.newegg.com/Product/Product.aspx?Item=N...
And a few other miscellaneous things like hand tools, soldering iron, hot melt glue gun, small pieces of plastic wood, etc.
Step

Step 1: Physical Assembly

Split the case, find the hardware bag inside, and set the rubber feet aside for later.

Attach the Raspberry Pi to the case bottom with the supplied hardware.

Remove the GPIO knockout with a razor blade or Xacto knife and snap the two case halves together.

To keep the power dissipation of the power supply and Raspberry Pi from effecting the sensor readings, I cut a piece of Azek plastic lumber about 1.1 x 2.4 x 0.75 inches as a standoff.

Heat up your hot-melt glue gun and stack the parts as in the picture. You'll have a few seconds to make the alignment perfect before the glue sets, so get the alignment close before you press the parts together.  Be careful not to use so much glue that it extrudes from the edges of the seams or extrudes into the case, where it might interfere with the SD card connector.

1) Glue the sensor to the standoff

2) Glue the standoff to the top half of the case. Be careful not to block the LED cutouts on the one side or the ribbon cable cutout for the camera on the other side.

3) Glue the case bottom to the top of the PoE adapter. Make sure the "LAN Out" connector is on the same side as the Raspberry Pi Ethernet adapter.

4) Stick the 4 rubber feet to the bottom of the power adapter.

5) Ensure the voltage-output selection switch is set to 5V. Put a dab of hot-melt glue in the switch to prevent it from being changed and destroying your Raspberry Pi.

<p>Ok gang, a colleague of mine helped out with a python script of his own that works really well with this project. You can set your temperature thresholds, and if three consecutive measurements exceed those thresholds, then an email is sent out using Python's mail feature. Example of the email received is below.<br>-----</p><p>Temperature and/or Humidity Anomaly Detected! </p><p>Temperature exceeded threshold for 3 consecutive <br>measurements at 2015-02-24 16:25:00</p><p>Humidity exceeded threshold for 3 consecutive <br>measurements at 2015-02-24 16:25:00</p><p>-----</p><p>I don't know how to attach the python script to this post, but I should probably make it available to wpnsmith so he can include it as an option.</p>
<p>Great, PM it to me and I'll figure out how to include it.</p><p>Thanks!</p>
<p>can u send me the script?</p>
<p>I can. Send me a private message and I will email you the python script for email alerts.</p>
<p>Hi Eduardo.</p><p>Will it be possible to send me the python script? I'm conducting a student project on the same topic and will be glad to have it as a reference.</p><p>You can mail it to me at qwamedusei@gmail.com</p>
<p>Excellent guide! Thanks for doing this.</p><p>Quick question for you:</p><p>I was going through the code and I have been trying to figure out how instead of having the y axis go in increments of 20, could I have the scale be in increments of 10? (Still going to 100)<br>Thanks again!</p>
<p>Good question! Sorry for the delay, the answer is well hidden. 8*)</p><p>in GraphTh.py after the line:</p><p>plt.axis(ymax=100,ymin=0)</p><p>add</p><p>plt.yticks(numpy.arange(start=0,stop=100,step=10))</p>
<p>I can't get it to start TH.c when it boots. It's pretty confusing since my rc.local file is essentially empty except for the /root/th &gt;&gt;<br>/root/th.log &amp; entry. I can tell it to print to the screen before and after that line and it does that just fine, and I can start the program manually after it boots up.</p>
<p>I'll say I had an issue with mine as well. I'm assuming being this recent you're running the newest image of Raspbian (Jessie), which is apparently known to have issues with certain things running out of the rc.local file (other comments below recognizing this, but not with any real solution). However, the issue I saw was not the rc.local file not running, it was that the file would run at boot but wouldn't actually read from the sensor. When I ran the tail cmd I would get that it was just printed up to the &quot;Sync to cycletime...&quot; message into the logfile but none of the temp entries -- and no entries were being added to the database. To get around this issue, I created a systemd service file and have enabled it to run at boot that way. This required modifying the th.c file to create a daemon as well. If you need any help figuring it out, let me know.</p>
<p>If you could tell me how you did this I would greatly appreciate it.</p>
<p>Hi,</p><p>in rc.local use this syntax:</p><p>/root/th &gt; /root/th.log 2&gt;&amp;1 &amp;</p><p>With &quot;2&gt;&amp;1&quot; you are redirecting errors to &quot;th.log&quot; together with normal output. In this way I saw that the problem was with mysql socket, basically I think that MySQL was still not running when th started.</p><p>I solved adding a delay in &quot;th.c&quot; before connecting to the DB. Just add line &quot;delay(60000);&quot; before line &quot;MYSQL *con = mysql_init(NULL);&quot;</p><p>It works for me!</p>
<p>I'm having the same issue (having to manually start th.c &quot;./th&quot; to get everything up and running.</p><p>I added the 2&gt;1 to my rc.local file, and now my th.log is giving me the error:<br>&quot;Can't connect to local MySql server through socket&quot;.</p><p>I added the &quot;delay(60000);&quot; in the line listed above, but no change.<br><br>Any ideas?<br></p>
<p>This was fixed by adding &quot;sleep 10&quot; to line above th&gt;&gt;th.log in /etc/rc.local file, fix given below for me.</p>
<p>I was having an issue after reformatting my drive and rc.local seems to not be running.</p><p>After looking, this can be updated by adding </p><p>&quot;sleep 10&quot; before the execution:</p><p>/root/th &gt;&gt; /root/th.log &amp;</p>
<p>Thanks for this, seems to have fixed the MySql failed socket connection on boot.</p>
<p>How do you connect the sensor to the pi?</p>
<p>Works great. Thanx for the write up. I need the code to email alert as well please. Also how can i change it from C&deg; to F&deg;?</p>
<p>I really enjoyed building this. I built 2 of them, and the worked great for a year. I updated when Jessie came out, and they no longer worked. I tried to patch them up, but was unsuccessful. Now I would like to try streaming video, but want to be sure it is going to last through time. Does anyone know a really stable way to stream video from numerous Raspberry pi computers to a web browser? I am monitoring with stills every minute, but want to go video. I have 5 cameras. Will have at least 8.</p>
<p>I upgraded to MacOS Sierra and now I can't view my temperature / humidity graph. Has anyone else run into this problem and have any tips on how to go about fixing this? I might just have to give up on my TH sensor project, and re-purpose this RasPi for something else. Bummer. </p>
So what error are you getting? It's possible there's a (m)DNS or Bonjour lookup problem, try going to http:// instead of http://name.local<br><br>
<p>I get a screen that says &quot;This site can't be reached... pitemp's server DNS address could not be found.&quot;</p><p>Thanks for your help! </p>
<p>I followed some instructions on how to re-setup apache2, etc. in Sierra, and that didn't seem to work. Then, out of the blue, I went to my graph site and it was back, working again. Can't explain it, but I'll take it! </p>
<p>Hi, I have a couple question for you.</p><p>I am getting stuck on the th.c bit. I have created the file in my root dir and when it hit make th i am getting this. Any Idea's?</p><p>root@raspberrypi:~# make th</p><p>cc th.c -o th</p><p>th.c:26:2: error: invalid preprocessing directive #defineRHT03_PIN7</p><p>#defineRHT03_PIN7</p><p>^</p><p>th.c: In function &lsquo;finish_with_error&rsquo;:</p><p>th.c:34:3: warning: incompatible implicit declaration of built-in function &lsquo;exit&rsquo;</p><p>exit(1);</p><p>^</p><p>th.c: In function &lsquo;main&rsquo;:</p><p>th.c:93:27: error: &lsquo;RHT03_PIN&rsquo; undeclared (first use in this function)</p><p>status = readRHT03 (RHT03_PIN, &amp;temp, &amp;rh);</p><p>^</p><p>th.c:93:27: note: each undeclared identifier is reported only once for each function it appears in</p><p>&lt;builtin&gt;: recipe for target 'th' failed</p><p>make: *** [th] Error 1</p><p>root@raspberrypi:~# ./th</p><p>bash: ./th: No such file or directory</p><p>Other question is it possible config a second sensor to it? and if so how?</p><p>Thanks</p>
<p>Awesome Tutorial! It is working well. </p><p>I was wondering how I can get the current temperature en humidity printed on my PNG. Can some help me out?</p>
<p>Could you possibly make a raspberry pi device that you could plug into your pc to display the pc's Core temp / clock speed / utilization in real time... output to some cool display made of nixie or neon tubes?</p><p><br>I think that would be totally bad as, and useful for gamers who don't want to tab out of a game to check hardware monitor or whatever</p>
<p>Just completed this.</p><p>Very pleased with the results.</p><p>Couple of alterations I had to make are; -</p><p>1. Ran the following to get ez setup - wget <a href="https://bootstrap.pypa.io/ez_setup.py" rel="nofollow">https://bootstrap.pypa.io/ez_setup.py</a><br>-O - | python</p><p>2. Had to enable root login</p><p>sudo nano /etc/ssh/sshd_config</p><p>look for </p><p>PermitRootLogin without-password</p><p>change it to</p><p>PermitRootLogin yes</p><p>3. Used <a href="https://www.instructables.com/member/scalimani" rel="nofollow">scalimani</a> solution to delay startup. as was generating SQL errors without it.</p><p>But all in all an excellent article. Thanks to all contributors.</p>
<p>Hi! I'm pretty far along on this, but the python script seems to be unhappy with something I have done. When I attempt to run it to verify that I'm on track, I discover that I am not when it returns as follows: </p><p>python GraphTH.py</p><p>GraphTH.py V1.69 12/04/2013 WPNS Thu May 19 03:51:15 2016 Samples: 18, DataPoints: 3 Anomalies: 0</p><p>Traceback (most recent call last):</p><p> File &quot;GraphTH.py&quot;, line 93, in &lt;module&gt;</p><p> plt.savefig(FileName)</p><p> File &quot;/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py&quot;, line 577, in savefig</p><p> res = fig.savefig(*args, **kwargs)</p><p> File &quot;/usr/lib/python2.7/dist-packages/matplotlib/figure.py&quot;, line 1470, in savefig</p><p> self.canvas.print_figure(*args, **kwargs)</p><p> File &quot;/usr/lib/python2.7/dist-packages/matplotlib/backend_bases.py&quot;, line 2194, in print_figure</p><p> **kwargs)</p><p> File &quot;/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py&quot;, line 526, in print_png</p><p> filename_or_obj = open(filename_or_obj, 'wb')</p><p>IOError: [Errno 2] No such file or directory: '/root/Graph/graphics/TH.png'</p><p>Only one diversion from directions to admit: I was getting by on &quot;sudo&quot; for a good part of this project even though the instructions said to run as root. I noticed no issues, though.</p><p>Anyone able to help me out?</p>
Did you create the /root/Graph/graphics/ directory (or if you are running with the pi user, it's probably /home/pi/Graph/graphics/ but then you have to fix the code...<br><br>
<p>Thanks! I ... should have taken it as a sign to review when I needed to say &quot;the only part of the directions I didn't follow was X, but I never compensated for this change.&quot; Awesome project!</p>
<p>Good morning!</p><p>I tried this project and it works really fine. I got just one last question. Under http://IP Adress/TH.png i can see the value from the last 18 hours.</p><p>Is there a option to display the values weekly, monthly or through a year? I don't like to open the database, i'd like to have it graphical</p>
<p>Sure, modify the SQL to get the data for the last (60*60*24*32) seconds (32 days), and then tweak set_major_formatter and set_major_locator for something like %m%d and matplotlib.dates.DayLocator</p>
<p>Excuse me . can we use ( wifi )instead of PoE splitters???</p>
<p>Umm, sure? Go right ahead, there are lots of WiFi setup totorials around, and the Pi3 even has built-in WiFi. Get a good power supply, if you see the power LED flickering or flashing, that's an indication that your power supply doesn't have enough capacity...</p>
<p>Hello everybody<br>I like this project and that's why I bought a pi. I tried to install but i failed. Can you help me?<br>I came up to step 8, my last successful step was: <br>emacs makeFile<br>change the two lines below to match this:</p><p><br>INCLUDE = -I/usr/local/include,/usr/include/mysql<br><br>LDFLAGS = -L/usr/local/lib,/usr/lib/arm-linux-gnueabihf -lmysqlclient -lpthread -lz -lm -lrt -ldl</p><p>Now copy th.c (included here) into your default directory. Change the password on line 68 from &quot;password&quot; to whatever you chose as the MySQL password.<br>But i can't find in &quot;password&quot; in the file.</p>
<p>What do you see on line 68 of the th.c file? It should look like:</p><p> printf(&quot;rh.c rev 1.79 12/04/2013 WPNS %sCycle time: %i seconds, %i retries\n&quot;,ctime(&amp;oldtime),CYCLETIME,RETRIES);</p><p> fflush(stdout);</p><p> MYSQL *con = mysql_init(NULL);</p><p> if (con == NULL) finish_with_error(con);</p><p> if (mysql_real_connect(con, &quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, </p><p> &quot;Monitoring&quot;, 0, NULL, 0) == NULL) finish_with_error(con);</p>
<p>Ooh i see the mistake! I opened the Makefile and edit the two lines (INCLUDE &amp; LDFLAGS). After that i searched line 68 in the same file.<br>Now i closes the Makefile but i can't find th.c, can you tell me how i can find it?</p>
<p>th.c is attached to that step in the Instructable</p>
<p>Thank you very much! I transmit the file with WinSCP and it works!<br><br>Unfortunately i'm hanging on Step 9 :-/<br>I can not access <a href="http://IP-Adress/TH.png" rel="nofollow"> http://IP-Adress/TH.png</a> or <a href="http://PI02/TH.png" rel="nofollow">http://PI02/TH.png</a> i just get the error 404 page not found.<br>Unter /var/www is a file named TH.png and a folder called html. I reboot my Pi but it didn't helps so i restarted the project on another sd card. The error is still present. When i try to access http://IP-Adress it will show me the Apache2 Debian Default Page</p><p><br>This was the last step i did:<br>root@PI02:~/Graph# python GraphTH.py<br>GraphTH.py V1.69 12/04/2013 WPNS Wed Aug 3 06:50:23 2016 Samples: 8, DataPoints: 3 Anomalies: 0 Copy to Web Server... Done at Wed Aug 3 06:50:24 2016</p>
<p>Two possibilities:</p><p>if your Pi is named Pi02, then try <a href="http://pi02/TH.png" rel="nofollow"> http://pi02/TH.png </a> or <a href="http://pi02.local/TH.png" rel="nofollow"> http://pi02/TH.png </a></p><p>Later releases of Raspian put the web server files in a subdirectory, so change this line in GraphTH.py:</p><p>Destination = '/var/www/'</p><p>to:</p><p>Destination = '/var/www/html'</p>
<p>The first i tried but the seccond one works! Thank you very much!</p>
Oops, see that the author has already replied, disregard
The structure of the webserver has changed since this instructable. You will need to adjust any scripts that place files in /var/www to place them in /var/www/html.
<p>Hi , I am not able to locate the code for SRC folder for .C files which we can see in M akefile. </p><p><a href="https://github.com/jervine/rpi-temp-humid-monitor" rel="nofollow">https://github.com/jervine/rpi-temp-humid-monitor</a></p><p>Can you please let me know where I can see these files.</p>blink.c blink8.c blink12.c \ blink12drcs.c \ pwm.c \ speed.c wfi.c isr.c isr-osc.c \ lcd.c lcd-adafruit.c clock.c \ nes.c \ softPwm.c softTone.c \ delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \ lowPower.c \ rht03.c piglow.c
<p>Sorry for the delay, those are all part of the WiringPi installation</p>
<p>cool!,can you send me the Python Script?</p>
<p>cool!,can you send me the Python Script?</p>
<p>for some reason, I can't get the th file to run on bootup. I've tried crontab, and rc.local, and even removed the part where it writes to the log file, and nothing. Can anyone help? It runs fine when I manually start it. </p>
<p>I couldn't, originally, get the wget ez_setup link to work -- for reference, I found it here: https://github.com/pypa/setuptools/blob/bootstrap/ez_setup.py where the project is upkept. </p>
<p>It had a few challenges, but it works great. I am going to add 3 more sensors.</p>
I now monitor 2 locations with temp/humid sensors &amp; cameras.

About This Instructable

533,385views

666favorites

License:

More by wpnsmith:Raspberry Pi Temperature & Humidity Network Monitor 
Add instructable to: