arduino one input - four outputs

hi ,
First of all i'm new to arduino and i need some Guidance to know at least what i'm looking for , sorry for this .

Well , the thing is i want to write Arduino code that reads the voltage value on one of the Arduino inputs (only one input in my case ) and base on the value of the voltage i want one of Four outputs to run , for example :
if the value of the voltage is 12 ---> then output 1 should work (2,3,4 are off !)
if the value of the voltage is 10 ---> then output 2 should work (1,3,4 are off !)
if the value of the voltage is 8 ---> then output 3 should work (1,2,4 are off !)
if the value of the voltage is 6 ---> then output 4 should work (1,2,3 are off !)

is it possible to do such thing using Arduino ? and is this considered to be demultiplexing ??

Sorry for my terrible knowledge and for my bad English also .

Please provide me with all the needed Guidance .

Kind regards

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Have you written any code yet, or tried to make a LED blink?

This link my help you.

Tom… :slight_smile:

No, this is not demultiplexing. Multiplexing is when you have more than one signal at a time on the same channel, demultiplexing is parsing out the individual signals.

I am doing exactly what you described. I need to monitor two states on an Arduino Shield from a Wemos D1 Mini. But I had no available GPIO pins on the Wemos. My solution was to use the Analog-in on the Wemos and send the GPIO outputs from the Arduino to a voltage divider circuit. This gives me four states to use.

When you calculate your voltage divider values, make sure that the highest voltage you can present to your Analog input (all digital lines high) does not exceed the analog input limit.

What is to happen when the voltage is between those values? I mean for instance, what happens if the value is 6.1 to 7.9 Volts?

(1,3,4 are off !)
Are those pin numbers? Be aware that pin 1 on most Arduinos is the hardware serial TX pin.

@gF

one of Four outputs to run

@Op
Yes, it can be done. Just make sure You use a voltage divider for the incoming analog voltage.
For Your outputs..... What kind of load do You intend to use? What voltage for the load?

Here is a sketch to illustrate turning on one output depending on the value of an analog input. 0 to less than 1 Volt, no output. 1V to less than 2V, output 4 on. 2V to less than 3V, output 3 on. And so on with all outputs on for over range. Modify as you like.

As Railroader says, you will need a voltage divider to bring the 12v down to 5V (or less) for the analog input.

The if structure reference.
The else structure reference.
The begiiner’s guide to millis() for timing tutorial.

const byte inputVoltagePin = A0;
const byte led1Pin = 2;
const byte led2Pin = 3;
const byte led3Pin = 4;
const byte led4Pin = 5;
float Vcc = 4.85;  // measure Vcc and replace with measured value

void setup()
{
   Serial.begin(115200);
   pinMode(led1Pin, OUTPUT);
   pinMode(led2Pin, OUTPUT);
   pinMode(led3Pin, OUTPUT);
   pinMode(led4Pin, OUTPUT);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 500;  // sample every 1/2 second
   if (millis() - timer >= interval)
   {
      timer = millis();
      int a2dValue = analogRead(inputVoltagePin);
      float voltage = a2dValue * (Vcc / 1024.0);
      Serial.print("input voltage = ");
      Serial.println(voltage);
      if (voltage < 1)
      {
         digitalWrite(led1Pin, LOW);
         digitalWrite(led2Pin, LOW);
         digitalWrite(led3Pin, LOW);
         digitalWrite(led4Pin, LOW);
      }
      else if (voltage >= 1 && voltage < 2)
      {
         digitalWrite(led1Pin, LOW);
         digitalWrite(led2Pin, LOW);
         digitalWrite(led3Pin, LOW);
         digitalWrite(led4Pin, HIGH);
      }
      else if (voltage >= 2 && voltage < 3)
      {
         digitalWrite(led1Pin, LOW);
         digitalWrite(led2Pin, LOW);
         digitalWrite(led3Pin, HIGH);
         digitalWrite(led4Pin, LOW);
      }
      else if (voltage >= 3 && voltage < 4)
      {
         digitalWrite(led1Pin, LOW);
         digitalWrite(led2Pin, HIGH);
         digitalWrite(led3Pin, LOW);
         digitalWrite(led4Pin, LOW);
      }
      else if (voltage >= 4 && voltage <= 5)
      {
         digitalWrite(led1Pin, HIGH);
         digitalWrite(led2Pin, LOW);
         digitalWrite(led3Pin, LOW);
         digitalWrite(led4Pin, LOW);
      }
      else
      {
         Serial.println("voltage out of range");
         digitalWrite(led1Pin, HIGH);
         digitalWrite(led2Pin, HIGH);
         digitalWrite(led3Pin, HIGH);
         digitalWrite(led4Pin, HIGH);
      }
   }
}