Setting up a temperature sensor with the esp8266

Yes I tried. but my level of programming is unfortunately low :confused:

Did you even manage to find a regular Arduino sketch for your sensors?

You will also need to indicate what kit you have as are there probably 100+ different devices that can connect to Blynk servers.

I think that’s the right sketch https://www.hackster.io/rei-vilo/weather-and-security-station-with-blynk-74608b

I have esp8266mod

my sketch is

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN            12    
#define DHTTYPE           DHT22

DHT_Unified dht(DHTPIN, DHTTYPE);

char auth[] = "1111111111111";

SimpleTimer timer;

void sendUptime()
{
  // V1 ที่ set ใน app อ่านค่าอุณหภูมิ
  Blynk.virtualWrite(V5, millis() / 1000);
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (!isnan(event.temperature)) {
    Blynk.virtualWrite(V1, event.temperature);
  }
  // V2 ที่ set ใน app อ่านค่าความชื้น
  dht.humidity().getEvent(&event);
  if (!isnan(event.relative_humidity)) {
    Blynk.virtualWrite(V2, event.relative_humidity);
  }
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "liza", "b123455ch");

  dht.begin();
  
  // Setup a function to be called every second
  timer.setInterval(5000L, sendUptime);
}

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

And what happens when you run this sketch?

my sketch work fine. but I can’t add bmp180 like this https://www.hackster.io/rei-vilo/weather-and-security-station-with-blynk-74608b

I asked if you had found a regular Arduino sketch for the BMP180 and you posted a Blynk sketch!!!

Try this link for starters.

the SFE BMP180 library works well with Blynk once you “Blynkify” it :slight_smile:

Please could you share the code with me? alvaroaguero55@gmail.com

Im trying to connect esp8266 nodemcu dht22 (same hardware that yours) and display values by serial print but is not working (same hardware and sketch works with Arduino Genuino but not with Nodemcu esp8266)

I am looking to create this project. I cannot find code that works

Try this…

Pete.

Thani you @PeteKnight . I will give it a try!

@PeteKnight I tried the code. I keep getting a message: Failed to read from DHT sensor.
can you tell me what pin on ESP8266 im supposed to connect to? From the code it seems like virtual pin 5

If you’re getting this message then it’s an issue on your hardware side, not on the Blynk datastream side.
I suspect you’ve not connected the DHT correctly. The code expects the DHT sensor’s data pin to be connected to GPIO2…

#define DHTPIN 2 // What digital pin we're connected to

which is the pin labelled “D4” on the NodeMCU.

The code uses Virtual pins 5 and 6 for humidity and temperature…

  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

so you’ll need to set these datastream up un your template and add widgets in the app connected to these datastreams to view the values.

Pete.

@PeteKnight That solved it! you are the man!
I’ve been trying to figure this out for some time now.

1 Like

Hello! Can you please direct me to any documentation that will explain what GPIO pin corresponds to the pins in the Blynk code?
In my previous post you stated “the code expects the DHT sensor’s data pin to me connected to GPIO2 = D4 on the NodeMCU”
Now I’m working with an LED on the ESP32. The code simply says “LED on V1”. How can I know the corresponding GPIO pin?

Currently I’m getting an alternating message “LED on V1: on” then “Led on V1: off” in the serial monitor.

Thanks in advance.

That’s referring to an LED widget in the Blynk app, connected to a datastream that uses virtual pin V1.

There is no connection whatsoever between virtual pins in Blynk datastreams and physical pins on your hardware device.

Pete.

I’m confused. I’m trying to connect to an external LED. Am I using the wrong code?

Yes.
If you want to turn a physical LED on/off you use the digitalWrite(GPIO number) command.

Your physical LED will need an appropriate current limiting resistor, and will need to be connected to the correct pin on your board.

I’d suggest that you create a new “need help…” topic and explain your aims, and post your hardware details and your current code if you need further help.

Pete.