W5100+DS18B20+Notification

Hello, I’m working on a project right now. The temperature was measured using a ds18b20 sensor in conjunction with the w5100 to send the value to blynk, but I wanted to add an alarm when the temperature was above a set value with blynk’s alert or email, so I need someone to know about it. To make this project possible
and here is my code

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

char auth[] = "xxxxxxxxxxxxxxx"; 
BlynkTimer timer;

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);


DallasTemperature DSTEMP(&oneWire);

uint8_t DSTEMP1[8] = { 0x28, 0x94, 0x88, 0x16, 0xA8, 0x01, 0x3C, 0xBD };
uint8_t DSTEMP2[8] = { 0x28, 0xBE, 0x2C, 0x79, 0xA2, 0x01, 0x03, 0x77 };


void setup(void)
{
  Serial.begin(9600);
  DSTEMP.begin();
  Blynk.begin(auth);
 

}

void loop(void)
{
  DSTEMP.requestTemperatures();
  Blynk.run();



  Serial.print("Temperature 1: ");
  Serial.print(DSTEMP.getTempC(DSTEMP1));
  Serial.print("C");


  Serial.print("Temperature 2: ");
  Serial.print(DSTEMP.getTempC(DSTEMP2));
  Serial.print("C");





  Blynk.virtualWrite(V5, DSTEMP.getTempC(DSTEMP1));
  Blynk.virtualWrite(V6, DSTEMP.getTempC(DSTEMP2));

  Serial.println();
  delay(1000);
}

@Thanet please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Thanks for your advice

Can you help me with anything I want to know?

First of all keep your void loop clean. No delays and Blynk virtual writes must be present. It should have only Blynk.run inside loop.

Create a function which is called by a timer every second to read and update on to Blynk app.

Create a second function or integrate in to the existing function which compares your set temperature and real-time temperature and then get the notification or email with Blynk.notify and Blynk.email.

Thank you,
but I’m not sure if I’m doing the right thing you suggest

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

char auth[] = "oSXO6bBHHSkWEfWmabL84V_wmst-uW2C";

BlynkTimer timer;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DSTEMP(&oneWire);

uint8_t DSTEMP1[8] = { 0x28, 0x94, 0x88, 0x16, 0xA8, 0x01, 0x3C, 0xBD };
uint8_t DSTEMP2[8] = { 0x28, 0xBE, 0x2C, 0x79, 0xA2, 0x01, 0x03, 0x77 };

void setup()
{
  Serial.begin(9600);
  DSTEMP.begin();
  Blynk.begin(auth);
  timer.setInterval( 10000, Sensor);


}

void loop()
{
  Blynk.run();
  timer.run(); 

}

void Sensor()
{
  DSTEMP.requestTemperatures();
  Serial.print("Temperature 1: ");
  Serial.print(DSTEMP.getTempC(DSTEMP1));
  Serial.print("C");


  Serial.print("Temperature 2: ");
  Serial.print(DSTEMP.getTempC(DSTEMP2));
  Serial.print("C");

  Blynk.virtualWrite(V5, DSTEMP.getTempC(DSTEMP1));
  Blynk.virtualWrite(V6, DSTEMP.getTempC(DSTEMP2));

  Serial.println();

}

That’s looking better, have you tested this new code?

You now need…

Global variables to hold the alarm trigger temperatures (different ones for each sensor location?)

Some code in your Sensor() function which compares the temperature sensor reading to the trigger temperatures and sends a notification if one or other is too high.

You should also have global variables that indicate if a notification has been sent already for the current high temperature alert status. You’ll use this as a flag, and the if statement mentioned above should look at the status of the notified flag to see if a notification has been sent already. if it has then do nothing. If the temperature drops below the alert level then you reset the notification flag. You may need two flags if you are sending different notifications for the two sensors, or need different logic if one sensor is below the alert level and the other is above.

Pete.

I would like to receive an alert when one of the sensors exceeds the set temperature and the other does not alert when the temperature is below a certain value. I still don’t have enough knowledge of what you are suggesting as this is my study project and of course this is my first project too. If you have any more detailed tips or articles It will be very helpful to me. And will definitely help me to continue this project

Maybe it’s time to start learning some simple C++ programming to help you achieve your own goals, rather than hoping that others will write your code for you?

You’ll get a much better reception here if you’ve done 90% of the work yourself already, and just need a little help ironing-our the wrinkles.

Pete.

I’ll definitely go back to learning C programming, but I don’t want anyone to code me like you think. Thanks for the advice.

1 Like