1

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?

kinkajou
  • 115
  • 1
  • 1
  • 7
  • 5
    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 05 '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 05 '11 at 17:03
  • 4
    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 05 '11 at 18:14
  • 2
    @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 06 '11 at 02:22

3 Answers3

3

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.

Chris Stratton
  • 33,282
  • 3
  • 43
  • 89
2

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:

enter image description here

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.

stevenvh
  • 145,145
  • 21
  • 455
  • 667
1

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).

trace goes to transistor gate!

AndrejaKo
  • 23,261
  • 25
  • 110
  • 186
  • great tutorials :) – kinkajou Nov 05 '11 at 17:32
  • +1 and use the break feature to turn the output low/high. – kenny Nov 05 '11 at 20:58
  • 3
    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 06 '11 at 01: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 06 '11 at 02: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 06 '11 at 03:07
  • -1. The undecoded UART signal will only give a few very short pulses, depending on the data, which you can't use to switch anything. – stevenvh Apr 09 '12 at 15:54