Learn to code

Arduino Home

Lessons 1
Arduino - Getting Started
Lessons 2
Arduino - Basics
Lessons 3
Arduino - Serial Communication
Lessons 4
Arduino - Digital / Analog
Lessons 5
Arduino - Visual Output
Lessons 6
Arduino - Motor Control
Lessons 7
Arduino -LCD Displays
Lessons 8
Arduino -LCD Displays

Logic level shifting with Arduino

in Arduino Digital / Analog

Logic Level Shifting (from 3.3V to 5V)

Arduino boards and other components operate on a range of different voltages. Many microcontrollers work with 5V. However, recently, new controllers have come into the market that operates at 3.3V while many components run on 3.3V. Sometimes you will need to convert the output of one device, 5V, to match the input voltage (3.3v). Matching the input is called level shifting. There are a couple of ways to achieve this.

If you are a beginner, the safest way of level shifting is to use a level converting module

Level Shifting with a Voltage Divider

You know from an earlier tutorial that two resistors in series can form a voltage divider. This is one way to reduce the voltage of a circuit. You will need to calculate the ratio of the resistor’s base on the ratio of the input voltage to the output voltage.

The tricky and challenging part of this is to have the exact right transistors for the job. Furthermore, resistors can slow down a high-speed signal.

You can see more about the voltage divider at http://www.ohmslawcalculator.com/voltage-divider-calculator

keep in mind that this solution only works in one direction. A voltage divider will never be able to step a lower voltage up to a higher one.

In the image, Vout = Vin * R2 / (R1 + R2).

If the resistors are equal, Vout = Vin/2.

If R2 = 2*R1, then Vout = Vin*2/3.

A voltage divider might seems an excellent solution to step down a 12V power supply to a 5V supply. However, voltage dividers should not be used to supply power to a load.

The first reason is power dissipation. Any current that the load is requiring will have to run through R1. The current and voltage across R1, produce power, which dissipates in the form of heat. If that power exceeds the resistor’s rating (usually a resistor is capable of 1Watt max), the heat becomes a problem. It can potentially meld down the resistor.

If you need to drop-down voltage to use it as a power supply, you can look at voltage regulators.

Voltage regulator

A voltage regulator converts unregulated voltage to a stable voltage that won’t change even if the input changes.

Voltage regulator “drop out” voltage: voltage regulators dropout voltage. This is when the input voltage, which will be regulated, is too low to keep a stable output voltage. Most voltage regulators have a dropout voltage of around 2V. This means that the input voltage should be at least 7V to get a stable 5V output of a standard LM7805 voltage regulator.

Voltage regulators generate a lot of heat: the higher the voltage input, the more heat a voltage regulator will create. Sometimes you will need a heatsink for that.

A tip: If you want to have a voltage regulator besides the Arduino Board. You could also look at step-down converters. These are voltage regulators that are pre-build.

The regulator in the figure will supply a 5V voltage from the output. Input 1 connects to the power source as well as the GND 2. Output 3 and GND 2 will generate a regulated 5V voltage that connects to a breadboard power row.

Logic Level Converter

The preferred method for logic level shifting is to use a Level Shifter IC. These are components that contain the circuitry to shift from one level to another automatically. They are the most reliable and convenient solution if your circuitry needs to use a level shifter.

Most of the logic level chips come in 4-channel or 8-channel models. It means that you can shift 4 or 8 wires.

Most of the logic level shifter modules will be Bi-Directional. This means that the shifting is down on either side. In other words, the converter can pass data from HIGH to LOW and LOW to HIGH on all the channels.

Let’s look at a logic level shifting module and a simple hook-up.

Bi-directional logical level shifter

The SparkFun bi-directional logical level shifter has two voltage input pins. The pins labeled HVLV, and two GND‘s provide high and low voltage references to the board. Supplying a steady, regulated voltage to both of these inputs is required. There are four separate data channels on the BD-LLC, each capable of shifting data to high and low voltages. These pins are labeled HV1LV1HV2LV2HV3LV3HV4, and LV4. The number at the end of each label designates the pin’s channel, and the HV or LV prefix determines whether it’s on a high or low side of the channel.

A low-voltage signal sent in to LV1, for example, will be shifted up to the higher voltage and sent out HV1. Something sent in HV3 will be shifted down and sent out of LV3. Use as many of these channels as your project requires. You don’t have to use every single one.

The figure below shows the connection between a 3.3V module (RFID Reader) and the Arduino supplying 5V. Of course, you could use the 3.3V output of the Arduino Board, but for learning purposes, a level shifter is used. Both devices are connected to the level shifter ground. This is very important to do, grounds should be connected between the devices. If you are using a level shifter board, be sure to check which side is for the HIGH voltage and which side is for the LOW voltage.

Breadboard Layout bi-directional level shifter

Previous Post
Using the map function for analog results with Arduino
You must be logged in to post a comment.