70Watt Latching Solenoid - erratic control issue

Ahh I didn't catch that...was writing something with state machines last week and guess I used else if as a force of habit! Ill give your code a try and see what happens!

Tom - sorry about the image, the low res dropped the diagram drawn on the top of the relays. However - I'm pretty confident the relays are wired properly to deliver reversible polarity (not necessarily to protect from kickback though, if that's necessary here) . As far as the solenoid connection - 1 leg of the solenoid connects to common of relay one, the other to common of relay two. NO relay 1&2 = V+, NC relay 1&2 = V-. Relay 3 common connected to V+ straight off supply, NO connected to NO of relay 1 & 2 (if that's too annoying to read Ill post a better schematic tomorrow (if avr_fred's coding suggestions haven't solved the problem already).

Nurimo - Availability mostly. I needed to try to get this going quickly and SPST relays were what I had on hand, and I've used them a lot more than optocouplers. I generally know what an optocoupler does and how it works, but not how to pick an appropriate one - plus the relays are plenty fast for this application.