[4-20mA Sensor][Arduino R4]Troubles reading the voltage with analog read

Hello guys,

premises:

  • using Arduino R4 wifi
  • I've low knowledge on electronics
  • I'm using the sensor YB‑2J‑F (5 meters one)

I've a water level sensor with standard 4mA-20mA, I'm trying to read the value of the sensor in this way:

I've tested the circuit some days ago and it worked just fine, I was able to read the voltage on the resistor which changed according to how much water was in the tank.

Now here is the problem: yesterday I tried to connect Arduino to the same circuit of last time with the same code and it seems the value I read with Arduino is always 0. I've doubled checked everything but nothing seems strange to me, as I said I've not changed the circuit nor the code since it worked, I've used Serial.println, the returned value of analogRead is always 0.

I've used a multimiter to check some measures and I've noticed:
without connecting the Arduino on the circuit above I read on the resistance:
Voltage = 1.81V
Current = 7.96mA
After connecting the Arduino:
Voltage = 0.75V
Current = 7.96mA

Using

This happens even if the Arduino is not powered, do you have any clue of what could be wrong?

Connecting a powered sensor to an unpowered MCU (or vice versa) can destroy the input or output pins on the MCU. It sounds like that may already have happened, as the Arduino appears to be drawing current from the sensor+sensor power supply.

If you cannot avoid such a situation, put a 1K to 10K resistor in series with input port pins to limit the current flowing from the sensor into the Arduino (if it is not powered).

1 Like

The exact same R4 WiFi or another?

Is there an easy way to check if the analog input pins have been destroyed?

Is the following what you mean?

That's correct, only one Arduino has been used for such tests

Read the voltage of a simple resistor divider or pot meter (which works out as the same thing). Use your multimeter to verify.

Try other analog inputs on the same Arduino.

If an input draws measurable current, within the normal input voltage range on a properly powered Arduino, it is definitely damaged. A zero reading when a valid voltage is present on the input is another indicator.

Is the following what you mean?

Yes, although 10K would be safer.

If the 220 ohm resistor accidently became disconnected or if there is a intermittent connection with that resistor or you connected the Arduino to the sensor before you connected the resistor, then 24V will be applied directly to A0 and at the very least damage that input.

It would be best to use a 4.7V zener diode and a 1K resistor to protect the Arduino

Thanks, appreciate the help.

I hope I've understood what you guys meant, I've made this simple circuit:

With this simple code:

#define ANALOG_PIN A0
    
void setup() {
  Serial.begin(9600);
  pinMode(ANALOG_PIN, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorValue = analogRead(ANALOG_PIN);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.print("Voltage: ");
  Serial.println(voltage);
  delay(2000);
}

The value printed in the serial monitor is:
analogRead 1.75

I've done this for all pins (A0, A1, A2, A3, A4, A5), the value is always the same. On the other hand mesuring the voltage with my multimeter like this:

I get 1.63V

What can we deduce from this test?

One possibility is that your voltmeter is out of calibration. Use a good quality DMM.

But that result is in serious disagreement with this statement from your previous post, so now I have no idea what is wrong.

I've used a multimiter to check some measures and I've noticed:
without connecting the Arduino on the circuit above I read on the resistance:
Voltage = 1.81V
Current = 7.96mA
After connecting the Arduino:
Voltage = 0.75V
Current = 7.96mA

Hi,
If you measure the 3V3 to gnd voltage with the divider connected, what does your DMM read?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

That at least the ADC seems to be pretty close to what you'd expect. The 120mV doesn't freak me out too badly; it's most likely due to your assumed "5.0V" not really being 5V, but closer to 4.7V or so. If you want a better/more accurate measurement, don't rely on the Vcc supply of the Arduino but use e.g. its built-in 1.1V reference (and/or whatever internal band-gap references you can pick from on this microcontroller).

20mA into a 220 resistor will give 4.40 V so I'd prefer to see a 20k series resistor for protection, and depending on the layout perhaps a small cap from A0 to ground.

Can you add a serial print of

 Serial.print("ADC: ");
  Serial.println(sensorValue);

assuming your resistor values are correct (ie exact) you would expect 3.3 / 2 = 1.65V
and a reading of around 338 from the adc

also use your meter to read the voltage at the 5V pin so we know what the reference voltage is.

See above; his 5V is likely 4.7V due to a series Schottky diode in the Vcc somewhere. In fact, I found it on the R4 schematic:
image
So that makes 5V about 6% low, and if you take 1.65V and add 6%, what do you get...exactly, around 1.75V. So his ADC test reading seems to be right on the money.

1 Like

Yeah this could be it, my voltmeter is a cheap 15€ since it was meant for hobby, I won't have access to a good quality one any soon unfortunately

Yeah I'm also clueless on what might be wrong

Just tested this out, I read 3.29V

Just tested this, i read 359
image

I'll learn more about the 1.1V reference and give it a try, thanks

Ok that makes sense then, the voltmeter is probably the fault, however I still don't know why the problem from which I started the topic happens, I'll try to make some more test on the circuit in some hour, let's see if I can figure out something

No, me neither, but the good news is that the Arduino sounds OK.

I'd like to refocus your attention to useful advice given earlier by @jim-p:

It won't solve the original problem, but will prevent damage.

As to the original issue - what details can you give us about the total circuit (full schematic, photos) and of the 4-20mA sensor (e.g. datasheet)?

So does the original problem still exist?
It's time to post your code so we can see what's going on.