Skip to content

Instantly share code, notes, and snippets.

@isaiah7p
Created August 1, 2020 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isaiah7p/b72c8443e0af1651cd1fc26ef9d37cc0 to your computer and use it in GitHub Desktop.
Save isaiah7p/b72c8443e0af1651cd1fc26ef9d37cc0 to your computer and use it in GitHub Desktop.
// Board to Sensors / Actuators Mapping
//
//1. Input Switch 1 : GPI0 03 (D9) >> Button 1
//2. Input Switch 2 : GPI0 01 (D10) >> Button 2
//3. Output Relay 1 : GPI0 05 (D1)
 >> Relay 1
//4. Output Relay 2 : GPI0 04 (D2)
 >> Relay 2
//5. Output LED : GPI0 12 (D6)
 >> LED
//6. Temperature & Humidity Sensor
//DHT-11 : GPI0 14 (D5) >> DHT Sensor
#include "DHT.h"
#define DHTPIN 14
#define DHTTYPE DHT11
int inputSwtich1 = 3;
int inputSwtich2 = 1;
int outputRelay1 = 5;
int outputRelay2 = 4;
int led = 12;
int dhtPin = 14;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200); // setting up serial monitor
// put your setup code here, to run once:
//INPUT, OUTPUT, or INPUT_PULLUP.
pinMode(inputSwtich1, INPUT);
pinMode(inputSwtich2, INPUT);
pinMode(outputRelay1, OUTPUT);
pinMode(outputRelay2, OUTPUT);
pinMode(led, OUTPUT);
Serial.println(" PinMode : Done ");
// setting initial conditions :
digitalWrite(outputRelay1, LOW);
digitalWrite(outputRelay2, LOW);
digitalWrite(led, LOW);
Serial.println(" Initialisation : Done ");
//
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
// Reading Sensor Data :
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)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
// Read switch 1 & 2
int val1 = !digitalRead(inputSwtich1);
digitalWrite(led, val1);
digitalWrite(outputRelay1, val1);
digitalWrite(outputRelay2, val1);
// Serial.println(" Turning on Relays and LED Devices : Done ");
// digitalWrite(outputRelay1, HIGH);
// digitalWrite(outputRelay2, HIGH);
// //digitalWrite(led, HIGH);
// delay(2000);
// Serial.println(" Turning off Relays and LED Devices : Done ");
// digitalWrite(outputRelay1, LOW);
// digitalWrite(outputRelay2, LOW);
//
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment