Environmental Sensor Data with Web Driven Relays

Hmm, where do I start with this one…

First of all I can’t find a decent schematic for the relay version of this board. The company website is terrible, and their download link contains the SSR version of the relay module. Most of their links on other products don’t even work.

Looks like a couple things point to the same thing you are saying, 0V is ON and 5V is OFF. Which in my opinion is the most backwards ridiculous thing I can think of. Here’s a schematic someone drew themselves for one of the circuits:

Ok, fine it’s backwards… I hate it… moving on… :wink:

You opt’d for the 10A relay board because you needed the extra current? In my opinion the SONGLE relays should not be trusted with anything mission critical. I’ve torn apart quite a few chinese relays and they are garbage. Desolder them and put some TE Connectivity, American Zettler or Omron relays in there for anything you care about not bursting into flames. There are no fuses on these outputs like the SSR board… so I would also fuse the connections to your AC equipment. Imagine your heater element shorting out, the relay turns on, and your wiring bursting into flames because your circuit breaker is supplying 15A-20A and the relay welds it’s contacts together and probably melts too.

FYI: the normally closed contact is probably rated much less than the normally open contact on this relay, and most relays for that matter. I don’t think you are using those… but just keep that in mind.

Assuming D7 is always off, t must be <= 77. What do you see for a value of t1 if you read the variable remotely with a GET request? Have you ever gotten proper readings from the temp sensor?

1 Like

Yikes, thanks for the advice. Once I have this working right I’ll be building this all into a case and using some better relays. Right now the only thing hooked up to the relay is a small led lamp. Nothing mission critical.

The temperature and humidity readings work great. I use the “temperature” variable and a modified version of your remote starter website to pull them. It’s currently 79.02 in the cage.

I see the problem!

please add this to your setup() { }

pinMode(D7,OUTPUT); // enable the D7 output

:wink:

1 Like

Yes Sir, that would be a problem. Thank you...

1 Like

Here is where I’m at so far. I’m using parts of BDubs Remote Starter application and a custom website running on my Raspberry Pi to control Spike’s cage and display the data online. As of right now, taking some advice as to the reliability of the relays I’m using, The lamps are still hooked up to a timer when I’m not at home. I don’t want to cause a house fire! Once I get everything working the way I want, I’ll transition to some better relays.

I’ve also hooked up a basic RGB LED to the :spark: that changes color based on the current temperature. It’s a way to quickly glance at the cage and know what’s going on.

The next part will be trying to enable and disable the relays based the time of day.

2 Likes

Looks great @shocku992! Hope Spike is nice and comfy in his Wired life :wink: Now you need a TTL SPI webcam to upload a pic every 10 - 30 seconds :smile:

Don’t worry it’s on the ToDo list! :wink:

81*F! Sounds pretty nice on a cold day in MN… :slight_smile:

I’m finally getting a change to do some work on my :spark: this evening. As of right now my heat lamp comes on if the temperature dips bellow 80 degrees and kicks back off at 90. That works for the most part, unless I get a bad read from the dht22 (which happens at least once a day). Then it will kick the lamp on even if it’s not needed. The lamp will turn off when the temperature hits 90, and life will continue on. I’ve added a second read function that averages two temp reads 2 seconds apart. I’m hoping that will cut out the bad reads, I just hate having the delay in my code.

Spike’s main lamps turn on at 7:30 AM and off at 7:30 PM. This works great unless I flash the :spark: after 7:30 PM. Then it stays in the ON state until the next night. If I flash the core or it reboots at 7:31 PM then the cage will be in the ON state for 23 hours. That’s not ideal. Any good ideas on how to remedy that?

You can use a non-blocking way to do the reading instead so your program does not stop there for 2seconds.


You can use the RTC library to check the timing when the Core 1st started/restart to see the time. So you are not relying on the time you flashed the code or restart but the actual time of the day itself :smiley:

Awesome! Thanks so much. I’ll check out the Non-Blocking. As for the RTC, that’s what I’m using. The problem is I’m just using an if statement to check if the time is equal to 7:30 PM or 7:30 AM. If neither is true it stays in it’s current state. So If i reboot it at 7:31 PM it won’t turn off again until the RTC reaches 7:30 PM the next day. Or did I completely miss what you were saying?

Let me think of the code and get back to you later :smiley:

It’s probably just some changes to the if statement :slight_smile:

So you need to test if the (currentTime >= 7:30am && currentTime < 7:30pm) the lamp should be ON, else it should be OFF. I'm not sure what methods you have available in your RTC library, but you should be able to work this out. 24 hour time would make it easier. You might have to break it up like this:

// first check that hours are within the right range
if(currentHour >= 7 && currentHour <= 19) {
  // then make sure the minutes are correct
  if(currentHour == 7 && currentMin >= 30) { // >= 7:30am ?
    // turn on the lamp
  }
  else if(currentHour == 7 && currentMin < 30) { // < 7:30am ?
    // turn off the lamp
  }
  else if(currentHour == 19 && currentMin < 30) { // < 7:30pm ?
    // turn on the lamp
  }
  else if(currentHour == 19 && currentMin >= 30) { // >= 7:30pm ?
    // turn off the lamp
  }
  else { // Must be between 8:00am - 6:59pm
    // turn on the lamp
  }
}
else { // Must be between 8:00pm - 6:59am
  // turn off the lamp
}

2 Likes

24 hour time. Ya, that would make a lot of sense huh? I must admit to feeling a little foolish for not thinking about that. I’ve completely rewritten my code and I must say it’s working much better! It’s not pretty, but at least I’m learning. I just got my second Spark Core in the mail, so I’ll be starting to work on my Neopixel alarm clock this next week.

3 Likes