1
\$\begingroup\$

I'm a noob just getting my feet wet in EE, so go easy on me, please. I bought an Arduino Uno and have been learning tons in the last couple weeks. I took an LM35 sensor, a generic thermistor (using a 10kohm resistor), a light-dependent resistor (photoresistor?) (using a 10k resistor), a button (using internal Arduino pullup resistor), and a couple LEDs (with 220ohm resistors), and wired them all to my Uno. I can provide a diagram, but I don't suspect that it matters much. Basically, some are sharing the same ground, and some are sharing the same 5v.

I'm noticing that the temperature data from the LM35 and the thermistor is very erratic. It varies all by itself, plus when I press the button. I've read many forum posts saying that these types of sensors need a voltage regulator to be accurate, so here's my question: Is it probable that the cause of my erratic sensor data is because the supply from my Arduino is not constant enough, and that it's sagging or spiking?

If so (or if not), what's the solution to this problem? Should I buy one of those little 5v bread-board power supplies?

Update: Ok, here's a diagram. It's a proud day for me, this is my first circuit schematic ever! enter image description here

And here's a graph of the LM35 readings. It's only read once every 9 seconds. It's just sitting on my office desk, no furnace vent nearby or anything. Now, the graph is not raw analog readings, but rather F temperature. But the raw analog readings are all over the map, including 116, 107, 90, 145, 129, etc. Don't get distracted by the analog->temperature math, I don't care about the accuracy, I just want it to be stable! enter image description here

Update 2: The photoresistor and the thermistor are reading very consistent, only the LM35 is all over the map.

\$\endgroup\$
  • 2
    \$\begingroup\$ You should provide a diagram -- it does matter. Include ALL connections to power and ground, and ALL connections to the Arduino. Your question isn't very answerable without this (and thus not a candidate for migration!!). You might even provide your code. \$\endgroup\$ – Scott Seidman Apr 14 '18 at 20:07
  • 2
    \$\begingroup\$ My recommendation would be to test each of your sensors alone in it's own circuit \$\endgroup\$ – Scott Seidman Apr 14 '18 at 20:08
  • \$\begingroup\$ @ScottSeidman Ok, whipped one up in Visio. Updated. I don't think the code is relevant. It basically just reads each sensor once every 9 seconds. \$\endgroup\$ – user3629081 Apr 14 '18 at 21:09
1
\$\begingroup\$

IMO much better than the average is a very simple digital low pass filter.

LPF_DEPTH_SHIFT as large as slower reaction to the changes (lower filter "frequency"). Remember that LPF_data has to accommodate (max value) << LPF_DEPTH_SHIFT. You need to choose the proper type.

#define LPF_DEPTH_SHIFT   3

unsigned int LPF_data = UINT_MAX;

unsigned int lowpassfilter(unsigned int value)
{
    unsigned int v = LPF_data >> LPF_DEPTH_SHIFT;
    if(LPF_data == UINT_MAX)
        LPF_data = value << LPF_DEPTH_SHIFT;
    LPF_data -= v;
    LPF_data += value;
    return LPF_data >> LPF_DEPTH_SHIFT;
}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This isn't what most would call a low-pass filter. \$\endgroup\$ – Scott Seidman Apr 14 '18 at 20:30
  • \$\begingroup\$ @ScottSeidman But it is. A very simple of course. It is called moving (or running) average low pass filter. Google it if you have not heard about it \$\endgroup\$ – P__J__ Apr 14 '18 at 20:35
  • \$\begingroup\$ @ScottSeidman Trust me this code does not as well. Read the code carefully and try to understand it. It is only 5 lines - not the rocket science \$\endgroup\$ – P__J__ Apr 14 '18 at 20:47
  • \$\begingroup\$ @ScottSeidman - is it the low pass filter or not? Have you google it? \$\endgroup\$ – P__J__ Apr 15 '18 at 8:22
  • 2
    \$\begingroup\$ It is a LPF, but certainly doesn't explain the LM35 problem - just covers it up. \$\endgroup\$ – Scott Seidman Apr 15 '18 at 13:12
1
\$\begingroup\$

You can RC filter the device as an alternative to buying a regulator. The datasheet shows that the IC can operate at 4V and you are supplying 5V. It also states that max current consumption is around 100uA assuming you aren't loading the output which your arduino likely isn't unless you are sampling as fast as possible. For safety margin let's assume the IC may consume up to 1000uA.

5V-4V=1V 1V/1000uA = 1k ohm

Apply the largest capacitor you reasonably can after the resistor and directly across the power supply inputs of the IC and you will have a much cleaner supply. Simulation link below.

Falstad Sim

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ That's cool, thanks for the simulation, and for the idea. I'll have to buy a cap and try that out. \$\endgroup\$ – user3629081 Apr 14 '18 at 21:15
  • \$\begingroup\$ Note you can also apply this same type of filter directly to the input of the ADC after the output of the LM35. This may prove more effective. \$\endgroup\$ – lucky bot Apr 14 '18 at 21:28
0
\$\begingroup\$

To be honest, I cannot remember how precise the LM35 is at best.

But a very known algorithm to be used (especially with 'erratic' sensors) is to use the 'moving average' of the last x measurements. This means you take the average of the last x values. If you get a new sensor value, you take again the average of the last x values (that's the 'moving' part).

This will make the temperature over time you get much more smooth. What x is you can define yourself. For a large x, you get a bit of 'delay' because you need first x measurements. But my suspicion if you take for x between 5 and 10 you will see a lot of improvement.

Another addition is to remove values which you know cannot be true (very low or high spikes).

If you don't take the spike values into account, and take the average of the last x measurements, you will get a much better value.

There seems to be even an Arduino library for it (it's calling running average), see here.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks for your suggestion. My data is so crazy that I'm not sure averaging out the data is going to be beneficial because the data is so scattered. I updated my post with a little more detail and a graph. \$\endgroup\$ – user3629081 Apr 14 '18 at 21:23
  • \$\begingroup\$ Well consider the average of the last 10 values each time, than the first 2/3 will have a reasonable smooth flow, the last 1/3 have have lower values but maybe the temperature changed in real time as well slightly. \$\endgroup\$ – Michel Keijzers Apr 14 '18 at 21:29
-1
\$\begingroup\$

Determine if the noise is correlated or random.

It will help if you capture a bunch of data and plot it. The frequency and type of noise can be very important. If you have "random" noise, it is easy to filter out in software as long as you are sampling your ADC fast enough. If your have correlated noise, which basically means the noise changes with the signal you are trying to measure, it can be more difficult.

So, to answer your original question, to determine if the noise is due to power supply fluctuations, I would connect another ADC pin on the Arduino to the power supply (through a resistor divider) and sample it at the same time as the sensor. If you plot data for both, it will be very clear if the noise is correlated.

If they are correlated, one option would be to keep the supply ADC in your design and subtract it from the sensor reading, giving a quasi differential reading.

If they are not correlated, the noise is probably coming from something else. In that case,

  • How long are the wires connected to the sensor?
  • Do you have any filtering caps on the remote sensor?

Also, This is an excellent tool I often use to quickly design software filters: http://t-filter.engineerjs.com/ It will generate source code for you. (For Arduino, make sure to set the number format to integer!)

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Definitelly FFT is the best for arduino and this more than simple task. Arduino is known for its computation power. \$\endgroup\$ – P__J__ Apr 15 '18 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.