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);
}