Advertisement
chillichump

Beginners Guide to Automation Episode 9

Mar 20th, 2020
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <Adafruit_BME280.h>
  2. Adafruit_BME280 bme; // I2C
  3. const byte lightPin = 34;
  4. int lightReading;
  5.  
  6. void setup() {
  7.   Serial.begin(9600);
  8.   if (!bme.begin(0x76)) { //other potential address for BME280 could be 0x77
  9.     Serial.println("Could not find BME280, check wiring!");
  10.     while (1);
  11.   }
  12. }
  13.  
  14. void loop() {
  15.   // put your main code here, to run repeatedly:
  16.   Serial.print("Temperature = ");
  17.   Serial.print(bme.readTemperature());
  18.   Serial.println(" °C");
  19.  
  20.   Serial.print("Pressure = ");
  21.   Serial.print(bme.readPressure() / 100.0F);
  22.   Serial.println(" hPa");
  23.  
  24.   Serial.print("Humidity = ");
  25.   Serial.print(bme.readHumidity());
  26.   Serial.println(" %");
  27.  
  28.   Serial.println();
  29.   lightReading = analogRead(lightPin); //0-4095 12bit -- esp8266 10bit 0-1023 -- arduino 8bit 0-254
  30.  
  31.   Serial.print("Light reading = ");
  32.   Serial.println(lightReading);
  33.  
  34.   Serial.println();
  35.   delay(3000);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement