Hello,
This is my first message and I would like to thank this community in advance.
I’ve built a small Temperature/Pressure/Humidity reader with an Arduino Mega, a BME280 sensor, a I2C 16x2 LCD and a button to light up the lcd screen.
Everything is working fine while the system is powered through the USB cable but when I switch to a 9v battery the LCD shows nonsense characters.
The code I’ve been using is this:
#include <cactus_io_BME280_I2C.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
BME280_I2C bme(0x76);
LiquidCrystal_I2C lcd(0x27,16,2);
int boton = 0;
void setup()
{
pinMode(22, INPUT);
lcd.begin(16,2);
lcd.backlight();
if (bme.begin()) {
lcd.print("OK");
delay(2000);
lcd.clear();
}
else
{
lcd.print("ERROR");
}
bme.setTempCal(-1);
}
void loop()
{
boton = digitalRead(22);
if(boton == HIGH) {
lcd.backlight();
}
else {
lcd.noBacklight();
}
bme.readSensor();
lcd.setCursor(0,0);
lcd.print("P:");
lcd.print(bme.getPressure_MB());
lcd.print("mbar");
lcd.setCursor(0,1);
lcd.print("T:");
lcd.print(bme.getTemperature_C());
lcd.print(" ");
lcd.print("H:");
lcd.print(bme.getHumidity());
lcd.print("%");
delay(1000);
}
I’ve tried replacing the BME280 with a BMP180 (same wiring, just replacing the sensor) and this code:
#include <LiquidCrystal_I2C.h>
#include <SFE_BMP180.h>
#include <Wire.h>
SFE_BMP180 bmp180;
LiquidCrystal_I2C lcd(0x27,16,2);
int boton = 0;
void setup()
{
pinMode(22, INPUT);
lcd.init();
lcd.backlight();
if (bmp180.begin()) {
lcd.print("OK");
delay(2000);
lcd.clear();
}
else
{
lcd.print("ERROR");
}
}
void loop()
{
boton = digitalRead(22);
if(boton == HIGH) {
lcd.backlight();
}
else {
lcd.noBacklight();
}
char status;
double T,P;
T = (T-1);
status = bmp180.startTemperature();//Inicio de lectura de temperatura
if (status != 0)
{
delay(status); //Pausa para que finalice la lectura
status = bmp180.getTemperature(T); //Obtener la temperatura
if (status != 0)
{
status = bmp180.startPressure(3); //Inicio lectura de presión
if (status != 0)
{
delay(status);//Pausa para que finalice la lectura
status = bmp180.getPressure(P,T); //Obtenemos la presión
if (status != 0)
{
lcd.setCursor(0,0);
lcd.print("T: ");
lcd.print(T,2);
lcd.print(" *C , ");
lcd.setCursor(0,1);
lcd.print("P: ");
lcd.print(P,2);
lcd.print(" mbar");
}
}
}
}
delay(1000);
}
This works perfect with both USB and 9V battery.
Any idea what’s going wrong with BME280 and 9V battery?
Thanks again for your help.