measuring voltage from battery and DC input while in parallel

I need help with my circuit, I’ve hit a road block and not sure how to go about it. It might be an easy fix or might be more complicated, I am hoping someone out there could possible help me solve this problem, or give me an idea in how to go about it.

Battery = 12v lead acid
DC input = 13v or 14v

I have attached a print screen of the wiring setup I have.

I can measure the voltage of both battery and DC input; separately however the battery and DC input are connected in parallel. Which means I can’t measure them separately and this is the issue I face?

to sum up the project, I need to basically be able to tell when the DC input has been taken out, however since the battery and input are parallel, as soon as I disconnect the input I’m reading the input for the battery not a 0V

below is my code it is simple, i have also connect an lcd screen (not important)

/* Arduino Tutorial: Learn how to use an LCD 16x2 screen
   More info:  */

//Include LCD library
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float input_voltage = 0.0;
float temp=0.0;
float r1=101000.0;
//float r1=98900.0;
float r2=10000.0;

float r3=101000.0;
//float r1=98900.0;
float r4=10000.0;
float input_voltage2 = 0.0;
float temp2=0.0;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  //lcd.print("Hello World!");
  //pinMode(led, OUTPUT);

void loop() {
 int analog_value = analogRead(A0);
    temp = (analog_value * 5.0) / 1024.0; 
   input_voltage = temp / (r2/(r1+r2));

 int analog_value2 = analogRead(A1);
    temp2 = (analog_value2 * 5.0) / 1024.0; 
   input_voltage2 = temp2 / (r4/(r3+r4));

 if (input_voltage2 < 0.1) 
   if (input_voltage < 0.1) 

 if(input_voltage == 13){

    lcd.setCursor(0, 1);
     lcd.print(" V=");


If anyone can help me, I will be grateful

Thank you.

You know, once you've started a circuit on F**ing, you can switch to "schematic view" which will show a proper schematic of the same circuit? You may need to rearrange the schematic a little to enhance readability but it's always better than the breadboard view.

It's a 12V battery, right? The power input is more than 13V. So you need to measure the voltage and determine if it's above or below 13V. From your code, it looks like you already know how to make a voltage divider.

Please post circuit diagram (no, a fritzing is not a circuit diagram, not even going to attempt to figure that one out). Also the drawing you posted contains a 3V battery, no 12V car battery or obvious external power input.

If your power supply is connected to the battery for charging, then of course you can't measure them separately, but from the info you provided that's unclear.

OP's image:


Maybe something like this would work. You don't have to measure anything, the diode logic takes care of that.

If the Arduino needs to know main power has failed you could place an optocoupler on the main DC in and feed its output, with an appropriate pullup resistor, to an Arduino pin.