微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ESP32 ph4502c 传感器不适用于 Blynk

如何解决ESP32 ph4502c 传感器不适用于 Blynk

互联网上的人

我遇到了一个感觉很奇怪的问题,因为我已经能够在常规情况下使用我的 pH 传感器,即 ph4502c 传感器。有这个代码

int pHSense = 27;
int samples = 10;
float adc_resolution = 1024.0;

void setup()
{
  Serial.begin(9600);
  delay(100);
  Serial.println("cimpleo pH Sense");
}

float ph (float voltage) {
  return 7 + ((2.5 - voltage) / 0.18);
}

void loop () {
  int measurings=0;
  float x = analogRead(pHSense);
  for (int i = 0; i < samples; i++)
  {
    measurings += analogRead(pHSense);
    delay(10);
  }
    float voltage = 5 / adc_resolution * (measurings/5.75)/samples;
    Serial.print("pH= ");
    Serial.println(ph(voltage));
    delay(3000);
}

在我将代码与 blynk 程序集成后,它不会读取传感器值:

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "b8gKEzFuKu-Vc_n9O1JUrv-jtZUAUF90";
int pHSense = 27;
int samples = 10;
int measurings = 0;
float ph = 0;
float adc_resolution = 1024.0;

BlynkTimer timer;

char ssid[] = "Family"; // Enter Your WiFi Name
char pass[] = "123toonix"; // Enter Your Passwword

void phsensor()
{
  for (int i = 0; i < samples; i++)
  {
    measurings += analogRead(pHSense);
    delay(10);
  }
  float voltage = 5 / adc_resolution * (measurings/5.75)/samples;
  float ph = 7+((2.5 - voltage) / 0.18);
  Serial.print("pH= ");
  Serial.println(measurings);
  
    }
    
void setup() {
  // Start the Serial Monitor
  Serial.begin(9600);
  Blynk.begin(auth,ssid,pass);
  timer.setInterval(1000,phsensor);
}


  void loop()
{
  //Blynk.run();
  Blynk.virtualWrite(V0,ph);
  //timer.run();
}

值读数始终为 0。也许有人可以提供帮助?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。