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).
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.
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
#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:
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
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.
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:
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.
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