Commit 45fece52 authored by Kencho Wangdi's avatar Kencho Wangdi
Browse files

code

parent 382c5a39
Pipeline #319280 passed with stage
in 55 seconds
......@@ -216,13 +216,9 @@ The design of the microcontroller case was printed using 3D printer.
Once all the above process were done I did the coding part.
```
// cdoe modified by kencho wangdi
// fabacademy student 2022
//BHUTAN
#include "DHT.h"
#include <WiFi.h>
#include "ThingSpeak.h"
#define DHT11Pin 19
#define DHTType DHT11
//OLED
......@@ -238,26 +234,38 @@ float tempF;
const char* ssid = "dd-wrt_vap"; // your network SSID (name)
const char* password = "fab172030!"; // your network password
const int TEMP_THRESHOLD_UPPER = 28; // upper threshold of temperature, change to your desire value
const int TEMP_THRESHOLD_LOWER = 25; // lower threshold of temperature, change to your desire value
const int HUM_THRESHOLD_LOWER = 70;
unsigned long onTime = 1000;
unsigned long offTime = 1000;
unsigned long previousMillis=0;
// Interval is how long we wait
int interval = onTime;
// Used to track if LED should be on or off
boolean state = true;
//OLED define
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
WiFiClient client;
unsigned long myChannelNumber = 1740990;
const char * myWriteAPIKey = "T0PLONIHX01RJ9TI";
void setup() {
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(19,OUTPUT);
pinMode(18,OUTPUT);
Serial.begin(9600);
//For DHT11
HT.begin();
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
//For OLED I2C
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
......@@ -270,10 +278,11 @@ void setup() {
}
void loop() {
delay(1000); //wait for few measurement.
delay(1000);
humi = HT.readHumidity();
tempC = HT.readTemperature();
tempF = HT.readTemperature(true);
Serial.println(humi);
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
......@@ -283,6 +292,8 @@ void loop() {
}
Serial.println("\nConnected.");
}
int x = ThingSpeak.writeField(myChannelNumber, 1, tempC, myWriteAPIKey);
int y = ThingSpeak.writeField(myChannelNumber, 2, humi, myWriteAPIKey);
display.clearDisplay();
oledDisplayHeader();
......@@ -291,30 +302,48 @@ void loop() {
oledDisplay(2,70,44,tempF,"F");
display.display();
digitalWrite(18,state);
unsigned long currentMillis = millis();
if( tempC >TEMP_THRESHOLD_UPPER)
if( tempC<25 ) // 12=Light Bulb , 13= FAN , 18=Humdifier
{
digitalWrite(13,HIGH); // turn on fan
digitalWrite(12,LOW);
}
else
{
digitalWrite(12,HIGH);
}
else if(tempC < TEMP_THRESHOLD_LOWER)
{
digitalWrite(12, LOW); // turn on Heater
}
if( humi< HUM_THRESHOLD_LOWER )
if( tempC>30 ) // 12=Light Bulb , 13= FAN , 18=Humdifier
{
digitalWrite(19,LOW);// dc motor turn on
}
digitalWrite(13,LOW);
}
else
{
digitalWrite(13,HIGH);
}
label:
if( humi<70 )
{
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
// Change wait interval, based on current LED state
if (state) {
interval = offTime;
} else {
interval = onTime;
}
state = !(state);
previousMillis = currentMillis;
}
}
else{
digitalWrite(19,HIGH);
delay(2000);
digitalWrite(18,HIGH);
}
}
void oledDisplayHeader(){
display.setTextSize(1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment