EcoRenovator

EcoRenovator (https://ecorenovator.org/forum/index.php)
-   Appliances & Gadgets (https://ecorenovator.org/forum/forumdisplay.php?f=21)
-   -   Daox's diy arduino thermal differential controller (https://ecorenovator.org/forum/showthread.php?t=1503)

SDMCF 01-05-15 07:00 AM

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.

nkuck 01-05-15 07:11 AM

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.

Daox 01-05-15 09:28 AM

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?

SDMCF 01-05-15 10:07 AM

Quote:

Originally Posted by Daox (Post 42854)
As long as you're not physically wiring the pins together...

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.

jeff5may 01-05-15 09:46 PM

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

just comment out those lines and insert:
Code:

#define SsensorPin 1//Arduino analog pin where the Sensor1 is connected
#define TsensorPin 2//Arduino analog pin where the Sensor2 is connected

then change your analog sensors to pin a1 and a2 on the arduino board
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.

nkuck 01-06-15 08:15 AM

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!

Daox 05-18-15 12:56 PM

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);
        */
}



All times are GMT -5. The time now is 02:49 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger