Virtual Write of an Analog Pin

I have not read the data sheet regarding the warm up time but by feeling it i can tell it gets hot after five minutes. i also notice the readings dont jump around so much after it gets hot.

i want only the raw 1024 number not for early warning but to track throughout the day periodically, for example i want it to turn on, remain on for 6 minutes, turn off for 24 minutes continuously. i can from there see the values rise or fall for interest sake on my weather station.

i am going to try separate the two functions then, i will keep the raw reading one if i can find it, i only really understand excel this code is a whole other level.

Thank you very much your very helpful, especially about the long integer

sorry it is A2 to V2

Your problem is that you are using GPIO2 (personally Iā€™d just reference it as 2 rather than A2 and that is an ADC2 pin, whic canā€™t be used at the same time as WiFi.

As a result, you need to use an ADC1 pin, which means one of the followingā€¦

  • ADC1_CH0 (GPIO 36)
  • ADC1_CH1 (GPIO 37)
  • ADC1_CH2 (GPIO 38)
  • ADC1_CH3 (GPIO 39)
  • ADC1_CH4 (GPIO 32)
  • ADC1_CH5 (GPIO 33)
  • ADC1_CH6 (GPIO 34)
  • ADC1_CH7 (GPIO 35)

You can read more hereā€¦

Pete.

Iā€™ve explained that the problem is the GPIO pin using for the analog input.

Pete.

Then would i reference it as ADC1 or 32? if i was using that one.

32

Pete.

I have been trying the whole night, trying by changing and swapping around terms i think i know.
please could someone tell me where its wrong or how to fix it


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Home";
char pass[] = "H@1l3yB3@r21";

#define DHTPIN 4          // What digital pin we're connected to
#define V2 32

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
    
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  Blynk.virtualWrite(V2, int);
  
}



void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  dht.begin();
 
    
  // Setup a function to be called every second
  timer.setInterval(5000L, sendSensor);
}
void loop()
{
  Blynk.run();
  timer.run();
}

The temperature and humidity from the DHT11 is wroking fine but i cant pull reading from the MQ7 sensor on pin A4/32

This makes no sense.
Previously you had ā€¦

Which should have been changed toā€¦

#define A_PIN 32

Nowhere in your code are you taking a reading of the A_PIN and storing the result in a variable, and this makes no sense at allā€¦

Pete.

Try this:

Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
Serial.print("Sensor reading: ");
Serial.println(Gas);
Gas = 1000;
Blynk.virtualWrite(V2, Gas);

If you see some other tnan 0 as sensor reading at your serial monitor - the problem is in blynk.
Is you see 1000 at your appā€™s gauge and 0 at your serial monitor- blynk is OK, the problem is in your hardware.

P.S. Is it a good idea to name your variable ā€œintā€? Definitely you should get error message when youā€™re trying to compile this piece of code.