Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_Sensor.h>
- #include <Wire.h>
- #include <Adafruit_TSL2561_U.h>
- #include <ArduinoJson.h>
- #include <DHT.h>
- #include <DHT_U.h>
- //センサーの使用PINの割り当て
- const int PIN_DHT1 = 8;
- const int PIN_DHT2 = 4;
- const int PIN_SOIL = A0;
- DHT dht1(PIN_DHT1,DHT11);
- DHT dht2(PIN_DHT2,DHT11);
- Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
- void setup() {
- Serial.begin(9600);
- dht1.begin();
- dht2.begin();
- /* You can also manually set the gain or enable auto-gain support */
- // tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */
- // tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */
- tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */
- /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
- //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
- tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */
- // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */
- }
- void loop() {
- delay(10000);
- //センサーの値の読み込み
- float humidity1 = dht1.readHumidity();
- float temperature1 = dht1.readTemperature();
- float humidity2 = dht2.readHumidity();
- float temperature2 = dht2.readTemperature();
- int soil_moisture = analogRead(PIN_SOIL);
- sensors_event_t event;
- tsl.getEvent(&event);
- float light = event.light;
- StaticJsonBuffer<200> jsonBuffer;
- char buffer[256];
- JsonObject& root = jsonBuffer.createObject();
- root["humidity1"] = humidity1;
- root["temperature1"] = temperature1;
- root["humidity2"] = humidity2;
- root["temperature2"] = temperature2;
- root["soil_moisture"] = soil_moisture;
- root["light"] = light;
- root.printTo(buffer, sizeof(buffer));
- Serial.println(buffer);
- }
Add Comment
Please, Sign In to add comment