Analog Read Issues (Interference?)

I recently purchased an Arduino MKR Wifi 1010. I tried building a simple circuit to measure temperature with a TMP36. This works just fine without Wifi running. Once I connect to Wifi with my Arduino the readings via analog read are all over the place and wildly inaccurate. Is this to be expected when using Wifi and analog read? I don't know enough about electronics to know if there is an issue with my board or if I am doing something wrong. If anyone can help, I'd love to learn more about this.

In order to provide a helpful answer we need to see a schematic showing how you have it wired up and some photos that clearly show the wiring. Please read How to get the best out of this forum

The sort of problem you describe is typically caused by bad wiring practice, but without being able to see what you have it's impossible to give specific help.

WiFi with an ESP32 requires a very good power supply.

I make sure the power supply has an extra bit of backside.

See post#2

Thanks! I grabbed a schematic that represents how I've wired it my MKR Wifi 1010.

Ok. I just have it hooked up via USB to my computer. I've attached a diagram that shows how it's wired. Do you believe the power supply is the issue then?

Thanks but the board shown is not a WiFi 1010.

Please post some photos.

Right. Here are some photos. I just want to mention again, that this works 100% fine when I am not using the Wifi on the Arduino.

Photo 1 of 3:

Photo 2 of 3:

Photo 3 of 3:

That's much better!

I agree with @Idahowalker about power. Wi-Fi draws a lot of current when working. At the very least put a 1000μF (exact value unimportant, bigger is better) across the 5V and GND pins of the 1010. Make the leads as short as practical.

Your wiring forms 3 big loops. Loops make excellent aerials and will pick up all sorts of interference, including from the WiFi when it is working. Just twisting the 3 wires together for as much of their length as possible will probably reduce the interference. Run the now twisted wires so that they keep away from the WiFi as much as possible. Make the wiring neat. Neat wiring doesn't just look better, it works better too.

Also try a 0μ1 ceramic capacitor between GND and the analogue input close to the connector on the 1010.

As a general rule in electrical circuits the current flowing to and flowing back from any device should be in wires that are close to each other, ideally bound together in one cable. Putting a load of wires into a cable isn't just neat, it is electrical good practice and vastly reduces interference.

1 Like

Thanks! I appreciate the advice! If I did want to add a bigger power supply, what should I use? How do I go about determining that?

Along with adding the 0.1μF ceramic capacitor as suggested by @PerryBebbington, I would also twist the wires connecting to the sensor.

The board runs on 5V* so the first thing is you need a 5V power supply. If it has a USB connector you can connect it to the USB port, otherwise connect it to the GND and 5V pins**. It would be better to put the 1010 in the breadboard so you have more connection points.

I don't know how much current the 1010 requires, but experience suggests that a power supply capable of 1A or more will be fine. If the specifications for the Arduino MKR WiFi 1010 — Arduino Official Store show the current demand I cannot see where.

* The actual processor runs on 3V3, there is an on board regulator to drop the voltage to 3V3. 5V PSUs are common as they are used for mobile phones, I would expect you to be able to find one somewhere.

** Best to avoid connecting to the 5V pin while the USB connector is connected to your computer in case you end up trying to power your PC from the USB port, which could end badly.

Adding the two capacitors as you suggested was the fix here. Thanks again for all the help!

1 Like

Good. I still think you need to pay attention to the loops in the wires.

You're welcome!

The main problem is that the TMP36 is not ratiometric, so variations in Vcc due to WiFi current demand will cause variations in the value returned by analogRead and, therefore, the calculated temperature. The solution is not capacitors (though they will help somewhat). The solution is to use one of the internal reference voltages, which are stable and do not vary with Vcc.

1 Like

Thanks Dave. I tried to use the internal voltage references and it didn't seem to work. The readings seemed to be all over the place. Do you have a code example of how I should do this?

Try the code in the post by @Wawa here, except for the MKR Wifi 1010, use AR_INTERNAL1V0 You'll have to change the calibration factor a bit...0.001632

Or, ditch the old school TMP36 and use the digital ds18b20.

This method just doesn't work for me. I had very accurate results with previous approach using capacitors. I wonder if the internal reference voltage is all varying as well because of the Wifi. On a related note, I am planning on using the ds18b20. I just received a few. My end goal is to measure and report temperature in a liquid. Any advice on how to wire up one of those and use it?

That's odd. Well, switching to the ds is a good move.

Here's a waterproof one: