LundyCam - DIY Power Monitoring using an RS-232 Port

Home - Background - Technical - Gallery - Modified Toucam - Current status

DIY RS-232 Power Monitor

DIY RS-232 Power Monitor. Circuit diagram for simple RS-232 Power Monitor.

This page describes a technique for monitoring the status of mains electrical power (on or off) using a PC's RS-232 port and a few electronic components. This is something you might want to do if you have a burglar alarm that switches on mains-powered devices, and you want your PC to take action (logging, send an email or SMS, etc) when the devices switch on. It could also be used to monitor thermostat-controlled devices or a PIR security light.

Circuit details

The RS-232 standard defines voltage levels of between -3V to -15V for OFF and +3V to +15V for ON, which makes circuit design a little complicated. Fortunately most computers will recognise 0V as OFF, which allows the circuit used here (see diagram on left) to be very simple. The 'wall-wart' power supply used has an unregulated output of 12V DC, and the output is not grounded. The wall-wart should be plugged into the power source that is to be monitored.

When the power supply is energised, the RI (Ring Indicator) pin of the RS-232 interface goes into the ON state. The exact voltage present on the RI pin does not seem to be critical, any value between +3V and +15V is likely to work. The purpose of resistor R1 (4.7kΩ) is to prevent excessive current flowing should there be a fault in the serial cable or the PC's RS-232 interface. Resistor R2 and the LED serve two purposes. They give a visual indication of the state of the circuit, and provide a path for the charge stored in the power supply's capacitance to discharge after it is switched off. The value of R2 used here (4.7kΩ) was chosen to match the low-current LED used. The power supply takes about 30 seconds to discharge through this circuit after being switched off, and during this time the RI pin remains ON. If a faster response to switch-off is required, a smaller valued resistor and a higher-rated LED could be used.

Using a wall-wart is an attractive option, as it means that mains voltages remain encapsulated within the purpose-designed power supply, and the circuit built here does not need to deal directly with mains voltages. If you build a circuit like this, please remember that it is still indirectly connected to the mains supply, and take appropriate precautions. I haven't tried using this circuit with a grounded power supply, but I think the results would be unpredictable.

An interesting aspect of this circuit is that in addition to the RI (ring indicator) pin used here, the RS-232 interface has 3 other pins that could probably be used for a similar purpose (CD, DSR and CTS), giving expansion possibilities.

Software details

I chose to use Java to monitor the RS-232 port. At present Java doesn't support serial port communications as standard, so an add-on library is required. I'm using Windows, and I didn't have much success with the Java Communications API from Sun. However, I found RXTX to be easy to install, and it is used in the attached source code. Here is a listing of a small Java class to monitor the RS-232 RI pin. The checkRinger() method returns true or false according to whether the RI pin is ON or OFF. The code is particularly simple because it only monitors the state of RI, and does not need to deal with baud rates and other details.