NodeMCU 似乎没有将数字引脚设置为低电平

NodeMCU doesn't seem to set digital pin low

我正在编写一个简单的项目,使用 NodeMCU 作为我的开发板。我有 2 个模拟设备:湿度传感器和亮度传感器。由于 NodeMCU 只有一个模拟引脚,我尝试轮流为它们供电。为此,我将它们连接到 NodeMCU 的数字引脚。数字引脚输出 3.3V 20-40mA HIGH 状态(用万用表检查)。这一定足以为这些设备供电。在 LOW 状态下,根据 Arduino IDE 文档,电压必须为 0V(并且也已检查)并且传感器不得接收任何电流,因此不得向 A0 输出任何内容。然而,最后我得到了相关的结果:如果我在光敏电阻上闪光,湿度数据也会受到影响。和 vice-versa。我怎样才能避免它? 这是我用来做的代码,我描述的是:

const int analogInputPin = A0; // Analog 0 (A0) on the board

// Several devices will use the same analog pin to send data
const int lightSensorResultPin = analogInputPin;
const int moistureSensorResultPin = analogInputPin;

const int lightSensorPowerPin = 16;
int lightSensorResult = 0;

const int moistureSensorPowerPin = 5;
int moistureSensorResult = 0;

void setup() {
  Serial.begin(9600);
  pinMode(lightSensorResultPin, INPUT);
  pinMode(lightSensorPowerPin, OUTPUT);
  digitalWrite(lightSensorPowerPin, LOW);

  pinMode(moistureSensorResultPin, INPUT);
  pinMode(moistureSensorPowerPin, OUTPUT);
  digitalWrite(moistureSensorPowerPin, LOW);
}

void loop() {
  /*==LIGHT SENSOR DATA READ BLOCK==*/
  digitalWrite(lightSensorPowerPin, HIGH);
  delay(1000);
  lightSensorResult = analogRead(lightSensorResultPin);
  digitalWrite(lightSensorPowerPin, LOW);
  delay(1000);
  /*==END OF LIGHT SENSOR DATA READ BLOCK==*/

  /*==MOISTURE SENSOR DATA READ BLOCK==*/
  digitalWrite(moistureSensorPowerPin, HIGH);
  delay(1000);
  moistureSensorResult = analogRead(moistureSensorResultPin);
  digitalWrite(moistureSensorPowerPin, LOW);
  delay(1000);
  /*==END OF MOISTURE SENSOR DATA READ BLOCK==*/

  Serial.print("Value on the light sensor: ");
  Serial.println(lightSensorResult); // Light value. Low for bright
  Serial.print("Value on the moisture sensor: ");
  Serial.println(moistureSensorResult); // Moisture value. Low for wet
}

UPD:这是原理图

我不会使用数字输出来打开和关闭不同的传感器,而是结合它们的模拟输出,我会使用模拟开关,例如 4066 到 select 您要测量的传感器。