This project builds an environmental monitoring station that measures temperature, humidity, light intensity, and air quality on a single 16x2 LCD display. The ESP32 reads data from a DHT22 temperature/humidity sensor, BH1750 light sensor, and MQ135 gas sensor, displaying readings that update every 2.5 seconds with page-switching capability.
The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions for breadboard construction. You'll learn how to interface multiple I2C sensors with the ESP32, use a level shifter to protect the LCD communication, and handle analog gas sensor readings with proper signal conditioning. The included firmware handles sensor initialization, I2C device detection, and efficient display updates.
Wiring diagram

Gather all the parts
Assemble it in 5 steps
1. Prepare your 30-row breadboard
Unplug USB first. Keep the ESP32 beside the breadboard so it does not cover the holes. In each numbered row, A–E are connected together and F–J are connected together; the centre gap separates them. Use jumper wires to the board. Keep modules beside the board if space is tight.
- Use one power rail for 3.3V, a separate rail for 5V, and a common ground rail. Never join the two positive rails. Check for breaks in the rails.
2. Connect power
ESP32 3V3 feeds the 3.3V rail, USB-fed 5V/VIN feeds the 5V rail, and GND feeds ground. Light sensor and DHT22 use 3.3V; LCD and MQ135 use 5V. Power the level shifter LV from 3.3V and HV from 5V, with its GND connected to ground. Use a reliable USB supply rated at least 1A.
- Verify the board's 5V/VIN pin carries USB 5V before connecting these loads. Never apply 5V to 3V3 or an ESP32 signal pin.
3. Connect light and temperature sensors
BH1750 SDA goes to GPIO21 (data), SCL to GPIO22 (clock), and ADDR to ground. DHT22 DATA goes to GPIO4; connect the 10k pull-up resistor between DATA and 3.3V. For a bare four-pin DHT22, facing the grille with legs down: VCC, DATA, unused, GND from left to right. For a module, follow its printed labels.
4. Protect and connect the gas signal
Use an MQ135 module with VCC, GND, A0 and D0 labels. Leave D0 disconnected. Put the 10k resistor between A0 and breadboard A20; the 15k resistor between B20 and ground; connect C20 to GPIO34. These three holes share the same row, creating the safe measurement junction. Keep all other resistor ends in different rows.
- Allow warm-up and initial conditioning per the sensor manual; early readings drift. The LCD shows uncalibrated module output voltage, not ppm.
- Never connect A0 directly to the ESP32: it can reach 5V. The sensor gets hot; keep it away from flammable material. This is not a safety alarm or a calibrated CO2 meter.
5. Connect the LCD through the level shifter
Connect BSS138 LV to ESP32 3V3, HV to USB-fed 5V, and GND to the common ground. GPIO21 connects to both BH1750 SDA and BSS138 LV1 (3.3V data). GPIO22 connects to both BH1750 SCL and BSS138 LV2 (3.3V clock). BSS138 HV1 goes only to LCD SDA (5V data), and HV2 goes only to LCD SCL (5V clock). LCD VCC connects to 5V and LCD GND to common ground. This protects the ESP32 from the LCD's 5V signals. Leave unused shifter channels disconnected. Adjust the LCD backpack contrast screw gently until letters appear.
- Firmware checks common LCD addresses 0x27 and 0x3F. The screen alternates temperature/humidity and light/gas pages every four seconds.
Review all connections
1. Connections between "light" and "ESP32"
2. Connections between "climate" and "ESP32"
3. Connections between "pullup" and "ESP32"
4. Connections between "gas" and "ESP32"
5. Connections between "upper" and "ESP32"
6. Connections between "lower" and "ESP32"
7. Connections between "shift" and "ESP32"
8. Connections between "lcd" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <BH1750.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
DHT climate(4, DHT22);
BH1750 light;
LiquidCrystal_I2C* lcd = nullptr;
float temperature=NAN, humidity=NAN, lux=-1;
uint32_t gasMv=0, lastSample=0, lastPage=0;
bool lightOK=false, page=false;
String previous[2];
bool present(uint8_t a) { Wire.beginTransmission(a); return Wire.endTransmission()==0; }
void line(uint8_t row, String text) {
if (!lcd) return;
text=text.substring(0,16); while(text.length()<16) text+=' ';
if(text!=previous[row]) { lcd->setCursor(0,row); lcd->print(text); previous[row]=text; }
}
void setup() {
Serial.begin(115200); Wire.begin(21,22); Wire.setClock(100000);
climate.begin(); analogReadResolution(12); analogSetPinAttenuation(34, ADC_11db);
uint8_t address=present(0x27)?0x27:(present(0x3F)?0x3F:0);
if(address) { lcd=new LiquidCrystal_I2C(address,16,2); lcd->init(); lcd->backlight(); }
else Serial.println("LCD not found at 0x27 or 0x3F");
lightOK=light.begin(BH1750::CONTINUOUS_HIGH_RES_MODE,0x23,&Wire);
line(0,"Sensors starting"); line(1,"MQ needs warmup");
lastSample=millis(); lastPage=millis();
}
void loop() {
uint32_t now=millis();
if(now-lastSample>=2500) {
lastSample=now; temperature=climate.readTemperature(); humidity=climate.readHumidity();
lux=lightOK?light.readLightLevel():-1;
uint32_t total=0; for(int i=0;i<16;i++) total+=analogReadMilliVolts(34);
gasMv=total/16;
Serial.printf("T=%.1f C RH=%.1f %% Light=%.0f lx MQ output=%.3f V (uncalibrated)\n",temperature,humidity,lux,gasMv/600.0f);
}
if(now-lastPage>=4000) {lastPage=now; page=!page;}
if(now>=2500) {
if(!page) {
line(0,isnan(temperature)?"Temp: error":"Temp: "+String(temperature,1)+" C");
line(1,isnan(humidity)?"Humidity: error":"Humidity: "+String(humidity,1)+"%");
} else {
line(0,lux<0?"Light: error":"Light: "+String(lux,0)+" lx");
line(1,"MQ: "+String(gasMv/600.0f,2)+"V raw");
}
}
delay(10);
}
// Wiring verified: shared I2C on 21/22, DHT on 4, divided ADC on 34.Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




