[SOLVED] Arduino Temperature Personalization

Well, if you get errors, please show us. We may be able to help with that too :wink:

As for the BLYNK_WRITE part, you have to do something with the value you got. Show us the whole code and we can answer you better.

@Lichtsignaal Thanks again! I ll post the code when I go home tonight.

1 Like

I didn’t yet create a history graph for my project, but I’m certain the readings can be logged to a widget that way.

Blynk has built-in data logging using the History widget :slight_smile:

@Lichtsignaal Here is my code. Bare with me, I never used c or c++ before and this is my first experience. I want to change the value of X ( the temperature setting) based on user preference.

//#define BLYNK_PRINT Serial
#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=0 ; 

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


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

void setup()
{
  // Debug console
 Serial.begin(9600);
 delay(10);
  //Serial.begin(9600);
  Blynk.begin(Serial, auth);
 
 pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);

  // Send e-mail when your hardware gets connected to Blynk Server
  // Just put the recepient's "e-mail address", "Subject" and the "message body"
  Blynk.email(" ", "Subject", X  );
 
}

void sendData()
{
   int reading = analogRead(sensorPin);  
 
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
 // print out the voltage
 Serial.print(voltage); Serial.println(" volts");
 
 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((voltage - 500mV) times 100)
 Serial.print(temperatureC); Serial.println(" degrees C");
 
 // now convert to Fahrenheit
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 
 Serial.print(temperatureF); Serial.println(" degrees F");
 
 delay(1000);                                     //waiting 5 seconds
 
  Blynk.virtualWrite(V1,70);

  if(temperatureF > X && notified == 0)
 {
  notified = 1; 
  Blynk.email(" ", "Subject", X );
  setColor(255, 0, 0);
  digitalWrite(redPin, HIGH);
  delay(1000);
  timer.setTimeout(300000L, resetNotified);
 }else if(temperatureF<78){
  notified = 0;
  setColor(0, 0, 255); // blue
 digitalWrite(bluePin, HIGH);
 delay(1000);
 }
}

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);
}

@Lichtsignaal that’s what I want to use next.

@Lichtsignaal has mentioned there is a history widget, I will do that next.

Two remarks here, remove the delay from the sendData function. Second, your timer will never work because you don’t set a timer interval:

int BlynkTimer = timer.setInterval(5000, sendData);

This will effectively run the sendData() function every 5 seconds. You can put this line in setup() part.

@Lichtsignaal Im trying to change my library from simple timer to Blynk timer. My coonection is through USB Serial. The blynktimer library for USB Serial is
include <BlynkSimpleSerialBLE.h>
Im guessing this is for BLE use. Do you know how should I use for USB Serial?
Also I still have problem for the slider, the value of X i am getting in the email is always 0.

See my post above yours, you need to set a timer to run periodically, that’s how you do it.

The library for USB Serial connection for Blynk is in the Blynk Example Browser, top of this page, Sketch Builder. Select Arduino and see the Serial USB or SoftSerial USB example :slight_smile:

@Lichtsignaal From the timer example for USB Serial, it looks like there is no need for a timer library. However, when I run the code, it say that Blynk timer does not name a type and it refer to this line of code:
BlynkTimer timer;

Also, for this line of code. I realized I have to change it from 70 in the earlier code to X. But I I have to call for X under the Send data Function because X is not declared in that scope. Can you please tell me how to call for it?

 Blynk.virtualWrite(V1,X);

  if(temperatureF > X && notified == 0)
 {

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.