Guest User

Untitled

a guest
Jul 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include <Adafruit_Sensor.h>
  2. #include <Wire.h>
  3. #include <Adafruit_TSL2561_U.h>
  4. #include <ArduinoJson.h>
  5. #include <DHT.h>
  6. #include <DHT_U.h>
  7.  
  8. //センサーの使用PINの割り当て
  9. const int PIN_DHT1 = 8;
  10. const int PIN_DHT2 = 4;
  11. const int PIN_SOIL = A0;
  12. DHT dht1(PIN_DHT1,DHT11);
  13. DHT dht2(PIN_DHT2,DHT11);
  14. Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
  15.  
  16. void setup() {
  17. Serial.begin(9600);
  18. dht1.begin();
  19. dht2.begin();
  20.  
  21. /* You can also manually set the gain or enable auto-gain support */
  22. // tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */
  23. // tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */
  24. tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */
  25.  
  26. /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
  27. //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
  28. tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */
  29. // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */
  30. }
  31.  
  32. void loop() {
  33. delay(10000);
  34.  
  35. //センサーの値の読み込み
  36. float humidity1 = dht1.readHumidity();
  37. float temperature1 = dht1.readTemperature();
  38. float humidity2 = dht2.readHumidity();
  39. float temperature2 = dht2.readTemperature();
  40. int soil_moisture = analogRead(PIN_SOIL);
  41. sensors_event_t event;
  42. tsl.getEvent(&event);
  43. float light = event.light;
  44.  
  45. StaticJsonBuffer<200> jsonBuffer;
  46. char buffer[256];
  47. JsonObject& root = jsonBuffer.createObject();
  48. root["humidity1"] = humidity1;
  49. root["temperature1"] = temperature1;
  50. root["humidity2"] = humidity2;
  51. root["temperature2"] = temperature2;
  52. root["soil_moisture"] = soil_moisture;
  53. root["light"] = light;
  54. root.printTo(buffer, sizeof(buffer));
  55. Serial.println(buffer);
  56. }
Add Comment
Please, Sign In to add comment