BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Analog Values not showing

Hello Everyone!

I have a question. im trying to read multiple analog sensors with a multiplexer on mij D1mini. But when i connect the multiplexer it does not read the values. When i remove the multiplexer and connect my Potmeter to the analog pin everything works alright… I tryed to replace the multiplexer with a new one but same problem. i also checked my wiring and its all how it should be… can someone help me?


// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID           "TMPL000000"
#define BLYNK_DEVICE_NAME           "NAME"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD

#include "BlynkEdgent.h"

/* 16 channel Analog Multiplexer */

    #define S0 D3                             /* Assign Multiplexer pin S0 connect to pin D0 of NodeMCU */
    #define S1 D4                             /* Assign Multiplexer pin S1 connect to pin D1 of NodeMCU */
    #define S2 D5                             /* Assign Multiplexer pin S2 connect to pin D2 of NodeMCU */
    #define S3 D6                             /* Assign Multiplexer pin S3 connect to pin D3 of NodeMCU */
    #define SIG A0                            /* Assign SIG pin as Analog output for all 16 channels of Multiplexer to pin A0 of NodeMCU */

    int decimal = 2;                          // Decimal places of the sensor value outputs 
    int sensor0;                            /* Assign the name "sensor0" as analog output value from Channel C0 */
    int sensor1;                            /* Assign the name "sensor1" as analog output value from Channel C1 */
    int sensor2;                            /* Assign the name "sensor2" as analog output value from Channel C2 */
    int sensor3;                            /* Assign the name "sensor3" as analog output value from Channel C3 */
    int sensor4;                            /* Assign the name "sensor4" as analog output value from Channel C4 */
    int sensor5;                            /* Assign the name "sensor5" as analog output value from Channel C5 */
    int sensor6;                            /* Assign the name "sensor6" as analog output value from Channel C6 */
    int sensor7;                            /* Assign the name "sensor7" as analog output value from Channel C7 */
    int sensor8;                            /* Assign the name "sensor8" as analog output value from Channel C8 */
    int sensor9;                            /* Assign the name "sensor9" as analog output value from Channel C9 */
    int sensor10;                           /* Assign the name "sensor10" as analog output value from Channel C10 */
    int sensor11;                           /* Assign the name "sensor11" as analog output value from Channel C11 */
    int sensor12;                           /* Assign the name "sensor12" as analog output value from Channel C12 */
    int sensor13;                           /* Assign the name "sensor13" as analog output value from Channel C13 */
    int sensor14;                           /* Assign the name "sensor14" as analog output value from Channel C14 */
    int sensor15;                           /* Assign the name "sensor15" as analog output value from Channel C15 */



void setup()
{
  Serial.begin(115200);
  delay(100);

    pinMode(S0,OUTPUT);                       /* Define digital signal pin as output to the Multiplexer pin SO */        
    pinMode(S1,OUTPUT);                       /* Define digital signal pin as output to the Multiplexer pin S1 */  
    pinMode(S2,OUTPUT);                       /* Define digital signal pin as output to the Multiplexer pin S2 */ 
    pinMode(S3,OUTPUT);                       /* Define digital signal pin as output to the Multiplexer pin S3 */  
    pinMode(SIG, INPUT);                      /* Define analog signal pin as input or receiver from the Multiplexer pin SIG */
    pinMode(D8, OUTPUT);

  

    BlynkEdgent.begin();
}

void moistureSend() {
     /* 16 channel Analog Multiplexer */

    // Channel 0 (C0 pin - binary output 0,0,0,0)
    digitalWrite(S0,LOW); digitalWrite(S1,LOW); digitalWrite(S2,LOW); digitalWrite(S3,LOW);
    sensor0 = analogRead(SIG);
    delay(100);
  
    // Channel 1 (C1 pin - binary output 1,0,0,0)
    digitalWrite(S0,HIGH); digitalWrite(S1,LOW); digitalWrite(S2,LOW); digitalWrite(S3,LOW);
    sensor1 = analogRead(SIG);
    delay(100);
  
    // Channel 2 (C2 pin - binary output 0,1,0,0)
    digitalWrite(S0,LOW); digitalWrite(S1,HIGH); digitalWrite(S2,LOW); digitalWrite(S3,LOW);
    sensor2 = analogRead(SIG);
  
    // Channel 3 (C3 pin - binary output 1,1,0,0)
    digitalWrite(S0,HIGH); digitalWrite(S1,HIGH); digitalWrite(S2,LOW); digitalWrite(S3,LOW);
    sensor3 = analogRead(SIG);
  
    // Channel 4 (C4 pin - binary output 0,0,1,0)
    digitalWrite(S0,LOW); digitalWrite(S1,LOW); digitalWrite(S2,HIGH); digitalWrite(S3,LOW);
    sensor4 = analogRead(SIG);
  
    // Channel 5 (C5 pin - binary output 1,0,1,0)
    digitalWrite(S0,HIGH); digitalWrite(S1,LOW); digitalWrite(S2,HIGH); digitalWrite(S3,LOW);
    sensor5 = analogRead(SIG);

    // Channel 6 (C6 pin - binary output 0,1,1,0)
    digitalWrite(S0,LOW); digitalWrite(S1,HIGH); digitalWrite(S2,HIGH); digitalWrite(S3,LOW);
    sensor6 = analogRead(SIG);

    // Channel 7 (C7 pin - binary output 1,1,1,0)
    digitalWrite(S0,HIGH); digitalWrite(S1,HIGH); digitalWrite(S2,HIGH); digitalWrite(S3,LOW);
    sensor7 = analogRead(SIG);

    // Channel 8 (C8 pin - binary output 0,0,0,1)
    digitalWrite(S0,LOW); digitalWrite(S1,LOW); digitalWrite(S2,LOW); digitalWrite(S3,HIGH);
    sensor8 = analogRead(SIG);

     // Channel 9 (C9 pin - binary output 1,0,0,1)
    digitalWrite(S0,HIGH); digitalWrite(S1,LOW); digitalWrite(S2,LOW); digitalWrite(S3,HIGH);
    sensor9 = analogRead(SIG);

    // Channel 10 (C10 pin - binary output 0,1,0,1)
    digitalWrite(S0,LOW); digitalWrite(S1,HIGH); digitalWrite(S2,LOW); digitalWrite(S3,HIGH);
    sensor10 = analogRead(SIG);

    // Channel 11 (C11 pin - binary output 1,1,0,1)
    digitalWrite(S0,HIGH); digitalWrite(S1,HIGH); digitalWrite(S2,LOW); digitalWrite(S3,HIGH);
    sensor11 = analogRead(SIG);

    // Channel 12 (C12 pin - binary output 0,0,1,1)
    digitalWrite(S0,LOW); digitalWrite(S1,LOW); digitalWrite(S2,HIGH); digitalWrite(S3,HIGH);
    sensor12 = analogRead(SIG);

    // Channel 13 (C13 pin - binary output 1,0,1,1)
    digitalWrite(S0,HIGH); digitalWrite(S1,LOW); digitalWrite(S2,HIGH); digitalWrite(S3,HIGH);
    sensor13 = analogRead(SIG);

    // Channel 14 (C14 pin - binary output 0,1,1,1)
    digitalWrite(S0,LOW); digitalWrite(S1,HIGH); digitalWrite(S2,HIGH); digitalWrite(S3,HIGH);
    sensor14 = analogRead(SIG);

    // Channel 15 (C15 pin - binary output 1,1,1,1)
    digitalWrite(S0,HIGH); digitalWrite(S1,HIGH); digitalWrite(S2,HIGH); digitalWrite(S3,HIGH);
    sensor15 = analogRead(SIG);
  
    Serial.print("Sensor 0 : ");Serial.println(sensor0);          /* state value for sensor 0 */
    Serial.print("Sensor 1 : ");Serial.println(sensor1);          /* state value for sensor 1 */
    Serial.print("Sensor 2 : ");Serial.println(sensor2);          /* state value for sensor 2 */
    Serial.print("Sensor 3 : ");Serial.println(sensor3);          /* state value for sensor 3 */
    Serial.print("Sensor 4 : ");Serial.println(sensor4);          /* state value for sensor 4 */
    Serial.print("Sensor 5 : ");Serial.println(sensor5);          /* state value for sensor 5 */
    Serial.print("Sensor 6 : ");Serial.println(sensor6);          /* state value for sensor 6 */
    Serial.print("Sensor 7 : ");Serial.println(sensor7);          /* state value for sensor 7 */
    Serial.print("Sensor 8 : ");Serial.println(sensor8);          /* state value for sensor 8 */

    Blynk.virtualWrite(V0, sensor0);
    Blynk.virtualWrite(V1, sensor1);
    Blynk.virtualWrite(V2, sensor2);
    Blynk.virtualWrite(V3, sensor3);
    Blynk.virtualWrite(V4, sensor4);
    Blynk.virtualWrite(V5, sensor5);
    Blynk.virtualWrite(V6, sensor6);
    Blynk.virtualWrite(V7, sensor7);

    delay(1000);
}


void loop() {
  BlynkEdgent.run();
  timer.run(); // Initiates BlynkTimer

  if (Blynk.connected() == true){
    moistureSend();
    digitalWrite(D8, LOW);
  }
  else {
    digitalWrite(D8, HIGH);
  }
}

What are you seeing in your serial monitor?

Why do you have this line in your code:

Pete.

thankyou for the quick response :slight_smile:

the serial monitor prints everything but the value of al the inputs doesn’t change. when the potmeter is at 0 the serial monitor says 16. when the potmeter is at 1025 the serialmonitor says 14. so there is nog change.

i forgot to remove the delay… it was from another project. does it matter? it’s just making sure that every second a reading had done right? i’m new to this so thats why im asking hahaah

Rick

What is the potentiometer connected to?

How is the whole thing wired?

It will matter with Blynk, it will lead to disconnections.
You may also need to add some BlynkEdgent.run commands in your moistureSend() function to avoid disconnections, once you get your multiplexer working.

Pete.

thankyou! i tought it was only in the loop that it did matter :slight_smile:

the potmeter is connected to 5v and ground. the signalpin to C0 on the multiplexer.

the multiplexer is connected as follows:
S0 to D3
S1 to D4
S2 to D5
S3 to D6
SIG to A0
EN to GND
VCC to 5V
GND to GND

And when i disconnect the multiplexer (so Potmeter to A0) then it works.

Rick

I don’t understand what this means. I could guess, but I’d prefer to see a schematic.

What type of multiplexer are you using?

Also, D3 (GPIO0) and D4(GPIO2) aren’t the best choice of pins…

I’d suggest that you start by hard-wiring the multiplexer pins high and low to enable one specific input channel and see what results you get that way.

Pete.

you’re a actual hero!!! this was the problem! thankyou for the help!

1 Like

what did you mean with the You may also need to add some BlynkEdgent.run commands in your moistureSend() function to avoid disconnections, once you get your multiplexer working. ?

and do you know how i can stabilise my analog output? it’s jumping litterly erveywhere…

You should read this (Blynk.run() was the predecessor of BlynkEdgent.run())

Not without more info…

Pete.