Skip to main content
. 2022 Sep 6;22(18):6733. doi: 10.3390/s22186733
Algorithm A1: Source Code RTU 1
  1. //#include "DHT.h"

  2. //#define DHTPIN 2   // Digital pin connected to the DHT sensor

  3. //#define DHTTYPE DHT11   // DHT 11

  4. //DHT dht(DHTPIN, DHTTYPE);

  5. // Configuration of Analog input and outputs

  6. int sensorPin0 = A0;   // select the input pin for the potentiometer

  7. int sensorPin2 = A2;

  8. int sensorPin4 = A4;

  9. int sensorValue0 = 0;  // variable to store the value coming from the sensor

  10. int sensorValue2 = 0;  // variable to store the value coming from the sensor

  11. int sensorValue4 = 0;  // variable to store the value coming from the sensor

  12. int Value0 = 0;   // variable to store the value coming from the sensor

  13. int Value2 = 0;   // variable to store the value coming from the sensor

  14. int Value4 = 0;   // variable to store the value coming from the sensor

  15. int Final_Value0 = 0;

  16. int Final_Value2 = 0;

  17. int Final_Value4 = 0;

  18. int i = 0;

  19. const int nodeID = 5;

  20. int h = 0.0;

  21. int t = 0.0;

  22. void setup() {

  23. Serial.begin(38400);

  24. //dht.begin();

  25. }

  26. void loop ()

  27. {

  28.  //h = dht.readHumidity();

  29.  //t = dht.readTemperature();

  30.   sensorValue0 = analogRead(sensorPin0);

  31.   sensorValue2 = analogRead(sensorPin2);

  32.   sensorValue4 = analogRead(sensorPin4);

  33.   Value0 = Value0+sensorValue0;

  34.   Value2 = Value2+sensorValue2;

  35.   Value4 = Value4+sensorValue4;

  36.   i = i+1;

  37.   if (i==10)

  38.   {

  39.  Final_Value0 = Value0/10;

  40.  Final_Value2 = Value2/10;

  41.  Final_Value4 = Value4/10;

  42.  Value0 = 0; // variable to store the value coming from the sensor

  43.  Value2 = 0; // variable to store the value coming from the sensor

  44.  Value4 = 0;

  45.  i = 0;

  46.  }

  47. Serial.print(nodeID); Serial.print(' ');

  48. Serial.print(Final_Value0); Serial.print(" "); // These for compatibilit$

  49. Serial.print(Final_Value2); Serial.print(" ");

  50. Serial.print(Final_Value4); Serial.print(" ");

  51. Serial.print(h); Serial.print(" ");

  52. Serial.print(t); Serial.println();

  53. delay(1000);

  54. }