Hi Everyone!
I'm facing a problem with reading a voltage through Arduino.
GOAL: I have to create a circuit which is able to read a voltage (less than 3V), provided by an external source and print it in Serial. I have also to disconnected/connected the external source from Arduino and I thought abount using a MOSFET type N or a RELAY controlled by a digital pin from Arduino.
I used the software thinkercad to practice and try to make it work, I used to simulate my external source a 1.5V battery.
Without the MOSFET or the RELAY connecting the positive pole of the battery to a analog pin (like A0 ) and the negative pole to the GND making the map from 0 to 1023 (10 bit resolution ADC) and from 0V to 5V I'm able to read correctly the Battery Voltage until now, so far so good.
PROBLEM: when I try to connect the MOSFET or the RELAY I have the same result. Without giving the voltage through the Gate-Source(using mosfet) or the coil(using relay) the Arduino reads in serial the Voltage.
If you are worried about draining the battery, the Arduino's inputs have nearly infinite resistance so almost no current flows and you aren't draining the battery (as long as the Arduino remains powered).
Maybe this schematic could help. I will also attached the Arduino code
I talk about a MOSFET because I tried two types of circuit, one with the relay and one with a mosfet for the same aim disconnect the battery from the circuit. Maybe I was not that clear with the post so I will focus just with the circuit with the relay
What is the coil current specification for relay K1?
The way you have configured it, the relay doesn't conserve any battery power. The voltage divider is always connected to the battery so it's always draining it.
The only effect of disengaging the relay, is to make input A0 "float" disconnected, rendering the input value meaningless.
I want to use the relay or the mosfet to disconnect the battery from the circuit when i don't want to read the voltage.
Thanks for your advice about the draining the battery, but I think I have to put the relay or the mosfet because the next step is to read not only one type of battery but at minimum 3 different batteries so I have also to think a way to read the voltage that I need in a certain moment. Other advices are appreciated
What same result? It works correctly?
The result is that even if I put digitalWrite(13, LOW); or digitalWrite(13, HIGH); the Arduino gives me the voltage of the battery
What is the coil current specification for relay K1?
40 mA
The way you have configured it, the relay doesn't conserve any battery power. The voltage divider is always connected to the battery so it's always draining it.
Yes, sorry I choose the wrong spot to the relay, but since my arduino should be always powered on I can choose to continously provide voltage through the pin 13 and do not draining the battery, it's not that efficient but a solution. Anyway I change the spot
I can't see what your clipped drawing shows. Please re-post the entire schematic.
Also, 40mA is too much current for an Arduino pin, you risk permanent damage to the pin. You have no flyback diode to absorb inductive kick back, as well.
but since my arduino should be always powered on I can choose to continously provide voltage through the pin 13 and do not draining the battery
this part, I can't understand what you are talking about...
Thanks for the advice , I will put it but since i'm working on the simulator I want to solve firstly the voltage reading to disconnect the battery from the circuit.
Arduinos have multiple analog inputs. You don't need to switch anything externally and you're not going to drain the battery. Your relay is likely to do more harm than good unless you're using a mercury-wetted reed relay and even then it's unnecessary. Power relays are not very good for switching low currents.
On a standard Uno you have 6 analog inputs.
You keep mentioning disconnecting the battery? Do you need a switching circuit, a measuring circuit or both?
If one of the batteries you want to measure is higher than 5V then you will need a Voltage divider to measure it.
as @anon57585045 and @cedarlakeinstruments posted, a relay is not a good idea.
If you just want to measure the Voltage, as @DVDdoug posted the arduino pins have high resistance and you could even put a 100K resistor in series if you wanted to.
If the resistive divider is switched, unlike in the diagram, then additional resistors are not necessary. The divider output provides a resistive path to ground.
if its less then arduino 5V just tie it directly + to A0....... or over any resistance, no current, no V drop...
relay must be controlled over a transistor and the coil must have a reverse diode across it to choke coil transient
JCA34F is right, he could tie gnd to relay tho on the top right nc, would flicker a bit while relay closes.
ofc I wouldnt do a real circuit quite like this, but it would probably work, and sry for the paint...
to me even this has more sense then relay just for measures, there should also be a forward diode on the BAT1+ going out to get any practicality as a low V cutout circuit out of this...
Thanks for the advice, so do you suggest to connect the external source (in this case the batteries) directly to the Arduino?
The positive to one of the analog input and the negative to the ground?
My suggestion was to run the relay contacts between the battery and the resistive divider.
Are you ever building a physical circuit? If so, you'll have to deal with the hardware limitations I mentioned.
Running the battery directly into an analog pin, means when the Arduino is turned off, the battery will supply current into the pin via the internal clamping diodes.
y seems about right, but resistive divider is only good for overvoltage protection in this case, and should be on the arduino side like you said, to not let analog input float, or at least a pulldown, else he might get readings all over the place when the relay disconects, if not it can be coded to stop reading when relay is off
You could also use only a large (100k) series resistor,on the analog lines, without relay, to eliminate current going thru clamping diodes when arduino is off...
It would be good to get a better perspective on what you are trying to achieve, are you designing a real circuit?