Multiple LDR sensor inconsistent value with multiplexer 74HC4051N8

Hi,

I am having problem with my sketch. I setup my circuit as follows. However the value from each LDR are completely random and inconsistent.
I would love the help from anyone to figure out what is wrong or what cause such inconsistency.
Thank in advance for taking your time to read the post. I would happy to provide more context for the project.
Hardware:
Wemos D1R2

Schematic


float mainPin = A0;

int topl, topr, botl, botr;
float vout;
int toprf()
{
  digitalWrite(D7, 0);
  digitalWrite(D6, 0);
  digitalWrite(D5, 0);
  delay(1000);
  int val = analogRead(mainPin);
  Serial.print("topr = "); // A0
  Serial.println(val);
  return val;
}
int botrf()
{
  digitalWrite(D7, 1);
  digitalWrite(D6, 0);
  digitalWrite(D5, 0);
  delay(1000);
  int val = analogRead(mainPin);
  Serial.print("botr = "); // A1
  Serial.println(val);
  return val;
}
int botlf()
{
  digitalWrite(D7, 0);
  digitalWrite(D6, 1);
  digitalWrite(D5, 0);
  delay(1000);
  int val = analogRead(mainPin);
  Serial.print("botl = "); // A2
  Serial.println(val);
  return val;
}
int toplf()
{
  digitalWrite(D7, 0);
  digitalWrite(D6, 1);
  digitalWrite(D5, 1);
  delay(1000);
  int val = analogRead(mainPin);
  Serial.print("topl = "); // A6
  Serial.println(val);
  return val;
}
int voltf()
{
  digitalWrite(D7, 0);
  digitalWrite(D6, 0);
  digitalWrite(D5, 1);
  delay(1000);
  int val = analogRead(mainPin);
  Serial.print("voltage = "); // A4
  Serial.println(val);
  return val;
}

void setup(){
  Serial.begin(9600);
  Serial.println("Start");
  pinMode(D7, OUTPUT); // s0
  pinMode(D6, OUTPUT); // s1
  pinMode(D5, OUTPUT); // s2
}

  void loop(){
    topr = toprf(); // Input analog input value
    topl = toplf();
    botl = botlf();
    botr = botrf();
    vout = (voltf() * 5.0) / 1023;
    String toprs = "topr=";
    String topls = "&topl=";
    String botls = "&botl=";
    String botrs = "&botr=";
    String vouts = "&vout=";
    String httpRequestData = toprs + topr + topls + topl + botls + botl + botrs + botr + vouts + vout;
    Serial.println(httpRequestData);
    delay(10000);
}

What does this have to do with Blynk?

Why have you chosen the D1R2 rather than an ESP32 based board?

Pete.

I didnt really implement anything yet with blink, i am really sorry for that , I guess this is a nonblnykrelated issue.

I have no particular reason of choosing D1R2, I was choosing any development board with wifi module esp8266 onboard. I breaks my nodemcu board and arduino uno because I could not setup the serial communication properly. So I proceed with D1R2 that does not external power supply and already have wifi module onboard.

I don’t really understand this comment. The NodeMCU has WiFi onboard, and the D1R2 is basically a NodeMCU with a different form factor.

The ESP32 has 8 analogue input pins that can be used at the same time as WiFi, so the multiplexer would be redundant.

We’d normally recommend that you get your hardware working correctly before asking for help on this forum, maybe by visiting sites or forums that are related to the hardware that you’re having problems with - the 74HC4051N8 in this case.

Then, when you want to “Blynkify” the project visit this site and ask your Blynk specific questions. In your case, the first piece of Blynk related advice would be to clean-up your void loop and remove the blocking delay commands, and use timers instead…

Pete.

What I meant by that that comment I could not setup the nodeMCU probably because of lack of understanding of circuit setup.

Interesting, I’ll look into ESP32 in case I couldn’t work on this issue.
I see, I’ll refer to hardware related forum to solve my issue.

I thought the delay solve the multiplexer issue. Definitely will clean up those.

Thank you
fik

The better option would probaly be to stop using analogue sensors entirely, and go for an I2C light level sensor that allows the I2C address to be changed via a solder bridge. This way you can have multiple I2C sensors on the same bus, each with different addresses.
You are then working with digital signals rather than analogue.

Pete,

I appreciate the suggestion sir. I’ll take note of your suggestion, I need to do some exploring since there a lot unfamiliar term and component I need to learn about.

Thank you
fik