BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk + Wemos D1 mini + TMP36


#15

So perhaps look at the examples? :stuck_out_tongue_winking_eye: This is just one of many, including the link I sent you above.

https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=GettingStarted%2FVirtualPinWrite


#16

thank you. i didnt know about the example sketch generator. what is virtual pin 5? on my wemos d1 mini i dont have any such pin.


#17

All the links for the Documentation, Help Center and Sketch Builder are at the top of this page… you may need to scroll up to see them.

here is a link for that info…

Virtual pins are virtual :stuck_out_tongue_winking_eye: and are meant to transfer information between the App and the sketch, not part of the physical GPIO.

Note, when programming ESP boards with Arduino IDE you do NOT normally use the silkscreened pin designations, rather you would use the Arduino pin designations.


#18
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "aec5825e0cee4708b9b293f0d8755fae";

char ssid[] = "YYYY";
char pass[] = "XXXXXXX";

BLYNK_READ(V5) //Blynk app has something on V5
{
  sensorData = analogRead(A0); //reading the sensor on A0
  Blynk.virtualWrite(V5, sensorData); //sending to Blynk
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

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

ok so i tried uploading this code after reviewing some of the examples but the code wont upload. its says sensor data was not declared in this scope.


#19

All variables need to be declared in some way, either within the function where that are used or globally where they can be used throughout the code.

Programming 101…

https://www.arduino.cc/en/Reference/VariableDeclaration

https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/


#20
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "aec5825e0cee4708b9b293f0d8755fae";

char ssid[] = "xxxx";
char pass[] = "xxxx";

int sensorPin = 0;

BLYNK_READ(V5)
{
 int reading = analogRead(sensorPin); 
 float voltage = reading * 3.3; 
 voltage /= 1024.0;
 float temperatureC = (voltage - 0.5) * 100;
 Blynk.virtualWrite(V5, temperatureC); //sending to Blynk
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

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

So something is happening. the code uploaded. i am getting values on the app however they not accurate. i remember with serial monitor they were making sense.


#21

Again… Proper method for formatting posted code is as follows…

Blynk - FTFC


#22

yes i fixed the formatting now. thanks


#23

You last code looks like it is missing libraries for the sensor?

EDIT, hard to say now… I am unfamiliar with that sensor… however Blynk cannot alter how the sensor works. Only your code and calculations for the sensor and MCU variances matter.

What is the reading frequency you are using in the display widget?


#24

under input
V5 pin, 0 to 1023
reading rate
push


#25

You need a timer and BLYNK_WRITE() for that setting

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynk_writevpin

http://docs.blynk.cc/#blynk-firmware-blynktimer

Or just change the Widget to a reading rate of 1 second or more to properly work with BLYNK_READ()

Is this sensor hooked up to the Analog pin (if so, use A0 - It is in a pin category of it’s own) or the digital pin 0 (D3)? I don’t think it works on the digital, so you are probably not reading the sensor at all :stuck_out_tongue:


#26
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";

char ssid[] = "";
char pass[] = "";

BLYNK_READ(V5)
{
 int reading = analogRead(A0); 
 float voltage = reading * 3.3; 
 voltage /= 1024.0;
 float temperatureC = (voltage - 0.5) * 100;
 Blynk.virtualWrite(V5, temperatureC); //sending to Blynk
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

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

The above code worked. Thanks Gunner! You pushing me helped for sure.

for noobs out there like me the above code gets uploaded on wemos d1 mini using adruino.

on blynk app select value widget, go to its settings set v5 as input and reading rate to anything expect push

the hardware set up is as such
connect tmp36 pin 1 to 3v3 pin on wemos d1 mini board
tmp36 pin 2 to a0 pin on wemos d1 mini board
tmp36 pin 3 to gnd on wemos d1 mini

Next is to have blynk push a notification on my android phone when the temperature drops below a set point to monitor temperature on my house pipes. Is that possible?


#27

Yes, but you need to make sure there is a degree (pun intended) of hysteresis and other logic to keep from spamming notifications too frequently if the temperature is fluctuating a degree back and forth. That basically comes down to code. Search this site for keywords like hysteresis, notification etc.

http://docs.blynk.cc/#widgets-notifications-push-notifications

https://www.arduino.cc/reference/en/language/structure/control-structure/if/

https://www.arduino.cc/reference/en/

Also, I believe the BLYNK_READ() & Widget reading rate combo only works when the App is active… for background monitoring, look at the BlynkTimer, BLYNK_WRITE() and Widget PUSH combo.


#30

I have modified yesterday working code which displayed real time temp on blynk app every 1 sec to add functionality of notify at set point or below. display function still works on app but it does not notify. any one that can point me in the right direction it will help

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";

char ssid[] = "";
char pass[] = "";

BLYNK_READ(V5)
{
 int reading = analogRead(A0); 
 float voltage = reading * 3.3; 
 voltage /= 1024.0;
 float temperatureC = (voltage - 0.5) * 100;
 Blynk.virtualWrite(V5, temperatureC); 
}

void notifyOnhightemp()
{
 
  int temperatureC = analogRead(A0); 
  if (temperatureC > 20 ) {
    Serial.println("pipe temp is getting high");
    Blynk.notify("Danger..Pipe Temp is high");
  }
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
    
}

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


#31

You have nothing calling notifyOnhightemp() so of course nothing happens. You would need to merge this process into the BLYNK_READ() or add a function call into the BLYNK_READ() or use a seperate timer, etc.

Also, the way you have it, once something is setup to call that function it will constantly notify you when the temperature is above 20, you need some form of flag to prevent it from happening more than once.

Remember, you also need to have the Notification Widget in your Project.

Search this forum for other topics about temperature notifications and read how they do it… but keep your questions in your own topic, no need to reopen old topics.


#32

i have notification widget setup in the project. how do i add a function call in the BLYNK_READ()?


#33

#34
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";

char ssid[] = "";
char pass[] = "";

BLYNK_READ(V5)
{
 int reading = analogRead(A0); 
 float voltage = reading * 3.3; 
 voltage /= 1024.0;
 float temperatureC = (voltage - 0.5) * 100;
 Blynk.virtualWrite(V5, temperatureC); 
 notifyOnhightemp;
}

void notifyOnhightemp()
{
 
  int temperatureC = analogRead(A0); 
  if (temperatureC > 20 ) {
    Serial.println("pipe temp is getting high");
    Blynk.notify("Danger..Pipe Temp is high");
  }
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

i have added a function call and the sketch uploads but it still doesnt notify me. PS i do have notify widget on the app as well.


#35

You are only declaring your variables within a single function, if you want them to work outside of that function you need to declare them Globally.

https://playground.arduino.cc/Code/VariableScope


#36

not working but i appreciate your help. thanks you may close this post.