• Worldwide Shipping

  • 24/7 Customer Support

  • FAQ
  • Worldwide Shipping

  • 24/7 Customer Support

  • FAQ

HUM: Logic Level Converter

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Croduino and the basic code. Everything else is left to your imagination.

Introduction

You must have already noticed how some modules and microcontrollers work at 5V, and the other at 3,3V. Why is it so? How to interconnect parts of your system that are at different voltage levels? The answers to your questions follow in continuation.

 

How does it work?

Microcontrollers, as well as peripheral devices for communication, use transistors to achieve their function. According to that, all logical operations are created by assembling or discharging the transistor. If during some period of time, we observe the transistor work, we can notice how it turns on/off with some medium frequency. The bigger the frequency, the more logical operations can be done in a shorter period of time. In addition to the operation execution speed, electric energy consumption is also very important, especially if we are making some project which would supply from some low-capacity source such as button cell battery CR2032. Consumption depends on the frequency of assembling the transistor, and voltage. If we reduce the voltage at which the transistor works, we will reduce the circuit's consumption which is the main reason why we have modules and controllers that work at 3,3V, instead of 5V.

If you are reading this tutorial, you must be in a situation similar to our, having a sensor module you do not really like and wanting to use it with you microcontroller, but unfortunately they use different voltage levels. In our example, we are using the SHT21 temperature and humidity sensor module that has the I2C communication interface at 5V, and we would like to connect it to our Croduino Nova which has the SDA and SCL connectors that work at 3,3V. With the SHT21 module, as with many others, SDA and SCL connectors are connected via pull-up resistor for supplying the module which is 5V. If we would now directly connect these two connectors to the controller operating at 3,3V, it would lead to damaging the controller because much higher current would flow through, due to the increased voltage. In order to solve this problem, we will use logic level converter module which has the ability to reduce 5V logic levels to 3,3V, for what it uses the BSS138 N-channel MOSFETs (What is MOSFET?), and along with that functionality, it contains a voltage regulator from 5V to 3,3V which means that, using this module, you can supply other 3,3V devices.

How to connect it?

 

With this example, we want to show you how to realize the previous SHT21 tutorial using our wireless Croduino Nova controller. Let's start the connection by bringing 5V power supply to the connector or directly to the breadboard. We use the 5V power supply for powering sensors. 5V and gnd connectors are brought to the logic level converter module, to its AVCC and AGND connectors as shown in the table above. Croduino's power supply is achieved by connecting BVCC and BGND connectors to +3,3V and Croduino's gnd. In order for us to communicate, we must connect the SDA and SCL connectors so that they are brought from the sensor to the A side of the converter, and later from B connectors to the controller.

 

Arduino code

For proper execution of the program code, you need the SHT21 breakout library. In case you do not know how to install the library, read our tutorial. Since we are using Croduino Nova in this example, we suggest that you check other tutorials about this controller.

#include "ESP8266WiFi.h"
#include "SHT21.h"  // include SHT21 library

SHT21 sht; 

float temp; 	// variable to store temperature
float humidity; // variable to store hemidity

void setup() {
  Wire.begin();		// begin Wire(I2C)
  Serial.begin(9600); // begin Serial
}

void loop() {

  temp = sht.getTemperature();  // get temp from SHT 
  humidity = sht.getHumidity(); // get temp from SHT

  Serial.print("Temp: ");			// print readings
  Serial.print(temp);
  Serial.print("\t Humidity: ");
  Serial.println(humidity);

  delay(85);	// min delay for 14bit temp reading is 85ms
}
Leave a Reply