Temperature readings dropping to zero

Hello Hope some on can help.
I have a water solar system which is being run by an Arduino Megga. The Arduino takes the temperature from the solar panel and the water cylinder, decides if the water in the panel is hot enough and if so turns the pump on. it then sends the data to my web page.
Last year this was running all ok but this year for some reason it is running for a while then all the reading drop to zero. If i reset the arduino it will run again for a day then drop to zero again.
Not sure if this would be a programming issue as it was all ok last year.
the arduino output runs a relay witch is via a transistor so should not cause any back EMF. but this seems to happen every time the panel is hot.
could be a sensor breaking down would this cause the other 2 sensors to stop reading.

code is below

my site which shows the readings is at http://www.duffahome.com/Solar_panel/solarpanel.php

#include <SPI.h>
#include <Ethernet.h>
#include<OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 12

byte mac[] = {*****************};
//IPAddress ip (***************);
//IPAddress server (**************);//ip address for my web server
char serverName[] = "www.duffahome.com";

OneWire oneWire(ONE_WIRE_BUS);
EthernetClient client;
DallasTemperature sensors(&oneWire);
 
DeviceAddress panelTemp = { 0x28, 0xB4, 0x52, 0x9D, 0x04, 0x00, 0x00, 0x31 }; 
DeviceAddress lowerCylinder = { 0x28, 0x7C, 0xB4, 0xA0, 0x04, 0x00, 0x00, 0x9C};
DeviceAddress upperCylinder  = {0x28, 0xC4, 0xB5, 0xA1, 0x04, 0x00, 0x00, 0x78 };
int panelin;// variable to store panel temperature
int lowerin;// variable to store lower cylinder temperature
int upperin;// variable to store upper cylinder
int pump = 8;
int diff;



void setup(){
  
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
Serial.begin(9600);
   Serial.println("Start setup");
  pinMode(pump, OUTPUT);
Serial.println ("setup end");
}
  

void loop (){
  //Serial.println ("start loop");
  for (int x=0; x<50; x++)
  {
    //Serial.println (x);
  panelin = sensors.getTempC(panelTemp);// read sensor into var panelin to send to GET function
  lowerin = sensors.getTempC(lowerCylinder);
  upperin = sensors.getTempC (upperCylinder);
  sensors.requestTemperatures ();
  Serial.println (panelin);// serial print for fault finding
  Serial.println (lowerin);// fault finding
  Serial.println (upperin);
  pumpcontrol ();
  
  }
  sendGET();
}

void sendGET() //client function to send/receive GET request data.
{
  //Serial.println ("send data");
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.print("GET ***************=");//send panel = to server
    client.print(panelin);//add panelin temperature to above line note no println in code
    client.print("&lower=");
    client.print(lowerin);
    client.print("&upper=");
    client.print(upperin);
    client.println(" HTTP/1.0");// add to end of GET send with println
      
    client.println("Host: www.duffahome.com");// my web host address
    client.println(); //end of get request
    Serial.println ("end send data");
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
   int noCharCount = 0;
  
  while(client.connected())
  {
    while(client.available())
    {
      char c = client.read();
      Serial.write(c);
      noCharCount = 0;
    }

    delay(10);
    noCharCount++;

    // change this value to suit you. this is 10 seconds    
    if(noCharCount > 1000)
    {
      Serial.println();
      Serial.println("Timeout");
      client.stop();
    }
    
  }
}


void pumpcontrol(){
  
  diff = lowerin + 25;
  
  if (diff < panelin){
    digitalWrite (pump, HIGH);
    delay(5000);
    digitalWrite (pump, LOW);
    delay(9000);
  }
  else{
    delay (10000);
  }
}
  panelin = sensors.getTempC(panelTemp);// read sensor into var panelin to send to GET function
  lowerin = sensors.getTempC(lowerCylinder);
  upperin = sensors.getTempC (upperCylinder);
  sensors.requestTemperatures ();

Does this make sense? Get the temperatures, and then ask the bus to get the sensors ready to report temperatures?

Not quiet clear what you mean paul, i'm not fully clued up on programming being a hobbyist.

from the code i have a variable panelin which will record the temperature from the panel using the code sensors.getTempC(panelTemp);

panelTemp being the address for the sensor. this is repeated for the lower temp and upper temp of my cylinder.

Are you refereeing to the sensor.requestTemperatures ();

if so i think i put this in so i could serial print the temperatures out when i was having other trouble last year. I expect I don't need this line in the code then

thank for any help paul

if so i think i put this in so i could serial print the temperatures out when i was having other trouble last year. I expect I don't need this line in the code then

I suspect that you do, but that line needs to be BEFORE the calls to get the temperatures.

OK paul I will change this around.

But this wouldn't cause the problem i'm getting at the moment as it was working ok last year and works at the moment fo at least half a day.

I'm wondering if this could be a hard ware fault or if the code could get corrupt over time.

There needs to be a requestTemperatures() call plus delay in loop before the for loop
to prime the system, otherwise it will pick up nonsense the very first time through.

Otherwise its fine, the requestTemperatures in one iteration gets used the next time
round the for-loop.

I think more information (a diagram) of the wiring would be useful, and I'm very
suspicious of the comment

the arduino output runs a relay witch is via a transistor so should not cause any back EMF

since its a flyback diode that does that job

Hello Mark.

I thought the requestTemperatures () was at the start as it would be the first thing done during the for loop. do you mean I need to request this before the for loop as well.

could be the reason why i get temperature spikes of 85 deg for no apparent reason.

As for the relay you are right it should be a diode and i expect it has one on the PC board. It is a relay apparently for the arduino board. it has a power supply 5v which comes from the arduino power circuit and a separate input to turn the relay on via a transistor. so the arduino is not directly controlling the relay it is via the transistor. I was thinking of putting an optocoupler in to control the relay to give even more disconnection between the arduino and the relay.

The only reason why i think its the relay connected it seems to be all ok during the night then goes wrong during the day when the pump is running. Could be a sensor breaking down this may cause all 3 sensors to go wrong as they are all on the same BUS line and same power supply as the relay.

I will knock a drawing up when i get some time.

if you see on my web site the reading where all ok today and have just dropped off. this will stay like this now until i go and reset the arduino

Hi, does this only do it on a warm/hot day?

How hot does your mega get?

Could it be heat sensitive?

Tom...... :slight_smile:

well its only started happening since ive got the system up and running again, i drained it over the winter and have just refilled the panel with antifreeze.

so the Megga is in my garage and does not get any heat from the sun. the panel is on the roof and the sensor goes to the megga. It does seem to happen when the sun is out. this is why is a bit suspicious with the panels sensor. if it is breaking down then it could be shorting out the data line to may be ground causing all the sensors to go to zero.

but then why would it correct it self when i reset the megga.

I might try changing the panel sensor over the weekend see if this helps. At least now i know the code is all ok

I've attached a very basic drawing of the set up. I don't know the exact resister value of R1 and the relay set up will have current limiting resistors and two LEDs to show the relay state.

When i get home i will get this updated with all the specifics but this shows how the relay is decoupled from the megga.

arduino.pdf (25.2 KB)

I'm not sure there is much point in discussing the software. If it worked before, it should work now, and your problem is more likely to be mechanical.

Nonetheless, I wonder what's going on, and the line

sensors.requestTemperatures ();

may be redundant.

I use the same line but several lines previously

  sensors.requestTemperatures();

  InTemp = (sensorValue(InThermo));
  OutTemp = (sensorValue(OutThermo));  
  DrainTemp = (sensorValue(DrainThermo)); 

  diff = OutTemp - InTemp;

Along with the subroutine

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  float tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

your probably write it may not be a program issue. just wondered if an arduino can become corrupt over time.

We have CCTV cameras that are IP addressed and there was an issue where the flash PIC needed uploading the firewall every 6 months due to the chip becoming corrupt.

Its a shame as now the sun is coming out it is starting to play up

What (if anything) have you changed? Did you reload the sketch for example? If not, it does indeed seem unlikely to be the code. What does the serial output tell you?

Another possibility is that activity on your network has changed - I once had an issue with my ISP sending packets that exceeded the size of the buffer my wifi code used.

hello Bill

i haven't changed anything but the system was turned off for a while during the winter. I can only assume that during the winter the outside sensor has either got to cold or damp got in, but i would have thought by now this should have cleared itself unless the sensor is beyond recovery.

As for the network this is a possibility, in not very well clued up on the network connection. I had a lot of problems at the beginning of this project with doing this. What i can say is the temperature reading are still being sent all do they are at zero. the last reading a few hours ago was all ok and since then ive had about 20 readings to MySql all at zero for all 3 sensors.

So with this i would expect the network is working ok. if it wasn't i would expect no readings to MySql

I've just found out why i get the 85 deg reading for no apparent reason, this is where the sensor has lost its supply and resets which produces an 85 deg reading.

so i would like to not record this on my web site or control the pump when this happens. I was wondering if the following would work.

for (int x=0; x<1;)
  {
    panelin = sensors.getTempC (panelTemp);
    if panelin == 85 { x=0 }
        else { x=1 }
  }

inserted in this part of the code

void loop (){
  //Serial.println ("start loop");

sensors.requestTemperatures ();

  for (int x=0; x<50; x++)
  {
    //Serial.println (x);
  panelin = sensors.getTempC(panelTemp);// read sensor into var panelin to send to GET function
  lowerin = sensors.getTempC(lowerCylinder);
  upperin = sensors.getTempC (upperCylinder);
  
  Serial.println (panelin);// serial print for fault finding
  Serial.println (lowerin);// fault finding
  Serial.println (upperin);
  pumpcontrol ();
  
  }
  sendGET();
}

to replace the panelin line. and do the same for lower in and upperin

I was wondering if the following would work.

No. You've potentially created an infinite loop. Store the value returned by getTempC() in a temporary variable. Copy that to panelin, etc. if the value is not 85.

cheers Paul

not quiet sure how to implement what you are saying.

possibly some thing like this

int temp1 = sensor.getTempC(panelTemp);

if temp1 != 85 {
  panelin = temp1
}

if sensor is not equal to 85 then i assume it will stay as the previous value.

i will have a play with this

i've got to go so so will probably not reply to any further post for a while

steve8428:
I've just found out why i get the 85 deg reading for no apparent reason, this is where the sensor has lost its supply and resets

so i would like to not record this on my web site or control the pump when this happens

This is correct but I submit the rest is nonsense, there is nothing "no apparent" about it and the idea of fixing the problem by fartarsing about with temporary variables is absurd.

How about this for a blinding flash of inspiration? The reason why you are getting the power on reset signal is because the sensor is losing power and then regaining it and resetting. Therefore the solution is to stop it losing power and it will then stop resetting. Far be it for me to claim to be the fount of all wisdom, but I do suggest you read the first line of my previous again, and reading it twice might be a good idea.

As I understand it, by

so i would like to not record this on my web site or control the pump when this happens

you are implying is that you should re-write your code to ignore all readings of 85C - even though, in your game, a legitimate reading of 85C is something you are likely to get quite often, and would rather like to know about. I think you ought first ponder a bit on how long it took for the morons at Dallas to lose their jobs after designing a sensor that required code like that. Further, if it was required, everybody would be doing it, and they are not, so it doesn't, because they didn't - and they may still be working there.

I had these signals, I believe it was just on startup and it was fixed by using a 9v wall wart rather than USB cable. Having said that I have a Mega in front of me that is running three sensors just fine on USB power. Power problems can also be caused by long cables, particularly cheap ones. This has come up before and I believe the person who actually has the practical knowledge, and something sensible to say about it, was el Supremo. You might like to google him up on this matter.

Note that I seem to recall, IF and only IF, you get the 85 every time on startup, it probably IS a code problem. It is simply an an order of operations issue whereby you are displaying data before the sensor has actually read anything. I think that was another pearl from el_Supremo!

Hello Nick

Thanks for the flash of inspiration; I understand that the reason why I’m getting the reading of 85 is due to the sensor losing its supply. However I cannot find out why this is happening. I have replaced the cable length twice and now have very good quality screened audio cable to the sensor. All solder joints are ok. So I am still at a loss to why I am loosing the power supply.

I have read some ware about putting a 10 uF capacitor across the supply at the sensor but have not done enough research on this yet. When this happens I get a recording of 85 from all 3 sensors so cannot see why this would be a power supply problem to the sensors as the panel and cylinder sensors are separately wired

The length of the cable is below 8 metres so this is well within the specifications of this sensor.

I did read you last post and do agree that the program was working all ok before I started to get the zero readings. So yes this is more than likely mechanical for this problem but still not sure what.

As for the 85 readings I've had this ever since I first started using this program so had to explore the possibility that this could be a program problem. But now I now it is not I will look at a way to stop the power supply problem. However there may be an issue where the program is asking for the sensors temperature but is not waiting long enough for the sensor to respond. As you stated at the end of your post. So a 1 second delay after the request may be in order.

I do want to record the 85 reading when it is a true reading, but if I cannot solve the power issue then to code this value out would not be to detrimental to the system as the panel fluctuates a lot.

I did not imply the engineers at Dallas where morons at any time during this post. I am just trying to work around a problem that at present I cannot solve, which is most probably due to my setup.

As for power supply I am using the USB for the supply, I did run it on a DC adapter but had a lot of problems with the network connection crashing. I don’t know why this was but found it did not happen with the USB connection. I will look at the Wall Wart supply and see if I can start using a dedicated DC supply, may be this will also solve the reason why I keep getting zero reading.

At the moment I reset the panel last night and it has run all night and day without dropping to a constant zero. I think the reason why all sensors drop to zero is the program may be losing the addresses to the sensors for some reason. I got two 85 readings during this time

I will Google el supremo thanks for this information

Hi, just viewed your basic circuit diagram, do you really run the relay off the mega and supply the senors from the same point.
As well as the network shield?????
Where is the base resistor for the pump relay circuit?
Where is the bypassing that should be at the sensors,at the arduino 5V terminal, at the relay?

I don't know how much current the relay draws, but it might be the problem. I would say in general practice run low power input devices off the arduino 5V, but any pulsing or relay load type output devices off their own supply.
With the sudden increase in total load when the relay is activated, the 5V to becomes unregulated for an instant, the arduino resets if supply goes low enough or locks up because it doesn't drop low enough.

Tom........ :slight_smile: