01-05-15, 08:00 AM | #71 |
Apprentice EcoRenovator
Join Date: Jul 2014
Location: Finland
Posts: 125
Thanks: 5
Thanked 35 Times in 34 Posts
|
With my limited knowledge I don't see anything wrong with your use of those pins for the sensors or for the LCD but using them for both purposes at the same time sets off alarm bells to me. Have you seen anything documented to say it is possible to share the pins in that way? It looks unlikely to me and I would avoid it if at all possible.
|
01-05-15, 08:11 AM | #72 |
Lurking Renovator
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
I agree that what I am doing is not correct, but I don't know how to write the sketch properly and to wire it so that the lcd pins use the digital pins on the Arduino and the analog pins on the Arduino are just used for the LM34 temp sensors. I need to do more research. Thanks.
|
01-05-15, 10:28 AM | #73 |
Administrator
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
|
As long as you're not physically wiring the pins together, the arduino software is smart enough to differentiate the digital pins from the analog pins. That shouldn't cause any issues. If you want to test it, just comment out your LCD code and disconnect the LCD.
Do you have a link to the relay shield you're using? Are there any known issues with it?
__________________
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. |
01-05-15, 11:07 AM | #74 |
Apprentice EcoRenovator
Join Date: Jul 2014
Location: Finland
Posts: 125
Thanks: 5
Thanked 35 Times in 34 Posts
|
The issue as I see it is not that he is wiring different pins together but that he is connecting 2 things (sensor and LCD) to the same pin. I would be very surprised if that can ever be reliable without some sort of multiplexing setup.
Agree about commenting out and disconnecting the LCD as a quick test. |
01-05-15, 10:46 PM | #75 |
Supreme EcoRenovator
|
in post number 66, you define your sensor pins here:
Code:
int SsensorPin = 4; // the pin to read solar panel temperature int TsensorPin = 5; // the pin to read water tank temperature Code:
#define SsensorPin 1//Arduino analog pin where the Sensor1 is connected #define TsensorPin 2//Arduino analog pin where the Sensor2 is connected if you want to keep them connected to the same pins, just change the 1 and 2 to 4 and 5. it should work better then. defining pin locations as variable integers is risky business. you want to define them as constants to prevent murphy's law. Last edited by jeff5may; 01-05-15 at 10:49 PM.. |
01-06-15, 09:15 AM | #76 |
Lurking Renovator
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
|
Thanks for the response. It does seem to add stability, but I am not sure why the #define function works better than the int function. I will dig in!
|
05-18-15, 01:56 PM | #77 |
Administrator
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
|
I found a small inaccuracy with the code today. I wasn't resetting the variable that is used to hold the sensor readings. So, for example, on the first run through it starts as 0, takes 10 readings, averages them to eliminate any noise over the lines. The second time through it reads that averaged number going into it, then adds 10 more values, then averages them. This definitely throws the true readings off. However, since its a differential controller, its not horribly important because both sensors will be off relatively the same amount. However, it is fixed now.
I've been having some issues with the attic fan not turning off like it should, so I've been troubleshooting. Here is the latest code. Code:
/* Thermal Differential Controller The program monitors two temperature sensors and activates a relay when one sensor is warmer than the other. */ // Pin declaration const int SsensorPin = 4; // the pin to input heat source temperature const int TsensorPin = 5; // the pin to input sink temperature const int RelayPin = 2; // the pin to operate the relay const int ledPin = 13; // led pin (verify load power on condition) // Variable declaration int Ssensor = 0; // variable to store the value of the heat source temperature int SensorOnDiff = 0; // variable to store the Ssensor value plus on differential (OnDiff) int SensorOffDiff = 0; // variable to store the Ssensor value plus off differential (OffDiff) int Tsensor = 0; // variable to store the value of the heat sink temperature int SensorReadings = 15; // number of sensor readings to take int Counter = 0; // sensor readings loop counter int OnDiff = 6; // temperature difference that must exist between heat and sink sensors before relay enables (degrees C) int OffDiff = 2; // temperature difference that must exist between heat and sink sensors before relay disables (degrees C) void setup() { pinMode(SsensorPin, INPUT); pinMode(TsensorPin, INPUT); pinMode(RelayPin, OUTPUT); pinMode(ledPin, OUTPUT); // Serial.begin(9600); digitalWrite(RelayPin, LOW); } void loop() { // reset sensor variables and counter Ssensor = 0; Tsensor = 0; Counter = 0; // read sensor inputs and assign to variables while(Counter < SensorReadings) { Ssensor += analogRead(SsensorPin) / 2; Tsensor += analogRead(TsensorPin) / 2; Counter++; digitalWrite(ledPin, HIGH); delay(100); digitalWrite(ledPin, LOW); delay(100); } // smooth & 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(300000); } // if heat source sensor is cooler than heat sink sensor, disable relay if (SensorOffDiff < Tsensor) { digitalWrite(RelayPin, LOW); digitalWrite(ledPin, LOW); delay(1000); } // send temperature signals back to computer /* Serial.print(Ssensor); Serial.print(", "); Serial.println(Tsensor); */ }
__________________
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. |
The Following User Says Thank You to Daox For This Useful Post: | nkuck (05-18-15) |
Tags |
arduino, controller, differential, thermal |
|
|