Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. /*
  2. Communicate with BME280s with different I2C addresses
  3. Nathan Seidle @ SparkFun Electronics
  4. March 23, 2015
  5.  
  6. Feel like supporting our work? Buy a board from SparkFun!
  7. https://www.sparkfun.com/products/14348 - Qwiic Combo Board
  8. https://www.sparkfun.com/products/13676 - BME280 Breakout Board
  9.  
  10. This example shows how to connect two sensors on the same I2C bus.
  11.  
  12. The BME280 has two I2C addresses: 0x77 (jumper open) or 0x76 (jumper closed)
  13.  
  14. Hardware connections:
  15. BME280 -> Arduino
  16. GND -> GND
  17. 3.3 -> 3.3
  18. SDA -> A4
  19. SCL -> A5
  20. */
  21.  
  22. #include <RCSwitch.h>
  23.  
  24. #include <BH1750FVI.h>
  25. RCSwitch mySwitch = RCSwitch();
  26. #include <Wire.h>
  27.  
  28. #include "SparkFunBME280.h"
  29. BME280 mySensorA; //Uses default I2C address 0x77
  30. BME280 mySensorB; //Uses I2C address 0x76 (jumper closed)
  31. uint16_t lux = 1000;
  32. int temp = 1;
  33. int humidity = 1;
  34. int pressure = 1;
  35. BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);
  36. int rainSensor = A0;
  37. int rainLED = 2;
  38. int dryLED = 3;
  39. int sensorVal;
  40. int sensortrigger = 200;
  41.  
  42.  
  43. void setup()
  44. {
  45. mySwitch.enableTransmit(10);
  46. Serial.begin(9600);
  47. pinMode(rainSensor, INPUT);
  48. pinMode(rainLED, OUTPUT);
  49. pinMode(dryLED, OUTPUT);
  50. digitalWrite(rainLED, LOW);
  51. digitalWrite(dryLED, LOW);
  52. LightSensor.begin();
  53. Serial.println("Example showing alternate I2C addresses");
  54.  
  55. Wire.begin();
  56.  
  57. mySensorA.setI2CAddress(0x77); //The default for the SparkFun Environmental Combo board is 0x77 (jumper open).
  58. //If you close the jumper it is 0x76
  59. //The I2C address must be set before .begin() otherwise the cal values will fail to load.
  60.  
  61. if(mySensorA.beginI2C() == false) Serial.println("Sensor A connect failed");
  62.  
  63. mySensorB.setI2CAddress(0x76); //Connect to a second sensor
  64. if(mySensorB.beginI2C() == false) Serial.println("Sensor B connect failed");
  65. }
  66.  
  67. void loop()
  68. {
  69. int sensorVal = analogRead(rainSensor);
  70. Serial.print(sensorVal);
  71. if(sensorVal < sensortrigger){
  72. Serial.println("Water Detected!");
  73. digitalWrite(dryLED, LOW);
  74. digitalWrite(rainLED, HIGH);
  75. }
  76. else {
  77. Serial.println("No Water Detected!");
  78. digitalWrite(rainLED, LOW);
  79. digitalWrite(dryLED, HIGH);
  80. }
  81. temp =mySensorB.readTempF();
  82. humidity = mySensorB.readFloatHumidity();
  83. pressure = mySensorB.readFloatPressure();
  84. lux = LightSensor.GetLightIntensity();
  85. Serial.print(temp);
  86. Serial.print(",");
  87. Serial.print(humidity);
  88. Serial.print(",");
  89. Serial.print(pressure);
  90. Serial.print(",");
  91. Serial.print(lux);
  92. Serial.println();
  93. mySwitch.send(100, 16);
  94. mySwitch.send(temp, 16);
  95. // delay(100);
  96. mySwitch.send(200, 16);
  97.  
  98. mySwitch.send(humidity, 16);
  99. // delay(100);
  100. mySwitch.send(300, 16);
  101.  
  102. mySwitch.send(pressure, 16);
  103. mySwitch.send(400, 16);
  104. mySwitch.send(lux, 16);
  105. mySwitch.send(00, 16);
  106. mySwitch.send(sensorVal, 16);
  107. delay(300000);
  108. Serial.print(mySensorB.readFloatHumidity(), 0);
  109. Serial.print(" HumidityB: ");
  110. Serial.print(" PressureB: ");
  111. Serial.print(mySensorB.readFloatPressure(), 0);
  112.  
  113. Serial.print(" TempB: ");
  114. Serial.print(mySensorB.readTempC(), 2);
  115. Serial.print(mySensorB.readTempF(), 2);
  116.  
  117. Serial.println();
  118.  
  119. delay(50);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement