Advertisement
Guest User

Meteostation(DHT11, BMP180, DS18B20x2)

a guest
Dec 28th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <Wire.h>
  4. #include <BMP085.h>
  5. #include <DHT.h>
  6. #include <DS1307.h>
  7. #include <EEPROM.h>
  8.  
  9. #define ONE_WIRE_BUS 4
  10.  
  11. OneWire oneWire(ONE_WIRE_BUS);
  12.  
  13. DallasTemperature sensors(&oneWire);
  14.  
  15. DeviceAddress Thermometer1 = {
  16. 0x28, 0x00, 0x54, 0xB6, 0x04, 0x00, 0x00, 0x92 };
  17. DeviceAddress Thermometer3 = {
  18. 0x28, 0x94, 0xAC, 0xDF, 0x02, 0x00, 0x00, 0xB5 };
  19.  
  20. BMP085 dps = BMP085();
  21. long Temperature = 0, Pressure = 0, Altitude = 0;
  22.  
  23. DHT dht(8, DHT11);
  24.  
  25. char incomingByte;
  26.  
  27. int x=0;
  28.  
  29. void setup() {
  30.  
  31. sensors.begin();
  32. sensors.setResolution(Thermometer1, 10);
  33. sensors.setResolution(Thermometer3, 10);
  34.  
  35. Wire.begin();
  36. dps.init(MODE_ULTRA_HIGHRES, 21000, true);
  37. dht.begin();
  38.  
  39. Serial.begin(9600);
  40. }
  41.  
  42. void printTemperature(DeviceAddress deviceAddress) {
  43. float tempC = sensors.getTempC(deviceAddress);
  44. Serial.println(tempC,1);
  45. }
  46.  
  47. void loop(){
  48.  
  49. sensors.requestTemperatures();
  50.  
  51. dps.getPressure(&Pressure);
  52.  
  53. int h = dht.readHumidity();
  54. float t = dht.readTemperature();
  55.  
  56. if (Serial.available() > 0) {
  57. incomingByte = Serial.read();
  58. if(incomingByte == '1') {
  59. x=2;
  60. }
  61. if(incomingByte == '2') {
  62. x=1;
  63. }
  64. if(incomingByte == '3') {
  65. x=3;
  66. }
  67. if(incomingByte == '4') {
  68. x=4;
  69. }
  70. }
  71. delay(100);
  72. switch (x) {
  73. case 1:
  74. printTemperature(Thermometer1);
  75. break;
  76. case 2:
  77. printTemperature(Thermometer3);
  78. break;
  79. case 3:
  80. Serial.println(Pressure/133.3,1);
  81. break;
  82. case 4:
  83. Serial.println(h);
  84. break;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement