Hi folks, I am using an Arduino MKR WAN 1310 with a multiplexer (74HC405). I want to connect several sensors to the multiplexer, but, I want each sensor to have a controllable supply voltage. Like to turn the sensor supply on and off. Now I tried connecting a simple temperature sensor to the MUX using the 5v supply from the Arduino to power the mux and then used the mux output supply voltage vcc and gnd to power the sensor and have the sensor wire to the input of the mux, it worked fine (along with other sensors). But I want to control the sensor supply voltage. I tried to connect the sensor supply wires to two digital outputs of the Arduino (3.3V) with the signal still going to the Arduino, but I got rubbish sensor readings. Do I need to use the same supply from the MUX to drive the sensor? I also tried driving the MUX itself from two digital pins (High and Low) that way I could just turn the MUX on and off and therefore the sensors, but this did not work either, again rubbish from the sensors. Any help would be greatly appreciated, thank you.
In summary I would like to use a MUX but have my sensor supply controllable from two digital pins whilst having the sensor line connected to the MUX.
Hello dicko123abc,
it would be helpful if you can provide a hand drawn schematic.
Best regards Markus
I will do that very soon, mascho. I went for a walk in the warm Scottish weather today and thought I’d send this in the meantime.
So the working setup:
Vcc and Gnd at 3.3V and 0V respectively from the Arduino to the Vcc and Gnd pins of the Mux (same side as the select pins S0, S1 and S2). The sensor power comes from the other side of the board, pings Vcc and Gnd , same voltage and on the input side. Each sensor line (they are 3 wire devices) goes to a pin Y0, Y1 and Y2. The analogue output of the MUX, Z, goes to A1 of the Arduino. All works as expected.
Now I keep the code the same except this bit:
I want to power the sensors from digital pins 0 and 1 from the Arduino, instead of the Mux. So I connect the input Vcc and Gnd lines from the Mux to pins 0 and 1 of the Arduino - no longer using the Arduino Vcc and Gnd pins.
In the code I wrote:
pinMode(0,Output)
pinMode(1,Output)
Then I start these both off low.
digitalWrite(0,Low)
digitalWrite(1,Low)
Then In the loop I write:
digitalWrite(0,High)
Then the sensor bit same as before.
And then after a delay I set the line Low so
digitalWrite(0,Low)
and although the output pins do give 3.3V when set High (I measured with a multimeter), the sensor values are just rubbish.
What sensor it is in detail? Name? Linkt to DataSheet? Why you like to give a switchable supply to your sensors? Is it to reduce the current consumption? If not then I would supply all sensors well and then decide via the mux which result I want to read.
Good morning folks.
I want to use an output channel of a multiplexer to provide the supply voltage for my DS18B20 temperature sensor. I tested the MUX by itself, I have it set to output 3.3V for 5 seconds before setting it low to 0V. This checks out with a multimeter.
I now connect the positive supply wire of my DS18B20 sensor to the output channel (channel 7) of the MUX and connect the negative wire to the ground connection of the MUX. Giving the sensor 3.3V supply.
I have set analogue channel A1 to read the sensor (worked fine in the past without MUX), but all I am getting is -127 or sometimes 85 from the serial console.
Any help would be appreciated, thanks.
Here is my code:
Preformatted text#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS A1 // was A1
OneWire oneWire(A1);
DallasTemperature sensors(&oneWire);
float Celcius=0;
float Fahrenheit=0;
/////////////////////
// Pin Definitions //
/////////////////////
const int selectPins[3] = {2, 3, 4}; // S0~2, S1~3, S2~4
const int zOutput = 5; // Connect common (Z) to 5 (PWM-capable)
void setup()
{
Serial.begin(9600);
sensors.begin();
// Set up the select pins, as outputs
for (int i=0; i<3; i++)
{
pinMode(selectPins[i], OUTPUT);
digitalWrite(selectPins[i], LOW);
}
pinMode(zOutput, OUTPUT); // Set up Z as an output
}
void loop()
{
selectMuxPin(7);
Serial.println("3.3 V Supply");
analogWrite(zOutput,255);
delay(1000);
sensors.begin();
sensors.requestTemperatures();
delay(1000);
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
Serial.print(" C ");
Serial.print(Celcius);
Serial.print(" F ");
Serial.println(Fahrenheit);
delay(5000); // 5 seconds
Serial.println("0 V Supply");
analogWrite(zOutput,0);
delay(5000); // 5 seconds
//selectMuxPin(6);
}
// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-7.
void selectMuxPin(byte pin)
{
if (pin > 7) return; // Exit if pin is out of scope
for (int i=0; i<3; i++)
{
if (pin & (1<<i))
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}

I fixed it guys, I hope this helps someone else. Instead of using the analogueWrite, it should be digitalWrite(pin, HIGH) and then digitalWrite(pin, LOW)
Why the heck do you want to do that for a sensor that draws less than 1uA.
The muxer itself could draw more than eight sensors.
Leo..
Hi,
To add code please click this link;
Thanks.. Tom...
![]()
For EMC purposes I want to isolate both the power and ground lines of each sensor. The two Mux’s allow me to do this, one provides the positive through a pin set High and the other MUX provides the ground or low pin voltage. Therefore there are no shared ground lines between the sensors, this is more important for electronics in electrical noisy environments where the sharing of ground lines can cause interference leading to misleading sensor readings and inaccuracies.
Hi,
Can you explain your EMC purposes, how far is the 18B20 away from the controller?
What environment are you placing your project?
Have you experienced the EMC or are you assuming it?
Thanks.. Tom...
![]()
@TomGeorge,
Maybe hold your replies until reported cross posts have merged.
Leo..
Yea I will have sensors in an outdoor environment, looking at interference caused by nearby lightning. I am familiar with EMC from a subsea background. The sensors are physically buried in the earth. Therefore share a common ground. I want to isolate their power (positives and ground), I will then use an opto-isolator between the sensor wires and the Arduino. Other circuitry deals with surge protection. My main interest so far is to isolate the power for the sensors. I managed to do this for the temperature sensor as described above. Although I’m having a little trouble doing the same for a capacitive moisture sensor.
Your two topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
-
Your OS and version can be valuable information, please include it along with extra security you are using.
-
Always list the version of the IDE you are using and the board version if applicable.
-
Use quote or add error messages as an attachment NOT a picture.
-
How to insert an image into your post. ( Thanks @sterretje )
-
Add your sketch where applicable but please use CODE TAGS ( </> )
-
Add a SCHEMATIC were needed even if it is hand drawn
-
Add working links to any specific hardware as needed (NOT links to similar items)
-
Remember that the people trying to help cannot see your problem so give as much information as you can
COMMON ISSUES
-
Ensure you have FULLY inserted the USB cables.
-
Check you have a COMMON GROUND where required. ( Thanks @Perry)
-
Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.
-
Try other computers where possible.
-
Try other USB leads where possible.
-
You may not have the correct driver installed. CH340/341 or CP2102 or FT232 VCP Drivers - FTDI
-
There may be a problem with the board check or remove your wiring first.
-
Remove any items connected to pins 0 and 1.
COMPUTER RELATED
-
Close any other serial programs before opening the IDE.
-
Ensure you turn off any additional security / antivirus just to test.
-
There may be a problem with the PC try RESTARTING it.
-
You may be selecting the wrong COM port.
-
Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.
-
Clear your browsers CACHE.
-
Close the IDE before using any other serial programs.
-
Preferably install IDE’s as ADMINISTRATOR or your OS equivalent
ARDUINO SPECIFIC BOARDS
-
CH340/341 based clones do not report useful information to the “get board info” button.
-
NANO (Old Types) some require you to use the OLD BOOTLOADER option.
-
NANO (ALL Types) See the specific sections lower in the forum.
-
NANO (NEW Types) Install your board CORE’s.
-
Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default “AVRISP mkII”.
-
Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.
CREATE editor install locations.
-
On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini
-
On Linux ~/ArduinoCreateAgent-1.1/config.ini
-
On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1
Performing the above actions may help resolve your problem without further help.
Language problem ?
Try a language closer to your native language:
Thanks to all those who helped and added to this list.
You seem to think that a muxer is the same as a mechanical switch, which it is not.
Sensor potentials must (and will) stay within the boundaries of supply and ground, so no full isolation with an open switch, also because of the muxer's build-in clamping diodes.
I don't know why you think a common ground for buried sensors is bad.
The sensor itself is (should be) only grounded to the Arduino, not to mother-earth at the sensor side.
I assume you use a "waterproof DS18B20", which is not waterproof.
The metal tube is also not connected electrically to the sensor.
Leo..
I don’t think a Mux is like a mechanical switch.
In the event of nearby lightning strikes, where sensors are buried in the ground, induces currents can flow through the ground, between the sensors and interfere. One method to avoid this is to isolate the grounds. This can be achieved using multiplexers.
I wanted to use on as a demuxer, select the channel output which will output a high pin voltage, the other end of the sensor will output a low pin voltage as shown in the screenshot above, this works for the temperature sensor. The readings are accurate as they were verified by another temperature sensing device.
So you still think it behaves like a mechanical switch.
There is a pair of internal (clamping) diodes from each muxer pin to VCC and ground of the chip.
Any voltage greater than VCC +0.5volt and GND -0.5volt will just blow through the muxer.
Leo..
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.






