Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Communicate with BME280s with different I2C addresses
- Nathan Seidle @ SparkFun Electronics
- March 23, 2015
- Feel like supporting our work? Buy a board from SparkFun!
- https://www.sparkfun.com/products/14348 - Qwiic Combo Board
- https://www.sparkfun.com/products/13676 - BME280 Breakout Board
- This example shows how to connect two sensors on the same I2C bus.
- The BME280 has two I2C addresses: 0x77 (jumper open) or 0x76 (jumper closed)
- Hardware connections:
- BME280 -> Arduino
- GND -> GND
- 3.3 -> 3.3
- SDA -> A4
- SCL -> A5
- */
- #include <RCSwitch.h>
- #include <BH1750FVI.h>
- RCSwitch mySwitch = RCSwitch();
- #include <Wire.h>
- #include "SparkFunBME280.h"
- BME280 mySensorA; //Uses default I2C address 0x77
- BME280 mySensorB; //Uses I2C address 0x76 (jumper closed)
- uint16_t lux = 1000;
- int temp = 1;
- int humidity = 1;
- int pressure = 1;
- BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);
- int rainSensor = A0;
- int rainLED = 2;
- int dryLED = 3;
- int sensorVal;
- int sensortrigger = 200;
- void setup()
- {
- mySwitch.enableTransmit(10);
- Serial.begin(9600);
- pinMode(rainSensor, INPUT);
- pinMode(rainLED, OUTPUT);
- pinMode(dryLED, OUTPUT);
- digitalWrite(rainLED, LOW);
- digitalWrite(dryLED, LOW);
- LightSensor.begin();
- Serial.println("Example showing alternate I2C addresses");
- Wire.begin();
- mySensorA.setI2CAddress(0x77); //The default for the SparkFun Environmental Combo board is 0x77 (jumper open).
- //If you close the jumper it is 0x76
- //The I2C address must be set before .begin() otherwise the cal values will fail to load.
- if(mySensorA.beginI2C() == false) Serial.println("Sensor A connect failed");
- mySensorB.setI2CAddress(0x76); //Connect to a second sensor
- if(mySensorB.beginI2C() == false) Serial.println("Sensor B connect failed");
- }
- void loop()
- {
- int sensorVal = analogRead(rainSensor);
- Serial.print(sensorVal);
- if(sensorVal < sensortrigger){
- Serial.println("Water Detected!");
- digitalWrite(dryLED, LOW);
- digitalWrite(rainLED, HIGH);
- }
- else {
- Serial.println("No Water Detected!");
- digitalWrite(rainLED, LOW);
- digitalWrite(dryLED, HIGH);
- }
- temp =mySensorB.readTempF();
- humidity = mySensorB.readFloatHumidity();
- pressure = mySensorB.readFloatPressure();
- lux = LightSensor.GetLightIntensity();
- Serial.print(temp);
- Serial.print(",");
- Serial.print(humidity);
- Serial.print(",");
- Serial.print(pressure);
- Serial.print(",");
- Serial.print(lux);
- Serial.println();
- mySwitch.send(100, 16);
- mySwitch.send(temp, 16);
- // delay(100);
- mySwitch.send(200, 16);
- mySwitch.send(humidity, 16);
- // delay(100);
- mySwitch.send(300, 16);
- mySwitch.send(pressure, 16);
- mySwitch.send(400, 16);
- mySwitch.send(lux, 16);
- mySwitch.send(00, 16);
- mySwitch.send(sensorVal, 16);
- delay(300000);
- Serial.print(mySensorB.readFloatHumidity(), 0);
- Serial.print(" HumidityB: ");
- Serial.print(" PressureB: ");
- Serial.print(mySensorB.readFloatPressure(), 0);
- Serial.print(" TempB: ");
- Serial.print(mySensorB.readTempC(), 2);
- Serial.print(mySensorB.readTempF(), 2);
- Serial.println();
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement