Arduino to detect 20 VDC to 0 VDC drop?

Hello!

Brand new to Arduino and amateur with electronics, I have a question - would like to know if this is possible

I have a remote circuit energized at 20VDC. I would like for an Arduino Uno to monitor this circuit, so that when the circuit drops to 0VDC, Arduino will execute an interrupt.

I have been looking for the answer to this, and think it might be possible with the Arduino analog comparator. I am assuming I would need a voltage divider to bring the 20VDC to a lower level acceptable to the Arduino.

I also thought about opto-isolators and relays and am not sure they would work.

You will need a voltage divider - 4 to 1 - and do an analogread() and if it drops set a pin high. optionally a reset pin

partial core code

void loop()
{
  float voltage = 20.0 * analogRead(A0) / 1023;

  Serial.println(voltage);  // or LCD.print ..

  if (voltage < 18.0)  // assuming 18V is the warning level
  {
    digitalWrite(alarmpin, HIGH);
  }

  if (digitalread(resetpin) == HIGH)
  {
    digitalWrite(alarmpin, LOW);
   //
  }
}

update - some typo’s fixed

Its not clear if this is an analog or digital (on/off) signal - a resistor divider and digital pin ought to sufice if the latter.

Dunno where the 18.0 came from in that snippet BTW - and the reset pin ought to reset, not set the alarmpin!

Dunno where the 18.0 came from in that snippet BTW - and the reset pin ought to reset, not set the alarmpin!

added a comment and fixed the alarmpin.

Thanks,

Thank you both robtillaart and MarkT! Between the two of you, my question has been answered. Arduino rocks!