[SOLVED] How to build level shifter 3.3v to 24v

I'd be inclined to use an N-channel fet or NPN transistor to switch a P-channel mosfet. Note that you should have a resistor in series with the gate drive such that it will form a voltage divider with the gate pullup, and ensure that the voltage on the gate stays within the spec of the fet - often they're +/- 20V on gate, so you can't safely pull it all the way to ground.

If you use a fet, you need one that will work at 3.3v on gate, which is hard to find in through-hole Here's one: http://www.digikey.com/product-detail/en/5LN01SP-AC/5LN01SP-ACOSCT-ND/5213189

Open-collector stage is how to do this, its the standard way to handle high voltage logic signals since the receiving circuit can be whatever voltage you like within reason.

I smell an XY-problem http://xyproblem.info/

footswitch, please tell us about your project. Which PIR motions sensors are they ? Are the PIR sensors already powered (with 24V) ? Are you sure the output is 3.3V ? Is that a digital signal or an open collector output ? What do you want to do with the PIR sensor outputs ? How long are the cables ?

It seems that you need to signal a device that has as input a 12-24V signal. Then please tell us what device that is, so we can check if it needs indeed that input voltage.

Did you know that sending a signal over 1km cable is not necessary better when the voltage is increased. It depends on things like the impedance and the capacitive coupling of the cable and the terminators at the end.

Hi guys, Sorry but somehow I wasn't receiving notifications on this topic's activity.

I sometimes wonder myself if my questions are "xy problems". And I try to make it simple so it doesn't get people bored just from reading the first post. Maybe others do this too, be it consciously or not.

Okay, let's lay all my assumptions on the table. To transmit a signal over 40 meters, 5v won't do it, let alone 3.3v, at least not easily, and not with any cable. The most simple reasons, I think, leaving out losses, impedance, capacitive coupling - I really don't know the theory - are the cable not being shielded, "cross-talk" with the other communication wires, generally the noise from AC cables near it, or EMF (I mean radio noise). Maybe all this counts as capacitive coupling, I wouldn't know. I think that's what you get when you try to learn things over the internet.

And then, a device can only go so far as to drive an output, being able to sustain it over distance, and unprotected from external hazards. This stresses the device, and stress is bad for your health.

Also, I was always led to believe that a higher voltage would be okay to work around distance/interference problems. Work around as in "not having to worry about solving" those issues at all.

The facts: - There's a pair of wires with 15V and ground respectively, to feed all or each group of PIR motion sensors. The sensors can be powered with 5-20Vdc, and I thought 15V would be a good value to minimize the overall current over the cable. - The sensor is provided already fitted in a PCB. It has quite a few components soldered in it. - The output is indeed 3.3v, triggered whenever motion is detected. Maybe the sensor's internals are all 3.3v, I'm not sure, but it would make sense. - These signals need to go into inputs on an automation device, which accepts signals from 10 to 30Vdc (the inputs are officially 24V in, but this tolerance is mentioned, and below 8V they're not guaranteed to read HIGH).

So I reasoned that I needed to up the voltage, and since I'm heading there, I might as well do it right next to the output. Is this explanation any better?

Thanks for your help so far.

  1. I did like the idea of using an optocoupler, and it looks simple enough.
  2. Using two FETs and resistors... I never used small FETs so I'd need further help with model numbers and resistor values to make it work. Or a source to learn from. Or a comparison table of sorts.
  3. @MarkT, open-collector stage - I hope this is the N-channel FET part that you're talking about, or else I'd need further explaining / practical example.
  4. When I try to explain myself, it can take forever because English isn't my native language :)

Guys... I wish I'd just know where to start learning electronics. Usually a search engine feeds me the information I need on a day-by-day basis. It doesn't teach a man to fish. There's so much information repeated, scattered, and without proper foundations to work the way up.

As we don't know what current the PIR output can drive, I suggest using a voltage comparator integrated circuit (or operational amplifier). Connect the PIR output to its non-inverting input and connect the inverting input to a voltage divider giving about 1.7 volts. (Check the comparator can supply the input current of the "automation device" in both high and low states.)

footswitch: To transmit a signal over 40 meters, 5V won't do it, let alone 3.3V, at least not easily, and not with any cable.

As you are not transmitting a high speed digital signal, there's no problem transmitting over several kilometres.

What is the make and model of your PIR?

I have to shake up your facts a little.

As Argibald wrote, 40 meters is not a very long able. The voltage is not that important. You could easily transmit a few millivolts. So 5V or 3.3V is perfectly fine. A lot depends on the cable. Is it twisted pair ? Tell us what cable it is, and what the other signals are in the cable.

That sensor runs internally on 3.3V. Which makes sense, because allmost all PIR sensors run at 3.3V (the 5V modules have a internal voltage regulator for 3.3V). There is probably a voltage regulator in your PIR sensor that accepts 5-20V. The higher the voltage, the more heat is wasted by the voltage regulator. It probably will not use a lot current, so there will be only very little losses in the cable. I think about 7 or 8V would be okay.

An optocoupler would be the best solution, as long as the output of the PIR sensor is capable to drive the led of the optocoupler. But we don't know that, so again I agree with Argibald: how much current can the PIR sensor drive ? what is the make and model of your PIR sensor ? You can use a comparator (perhaps with a optocoupler behind it), but what if the output of the PIR sensor is open collector ?

What is the make and model of the automation device ? What if the input is a 20mA current input ?

footswitch, you make erroneous assumptions about long distance signalling, for instance ethernet is 3.3V and happily does 100m+ at a 125MHz bit rate and is completely unshielded.

LVDS can go upto a few metres at 300mV at GHz rates. Again unshielded.

Microwave signals can sent along coax for fairly long distance at 10's of GHz... That is shielded though.

Impedance is everything for high speed signalling, voltage is much less important. You would normally use twisted pair or shielding (or both) and differential signalling (like ethernet, RS485, USB, firewire, LVDS)

Reliable signalling in harsh environments at low rates over any old cable is best done by current, not voltage, for instance the 20mA current-loop standard and MIDI.

For very low datarates who cares about noise, you just low-pass filter at the receiving end and eliminate the noise - at the expense of a few milliseconds delay.

The one situation where you will still have problems is if you run a signal wire alongside high current wiring like mains or motor. Don't do that.

And finally an observation that 40m of cable may be more expensive than two wireless modules.

Hi... I always had problems with keeping a low-voltage signal stable over distance. From what I've read, it acts as an antenna, and picks up a lot of noise. The signal fluctuates a lot on the input.

Usually to reduce this effect I place a 100nF ceramic capacitor on the input, along with the pull-up/down resistor. Sometimes lowering the resistor value as well. That's the only thing I ever did on that matter. It doesn't work as I wish it would. A short false positive and the lights turn on, or the alarm goes off. I have absolutely no idea how a few milivolts can be transmitted reliably. This is what I think: it must require some other design that I just don't know, and a proper cable.

From my experience, things easily go south when using the common 2-wire cable (non-twisted, non-shielded). UTP cable is a bit better. - this is what I want to use... For each cable, the remaining wires would be for power and 2 more identical sensors. And [u]parallel to this cable are unshielded cables with high-frequency PWM (around 2 amps @ 24V).[/u]

Ok I'm very interested in keeping a low-voltage signal stable over distance. But that's for all the other projects.

The automation device here is a Crouzet M3 XD26 (Product no. 88970161). And I screwed up on the specs. I had a datasheet for the wrong model. But the point stands: Input HIGH: >= 15Vdc, up to 30Vdc Input LOW: <= 5Vdc Input impedance: 7.4 kOhm

The PIR motion sensors are mainly HC-SR501, some of them only say SR501.

Your Crouzet XD26 88970161 : http://www.crouzet.com/english/catalog/millenium-3-logic-controller-millenium-3-essential-expandable-range-with-display-xd26-Part%20number-88970161.htm It costs 270 euros at Conrad.com I suppose you have the 24V DC version, and the inputs must be 24V as well.

The HC-SR501 is for mostly for 5V (it runs internally at 3.3V), but it can handle higher supply voltages. The output is a normal digital 3.3V signal, but it is weak (there is a 1k resistor to limit the current).

Okay, that is all clear now.

The output of the PIR sensor is weak. You need a logic gate, or a comparator. Then you have to make 24V out of it. That is possible with a optocoupler, but there are other options. 1 ) using two transistors. 2 ) a good old comparator. 3 ) using a chip for a relay / led / mosfet driver. 4 ) using a special chip to convert the signal. 5 ) using a fancy low input current opto-coupler with logic high voltage output.

There are many opto-couplers that are made for special things. I might even have a few somewhere. But I forgot what they are called, so I can't find them on the internet right now :( A comparator at 24V is no problem, for example the LM339, LM393.

You could make an add-on board with comparators for the Crouzet automation device, and use the same 24V DC for the comparators. However the output of the PIR sensor is weak, I don't like to put that on a 40 meter cable. If you have 24V at the PIR sensors, you could make modules with a PIR and a comparator with 24V output.

After all these posts, you initial thoughts seems to be right ;) (convert voltage, put high voltage on the cable). We had to know the details to get there.

Thank you for your help so far. Please excuse my ignorance, I never actually used a comparator / opamp.

  1. Why would it be a good option? Is it because the comparator's inputs are higher impedance / less capacitance than FETs? More reliable? Or simply because it'll be easier to connect overall (less parts)?

  2. How should I connect the comparator for this purpose? 24V to Vcc? The comparator's output would be either 24V or 0V? What would I compare the sensor's 3.3v digital output to? I mean where would the Vref come from?

Too many questions I know :confused:

A comparator is not an OpAmp.

I think it is simple because there are less parts. You need to power it with 24V to VCC and the output will be 24V or 0V (or some less than 24V and some above 0V). You have to make the reference voltage with two resistors from a fixed voltage (the 24V or 5V). You might even use a zener diode or three normal diodes (3 * 0.6V forward voltage = 1.8V) as reference.

Hmm, the LM339 / LM393 are open collector output. I can't find comparators with normal output that are common. The sink current is 16mA, and minimal 6mA. That is not a lot. Assuming 10mA, then the lowest resistor with 24V is 2k4. We make that 2k2 for a maximum current of 11mA. The 2k2 to 24V to the input of the XD26 results into a voltage divider with the input impedance of 7.4k. 2k2 and 7.2k makes 18.5V. That will work, but it is not nice.

Here are pictures : https://blog.adafruit.com/2012/06/11/ask-an-educator-how-can-i-convert-an-analog-value-to-a-digital-one/ Note that VDD is the 24V.

If you send the 3.3V signal via the cable, then you could use the circuit with feedback for a Schmitt-Trigger effect. For example with R3=75k, R1=1k8, R2=22k, then the output turns low when the voltage is below 1.2V, and high when the voltage is above 2.3V. That will filter out noise of 1Vtt. The pullup resistor R4 is 2k2 as I calculated above.

I think the ULN2803 can also be used. It is 8 open collector relay drivers in a chip. You need to add an inverter chip. The TLP250 is a isolated gate driver or optodriver chip. That is such a fancy chip that I might have somewhere in a box. The TLP250 needs 10mA at the input, but there are chips that need only 1mA.

Is your 3v3 input a floating voltage, or is it off at less than 0.5v, and on at over 3v ? Is it a digital signal (on / off), or an analog signal ?

Is this just a level shifter, or is it a driver? What is it feeding into, an IC, or a load ?

[quote author=jack wp date=1447458079 link=msg=2477857] Is your 3v3 input a floating voltage, or is it off at less than 0.5v, and on at over 3v ? Is it a digital signal (on / off), or an analog signal ? [/quote] The motion sensor outputs a digital signal, either 0V or 3.3V. I want to take that low-voltage digital signal into some circuitry, and with the help of a 24V line, have an output of 24V when the original signal is HIGH, and 0V when the signal is low. [quote author=jack wp date=1447458079 link=msg=2477857] Is this just a level shifter, or is it a driver? What is it feeding into, an IC, or a load ? [/quote] It sounds like what I want is a level shifter. It will go into a 24V input with ~7k impedance.

Should be able to work the Philips recommended I2C level converter circuit this way.

Simple 0/24V buffers:

@Runaway Pancake, I think you meant "Should be able to work. Philips recommended...", but I find this comparison a bit confusing.

I think this topic needs some sort of closure. Or else I would have settled with my initial "investigation" :)

We concluded that [u]the sensor can output up to about 3.x mA/u. I think everyone agrees that [u]this leaves the most common optocouplers out of the question[/u], since they would require about 10~20mA to function reliably.

Moving forward. As I gather, an open collector output can either be open (high impedance) or closed (tied to the emitter which would be GND). Is this correct? So it stands to reason that any open collector needs to be provided with an arbitrary V+ through a resistor/load, just like a NPN BJT or N-channel FET does. Right?

Ok, so [u]using a NPN transistor[/u] in this case, it would invert the logic, and thus require a PNP transistor to restore the logic.

Now, [u]in the case of a comparator[/u], if its output is also open collector, then it requires a pullup, and it [u]would[/u] invert the logic; so the trick here (to NOT invert the logic) is connecting the 3.3v signal to the inverting input, and the voltage reference (1.7V) to the non-inverting input. Just to be complete and aware of the implications, [u]the circuit would draw about 10mA continuously while the output is LOW/u.

The amount of searching and reading required to reach this reasoning... Please tell me I'm right. But only if I am :)

If all is well, let's try to provide the forum with some answers: - One solution is using a comparator. A good choice for this purpose would be the LM393-N, plus two or three parts (resistor pair/diode(s) for the voltage reference, and the pullup resistor on the output). Concern: 20 circuits like this would draw about 5W. - If more output current is required (>15mA), and lower "idle current", the N-channel+P-channel FET pair would be best. Along with some resistors as well. In that case, the N-channel FET BS170 looks good for the job, however I can't find the adequate P-channel partner for it.

I'd like to verify these allegations with you guys if possible. Both solutions are desirable to pursue, for verification and energy efficiency comparison.


Can use two N-channel MOSFETs for next to 0mA current flow in the control section.
Add P-channel MOSFET and pulldown resistor for off condition.

@CrossRoads, your schematics are enlightening. But it raises some questions. I don't see how it's possible to have +24V on the gate. Also the "low-current non-inverting buffer" has two N-channel MOSFETs? Couldn't I just do that "resistor to ground" with just one N-channel MOSFET then? And what's wrong with the off condition, since the output is already pulled down?

It's very late here. I should revisit this tomorrow morning, with a fresh set of eyes.


[quote author=Runaway Pancake date=1447466697 link=msg=2477938] Should be able to work the Philips recommended I2C level converter circuit this way. [/quote] The maximum value of pull-up resistor to 24V would be 4.3kΩ. That's to ensure at least 15V in the high state with the input resistance of 7.4kΩ (to ground). In the low state, the current through that resistor would be 5.6mA. With the 'Philips' level shifter circuit, the PIR circuit output is not capable of sinking that current via the MOSFET (according to data I have found on the PIR). I therefore don't think such a level converter will work unless there are more components.

As shown by Koepel, a comparator would work, so too would a two-transistor non-inverting buffer.

For a transistor buffer, I would use NPN followed by PNP so the PNP transistor can give near rail-to-rail swing when connected to the 7.4kΩ input of the automation device.

I don't see much point using an optocoupler unless it is configured to give total isolation between the PIR and the automation device . . . . . which could be well worthwhile.

It's very late here. I should revisit this tomorrow morning, with a fresh set of eyes.

Indeed, then you would see the difference between N-channel and P-channel, and recognize the pullup on the open-drain of the N-channel MOSFET.

Circuit as-is relies on 24V tolerant parts for Vgsf, which may or may not be available. I haven't looked.