// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// 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 DHT1_PIN 13 // for first DHT module
#define DHT2_PIN 12 // for 2nd DHT module and do the same for 3rd and 4th etc.
#define DHT3_PIN 14 // for 2nd DHT module and do the same for 3rd and 4th etc.
#define DHT4_PIN 27 // for 2nd DHT module and do the same for 3rd and 4th etc.
#define DHT5_PIN 26 // for 2nd DHT module and do the same for 3rd and 4th etc.
#define sensor_suara 34
#define sensor_kecepatan_angin 35
//#define DHTPIN 15 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
//DHT dht(DHTPIN, DHTTYPE);
DHT dht1(DHT1_PIN, DHTTYPE); //for first DHT module
DHT dht2(DHT2_PIN, DHTTYPE); // for 2nd DHT module and do the same for 3rd and 4th etc.
DHT dht3(DHT3_PIN, DHTTYPE); // for 2nd DHT module and do the same for 3rd and 4th etc.
DHT dht4(DHT4_PIN, DHTTYPE); // for 2nd DHT module and do the same for 3rd and 4th etc.
DHT dht5(DHT5_PIN, DHTTYPE); // for 2nd DHT module and do the same for 3rd and 4th etc.
float t1;
float t2;
float t3;
float t4;
float t5;
float h1;
float h2;
float h3;
float h4;
float h5;
//int sensor_suara = 34; // select the input pin for the potentiometer
int nilai_Sensor_suara = 0; // v
//int sensor_kecepatan_angin = 35; // select the input pin for the potentiometer
int nilai_sensor_kecepatan_angin = 0; // v
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht1.begin(); //for first DHT module
dht2.begin(); //for 2nd DHT module and do the same for 3rd and 4th etc.
dht3.begin(); //for 2nd DHT module and do the same for 3rd and 4th etc.
dht4.begin(); //for 2nd DHT module and do the same for 3rd and 4th etc.
dht5.begin(); //for 2nd DHT module and do the same for 3rd and 4th etc.
//dht.begin();
}
void loop() {
cek_sensor();
}
void cek_sensor() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h1 = dht1.readHumidity();
// Read temperature as Celsius (the default)
t1 = dht1.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h1) || isnan(t1)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity1: "));
Serial.print(h1);
Serial.print(F("% Temperature1: "));
Serial.print(t1);
Serial.println();
// Wait a few seconds between measurements.
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h2 = dht2.readHumidity();
// Read temperature as Celsius (the default)
t2 = dht2.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h2) || isnan(t2)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity2: "));
Serial.print(h2);
Serial.print(F("% Temperature2: "));
Serial.print(t2);
Serial.println();
// Wait a few seconds between measurements.
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h3 = dht3.readHumidity();
// Read temperature as Celsius (the default)
t3 = dht3.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h3) || isnan(t3)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity3: "));
Serial.print(h3);
Serial.print(F("% Temperature3: "));
Serial.print(t3);
Serial.println();
// Wait a few seconds between measurements.
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h4 = dht4.readHumidity();
// Read temperature as Celsius (the default)
t4 = dht4.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h4) || isnan(t4)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity4: "));
Serial.print(h4);
Serial.print(F("% Temperature4: "));
Serial.print(t4);
Serial.println();
// Wait a few seconds between measurements.
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h5 = dht5.readHumidity();
// Read temperature as Celsius (the default)
t5 = dht5.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h5) || isnan(t5)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity5: "));
Serial.print(h5);
Serial.print(F("% Temperature5: "));
Serial.print(t5);
Serial.println();
nilai_Sensor_suara = analogRead(sensor_suara);
nilai_Sensor_suara = map(nilai_Sensor_suara, 4095, 0, 1024, 0);
nilai_sensor_kecepatan_angin = analogRead(sensor_kecepatan_angin);
nilai_sensor_kecepatan_angin = map(nilai_sensor_kecepatan_angin, 4095, 0, 1024, 0);
Serial.println("Kebisingan: " + String(nilai_Sensor_suara));
Serial.println("Kecepatan udara: " + String(nilai_sensor_kecepatan_angin));
}