#define BLYNK_TEMPLATE_ID "TMPL3KDqpsa3o"
#define BLYNK_TEMPLATE_NAME "Smart cattle monitoring"
#define BLYNK_AUTH_TOKEN "uNpam4dUBEG_QjtQQdICGeYrYjXUcCm8"
#define BLYNK_PRINT Serial
#include <Wire.h>
#include<WiFi.h>
#include<WiFiClient.h>
#include<BlynkSimpleEsp32.h>
#include<DHT.h>
#include<HardwareSerial.h>
#include "ThingSpeak.h"
#define DHTTYPE DHT22
#define DHTPIN 17
byte led=12;
byte led2=27;
int buzzer=18;
char ssid[]="Wokwi-GUEST";
char pass[]="";
char auth[]="uNpam4dUBEG_QjtQQdICGeYrYjXUcCm8";
const int myChannelNumber =2716601 ;
const char* myApiKey = "77QT06E0MK2P6SGW";
const char* server = "https://thingspeak.mathworks.com/";
const float potPin=34;
float potValue=0;
const float rate=4;
float rate_value=0;
DHT dht(DHTPIN,DHTTYPE,22);
BlynkTimer timer;
WiFiClient client;
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, pass);
Blynk.begin(auth,ssid,pass);
timer.setInterval(2000L,sendData);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(buzzer, OUTPUT);
Serial.println("reading data from the cattle!");
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void sendData(){
potValue=analogRead(potPin);
rate_value=analogRead(rate);
float h=dht.readHumidity();
float t=dht.readTemperature();
Serial.println("oxygen:" +String(potValue));
Serial.println("humidity:" +String(h));
Serial.println("temperature:" +String(t));
Serial.println("Pluse_level:" +String(rate_value));
Blynk.virtualWrite(V2,potValue);
Blynk.virtualWrite(V1,h);
Blynk.virtualWrite(V0,t);
Blynk.virtualWrite(V3,rate_value);
ThingSpeak.setField(4,potValue);
ThingSpeak.writeFields(myChannelNumber,myApiKey);
if(t>38)
{
Serial.println("health issues is detacted!treat your cattle quickly");
Blynk.virtualWrite(V3,HIGH);
digitalWrite(led, HIGH);
tone(buzzer,200);
delay(1000L);
}
else
{
Blynk.virtualWrite(V3,LOW);
digitalWrite(led, LOW);
tone(buzzer,0);
}
if(potValue<50)
{
Serial.println("your cattle oxygen level is too low");
Blynk.virtualWrite(V4,HIGH);
digitalWrite(led2, HIGH);
tone(buzzer,200);
delay(1000L);
}
else
{
Blynk.virtualWrite(V4,LOW);
digitalWrite(led2, LOW);
tone(buzzer,0);
}
}
void loop(){
Blynk.run();
timer.run();
}