Fork me on GitHub

Project Notes

#569 Multi-voltage GPIO

A PWM charge-pump approach for driving low-current 0V, 5V, 12V output levels from an Arduino GPIO pin.

Build

Here’s a quick demo..

clip

Notes

For some microcontroller projects, especially those involving chip programming for older devices, it is necessary to apply higher-than-normal voltages on specific pins (for an EEPROM erase, for example). Usually only very low current/power is required.

How to do that with a nominally 5V microcontroller? This project outlines one approach, I’m sure there may be improvements or alternatives. It involves:

  • a PWM-controlled Dickson Charge Pump to generate a higher voltage (12V in this case) than the microcontroller power rail (5V)
  • high-side p-channel MOSFET switching of the high voltage to the intended output
  • BJT switching to enabled a “normal” high voltage of 5V, or a hard pull-down to 0V.

The net result is a 3-level output voltage (0V, 5V, 12V), using 4 GPIO from an Arduino.

  • 2 pins are actually used to drive the PWM charge pump - pins D3, D11 using Timer2 for PSM generation. These would not be required if a separate 12V supply or boost converter was used.
  • 1 pin (D4 in the example sketch) acts as the “high voltage” enable/disable
  • 1 pin (D5 in the example sketch) acts as the output high/low selector

Construction

I tested the circuit on a breadboard:

Breadboard

Schematic

I’ve added a voltage display unit to measure the actual output voltage (to within a few 10’s of mV):

Breadboard Build

Test

The test script MultiVoltageGPIO.ino exercises the circuit: it switches from 0V to 5V to 12V output on a loop, with each output change every 1 second.

To capture a scope trace of the output (below), I switched to a 100ms transition delay, and plotted the output with a -5V offset:

scope

Credits and References

About LEAP#569 ArduinoPower
Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.