# Using RS232 to light bulb or move motor

How to arrange RS232 with relays and other circuit parts to light a bulb or move a motor? I initially used micro-controller (arduino) to provide RS232 input and use the output from arduino to do tasks but as arduino costs money is there any way to simplify this process so that a beginner can do the task without using arduino! Any simple circuit diagram or helpful content pls?

-
Devices like microcontrollers have revolutionized circuitry because they can reduce the cost of tasks like these by such a large margin. You would have a hard time doing it any cheaper, and I doubt it possible. –  Kortuk Nov 5 '11 at 16:59
Also you may want to consider "graduating" from Arduino to bare AVR or some other microcontroller family. Starting cost can be a bit high (in the price range of a single Arduino), but when you have the setup ready, you can easily program large number of microcontrollers and each individual unit (depending on the capabilities) may very well be in the price range of a modified serial cable. –  AndrejaKo Nov 5 '11 at 17:03
If it's cost you're worried about, you should check out the MSP430 family of microcontrollers from TI. They typically cost < $1 each and can do all you want to do. It probably costs less than doing it with discrete components TBH. – Majenko Nov 5 '11 at 18:14 @AndrejaKo the MSP430 line that Majenko suggested is wicked cheap to get started in.$4.30 (and that included shipping for me!) for a TI Launchpad. –  rfusca Nov 6 '11 at 2:22

If you have a working arduino solution, you can probably reproduce it inexpensively by using your arduino to program another atmega 44/88/168/328 and placing that on a board. See http://arduino.cc/en/Tutorial/ArduinoToBreadboard

If timing is not critical you can use the internal oscillator - meaning your system comes down to a $3-4 atmega and a serial level shifter IC. Or potentially even a$2 attiny and soft serial.

If you only need to receive serial you can use the 1489 line receiver (its companion transmitter the 1488 is what required the extra power supplies) instead of a modern charge-pump level shifter. At a low baud rate you might even be able to use a resistive divider into a TTL inverter, or do soft serial and modify it to understand the "upside down" waveforms that would result from not bothering with the inverter.

-
Thanks for you valuable input!! –  Kitex Nov 6 '11 at 3:27

You don't have to upvote this. It's just an explanation why I think AndrejaKo's answer is wrong. Too long for a comment

Assuming that your RS232 data will consist of commands to switch the bulb on or off I completely disagree with AndrejaKo's answer. The command will pass by as a series of very short pulses which are totally unfit to switch anything. This won't allow you to switch a bulb on or off.

You'll want to decode the RS232 command, and for that you need a microcontroller, there's no way around it. Pass the incoming RS232 signal through a level shifter like the MAX232 to convert the +12V/-12V levels to levels which are safe for the microcontroller.

The microcontroller's code can be kept simple, especially if it has a hardware UART (most controllers do). Listen to incoming commands and switch outputs on and off accordingly. Since you only need 8 commands to switch 4 outputs (just an example) each command can be represented by a single byte, this avoids having to develop a complete data protocol.

The most versatile way to control bulbs, motors and such is by use of an electromechanical relay. This will switch just anything: AC or DC, low voltage or 230V, low or high current. Solid state relays are more limited; most types are for switching mains voltage.

You can't drive a relay directly from the microcontroller; it needs too much current. Use a transistor to drive the relay:

If you want to switch mains powered devices (like the bulb) you'll find alternative solutions here or here

So you need the MAX232, a cheap microcontroller and a set of relays with their driving transistor. While this is basically the functionality of an Arduino or other single board computer it will be cheaper if you build it yourself and limit it to this functionality.

-
He merely needs to use a control pin (RTS CTS DTR) and not the data transmit line. –  Ben Voigt Apr 10 '12 at 16:23

The answer is simple: You need a transistor connected to RS-232 port. Then using transistor, you can control a relay or whatever you want.

For transistors, there's a simple tutorial here that I like.

I recommend that at first you use an IC like MAX232 to provide a 0 V to 5 V at the output. While it is possible to connect a transistor directly to serial port, that could be problematic due to wide range of possible output voltages on the port. There's a nice tutorial for setting up a MAX232 circuit here.

There's actually one more thing I should mention in my example: Since FETs are supposed not to consume current, you may need to use a pull-down resistor on the output of the MAX232. The resistor should go from the MAX232 pin to the ground and have a large value, for example $100 \mbox{ } k \Omega$. When the output is high, the MAX232 will be able to "overpower" the resistor and produce high voltage at the gate. When the output switches to low, you'll be sure that it will quickly drop to ground level.

Here's a sketch. The trace goes from MAX232 to transistor gate (I don't have any circuit modelling program right now so I couldn't import the correct symbol).

-
great tutorials :) –  Kitex Nov 5 '11 at 17:32
+1 and use the break feature to turn the output low/high. –  kenny Nov 5 '11 at 20:58
This would be a lot simpler if you mentioned using a control signal such as DTR which can be set high or low in software, rather than the serial data signal itself. –  Chris Stratton Nov 6 '11 at 1:17
@Chris Stratton I was mostly concerned about the voltage range of the signal. Some transistors may not be able to support such high voltage difference which would require more complicated circuitry to solve. Of course, if that particular port has a reduced range, say from -5 V to 5 V, than the selection of the exact transistor would be easier and the transistor could be easily connected to any of the lines which can be driven from the computer. –  AndrejaKo Nov 6 '11 at 2:54
Or you could just use whatever general purpose junction transistor is handy, with a resistive voltage divider feeding it. Start with too large a series resistor and decrease it until the circuit starts working ;-) –  Chris Stratton Nov 6 '11 at 3:07
show 1 more comment