Connect 3 Current Sensors using Multiplexer with Wemos and send data to Blynk

Hi guys, I need ur help btw.

Well, im trying to connecting 3 current sensors SCT - 013 (Wemos D1 microcontroller) with the multiplexer (74hc4051) option and send the data to Blynk. i’ve search to internet so i find this method. the current sensor SCT-013 program need the analog input (A0*example) for calculate the current. but if we using the multiplexer i confused what we use for input. fyi in my progress i have done connect one current sensors from multiplexer

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "EmonLib.h"

char auth[] = "19e3********************";

char ssid[] = "";
char pass[] = "";

int s0 = D7;
int s1 = D6;
int s2 = D5;

int analogPin = 0;

int nilaiInput = 0;

EnergyMonitor emon1;
EnergyMonitor emon2;
EnergyMonitor emon3;

void setup() {
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  Serial.begin(115200);

   Blynk.begin(auth, ssid, pass);

   emon1.current(0,25); \\ my problem is in this part, this should be analog input pin, but if we use multiplexer what we called it? if we use the (0) pin from multiplexer for example
   emon2.current(1,25); \\ also this
   emon3.current(2,25); \\ also this

}

void loop() {
  inputMultiplekser(0);
  nilaiInput = analogRead(analogPin);
  inputMultiplekser(1);
  nilaiInput = analogRead(analogPin);
  inputMultiplekser(2);
  nilaiInput = analogRead(analogPin);
 
  float Irms1 = emon1.calcIrms(1480);
  float Irms2 = emon2.calcIrms(1480);
  float Irms3 = emon3.calcIrms(1480);
  {if (Irms1 < 0.020)Irms1 = 0;}
  {if (Irms2 < 0.020)Irms2 = 0;}
  {if (Irms3 < 0.020)Irms3 = 0;}
  Serial.print("Arus R : ");
  Serial.print(Irms1);
  Serial.print(" A  . ");
  Serial.print("Arus S : ");
  Serial.print(Irms2);
  Serial.print(" A  . ");
  Serial.print("Arus T : ");
  Serial.print(Irms3);
  Serial.print(" A \n")
  delay(100);

}

void inputMultiplekser(int y){
  if (y==0){
    digitalWrite(s0,LOW);
    digitalWrite(s1,LOW);
    digitalWrite(s2,LOW);
  }
  else if (y==1){
    digitalWrite(s0,HIGH);
    digitalWrite(s1,LOW);
    digitalWrite(s2,LOW);
  }
  else if (y==2){
    digitalWrite(s0,LOW);
    digitalWrite(s1,HIGH);
    digitalWrite(s2,LOW);
  }
  else if (y==3){
    digitalWrite(s0,HIGH);
    digitalWrite(s1,HIGH);
    digitalWrite(s2,LOW);
  }
  else if (y==4){
    digitalWrite(s0,LOW);
    digitalWrite(s1,LOW);
    digitalWrite(s2,HIGH);
  }
  else if (y==5){
    digitalWrite(s0,HIGH);
    digitalWrite(s1,LOW);
    digitalWrite(s2,HIGH);
  }
  else if (y==6){
    digitalWrite(s0,LOW);
    digitalWrite(s1,HIGH);
    digitalWrite(s2,HIGH);
  }
  else if (y==7){
    digitalWrite(s0,HIGH);
    digitalWrite(s1,HIGH);
    digitalWrite(s2,HIGH);
  }
  //jika input bukan 0-7, maka jadikan y0
  else {
    digitalWrite(s0,LOW);
    digitalWrite(s1,LOW);
    digitalWrite(s2,LOW);
  }
}

really really need your help. Thanks.

never use loop to do somethink else than blynk.run

where is blynk.run ???

void loop() {
  Blynk.run();
  timer.run();
}

does the void loop in blynk just only for that function?

I think you can’t use a multiplexer like that for do what you need to do…

Why you need to use a multiplexer? Does not have sufficient pins the wemos d1 for do it directly?

If not, i think you must use an Adafruit-MCP23017 or a chinesse copy… (a bidirectional i/o expander)

With this you can access each pin as if it was an original wemos d1 pin

Wemos D1 only have one analog input (A0) while i have need 3 analog input, for my 3 analog current sensors, is Adafruit-MCP23017 are expensive?

mmm

Ok, I just reviewed it and now I see that it’s like a digital multiplexer … the cost is 1-2USD
With the analog multiplexer you have … it should be possible … I do not have that integrated, so I can not do tests, but it is possible that the problem also lies in the library that you use to access the sensors.

It has happened to me several times that there are several libraries for the same device and some… they just do not work.

I’m sorry to not to be very helpful

The hardware you’re using should be fine.
The issue is that you can only read dat from one of the multiplexed analogue inputs at any one time. So, you’d need to set up a timer that polled each of your three sensors in turn - with sufficient time in between to let Blynk do its haeartbeat communication back to the server.

The 74hc4051 chip that you’re using can multiplex eight inputs and to do that you need three control pins to achieve the correct results. As you’re only using three of the inputs then you only need to use two of the control pins.
See this site for further details:

The problem you’re going to have is that you won’t get accurate power consumption readings from your sensors, so some sort of averaging will need to be done to give you actual power useage.

The alternative is three Wemos D1 Minis - one for each sensor. You could use an ESP32 instead, but you’d still need to poll the three analogue inputs in turn, so no different from your multiplexed device really.

Pete.

okay, no problem, i really really appreciate your intention bro,
GBU, Thanks…

Well sound good to use three wemos d1 for every each sensors, but i think it’s not efficient :joy:
but i still trying to find the best code for this project

Hi Alex,
for current measurement look at this project emontx from open energy monitor.
Good schematic,arduino library and Learning docs

Ideas:
Build your custom emontx without RF and multiplexer, only for CT aquisition, send data to serial to wemos D1 with blynk only.

yes just only to run blynk.
else you will flood blynk server and freeze your application.
you have to use blink timers instead.

I don’t sure about this Wemos D1… but some microcontrollers like lolin v3 has dual GPIOs (analog/digital) inputs and only digital output. Have you tried to read a sensor in another pin? Maybe it works…