# Best way to get +5V or +12V or 0V from arduino pin

I am working on an eeprom programmer as an Arduino shield. There are two pins on my eeprom that require a 12V signal as part of the programming process. One of them is an address pin that I am also driving by a signal through a 595 shift register, and the other is the output enable pin which is connected to a regular Arduino pin for 5V and 0V operation.

I would like to have a pin on the arduino for each of the 12V pins that will set it to the higher voltage without damaging any other components.

I was thinking I could use a simple transistor setup like Figure 1 on this page, but I'm really not sure how well that would work when connected to both sources at once. I would need diodes to protect my 5V components from getting damaged by the 12V signal, but I suspect that circuit may work out. I will simplify things by ensuring I that Vin is a solid 12V supply.

Here's my initial design:

My main problem is that I don't understand the circuit elements in play here very well. Will this explode? I'm still a bit confused by simple transistor circuits, and not sure what specific parts to use. I feel like what I am trying to do is not that hard, but my circuit skills are not good enough to know the best way to accomplish this. Thanks.

Here is a circuit that should work:

Your basic idea of using a high side PNP switch was fine. The problem with it is that this exposes the high voltage to the micro pin.

In this circuit, Q2 is the high side switch that turns the 12V output on or off. Q1 switches the high side switch, thereby isolating the micro from the 12V on the base of Q2.

When the base of Q1 is held at 5V, the emitter will be 4.3V, so there will be 1mA thru R1. Most of this also flows thru the collector of Q1, which thereby acts like a switchable 1mA current sink. Most of this can only come from the base of Q2. Figuring the two transistors each have a gain of at least 50, then the output is good for at least 45mA for Q2 to stay in saturation. The purpose of R3 is only to make sure Q2 is really off when Q1 is off.

• What are P1 and P2 here? – captncraig Jul 29 '11 at 20:21
• @CMP: connection points. They are just showing where the switched 12V comes out. – Olin Lathrop Jul 29 '11 at 20:53
• So p1 will go to my eeprom pin? Is it safe to put 5V there when the 12V signal is off? – captncraig Jul 29 '11 at 21:11
• @CMP: P1 will be high impedance when the 12V output is off. – Olin Lathrop Jul 29 '11 at 21:52
• Sorry I'm a little slow. I am thinking now I can just connect my 5v data pin to P1 through a diode, and then connect that to the pin on my eeprom. When the 12V is off, my data line will drive it, and when the 12V is on it won't hurt my micro pin. Is that right? – captncraig Jul 29 '11 at 22:02

While this is an old post, I recently had this same problem when I was making an EEPROM burner for retrocomputing (where I needed to write some 27C512-style EEPROMs). The currently accepted answer has the correct idea (which I used), but it is missing the logic level (5V) control and protection, and pull-down on the output side. The following circuit adds these, and worked for me:

The microcontroller pin connecting to HVCtl controls the "high" voltage (VPP, e.g., 12V), LVCtl controls the logic level voltage (e.g., 5V), and when both are low, R4 pulls the pin low. The Schottky diode protects the LVCtl pin on the microcontroller from VPP, while having such a low voltage drop that it doesn't affect recognition of the logic level.

That is, the output (OUT) is at VPP whenever HVCtl is high, otherwise it is at the state of LVCtl.

The diode and transistors may be substituted for other parts, these are just the ones that I used (because I had them around).

From previous questions I gather that you don't want a universal programmer, but rather one which can program the device you need for your homebrew CPU, CMIIW.

I would pick another EEPROM device. 12V programming voltage is really Fred Flintstone! Modern devices are programmable at 5V. I already suggested to have a look at Flash memory instead of EEPROM. The SST39SF010A can write at 5V, and for the money you get twice 64KB, so if you wish you can load two programs in it and switch between them by toggling A16. For future enhancements there are pin-compatible Flash devices with 256KB and 512KB (same datasheet). And it's available in DIL package. Who needs 12V?!

• Well if you want to be sensible, you are correct. I was planning on implementing my state machine in eeproms, because i assumed that was the best solution for nonvolatile memory. That chip does look like exactly what I need, and it is actually available. Accepting olin's because it actually answers my question. But props to you for identifying the question I should have asked. – captncraig Jul 31 '11 at 5:46
• @CMP - No problem that you accepted Olin's answer; he couldn't know what your actual problem is, and answered what was asked. That said it's striking that people (I don't want to exclude myself) often think about 1 particular solution, and if they get stuck with that ask about that particular problem, instead of going up one step and look at the original problem. Tunnel vision. Olin rightly pointed this out already a few times. – stevenvh Jul 31 '11 at 9:27