[SOLVED] Arduino Temperature Personalization

Try declaring X as a global variable, i.e. outside of the loop() and setup() but just somewhere at the top below the includes:

int x;

This will make sure you can access it fro anywhere in your program.

And yes, you need to include the SimpleTimer library, otherwise, you cannot use it.

@Lichtsignaal I am getting value of X=0 when I receive the email. is that something to do that X is not being used in my code, so it has 0 value?

For the timer issue, I did include the library, but I am getting this error:

Multiple libraries were found for "BlynkSimpleStream.h"

Error compiling for board Arduino/Genuino Mega or Mega 2560.

It means the IDE has found more than one library. Is you library folder clean? I.e. no other or double libraries in there?

I think you are right about X. You need to fill it with a value to see a result.

BLYNK_WRITE(V1) // Slider function to get  X Value for use in another function.
{
  int X =  param.asInt();
  
}

This should make the value of X change if you move the slider attached to V1 pin.

1 Like

@Lichtsignaal I had a library issue. I fixed it and then it complied, but its not sending me email as the timer assigned, It only send it once. And I am still getting X=0. I am not sure how to connect the code so X will be managed from the slider.

Can you show us what you got so far, as to the code? Yo must also remember you cannot send more than a couple messages (or even one I think) per minute. This is due to prevent server overload.

@Lichtsignaal I have been working on it since then. Sorry for not updating you, but I got the code working with the slider. This is my full code:

/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial
/* Set this to a bigger number, to enable sending longer messages */
#define BLYNK_MAX_SENDBYTES 128
#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>

int redPin = A2;
int bluePin = A3;
int sensorPin = A10;
unsigned int notified = 0;
int X;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "******";
BlynkTimer timer;

void setup()
{
  Serial1.begin(9600);
  Serial.begin(9600);
Blynk.begin(Serial, auth);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
 Blynk.email("****", "Watch!", "Tempreture Warning!");
 timer.setInterval(5000L,slider);

}

void slider()
{
Blynk.virtualWrite(V1,X);
}


  BLYNK_WRITE(V1) // Slider function to get  X Value for use in another function.
{
  int reading = analogRead(sensorPin);  
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 float temperatureC = (voltage - 0.5) * 100 ;
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
   X =  param.asInt();   
   int maxTemp=X+5;
   int minTemp=X-5;
 if(temperatureF >maxTemp ){
  int emailTemp=temperatureF-5;
  Blynk.email("********", "Warning! High Temp for Baby, Temperature is:",emailTemp );
  //  timer.setInterval(10000L,setup);
  setColor(255, 0, 0); 
  digitalWrite(redPin, HIGH);
 }
  if (temperatureF < minTemp ){
 int emailTemp=(temperatureF-5);
  Blynk.email("******", "Warning! Low Temp for Baby, Tempreture is", emailTemp);
   // timer.setInterval(10000L,setup);
  setColor(255, 0, 0); 
  digitalWrite(redPin, HIGH);
}
else{
setColor(0, 0, 255); // blue
 digitalWrite(bluePin, HIGH);
// timer.setInterval(10000L,setup);
}
timer.setInterval(10000L,slider);
}

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

void setColor(int red,int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
blue = 255 - blue;
#endif  
analogWrite(redPin, red);
analogWrite(bluePin, blue);
}
2 Likes

Thats no problem! I’d rather have you figure it out on your own, saves a lot of hassle later on if you grt a decent grip on things on your own. It’s how I learned too, lol. Tnx for sharing!

1 Like

I want to do something similar Blynk + Wemos D1 mini + TMP36 I hope you can shed some light and point me in the right direction.