Bme280 connect with blynk using usb

THIS IS MY CODE
HOW TO CONNECT IT WITH BLYNK USING USB

#include <DFRobot_BME280.h>

#define SEA_LEVEL_PRESSURE	1013.25f
#define BME_CS 10

DFRobot_BME280 bme; //I2C

float temp, pa, hum, alt;

void setup() {
    Serial.begin(115200);
    
    // I2c default address is 0x76, if the need to change please modify bme.begin(Addr)
    if (!bme.begin(0x77)) {
        Serial.println("No sensor device found, check line or address!");
        while (1);
    }
    
    Serial.println("-- BME280 DEMO --");
}


void loop() { 
	temp = bme.temperatureValue();
	pa = bme.pressureValue();
	hum = bme.humidityValue();
	alt = bme.altitudeValue(SEA_LEVEL_PRESSURE);
	
	Serial.print("Temp:");
	Serial.print(temp);
	Serial.println(" C");
	
	Serial.print("Pa:");
	Serial.print(pa);
	Serial.println(" Pa");
	
	Serial.print("Hum:");
	Serial.print(hum);
	Serial.println(" %");
	
	Serial.print("Alt:");
	Serial.print(alt);
	Serial.println(" m");
	
	Serial.println("------END------");
	
	delay(1000);
}

@hamza2 please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

1 Like

You should start by reading this:


and use these principals to move everything out of your void loop, and remove the delay from your code.

Then take a look at the Sketch Builder to see how to add-in the Blynk code for your device and connection type.

Pete.

1 Like

I tried this but I didn’t get any data

#include <DFRobot_BME280.h>
#define SEA_LEVEL_PRESSURE  1013.25f
#define BME_CS 10
DFRobot_BME280 bme; //I2C
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "#####";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "#####";
char pass[] = "######";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);
float temp, pa, hum, alt;
BlynkTimer timer; // Announcing the timer
void setup()
{
  // Debug console
  Serial.begin(9600);
// I2c default address is 0x76, if the need to change please modify bme.begin(Addr)
    bme.begin(0x77);
   
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}
void sensorDataSend()
{
  temp = bme.temperatureValue();
  pa = bme.pressureValue();
  hum = bme.humidityValue();
  alt = bme.altitudeValue(SEA_LEVEL_PRESSURE);         // reading sensor from analog pin
  Blynk.virtualWrite(V1, temp);  // sending sensor value to Blynk app
  Blynk.virtualWrite(V2, pa);
  Blynk.virtualWrite(V3, hum);
  Blynk.virtualWrite(V4, alt);
}
void loop()
{
  Blynk.run();        // run Blynk magic
  timer.run();        // run timer every second
}

That’s because you missed-out the bit where you add a timer in your void setup which calls your sensorDataSend on a regular basis.

:point_right:In void setup() you need to declare that your function sensorDataSend() should run every 1000 milliseconds, (which is 1 second).

void setup()
{
 timer.setInterval(1000L, sensorDataSend); //timer will run every sec 
}

Pete.

Thank you,
but even after I add it to the code still the same problem
no data appears
after that disconnect

did it work before?

Honestly i do not use this sensor, or have one to test with, so take this as you will. Looking at the DFRobot_BME280.h github page, all of the examples use the wire.h library as well. I do not see it in your sketch. As mentioned I do not use this sensor, so it may not be needed, just an observation.

2 Likes

Are you sure that your sensor is at address 0x77 ?

You should all some serial print statements to your code so that you can see what readings (if any) are coming from your sensor.

Pete.

1 Like

Yes , it worked well
I get results in the serial monitor

Do you want to share your latest code, and your serial monitor output showing the Blynk connection, readings and disconnection?

Pete.