Environmental Sensor Data with Web Driven Relays

As if there there hasn’t been enough projects with temperature and humidity sensors I’ve got another one! First off I must introduce you to Spike, my favorite little reptile. He’s the basis for this project.

As with most reptiles, Spike needs a pretty constant temperature and humidity level in his cage. Right now I just monitor his Temp and Humidity by little gauges stuck to the glass. While these work fine when I’m home I’d like to be able to monitor his environment while I’m away for the weekend.

On to the actual project: I’d like to use the my newly ordered Core to take environmental readings in his cage and upload them Apache on my Raspberry Pi. Ideally I’d love to have graph of the readings and an average over the last hour or so. I’d also like to be able to control his heat lamps, day lights, and heated rock (yes, he’s spoiled) from the web. I’d also like to have all the above on a schedule.

If I really wanted to add to the complication I’d add a webcam and have it viewable on the same page. I’m a Systems Admin by day, and very much a newbie when it comes to the world of Arduino’s and open source projects. Any help and advice would be greatly appreciated and welcomed.

I’ve seen lots of projects in the Arduino world that use the SainSmart 8-Channel Relay Module so that was my first thought for the relay control. I’m undecided on the humidity / temp monitoring, but this was an option I was looking at: AM2302

1 Like

I have a SainSmart 4-channel relay board that I use to toggle outdoor lighting from simple simple rocker switches mounted inside (no microcontrollers involved, just switches to pass 5V DC when they’re on). The relay works great and has endured a wet, toasty summer and a record-breaking winter (well, two days of the “polar vortex” anyways). I can’t complain there!

As for the sensor, the one you posted looks good and it should work with the DHT22, DHT11 and similar (Blocking version) library. If you aren’t afraid of putting a breadboard in the cage, you could get a breadboard version of that same sensor called DHT22 for $2.50 less. And still cheaper (but less accurate) is the DHT11 at $5.00.

The only problem you might have is that the relay board wants 5V, but the Spark Core only outputs 3.3V. Unfortunately, I’ve never messed with a DC-DC step-up converter, so I can’t offer any personal advice there. I tried looking on Adafruit’s site but couldn’t find one with a couple of quick searches. I did find this one on Sparkfun that may do the trick for you.

If you want a good stats storage and retrieval system, I love Graphite. It’s a little tricky to set up, but it’s awesome once you get it going. I plan on writing a library for submitting stats to a Carbon daemon using the TCP client library as soon as I can get the issues with my 2nd Spark figured out.

My first real foray into the world of Arduino and newbie-friendly microcontrollers involved an Arduino and a DHT22 sensor, so it’s a good first project. It can be a little challenging at first, but it’s not too terrible.

2 Likes

Looks like @wgbartley has you covered with great detail already! :smile:

I just wanted to mention you should think about building in a hardware cut-off for the heated items. A simple thermistor to create negative feedback (open the relay, or better yet open a second in-series relay) should work well to keep Spike from taking a permanent tropical vacaction.

You never know how reliable your code, electronics, power or internet connections are going to be…

a relay that should work nice with your setup is this http://www.amazon.com/Amico-SSR-25DA-Temperature-Control-Solid/dp/B004HZN628/ref=sr_1_1?s=hi&ie=UTF8&qid=1389593751&sr=1-1&keywords=solid+state+relay

A couple of dollars more expensive but you get a nicely compact unit that is rated down to 3 V and is also solid state so no clicking noise when switching and no worry of the relay breaking because of to many duty cycles. I have this for my SousVide machine which works nicely.

1 Like

If you want to use the 4-channel relay board, you can without a step up board. you would need to utilize the JD-VCC on the board…
basically, use a 5V power wall wart, and split it to power both the relay board (jd-vcc) and the spark (which can take up to 6v).
the problem with the spark is that it only outputs 3.3v. if you isolate the power for the relay board, the spark only handles signaling, and as long as the jd-vcc jumper is set correctly, the relay board will only expect a small power signal to switch the relay…and from what i understand, isolating the power on the relay board is actually the preferred method.

@wgbartley Thanks so much for the information. I looked at putting a dht22 on a breadboard inside the cage, but i’m pretty sure he would try and climb on it. Such is the way of the dragon. :wink: That’s why I was looking at one with leads, but still used the same library.

And now I feel like and idiot. My original plan had been to use a Arduino Uno for this project so I’ve been messing with 5v relays, it never crossed my mind after finding the Spark Core that it was only 3.3v. I’m glad to see there is options tho. I don’t know much about Graphite but I’ll take a look.

@BDub Great idea! I’d hate for to loose internet for over the weekend while I’m gone and leave all his heating lamps and lights on.

@sjunnesson Nice find. I’d love to use a SSR to keep from hearing the clicking noise early in the morning.

@avidan Thanks for the info. That sounds like the way to go. I’ve found a Solid State Relay Board (Here) that would keep me from having to hear all the switching and with your idea it sounds like one less point of failure.

How would I isolate the power from the switching? Sorry for still being very new at this, but I guess we all have to learn sometime.

@shocku992 a quick not about that relay board. It is rated at 2A so if your heating stone or heating lamp is using anything more then 100W I would worry. Probably better to look at a bit beefier relay

Be careful with that Chinese Amazon SSR… after looking at it a little more closely I remembered why SSR’s don’t typically pop to the top of my mind with thinking about switching AC. They are expensive.

That Amazon one smells too cheap to be good… the reviews claim some issues with it. Fotek does check out with UL’s database but are you really getting that one that they got approved?

Cheapest one on Digikey by Crydom is $20 and is only 3A at 60VDC (vs. 25A 240VAC of the chinese one):
http://www.digikey.com/product-detail/en/DC60S3/CC1126-ND/221844

Next in line at Digikey by Omron in price is $25 and is 10A 264VAC (but 5V input min):
http://www.digikey.com/product-detail/en/G3NA-210B-DC5-24/Z918-ND/206389

Want 25A 264VAC from Omron? You’ll pay $31 (but also 5V input):
http://www.digikey.com/product-detail/en/G3NA-225B%20DC5-24/Z921-ND/206392

Same ratings 25A 264VAC but need 3V input? Crydom has your back for $41:
http://www.digikey.com/product-detail/en/D2425/CC1006-ND/139477

Compare Chinese spec:
http://www.fotek.com.hk/page1e.htm

To similar component from Crydom:
http://www.crydom.com/en/Products/Catalog/s_1.pdf

Looks like at 3.3V input you’ll be sourcing 7-8mA which is fine for the Spark Core :spark:

Just put it all in a Fire Proof box and a check your circuit breaker’s operation! xD

thanks for the tip. The SSR I have been running now the last half year weekly without any problems. Have been running it at up to 18 hours cook session and so far so good. Could just been lucky though…

Thanks for all the information guys!

If I do decide to go for the relay board I believe each relay is rated at 10amps, so that shouldn’t be a problem even with 100w bulbs. At least that’s my understanding.

Tho I really like the idea of using the SSRs I’m leaning toward @avidan’s idea of using the jd-vcc on the relay board. Does anyone see a problem doing it that way?

I’ve also found a 5v 10a power supply that should be enough to power the Spark Core, bulbs, and heating rock. Link

It’s slowly starting to come together in my head. This community is awesome, thank you guys for all of your help as I slowly learn. The problem is I have a ton of idea’s and not enough knowledge (or money) to implement them all. After this project, I may work on a Spark Core powered alarm clock with RGB light strips to fade in as an artificial sunrise, but I guess I should get this project finished first. Thanks again!

Well, my relay board came in, and I must say it’s awesome! I bought a really cheap extension cord and wired it up to the first relay. I’m using my regular Arduino until my :spark: comes in. Hopefully my Temp/Humidity sensor will come in soon as well as my :spark:. Then I’ll be getting somewhere.

1 Like

Wow I missed your post about the SSR board. Yeah that looks like it will do the job, and I like the fact that it has OMRON UL recognized SSR’s with what looks like 2A pico fuses in series with each one! Very nice price too.

Update:

Using Bdub’s remote start application and wgbartley’s DHT22 library, I was able to create a very basic website that outputs temperature and humidity. I also kept part of the tinker application in my code so that I can turn on and off the relay’s I have. For testing I just have one hooked up on D7. Today I was trying to control that relay based on the temperature in the cage. I assumed (first mistake) it would be as simple as an if statement.

I wrote a if statement that said:

if (t <= 80) {digitalWrite(D7, HIGH)} else {digitalWrite(D7, LOW)}

That didn’t work, so maybe I can get some quick advice as to what I may have done wrong.
Thanks everyone!

Hmm…

if (t <= 77) {
  digitalWrite(D7, HIGH); // More Heat!
} 
else if (t >= 80){
  digitalWrite(D7, LOW); // Less Heat...
}
// else it's 78 or 79 and this gives you a couple degrees of hysteresis
// which will prevent relay chatter and allow for thermal capacitance lag

That makes sense. I’ll give it a try when I get home. In my code I did have it all broken up by lines and with semicolons. In fact, I’ll paste in exactly what I had later this evening.

I like the few degrees difference, that will help keep it from switch back and forth too much. I was thinking about using a count variable or a time variable so that it only switched every 5 minutes or so.

Thank you Sir, I’ll give it a try.

Oddly Enough this still isn’t working. I’ll show you what I have, tho it’s basically just copied and pasted so I don’t know what is going on.

My Code

Step one, Does the D7 led at least turn on and off?

Step two, try 77.0 and 80.0 in your if/else statements.

Step three, are you sure digitalWrite(D7,LOW); is for more heat? Not HIGH?

Step four, how much voltage is going to the relay board when D7 is on. Hopefully more than 2.5V.

Step five, wired up to the correct terminals on the relay board?

Step six, unplug AC and check the fuse (green thing)… is it still 0 ohms, or is it open?

The D7 LED doesn’t, In fact, that’s why I hooked it up there.

Great idea, tho it didn’t seem to make a difference.

As odd as it sounds it’s right. Thees relays switch on LOW

I’ll see if I can find a voltage tester, but I know the relay’s are working fine. I can switch it on and off with both a terminal command and the tinker app.

Just gathering more info, you bought the SainSmart 2A SSR board right?

I’m actually using the 8 channel. SainSmart 8-Channel Relay Module