I need to interface an ATTiny841 to an industrial controller that uses 0V - 5V for a logic 0 and 12V - 24V for a logic 1. To output from the 841 to the controller I'm just planning on using a transistor with the collector connected to 24V (via a resistor, of course) and switch the base from the 841; that'll give me 0V and 24 V. Inputting from the controller to the 841 is a little trickier, though. From the 841's datasheet, o low ranges from -.5V to .3VCC, or 1.5V since I'll be running the 841 off of 5V. A high is 3V - 5.5V (at VCC = 5V). If I use a 27% voltage divider followed by a 5.1V zener, I can convert the controller's high to a range of 3.24V - 5.1V and the low to a range of 0 - 1.35V. I may put optocouplers between the 841 and controller which, of course, would change these specs, but the circuit would stay the same.
On paper this looks fine, but there's not a lot of margin. Just wondering if anyone has any tips about this approach, or can provide a better one. Thanks.