Building a Level Shifting Circuit

This blog post on level shifting is an excerpt from Lesson B-13 of our Intro to Robotics program. Level B is the second level in Intro to Robotics and covers working with electronic components (including a variety of sensors), writing intermediate-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 18 lessons including 65+ videos and 50+ projects and activities. Sample lessons and a full scope and sequence for Level B can be found here.

 

Analog vs. Digital Signals

The Raspberry Pi output pins are limited to two states, high (3.3V) or low (ground). This type of on/off behavior is considered a digital signal. This type of signal is good for turning things on and off and using very fast switching between on and off can allow some types of different devices to communicate. This digital technology is what allows data from the internet to be sent into your home over a single copper or fiber optic cable.

While digital signals are very useful, there are some jobs they are not very good at, like driving speakers. The on/off nature of digital signals do not mix well with the smooth signal transitions required to drive a speaker. To do this well, you need an analog signal. You will dive deeper into the differences between analog and digital signals in Lesson C-8.

Unfortunately, the Raspberry Pi does not have the capability to input or output analog signals using its GPIO pins. The good news is that there are pieces of hardware that can be paired with the Pi to provide this functionality.

 

Hardware Level Shifting

What if you find a really interesting sensor that was designed to communicate with an Arduino using 5V, but you want to use it in your Raspberry Pi? For that, you can use hardware level shifting to convert the signal from 5V down to 3.3V.

A hardware level shifter is an IC or circuit board that converts one voltage level to another. They are available in many voltage levels, but for the Intro to Robotics lessons you will be focusing on 3.3V and 5V. These level shifters can come in a few different varieties:

  • 3.3V to 5V – converts a 3.3V input signal to a 5V output signal
  • 5V to 3.3V – converts a 5V input signal to a 3.3V output signal
  • 3.3V/5V Bidirectional – converts both 3.3V and 5V inputs into the opposite output

Bidirectional level shifters are generally more costly since they can convert between 3.3V and 5V in both directions. These devices are used to enable two-way communication between two devices, one using 3.3V signals and one using 5V signals.

If two-way communication is not required, then a standard, or unidirectional level shifter can be used to shift the voltage level of signals coming from a 5V sensor, into signals that are safe for Raspberry Pi GPIO pins. One model of IC used for this purpose is the 74LVC245 and it is included in the Level B kit.

The 74LVC245 is an 8-channel level shifter that is capable of level shifting 8 signals at once. By varying its input voltage, this IC has the ability to shift 3.3V inputs to 5V outputs, or shift 5V inputs to 3.3V outputs. Below is the pinout of the 74LVC245 IC.

74LVC245 IC Pinout Diagram

When shifting signals from 5V down to 3.3V, the IC should be powered by 3.3V. Below is a diagram of a 74LVC245 being used to connect a 5V sensor to a GPIO pin of the Raspberry Pi:

Level shifting diagram

 

In Lesson B-13 we teach you to build a level shifting circuit:

 

This blog post on level shifting is an excerpt from Lesson B-13 of our Intro to Robotics program. Level B is the second level in Intro to Robotics and covers working with electronic components (including a variety of sensors), writing intermediate-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 18 lessons including 65+ videos and 50+ projects and activities. Sample lessons and a full scope and sequence for Level B can be found here.

Older Post
Newer Post
Close (esc)

Popup

Use this popup to embed a mailing list sign up form. Alternatively use it as a simple call to action with a link to a product or a page.

Age verification

By clicking enter you are verifying that you are old enough to consume alcohol.

Search

Your cart is currently empty.
Shop now