The USB power supply is about the safest option here; another ghetto method would be to use a phototransistor (even the imp’s blinkup one!) pointed at an LED or neon hooked to the AC.
eg neons like this are designed to be connected directly to AC:
…you could then point it at the imp’s light sensor and poll the hardware.lightlevel() API to see when power comes/goes. One step further is using a phototransistor and resistor on an imp pin.
Why don’t you just use a 120V relay with the coil powered from the line you’re monitoring. Attach the output of the relay to your input sensor pin. Done and simple.
Why don't you just use a 120V relay with the coil powered from the line you're monitoring. Attach the output of the relay to your input sensor pin. Done and simple.
Yes. Terrific idea.
Exactly how? Please draw a schematic of the circuit.
This is what I would do. The way I’ve shown will mean that the pin will fall to LOW when the AC is removed because it is sensing the NC (Normally Closed) terminal of the relay. This would require similar code to the example in the IMP documentation:
What this can’t do is tell the difference between no AC and a cut/broken wire. If you used a 3 conductor wire, you could also monitor the NO (Normally Open) contact as well and know if the wire was severed because one of those terminals should always be connected to the COM (Common).
I assumed from the original post that the sensor was supposed to be added to something that was wired (like hard-wired) without much evasion or modification. If the monitored device is plugged into a standard outlet, that sort of makes it obvious how to monitor it, using a power supply or relay.
Adam, what exactly are the specifications for what you are monitoring? What is it you are monitoring?
mlseim: One application is to monitor the duty cycle of a sump pump - which has a float switch on the AC line before the pump itself. I can either non-invasively monitor if the pump is running, or put something inline between the float switch and the pump.