Too much variations in temperature?

I get the same variations in 1 second intervals too. Is this normal/to be expected?

I would say no, it sounds like you have noise on the line.
You can try a 0.1uaf cap across the analogue input.

MarkT:
If there's a breeze you will get rapid fluctuations since breezes stir the air (warm air high in room, cool air lower
in room).

But firstly try testing the sensor in a known constant/slowly varying temperature environment if your can (if its a probe
place it in a glass of water)

The unit was in a room with the windows closed for several hours, still got fluctuations of about 4C, it must be some sort of noise.

Grumpy_Mike:

I get the same variations in 1 second intervals too. Is this normal/to be expected?

I would say no, it sounds like you have noise on the line.
You can try a 0.1uaf cap across the analogue input.

Agree with your assessment of noise, that's the conclusion I have reached too.

Could you explain how this capacitor would help/work? I'm a newbie still with the electronic side of things (though quite comfortable with the software side).

Hi Levon,

Before we go too far, we should probably see your code to make sure it's doing what you think it's doing. Copy it and paste it in a reply, select the code and then select the # icon above to put it in a code block.

What you are seeing might be the result of a code error.

Pat.

patduino:
Hi Levon,

Before we go too far, we should probably see your code to make sure it's doing what you think it's doing. Copy it and paste it in a reply, select the code and then select the # icon above to put it in a code block.

What you are seeing might be the result of a code error.

Pat.

Fair enough Pat, seems like a good complete troubleshooting approach .. here it is

const int sensorPin = A0;
long count = 1;
const int SECONDS = 5; // update every X seconds

void setup()
{
  Serial.begin(9600);
}


void loop()
{
  int sensorVal = analogRead(sensorPin);
  Serial.print("\ncount: ");
  Serial.print(count);

  Serial.print("  Sensor Vals: ");
  Serial.print(sensorVal);

  float voltage = (sensorVal/1024.0) * 5.0;

  Serial.print(", Voltage: ");
  Serial.print(voltage);
  Serial.print(", degrees C: ");
  float temperature = (voltage - 0.5) * 100;
  Serial.print(temperature);

  delay(1000 * SECONDS);
  count++;
}

Could you explain how this capacitor would help/work? I'm a newbie still with the electronic side of things (though quite comfortable with the software side).

A capicitor looks like a low impedance to noise but a high impedance to the signal you want. It shorts out the noise.

Grumpy_Mike:

Could you explain how this capacitor would help/work? I'm a newbie still with the electronic side of things (though quite comfortable with the software side).

A capicitor looks like a low impedance to noise but a high impedance to the signal you want. It shorts out the noise.

Thanks .. I'll read up on this some more, but I get the basic idea.

Do you think this is a better approach than to say average 3 measurements taken in quick succession instead? I.e., one solution uses hardware, the other software ... just wondering which would be a better/more accepted way to deal with this type of problem.

average 3 measurements taken in quick succession

I've handsome good luck with that, so you might want to try it.

I also had a similar problem running the circuit from the USB port power. I recall that things got better when I also connected my wall wart. [faint memory...]

It is best to remove the defect with a capacitor rather than hide it with an averaging.
What is your board ? Uno or Mega?

If it is a UNO you can solder a 100 nF capacitor directly on the support of micro-controller.
On my UNO board the improvement was obvious.
Only capacitor at the bottom is helpful.
The second one, to the right, is difficult to sold and does not bring much improvement.

If it is a Mega board nothing is possible with SMD ATMega2560

Edit : the pin which is decoupled is Aref.

Forum12.png

patduino:

average 3 measurements taken in quick succession

I've handsome good luck with that, so you might want to try it.

I also had a similar problem running the circuit from the USB port power. I recall that things got better when I also connected my wall wart. [faint memory...]

The standard deviation definitely goes down as I take more measurements at once to average, 3-5 seems to be the sweet spot.

I do have a wall-wart, I may give that a try too .. at this point I'm just exploring and learning about the various tools I have at my disposal.

68tjs:
It is best to remove the defect with a capacitor rather than hide it with an averaging.
What is your board ? Uno or Mega?

Edit : the pin which is decoupled is Aref.

I have a UNO, thanks for the info. At this point I'm not confident enough to make the modification to the board you suggest, but I've stored this away for future reference.

Can I put this capacitor somewhere in the circuit on the breadboard .. all my circuits for now are on breadboards as I learn my way around this. Could I put this between the output of the sensor and the analog input on the board?

Thanks.

take 2 readings, discard the first one

float trash=analogRead(0);
float realone=analogRead(0);
Serial.print(realone);

there is also something in the datasheet for the atmega328p on getting better precision from the adc. and... 10.4 Adc noise reduction mode, page 39.

Could I put this between the output of the sensor and the analog input on the board?

No put it from the analogue input to ground.

take 2 readings, discard the first one

This is only useful when looking at two or more analogue inputs of high impedance. With only one input it is not going to do anything for you.

Can I put this capacitor somewhere in the circuit on the breadboard

No.
Aref is connected dirrectly to the heart of the ADC.
If Aref is noisy, measurement will be noisy.

The decoupling of Aref in entrance of the board does not work because after the decoupling capacitor Aref track is too long and acts as an antenna. This is a design error of UNO board and probably Mega
You must bypass the interference signals with a soldered capacitor as close as possible to the microcontroller.

The Mega 2560 has an internal voltage reference that cuts down on noise:

  //Set analog reference to 2.56 volts internal
  analogReference(INTERNAL2V56);

I also use a capacitor between ground and my analog pin.

I think you should use the digital DS18B20 one wire sensors.

The most important is to remember that Aref is dirrectly connect to the internal reference.
On Aref you can mesure the exact value of the "2.56V internal reference".
And if Aref is noisy Mesurment is also noisy.

ATMega328 Datasheet (for ATMega2560 it is the same):

ADC Voltage Reference
The reference voltage for the ADC (VREF) indicates the conversion range for the ADC. Single
ended channels that exceed VREF will result in codes close to 0x3FF. V REF can be selected as
either AVCC, internal 1.1V reference, or external AREF pin.
AVCC is connected to the ADC through a passive switch. The internal 1.1V reference is gener-
ated from the internal bandgap reference (VBG) through an internal amplifier. In either case, the
external AREF pin is directly connected to the ADC, and the reference voltage can be made
more immune to noise by connecting a capacitor between the AREF pin and ground.
VREF can also be measured at the AREF pin with a high impedance voltmeter. Note that VREF is a high
impedance source, and only a capacitive load should be connected in a system.
If the user has a fixed voltage source connected to the AREF pin, the user may not use the other
reference voltage options in the application, as they will be shorted to the external voltage. If no
external voltage is applied to the AREF pin, the user may switch between AVCC and 1.1V as ref-
erence selection.

The first ADC conversion result after switching reference voltage source may
be inaccurate, and the user is advised to discard this result.

Edit : doing an average without remove the origin of the default is like "to hide the dust under the carpet"

grendle:
take 2 readings, discard the first one

float trash=analogRead(0);

float realone=analogRead(0);
Serial.print(realone);




there is also something in the datasheet for the atmega328p on getting better precision from the adc. and... 10.4 Adc noise reduction mode, page 39.

Thanks, I'll take a look at the documentation, much to learn here :slight_smile:

68tjs:

Can I put this capacitor somewhere in the circuit on the breadboard

No.
Aref is connected dirrectly to the heart of the ADC.
If Aref is noisy, measurement will be noisy.

The decoupling of Aref in entrance of the board does not work because after the decoupling capacitor Aref track is too long and acts as an antenna. This is a design error of UNO board and probably Mega
You must bypass the interference signals with a soldered capacitor as close as possible to the microcontroller.

Thank you for the additional information, I see what you are saying.

turgo:
I think you should use the digital DS18B20 one wire sensors.

Would a digital sensor eliminate the noise issue (I'd think so, but being a newbie I'd rather know :slight_smile: