/*
* Created by Pi BOTS MakerHub
*
* Email: pibotsmakerhub@gmail.com
*
* Github: https://github.com/pibotsmakerhub
*
* Join Us on Telegram : https://t.me/pibots
* Copyright (c) 2020 Pi BOTS MakerHub
*/
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
#include "DHT.h"
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
// Configuration of Analog input and outputs
int sensorPin0 = A0; // select the input pin for the potentiometer
int sensorPin2 = A2;
int sensorPin4 = A4;
int ledPin = 13; // select the pin for the LED
int sensorValue0 = 0; // variable to store the value coming from the sensor
int sensorValue2 = 0; // variable to store the value coming from the sensor
int sensorValue4 = 0; // variable to store the value coming from the sensor
int Value0 = 0; // variable to store the value coming from the sensor
int Value2 = 0; // variable to store the value coming from the sensor
int Value4 = 0; // variable to store the value coming from the sensor
int Final_Value0 = 0;
int Final_Value2 = 0;
int Final_Value4 = 0;
int i = 0;
const int nodeID = 5;
float h = 0.0;
float t = 0.0;
void setup() {
Serial.begin(38400);
//Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
//delay(2);
h = dht.readHumidity();
// Read temperature as Celsius (the default)
t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t))
{
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
//Serial.print(F(" Humidity: "));
//Serial.print(h);
//Serial.print(F("% Temperature: "));
//Serial.print(t);
//Serial.print(F("C \n"));
// read the value from the sensor:
sensorValue0 = analogRead(sensorPin0);
sensorValue2 = analogRead(sensorPin2);
sensorValue4 = analogRead(sensorPin4);
//Serial.println();
//Serial.println(sensorValue0);
//Serial.println(sensorValue2);
//Serial.println(sensorValue4);
//Serial.println();
Value0 = Value0+sensorValue0;
Value2 = Value2+sensorValue2;
Value4 = Value4+sensorValue4;
i = i+1;
if (i==10)
{
Final_Value0 = Value0/10;
Final_Value2 = Value2/10;
Final_Value4 = Value4/10;
Value0 = 0; // variable to store the value coming from the sensor
Value2 = 0; // variable to store the value coming from the sensor
Value4 = 0;
i = 0;
//Serial.println("print value after 10 iterations");
//Serial.println(Final_Value0);
//delay(1000);
//Serial.println(Final_Value2);
//delay(1000);
//Serial.println(Final_Value4);
//delay(1000);
//Serial.println("Finish");
//Serial.println("Finish");
//Serial.println("Finish");
}
Serial.print(nodeID); Serial.print(' ');
Serial.print(Final_Value0); Serial.print(" "); // These for compatibilit$
Serial.print(Final_Value2); Serial.print(" ");
Serial.print(Final_Value4); Serial.print(" ");
Serial.print(h); Serial.print(" ");
Serial.print(t); Serial.println();
delay(1000);
}