Notifications
Clear all

temperature controlled relay for a motor

4 Posts
2 Users
0 Likes
808 Views
(@tperry724)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

Folks,

Newbie here. We have a pump that circulates water around a lake dock in the winter to help prevent it from freezing. When no one is there the motor runs constantly, even on nicer days when the temperature is well above freezing. Rather than having it run constantly, I thought a Nano, DHT22, and a SSR could help solve the problem.

I've got the circuit pretty much mapped out but it's the code that's giving me trouble. I'd like to use hysteresis (I didn’t know the word until two days ago), but I've never coded it before, plus I'm very new to programming anyway. Essentially, from what I understand, with hysteresis you look at the previous state of something. In this case, a motor, I guess. From what I understand, when the temperature reaches the low threshold, say 35 degrees, the pump comes on. It runs until the temperature reaches the upper threshold, say 45 degrees when the motor shuts off. Problem is I just can’t see the code. I’m just wasting paper here as I try to work in out by hand. Any help would be appreciated.

In the code below, the redLed takes place of the motor.  The greenLed is just a status light that should illuminate when the temp is above the upper threshold.  

Best,

Tony

#include "DHT_U.h"
#define Type DHT11

int sensePin=7;
DHT DHTT(sensePin, Type);

float humidity;
float tempC;
float tempF;

float lowerThresholdTemp = 35;
float upperThresholdTemp = 45;

int redLed = 9;
int greenLed = 11;
int lastMotorState = 0;

void setup() {
Serial.begin(9600);
DHTT.begin();
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}


void loop()
{
humidity = DHTT.readHumidity();
tempC = DHTT.readTemperature();
tempF = DHTT.readTemperature(true);

if (tempF < lowerThresholdTemp && lastMotorState==0)
{
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
lastMotorState = 1;
}

if (tempF >= upperThresholdTemp && lastMotorState==1)
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
lastmotorState = 0;
}

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(". TempC: ");
Serial.print(tempC);
Serial.print(". TempF: ");
Serial.print(tempF);
Serial.println(". ");

}

   
Quote
 Foxy
(@foxy)
Member
Joined: 3 years ago
Posts: 56
 

I don't see much fundamentally wrong with the code although there is some overkill.  Why are you using a DHT11 just to measure temperature when a simple resistance temperature detector (RTD) would do the job just as well and should be both simpler and cheaper? Also why concern yourself with humidity and TempC when neither enters into the on/off decision?  I've used the SSR and it should work fine.  Just as an aside, where I live we normally use a bubbler to prevent freezing around docks.  (I have to be careful saying this because in at least one part of the US a bubbler is a drinking fountain!!) 


   
ReplyQuote
(@tperry724)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

@foxy  Thank you for responding.  I think I have it working fairly well now.  I'm new to this so everything takes me a long time.

Happy holidays!


   
ReplyQuote
 Foxy
(@foxy)
Member
Joined: 3 years ago
Posts: 56
 

@tperry724

If it's not broke don't fix it.   Another thing to keep in mind in is to put in a timer so once the motor starts or stops it won't stop or start again for xx minutes or or so independently of temperature.---just a thought in case it's useful.  


   
ReplyQuote