0% found this document useful (0 votes)
29 views5 pages

Cod

Uploaded by

abhinavfystudent
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

Cod

Uploaded by

abhinavfystudent
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// T/F Monitoring

#include <Wire.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal.h>

LiquidCrystal lcd(8,9,10,11,12,13);

SoftwareSerial esp(2, 3);

//**************************************************
#include <DallasTemperature.h>
#define ONE_WIRE_BUS A2
// Setup a oneWire instance to communicate with any OneWire devices (not just
Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int temp;
//************************************

int CT=A0;

int celsius,p6,gas;

#define L A1

float current;
int bz=7;
int rl=6;
int val, reading;
//************************************
//String myAPIkey = "72E5WOY95GIS7DSV";//old

#define DEBUG true


#define IP "184.106.153.149"// thingspeak.com ip
String Api_key = "GET /update?key=B7L6K8WN6Q0DFM3T"; //change it with your api key
like "GET /update?key=Your Api Key"
//IV6Y77TOZW75L4G3
int err;
long writingTimer =20; //server response time in sec
long startTime = 0;
long waitTime = 0;

//***************************************

void setup()
{

pinMode(CT,INPUT);
pinMode(L,INPUT_PULLUP);
// pinMode(Lv,INPUT_PULLUP);
pinMode(bz,OUTPUT);
pinMode(rl,OUTPUT);

digitalWrite(bz,HIGH);
delay(500);
digitalWrite(bz,LOW);

delay(500);
lcd.print("T/F Monitoring");
Serial.println("transformer");
lcd.setCursor(0,1);
lcd.print("Project By:Pratik ");
delay(1500);
lcd.clear();
lcd.print("Vaibhav,Pratiksha");
lcd.setCursor(0,1);
lcd.print("Durgesh,Prathmesh");
delay(1000);
lcd.clear();
lcd.print("Machhindra");
delay(1000);
// wifi();
}

void loop()

temp1();

Oil();

ct();
if (waitTime > (writingTimer*1000))
{

lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Updating ");

updatedata();

}
void readSensor(){

p6 = digitalRead(L);
Serial.println(p6);
sensors.requestTemperatures();

temp =sensors.getTempCByIndex(0);
Serial.print("c: "); Serial.println(temp);
val = analogRead(CT);
//Serial.println(celsius);
Serial.println("CT");
float adcVoltage = (val / 1024.0) * 5;
//float current =((adcVoltage-2500)/66);
current=((4.73*adcVoltage)); // 330ohm
//Serial.println(val);
///Serial.println(adcVoltage);
//Serial.println(current);
}

void temp1()
{
sensors.requestTemperatures();
Serial.print("Temperature is: ");
temp =sensors.getTempCByIndex(0);
Serial.print("c "); Serial.println(temp);

if(temp>40)

Serial.println("Temprature Is High");
lcd.clear();
lcd.print("Over temp");

digitalWrite(bz,HIGH);
delay(1000);

digitalWrite(bz,LOW);
}
else
{
digitalWrite(bz,LOW);
}
}

void Oil()
{
if(p6 ==0)
{
Serial.println("Oil Level Below Normal level And Above 50%");
lcd.clear();
lcd.print("oil Level Low");

digitalWrite(bz,HIGH);
delay(1000);
}
else
{

digitalWrite(bz,LOW);

}
}

void ct()
{
if(current>2)
{

lcd.clear();
lcd.print("Over current");
delay(1000);
Serial.println("Over Current");
digitalWrite(rl,HIGH);
digitalWrite(bz,HIGH);
delay(2000);

digitalWrite(bz,LOW);

}
else
{digitalWrite(rl,LOW);

void display1()
{
lcd.clear();
lcd.print("Temp CT Oil");

lcd.setCursor(0,1);
lcd.print(temp);
lcd.setCursor(5,1);
lcd.print(current);
if(p6==1)
{
lcd.setCursor(10,1);
lcd.print("Normal");
}
else
{
lcd.setCursor(10,1);
lcd.print("LoW");

}
delay(1000);

void updatedata(){

String command = "AT+CIPSTART=\"TCP\",\"";


command += IP;
command += "\",80";
Serial.println(command);
esp.println(command);
delay(2000);
if(esp.find("err")){
return;
}
command = Api_key ;
command += "&field1=";
command += current;
command += "&field2=";
command += p6;
command += "&field3=";
command += temp;

command += "\r\n";
Serial.print("AT+CIPSEND=");
esp.print("AT+CIPSEND=");
Serial.println(command.length());
esp.println(command.length());

Serial.println("AT+CIPCLOSE");
esp.println("AT+CIPCLOSE");
//Resend...

String send_command(String command, const int timeout, boolean debug)


{
String response = "";
esp.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp.available())
{

}
}
if (debug)
{
Serial.print(response);
}
return response;
}

void wifi(){

send_command("AT+CWJAP=\"IOT\",\"IOT123456\"\r\n", 2000, DEBUG); //connect wifi


network
while(!esp.find("OK")) { //wait for connection
Serial.println("Connecting...");
lcd.clear();
lcd.print("connecting.....");
delay(500);

Serial.println("Connected ok");
lcd.clear();
lcd.print("Connected");
delay(500);

You might also like