EcoRenovator  

Go Back   EcoRenovator > Improvements > Appliances & Gadgets
Advanced Search
 


Blog 60+ Home Energy Saving Tips Recent Posts Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Display Modes
Old 12-18-14, 02:00 PM   #51
nkuck
Lurking Renovator
 
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Just stumbled across this thread and I have a question.
What is the purpose of dividing by 2:
"Ssensor = analogRead(SsensorPin) / 2;"
"Tsensor = analogRead(TsensorPin) / 2;"
I am using LM34s and anticipating degF readings; I am getting strange results.

nkuck is offline   Reply With Quote
Old 12-18-14, 02:36 PM   #52
Daox
Administrator
 
Daox's Avatar
 
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
Default

Hello nluck. Welcome to the site.

The LM34 will output 10mV per degree F (the LM35 does the same, but in degrees C). Each 'step' (aka the number returned by the analog read function) on the arduino is roughly 5mV. So, 2 steps = 1 degree. Thus, I divide steps by 2 and your variables Ssensor and Tsensor are now in degrees.
__________________
Current project -
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
&
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Daox is offline   Reply With Quote
Old 12-18-14, 03:07 PM   #53
Daox
Administrator
 
Daox's Avatar
 
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
Default

Haha, I totally forgot to update this thread. The new software smoothing worked very well. It still wasn't completely flawless, but it was much better. I'll have to grab that code when I'm home and post it up.
__________________
Current project -
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
&
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Daox is offline   Reply With Quote
Old 12-18-14, 03:16 PM   #54
Daox
Administrator
 
Daox's Avatar
 
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
Default

Aha, found it after all.

Code:
/* Thermal Differential Controller

  The program monitors two temperature sensors and
  activates a relay when one sensor is warmer than
  the other.
*/

// Pins
int SsensorPin = 4;  // the pin to read solar panel temperature
int TsensorPin = 5;  // the pin to read water tank temperature
int RelayPin = 2;  // the pin to control the pump relay
int ledPin = 13;  // led pin to verify relay on condition

// Variables
int Ssensor = 0;  // holds the value from SsensorPin
int SensorOnDiff = 0;  // holds the Ssensor value plus on differential (OnDiff)
int SensorOffDiff = 0;  // holds the Ssensor value plus off differential (OffDiff)
int Tsensor = 0;  // holds the value from TsensorPin
int SensorReadings = 10;  // number of sensor readings to take
int Counter = 0;  // sensor readings loop counter
int OnDiff = 4;  // temp diff that must exist to turn pump on (dec C)
int OffDiff = 2;  // temp diff that must exist to turn pump on (deg C)

void setup() {
  pinMode(SsensorPin, INPUT);
  pinMode(TsensorPin, INPUT);
  pinMode(RelayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);  
  
  Serial.begin(9600);
  
  digitalWrite(RelayPin, LOW);  // turn pump off
}

void loop() {

  // read sensor inputs, convert to degrees, and assign to variables
  Counter = 0;
  while(Counter < SensorReadings) {
    Ssensor += analogRead(SsensorPin) / 2;
    Tsensor += analogRead(TsensorPin) / 2;
    Counter++;
    digitalWrite(ledPin, HIGH);
    Delay(250);
    digitalWrite(ledPin, LOW);
    Delay(250);
  }


  // calculate average temp from sensor inputs
  Ssensor = Ssensor / SensorReadings;
  Tsensor = Tsensor / SensorReadings;

  
  // add temperature difference to Ssensor value
  SensorOnDiff = Ssensor - OnDiff;
  SensorOffDiff = Ssensor - OffDiff;


  // if heat source is warmer than heat sink sensor, enable relay
  if (SensorOnDiff > Tsensor) {
      digitalWrite(RelayPin, HIGH);
      digitalWrite(ledPin, HIGH);
      delay(30000);
    }

  
  // if heat source sensor is cooler than heat sink sensor, disable relay
  if (SensorOffDiff < Tsensor) {
    digitalWrite(RelayPin, LOW);
    digitalWrite(ledPin, LOW);
    delay(1000);
  }
}
__________________
Current project -
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
&
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Daox is offline   Reply With Quote
Old 12-18-14, 05:04 PM   #55
nkuck
Lurking Renovator
 
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hmm, thanks for the update. I am fairly new to C++ and trying to figure out some of the commands. At the moment, my pump relay (RelayPin) remains ON. Only made a few minor changes to your code (at least I think minor):
// Pins
int SsensorPin = A0; // the pin to read solar panel temperature
int TsensorPin = A1; // the pin to read water tank temperature
int RelayPin = 2; // the pin to control the pump relay
int ledPin = 13; // led pin to verify relay on condition

// Variables
int Ssensor = 0; // holds the value from SsensorPin
int SensorOnDiff = 0; // holds the Ssensor value plus on differential (OnDiff)
int SensorOffDiff = 0; // holds the Ssensor value plus off differential (OffDiff)
int Tsensor = 0; // holds the value from TsensorPin
int SensorReadings = 10; // number of sensor readings to take
int Counter = 0; // sensor readings loop counter
int OnDiff = 4; // temp diff that must exist to turn pump on (dec F)
int OffDiff = 2; // temp diff that must exist to turn pump on (deg F)

void setup()
{
pinMode(SsensorPin, INPUT);
pinMode(TsensorPin, INPUT);
pinMode(RelayPin, OUTPUT);
pinMode(ledPin, OUTPUT);

Serial.begin(9600);

digitalWrite(RelayPin, LOW); // turn pump off
}
void loop()
{

// read sensor inputs, convert to degrees, and assign to variables
Counter = 0;
while(Counter < SensorReadings)
{
Ssensor = analogRead(SsensorPin) / 2;
Tsensor = analogRead(TsensorPin) / 2;
Counter++;
digitalWrite(ledPin, HIGH);
delay(250);
digitalWrite(ledPin, LOW);
delay(250);

Serial.print(Ssensor);
Serial.print(", ");
Serial.print(Tsensor);
Serial.print("\n");
delay(250);
}

// calculate average temp from sensor inputs
Ssensor = Ssensor / SensorReadings;
Tsensor = Tsensor / SensorReadings;


// add temperature difference to Ssensor value
SensorOnDiff = Ssensor - OnDiff;
SensorOffDiff = Ssensor - OffDiff;


// if heat source is warmer than heat sink sensor, enable relay
if (SensorOnDiff > Tsensor) {
digitalWrite(RelayPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(3000);
}

// if heat source sensor is cooler than heat sink sensor, disable relay
if (SensorOffDiff < Tsensor) {
digitalWrite(RelayPin, LOW);
digitalWrite(ledPin, LOW);
delay(1000);
}
}
Any help is appreciated. Thanks.
nkuck is offline   Reply With Quote
Old 12-19-14, 09:13 AM   #56
Daox
Administrator
 
Daox's Avatar
 
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
Default

Well, I see one issue:

Quote:
Originally Posted by nkuck View Post
// read sensor inputs, convert to degrees, and assign to variables
Counter = 0;
while(Counter < SensorReadings)
{
Ssensor = analogRead(SsensorPin) / 2;
Tsensor = analogRead(TsensorPin) / 2;
Counter++;
digitalWrite(ledPin, HIGH);
delay(250);
digitalWrite(ledPin, LOW);
delay(250);

Serial.print(Ssensor);
Serial.print(", ");
Serial.print(Tsensor);
Serial.print("\n");
delay(250);
}

// calculate average temp from sensor inputs
Ssensor = Ssensor / SensorReadings;
Tsensor = Tsensor / SensorReadings;


It should be:

// read sensor inputs, convert to degrees, and assign to variables
Counter = 0;
while(Counter < SensorReadings)
{
Ssensor += analogRead(SsensorPin) / 2; Add the += here
Tsensor += analogRead(TsensorPin) / 2; Add the += here
Counter++;
digitalWrite(ledPin, HIGH);
delay(250);
digitalWrite(ledPin, LOW);
delay(250);

Serial.print(Ssensor);
Serial.print(", ");
Serial.print(Tsensor);
Serial.print("\n");
delay(250);
}

// calculate average temp from sensor inputs
Ssensor = Ssensor / SensorReadings;
Tsensor = Tsensor / SensorReadings;


The while loop adds all of the readings together and then afterwards, the readings get divided by the number of readings taken (SensorReadings). In your code, you're not adding the readings together. Your code is just using the last reading taken, and the dividing it by the readings taken. So, if you take 3 readings and read 30, 40, 50. Your code will use 50 degrees and divide by 3 (giving 17) instead of adding 30 + 40 + 50 and dividing by 3 (giving 40).

If fixing that doesn't help, I'd move the serial output after the line:

Ssensor = Ssensor / SensorReadings;
Tsensor = Tsensor / SensorReadings;

This will show you the values that are actually being compared vs the values that are being read by the temperature sensors.
__________________
Current project -
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
&
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Daox is offline   Reply With Quote
Old 12-22-14, 07:52 PM   #57
nkuck
Lurking Renovator
 
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Almost everything works well, except the relayPin starts HIGH. The temp readings are uniformly higher by about 12-15 degF than they should be. Any suggested corrections? Thanks for the help. My code follows:

// Pins
int SsensorPin = 4; // the pin to read solar panel temperature
int TsensorPin = 5; // the pin to read water tank temperature
int RelayPin = 2; // the pin to control the pump relay
int ledPin = 13; // led pin to verify relay on condition

// Variables
int Ssensor = 0; // holds the value from SsensorPin
int SensorOnDiff = 0; // holds the Ssensor value plus on differential (OnDiff)
int SensorOffDiff = 0; // holds the Ssensor value plus off differential (OffDiff)
int Tsensor = 0; // holds the value from TsensorPin
int SensorReadings = 10; // number of sensor readings to take
int Counter = 0; // sensor readings loop counter
int OnDiff = 4; // temp diff that must exist to turn pump on (dec F)
int OffDiff = 2; // temp diff that must exist to turn pump off (deg F)

void setup() {
pinMode(SsensorPin, INPUT);
pinMode(TsensorPin, INPUT);
pinMode(RelayPin, OUTPUT);
pinMode(ledPin, OUTPUT);

Serial.begin(9600);

digitalWrite(RelayPin, LOW); // turn pump off
}

void loop() {

// read sensor inputs, convert to degrees, and assign to variables
Counter = 0;
while(Counter < SensorReadings) {
Ssensor += analogRead(SsensorPin) / 2;
Tsensor += analogRead(TsensorPin) / 2;
Counter++;
digitalWrite(ledPin, LOW);
delay(250);
digitalWrite(ledPin, LOW);
delay(250);
}


// calculate average temp from sensor inputs
Ssensor = Ssensor / SensorReadings;
Tsensor = Tsensor / SensorReadings;


// add temperature difference to Ssensor value
SensorOnDiff = Ssensor - OnDiff;
SensorOffDiff = Ssensor - OffDiff;

Serial.print("Solar temp= ");
Serial.println(Ssensor);
Serial.print("Tank temp= ");
Serial.println(Tsensor);

// if heat source is warmer than heat sink sensor, enable relay
if (SensorOnDiff > Tsensor) {
digitalWrite(RelayPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(3000);
}


// if heat source sensor is cooler than heat sink sensor, disable relay
if (SensorOffDiff < Tsensor) {
digitalWrite(RelayPin, LOW);
digitalWrite(ledPin, LOW);
delay(500);
}
}
nkuck is offline   Reply With Quote
Old 12-22-14, 08:07 PM   #58
nkuck
Lurking Renovator
 
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Got the output working, now to adjust the temp readings.
nkuck is offline   Reply With Quote
Old 12-29-14, 08:58 AM   #59
Daox
Administrator
 
Daox's Avatar
 
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
Default

It doesn't really matter if both sensors are off as long as they're off the same amount and its consistent. You're only measuring the differential temperature, so they only need to be accurate to each other. If this bugs you, you can do some sort of manual calibration to dial them in closer.

When I tested mine, I put a short lead on them, put them right next to each other for a half hour and read the serial output. They were probably within a degree C of each other and that was close enough for my application.
__________________
Current project -
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
&
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Daox is offline   Reply With Quote
Old 12-29-14, 10:18 AM   #60
nkuck
Lurking Renovator
 
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes, I agree with the differential being the important item. Just prefer an accurate representation of the actual temp readings as it seems important to me. I will try to tweak them. Thanks for the reply.

nkuck is offline   Reply With Quote
Reply


Tags
arduino, controller, differential, thermal

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger
Inactive Reminders By Icora Web Design