Pages

Sunday, March 23, 2014

Voltage Level Shifting Tutorial

In this tutorial we look at three methods for shifting or converting a digital logic level from one voltage level to another voltage level. For instance how to convert a 3.3 V serial signal to a 5 V serial signal or vice versa. Voltage level shifting or voltage translation is needed for serial communication between an Arduino Uno (5 V) and an XBee Zigbee module or an RN42 Bluetooth module (3.3 V).


Level Shifting Tutorial Schematics
Level Shifting with a Voltage Divider
Level Shifting with a NPN Transistor
Level Shifting TX Arduino Sketch
/*The code was used for the Arduino Uno and Duo, whichever was acting as the serial communication transmitter in the tutorial at the time. This code is free and open to all to use. */

void setup() {
//Want to use fast baud rate for this example
Serial.begin(115200);
}

void loop() {
// Just transmit same message over and over
Serial.write("forcetronics\n");
delay(10);
}

Level Shifting RX Arduino Sketch
/*The code was used for the Arduino Uno and Duo, whichever was acting as the serial communication reciever in the tutorial at the time. This code is free and open to all to use. */

void setup() {
//Want to use a fast baud rat
Serial.begin(115200);
}

void loop() {
//look for a serial data and print it
while(Serial.available()) {
  char c = (char)Serial.read();
  Serial.print(c);
}

delay(2);
}

2 comments:

  1. The transistor circuit makes no sense! This is wht you wanted to do: https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlGNUt-YJoHt65Ssfe0U2QOazj7JieThSPd_tUOGkdFtbgyK0j

    ReplyDelete
    Replies
    1. Hey Marius, The circuit I posted worked fine for me and you can see the test results in the video. Can you provide some insight into where the theory of the posted level shifting circuit breaks down? Always looking to learn and fix mistakes, thanks.

      Delete