Optocoupler for "on demand" battery check

In a project with a "low consumption" aim I have created a 3.7V LiPo battery test that works fine - starting with a test sketch. I use AnalogReference(INTERNAL) and a divider (4.7KOhm and 1K for the 5V experiment).

I work on Arduino UNO R3 - original - with no other components.

As the divider will consume energy itself I'd like to check at a specific program command.

The basic project takes the voltage from 3.3 or 5V pin with appropriate dividers. I tried to get the voltage in from pin2 writing it HIGH but it does not work. The voltage goes down a lot. ???

I then tried with an OptoCoupler 4N35 (which was in my Arduino rookie kit) - as it should work as a completely detached "switch". It works, but the voltage is not precise and varies erratically of about 20%.

4N35 is connected (as for examples) with pin 1 to a 220Ohm and then to pin2 of the UNO. Pin2 GND. Pin4 gets the voltage from the divider and Pin5 is connected to the A1 pin on the UNO.
Thanks
Flavio

P.S. I am looking and using a MOSFET... next step...

int analoginput = 1; // our analog pin
int analogamount = 0; // stores incoming value
float percentage = 0; // used to store our percentage value
float voltage =0; // used to store voltage value
float referenceVoltage = 0;
int resist1 = 4604;      // 4.7 kOhm nominali
int resist2 = 975;       // 1   kOhm nominali
// int resist1 = 675000; // 680 kOhm nominali
// int resist2 = 216000; // 220 kOhm nominali

void setup()
{
  Serial.begin(9600);
  Serial.println("Test Voltmetro");
  analogReference(INTERNAL); // use INTERNAL (1.1V) for reference voltage
  referenceVoltage = 1100;
  // analogReference(DEFAULT); // use DEFAULT (5V) for reference voltage
  // referenceVoltage = 5000;
}

void loop()
{
  analogamount = 0;
  digitalWrite(2, HIGH);
  float t_zero = millis();
  while ((millis() - t_zero) < 1000) {
    if (analogamount < analogRead(analoginput)) {
      analogamount = analogRead(analoginput);
    }
  }
  digitalWrite(2, LOW);

  percentage=(analogamount/1024.00)*100;
  voltage=(analogamount/1024.00)*referenceVoltage; // in millivolts
  Serial.print("Lettura analog (0-1023): ");
  Serial.print(analogamount);
  Serial.print(" --------       % of AREF: ");
  Serial.print(percentage,2);
  Serial.print(" --------       A0 (mV): ");
  Serial.print(voltage,2);
  Serial.print(" --------     Real - no divider (V): ");
  Serial.println((voltage/1000*(resist1+resist2)/resist2),2);  // V_s = V_out * (R1+R2) / R2
  delay(2000);
}

So how about 10k/47k, that'll drop power draw by one order of magnitude with same performance. Or go even further to 100k/470k with 10nF cap over the bottom resistor.
Or a p-channel mosfet used as a high side switch to only enable the measurement when needed.
Basically anything but an optocoupler which serves no clear purpose here.

2 Likes

Spot on Koraks. :slight_smile:
1k+4k7 already loses 1mA!

The circuit shown below should let you switch on the divider only when you want to measure battery voltage. And you can use Vcc as the reference instead of 1.1V if Vcc has a regulated supply. The capacitor would allow you to measure a battery voltage that's higher than Vcc (not your situation), and make sure the divider is not active when the Arduino is powered down.

2 Likes

Yes, my "final" solution on the PRO MINI 3.3V was 680k/220k. Will try the 10nF cap.
Tks
F

Actually, the BASIC solution was quite simple. I did measurements for a "while" but apparently (I still have to check with the oscilloscope) there is a problem of timing - i.e. takes time to ramp to 5V (?).

The working sketch, I got with lucky trials, has a small delay after switching on the optcoupler and only a single analog reading. It is now quite stable.

Following the advice received, though, I dropped this extra component. I have used higher value resistance and will try the capacitor to get a stabler reading. I will also experiment on the side with the MOSFET.

Wrong section:

An issue with that circuit is the FET may be fried if the V+ rises rapidly to above the gate/source maximum voltage. There needs to be a zener across the FET gate/source junction to protect it from that transient if this can happen

Well, when D4 goes back high, it will temporarily raise the gate voltage to 3.3V (or 5V) above the source. It's hard to see how that would be a problem. V+ is the battery voltage, which should be pretty stable. In any case, I would just pick a mosfet with lots of GS room. The lowly 2N7000 will tolerate +/-20V, which should be plenty.

1 Like

Sure!
Thanks.
F

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.