LM358 output to Nano?

I have this low battery detector I’m trying to output to a Nano.

The op amp outputs to HIGH when the battery voltage is less than 12.3v.

I’m hoping to output the op amp signal to a Nano, but I thought the voltage should be reduced before reaching the input pin.

Until I know it all works, I’d like to keep using the op amp output to turn on the LED, while also outputting to the Nano.

Can you offer any ideas?

1) the opamp outputs a LOW (not HIGH) when the battery drops below the setpoint.

2) the LED is drawn backwards, and it needs a current limiting resistor.

Could use a diode (1N4148) between opamp output and digital pin (cathode/ring pointing to opamp!!!). Use internal pull up one the pin in pinmode.

pinMode(opampPin, INPUT_PULLUP);

Maybe easier to forget about the opamp, and use a voltage divider connected to an analogue input. Then you can display battery voltage, and set a threshold to light a LED with another Arduino pin. Leo..

The led has a resistor. It just not on the schematic.
Yes, i have the outputs backwards.

My main concern is putting more than 12v into the Nano. That can’t be good, right?

Zip_Ferndale: My main concern is putting more than 12v into the Nano. That can't be good, right?

12volt on a pin is indeed bad. But a voltage divider (two resistors) can drop that 12volt to a lower voltage. Is this for a 12volt lead/acid battery?

You might want to drop max voltage of the battery (~14volt) to ~1volt. And measure that with the more stable internal 1.1volt Aref of the Nano. Let us know if you need help with that. Leo..

Yes, a GSM battery.

I'm always into a better way, but I don't know how to do that.

Your help is certainly appreciated.

I dont understand how Aref would be used.

Example sketch I wrote some time ago.
Leo…

/*
  0 - ~17volt voltmeter
  works with 3.3volt and 5volt Arduinos
  uses the stable internal 1.1volt reference
  10k resistor from A0 to ground, and 150k resistor from A0 to +batt
  (1k8:27k or 2k2:33k are also valid 1:15 ratios)
  100n capacitor from A0 to ground for stable readings
*/

unsigned int total; // holds readings
float voltage; // converted to volt

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(9600); // ---set serial monitor to this value---
}

void loop() {
  total = 0; // reset
  analogRead(A0); // one unused reading to clear any ghost charge
  for (int x = 0; x < 64; x++) { // 64 analogue readings for averaging
    total += analogRead(A0); // add each value
  }
  voltage = total * 0.0002567; // convert readings to volt | ---calibrate by changing the last two or three digits---

  Serial.print("The battery is ");
  Serial.print(voltage);
  Serial.println(" volt");
  delay(1000); // use a non-blocking delay when used with other code
}

If that works, then add an if() statement to the code that lights (or flashes) a LED.

if(voltage < 11.5) digitalWrite(ledPin, HIGH);

Leo…

thank you.

Don’t forget the accompanying else to switch off the LED again:

if(voltage < 11.5) digitalWrite(ledPin, HIGH);
else digitalWrite(ledPin, LOW);