# A Quick Guide on Logic Level Shifting

21,554

37

9

## Introduction: A Quick Guide on Logic Level Shifting

Hello everyone!

I've introduced some of my friends into the wonderful world of Arduino and making and a lot of them have a hard time understanding working with different logic levels, so I thought it would be a good idea to make a simple guide about it. So if you ever struggled with logic level shifting this is the guide for you!

I'll show two really simple ways of doing logic level shifting and explain why or when you might need to do it.

Checkout the two minute video where I go through it and check out my YouTube channel for other videos on ESP8266 projects and tips.

Lets get to it!

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: What Are Logic Levels?

So what are logic levels?

Logic levels normally refers to the HIGH or LOW state of your arduino pins, but not all logic levels are the same.

More traditional Arduino boards such as an UNO or a Nano have a 5V logic level, which means when you set a pin HIGH, it will measure as 5V.

But other common boards such the ESP8266 have a 3.3V logic level, which, as you can probably guess, means that when you set a pin HIGH it will measure as 3.3V.

5v and 3.3V are by far the most common logic levels that you will come across in hobby electronics.

It's also important to note that sensors often have these logic levels too. An Ultrasonic sensor is a 5V sensor, while most screens run at 3.3V logic levels

## Step 2: Ok, But Why or When Do We Need to Shift Them?

If you are using a micro controller with a different logic level than a sensor you may have to consider logic level shifting, but not always.

### 3.3V signals going to a 5V device:

Normally if you have a 3.3V device sending signals to a 5V device you will not have any problems, so even though the 3.3V device will only measure at 3.3V when set to HIGH, this is normally over the threshold of what a 5V device considered HIGH. The first picture shows a visual representation of this.

There will be some exceptions to this, such as sometimes you will see Neopixels require logic level shifting as the 3.3V signal doesn't always reliably work with Neopixels running at 5V (My Google Maps Arduino Commute Tracker project didn't work with the 3.3v signal of my ESP8266 for example)

### 5V signals going to a 3.3V device:

This is where you will run into problems! Normally the max voltage a 3.3V device can accept on its pins is around 3.6V, so a 5V signal could potentially damage your device.

A good real world example of the above is connecting to an Ultrasonic sensor (5V) with an ESP8266 (3.3V). How an ultrasonic sensor works is when it receives a HIGH signal on its trigger pin it will emit an ultrasonic signal and when that signal bounces back it will send a HIGH signal on the echo pin and the microcontroller calculates the distance of the object based on how long there was between the trigger pin and the echo. The 3.3V signal on the trigger pin will work fine, but the 5V response on the echo pin will need to be shifted.

## Step 3: Method 1: a Voltage Divider

The simplest and most common method of logic level shifting is a voltage divider.

In the circuit shown as in the first picture, the output of the divider is the line coming out from the middle. There is a total of 5V dropped across the circuit, but we can can calculate how much voltage is dropped across each resistor. Meaning with specific resistor values, we can get the divider to output a signal that is safe for our 3.3V device.

The equation to calculate the voltage drop across a resistor is

(R2 / (R1 + R2) ) * V

So if we use 10K Ohm resistor for R1, and a 22K Ohm resistor for R2 you would get 3.4V on the output of the divider, which would be a safe value to use on our ESP8266.

If you look at the last image it might show a clearer image of how you would wire this up.

Additional Tip (can skip if you want!):
Someone asked before could they build it with a very limited values of resistors and the answer is yes! If you have 3 of any type of resistor, if you place 3 of them in series and take the output of the circuit between R1 and R2 you will get a perfect 3.3V signal! It is recommended you use higher value of resistors so your circuit uses less current. (at least 1K i'd say)

The equation for calculating the voltage drop across the last two resistors would be
(R2 + R3 / (R1 + R2 + R3) ) * V

But if all the resistor values are the same it cancels down to

2/3 * V

## Step 4: Method 2: a Bi-Directional Logic Level Shifter

This is my preferred method of doing Logic Level shifting, mainly because i'm terrible at organizing my resistors and find it hard to find the values I'm looking for! I also like them as you often need to shift several pins at once, so this is a good option for that.

It is a device called a Bi-Directional Logic Level Shifter, and they can be bought for about 30c delivered.

Basically how you use them is you connect your higher voltage (normally 5V) to the HV pin and then your lower voltage (normally 3.3V) to the LV pin, and then any signal received on any of the pins will be output on the equivalently numbered pin on the other side at the appropriate voltage.

So an example of this would be if a 5V signal was received on HV1, it would be output at 3.3V on LV1. And then also if a 3.3V signal was received on LV4, it would be output on HV4 at 5V

You can buy the Level shifters from Aliexpress for \$1.20 for 5*

They are also available on Amazon.com* and Amazon.co.uk* but are much more expensive!

## Step 5: Conclusion

So hopefully you now understand a little bit more about level shifting, why and when you need to do it and how to do it.

If you have any questions please let me know I'd be happy to try help!

Thanks a lot!

## 9 Discussions

FYI, a logic shifter will shift to higher than 5V. This is important if you're trying to to control a MOSFET or an H Bridge from a 3.3V Arduino. It would make more sense to set the high side to 9V or 12V. You can set the high side to as high as you like, so long as the FET in your level shifter can handle it. In the case of the ever popular BSS138, it's rated for up to 30V

Hi I am having a problem where when i plug my ESP8266 D4 pin into a logic shifter the ESP 8266 blue power light goes off. the same pin works if i plug it in via short jumper cable to the the ws2812b strip. I am powering the 5v+ and GND from a power distro block connected to my 5v power supply. the 3v+ and GND side is plugged to the ESP8266 3v+ and GND pins. and the 5v+ and GND pin of the ESP8266 is connected to the same power distribution block on my 5v power supply. any help would be much appreciated thanks .

I’ve just got a couple of these and thought I’d test the voltages in the pins before I wire up to my NodeMCU. I’m confused, as when I power up the board with 3.3v on low and 5v in the high side, *all* the pins seem to read high on my multi-meter 3.3v in the Lab pins and 5v on the HV pins). I’ve tried two different boards and they both seem to do this. I would have thought the meter would read 0v on the input and output pins until a 3.3v voltage is applied on, say a pin on the LV side, and 5v would then appear in the equivalent HV side. Is this a quirk if reading the pins with a multimeter or is this wrong? I don’t want to fry my NodeMCU by applying 3.3v to a pin that’s supposed to be providing an output from the NodeMCU.

Yes i believe so, I'm open for correction but I don't this it manipulates the signal in at all, I believe it uses the signal in as an input to a transistor once the input is high enough to trigger the transistor you should get LV lever signal (3.3 in our case) out

I haven't tested this but I'm 90% sure that's how it would work

The great thing about the adafruit stuff is it is all open source so you could actually take a look at the schematic to see what they use to make a sensor or display tolerant