#include <ESP8266WiFi.h>
#include <DHT.h> // Including library for dht
#include <DallasTemperature.h> //for body temp
#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h> /// for notfication
#include <UniversalTelegramBot.h> // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>
LiquidCrystal_I2C lcd(0x27,16,2); //0x27 is the i2c address, while 16 = columns, and 2 = rows.
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
#include <LiquidCrystal.h>
String apiKey = "AZG3E3KOTX4NH1H1"; // Enter your Write API key from ThingSpeak
const char *ssid = "EETD"; // replace with your wifi ssid and wpa2 key
const char *pass = "passwordattceetd2022*";
const char* server = "api.thingspeak.com";
char auth[] = "EHAfZjPGLhqktPgP34fxMCAcEqOZ9VDp"; // Enter the Auth Token provied by Blynk app
#define ONE_WIRE_BUS 4 //D2 pin of nodemcu
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
#define ledpin D0
#define switch D1 // pin where the led is connected
#define DHTPIN D5 //pin where the dht11 is connected
DHT dht(DHTPIN, DHT22);
#define ONE_WIRE_BUS D3 // Data wire is connected to GPIO 4 i.e. D2 pin of nodemcu
int val;
int PulseSensorpin = A0; //Pulse Sensor Pin Connected at A0 Pin
double alpha=0.75;
int period=20;
double refresh=0.0;
WiFiClient client;
void setup(void)
{
Serial.begin(9600);
pinMode(switch,INPUT); //set the pushbutton as input
pinMode(ledpin,OUTPUT); //set the led as output
Blynk.begin(auth, ssid, pass);
Serial.begin(9600);
delay(10);
sensors.begin();
dht.begin();
Wire.begin(2,0); // gpio 2 and gpio 0 which are D4, and D3
lcd.init(); //Init the LCD
lcd.backlight(); //Activate backlight
lcd.home();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop(void)
{
Blynk.run();
if(digitalRead(switch) == HIGH)
{
digitalWrite(ledpin,HIGH);
Serial.println("Send Notification to Blynk");
Blynk.notify("READY TO SEE PATIENT CONDITION"); // This notification will be sent to Blynk App
}
if(dht.readTemperature()<= 26 && sensors.getTempCByIndex(0)<=37){
Blynk.email("eyobmillion425@gmail.com", "Doctor Alert", "You are in good condition!");
}
else{Blynk.email("eyobmillion425@gmail.com", "Doctor Alert", "You have to go for more checkups!");
}
static double oldValue=0;
static double oldrefresh=0;
int val = analogRead(PulseSensorpin); //Read Analog values and Store in val variable
double value=alpha*oldValue+(0-alpha)*val;
refresh=value-oldValue;
oldValue=value;
oldrefresh=refresh;
delay(period*10);
Serial.println("Pulse Sensorvalue= "); // Start Printing on Pulse sensor value on LCD
Serial.println(110-refresh); // Start Printing on Pulse sensor value on LCD
delay(10);
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
delay(500);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
lcd.setCursor(0, 0);
lcd.print("Room Temp=");
lcd.print( dht.readTemperature());
lcd.setCursor(0, 1);
lcd.print("Body temp=");
lcd.print(sensors.getTempCByIndex(0));
delay(2000);
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(sensors.getTempCByIndex(0));
postStr +="&field2=";
postStr += String(t);
postStr +="&field3=";
postStr += String(h);
postStr +="&field4=";
postStr += String(refresh);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates
delay(1000);
}
Comments