So here is how I do it today:
I have the 24VDC line connected to an opto-coupler that can actually sense AC (had a few laying around). It's the LTV-844S chip (Digikey 160-1348-5-ND).
I have to have a current limiting resister so I have a 1600 ohm resister in series there. The other line of the opto input is tied to ground.
Ok, that lights up the little LED in the optoisolator. The output of the optoisolator is held high with a 10k pullup resistor with the other output tied to ground.
As such, when the LED inside lights up, the opto ties the line pulled up directly to ground. Obviously, the line being held high via pullup is connected to the AVR.
This all works peachy keen. Here's the trouble: The 1600ohm resistor has to be able to dissipate quite a lot of heat. Doing the math, a 24V circuit with a 1600ohm resistor has 15mA of current. The heat dissipation is 24 * 0.015 = 0.36Watts.
This requires me to have substantial size resistors (I chose 1-Watt to be safe) and they look crazy big next to all the 0805 resistors on the board.
I keep thinking there's got to be a simpler, smaller and cooler (as in temperature) way to do this kind of sensing. Anyone have any ideas?