# Converting serial signal (12V-5V) and reading it using Arduino

I'm trying to read some commands from a device that uses non-standard voltage levels for serial communication. It uses 0V for 0 and 12V for 1. For all I know, TTL levels are 0-5V, so if I want to communicate with it using my Arduino, I need to level down the 12V to match the 5V. The Arduino Mega provides a pin with an output of 5V, so I figured I could use it, add a diode and get about 5V which I can connect to RX. For now I only need to read the data. TX pin stays untouched.

I made a schematic, presented below:

I figured that the drop on the diode (about 1.8V) will allow me to have (~)5V on the RX pin when the signal from the device is at 12V, and 0, when its 0V. 12V - 5V - 1.8V = 5.2V. The R1 is 3kOhm. Could somebody explain to me why doesn't it work? Is this solution even proper? What do I need to change for it to work?

EDIT: I managed to get it to work - I modified the circuit:

The diode is a simple red diode, which has a drop of 1.8V. The three resistors are all 1kOhm. From my calculations, if the maximum signal voltage is 12V, I can now get 5V after reconnecting the diode to the GND.

What I don't understand is - when the pictured red line is disconnected, I get nothing - my Arduino doesn't respond. BUT when I connect the device's RX with TX I read the exact data I wanted! Now that's not very obvious to me, I got it accidentally by playing with the board. Is there an obvious reason why the device starts transmitting after I connect the red wire?

EDIT2: Below is the device's schematic. CONTROL SYSTEM is the only connector I am able to get to. 12V comes from a simple 12V adapter, ground is also connected to adapter. Rx is connected to arduino, the rest is exactly like on the picture with the red wire. Bigger version on Imgur

• I'm not quite sure, I was only told that the basics of communication stay the same, the only difference is that you need to convert 12V down to 5V. Also, I was told that this design might be flawed because I assumed that the +5V pin in Arduino can sink the current from the signal which is about 2.1 mA. I'm not quite sure if it can. – Bart May 16 '14 at 12:59
• You were probably replying to my comment I deleted earlier about that you may need an inverter because re-reading the question you mentioned 12V was a logic one. But if you're not sure on that it may be the case. When idle TTL serial is normally high so if it's 0V while idle you probably need an inverter (plus there are the other problems Russell has mentioned). – PeterJ May 16 '14 at 13:42
• I could launch into substantial "it may not work because ..." and "you could try ..." BUT it would be very useful if you could describe the so far secret device that you are trying to connect to and provide details re its communications protocol / connections / circuit / whatever. You are telling us things that you think you know but it is not obvious why you think you know them. Some of them are probably wrong. If we have the same source information as you it will probably help. || There is no blue cow - nor a standard red diode. No "ordinary" diode has a voltage drop of 1.8V. ... – Russell McMahon May 16 '14 at 23:39
• ... Most diodes have markings that tell you what they are. Or you may know where it came from. Or. ... || The new circuit is "safer" and you MAY be able to ground the bottom of the bottom resistor and remove the diode. || The RX line may be providing drive voltage that TX pulls down as required. Knowing what is on the input should help heaps. – Russell McMahon May 16 '14 at 23:42
• Currently I am not able to get my hands on any schematics or docs on the device, but I will be on thursday probably. I will try to provide you with some better info. Thanks for the help! – Bart May 22 '14 at 11:14

For the 12V->5V direction a simple 2-resistor voltage divider (e.g. 7kOhm + 5kOhm) will probably be perfectly fine.

Usually you can't just assume that the +5V source can actually sink any amount of current.

Plus, normal diodes are relatively low bandwidth so that your signals may become more or less distorted even for only a few kBit/s. Schottky diodes mitigate this issue.

Another simple solution could be like this (use Schottky if possible):

simulate this circuit – Schematic created using CircuitLab

• +1 General idea is good. His comments on connecting RX to TX to get data out suggest he MAY be working with an open collector TX or similar. Hard to say. Hopefully he will provide extra information as requested. – Russell McMahon May 16 '14 at 23:44

See below for a circuit that will work.

"RS232" serial is inherently very simple but can have a surprisingly large amount of "dark magic" added that means you are not seeing what you think you are. Addressing your hardware requirement is easy. Being sure that it really works as stated may be harder.

You say that "it doesn't work" but give no information re what it does do when it doesn't do what you hoped. And, some information on what levels you see where / when and how you measured them may help.

What you are doing is "illegal" and can cause the processor to malfunction or even destroy it. The basis for your formula is obscure. The diode dropp you use is wrong if it's a standard silicon diode and you should say what it is if it's a zener or other device. And your formula is almost certainly wrong if the circuit is as shown OR the circuit is wrong (or both).

As shown the diode will clamp Vin to a maximum of +5V PLUS one diode drop. If we use Vdiode = 0.6V then Vin_max =5+0.6 = 5.6V. This exceeds the maximum operating voltage allowed on input pins and can make the processor misbehave or die.

A 'safer' circuit is shown below.
Vout max is Vzener at the current offered. As shown if a 4V7 zener is used current will be about 0.7 mA and Voutmax will be somewhat less than 4V7 as zener voltages are usually specified at more than 0.7 mA.

A 5V1 zener will probably give <5V max as shown.

If you have no zener diodes and you do have a number of std silicon diodes you could make a temporary solution using a number of diodes in series. About 6 is probably about right. Try it and see - change R1 (affecting current) or number of diodes to adjust.

simulate this circuit – Schematic created using CircuitLab

• I've edited the post above and added a new circuit. Could you please take a look? I'm not sure if the edit triggers any notifications. – Bart May 16 '14 at 14:37

Assuming that "mark" and "space" polarities are the same for the 12 volt source's output and the Arduino's input, that the 12V signal comes from a voltage source which is stiff enough to source at least 1 mA and stay within a couple percent of 12V, and that the current into the Arduino's I/O is << 1mA, this'll work:

    0-12V in
|
[10k]
|
+-->0 to 4.86V out to Arduino
|
[6k8]
|
GND