Multiple inputs on 1 input pin

Hi,

I am using an attiny85 with 3 inputs left for me.

i need to have the following 4 inputs .

Brake light 12V
turn signal right 12V
turn signal left 12V
Parking light 12V

can have brake/parking on 1 input and how can i achieve that wiring wise for the arduino code to know the difference using digital read?

Use those inputs to drive a transistor each. Then do this with an analogue pin.
https://rayshobby.net/wordpress/multiple-button-inputs-using-arduino-analog-pin/

Or 4 to 1 (time) multiplexing. For example you may use 4051 (or 4052) (de)multiplexer and leave half of the channels unused.
Of course you may use shift register or port expander as well. It may be a bit more complicated but it will give you nearly unlimited amount of extra IOs.

With 12V on tail input, analog out will be about 1.48V, ADC value 303 with 5V AREF,
with 12V on brake input, 2.8V, ADC value 576, with 12V on both, 3.68V, ADC value 753.
div1(1).png

bool tail_lites, brake_lites;
int adcVal = analogRead(aInPin);
if(adcVal > 660)
{
  tail_lites = true;
  brake_lites = true;
}
else if(adcVal > 440)
{
  brake_lites = true;
  tail_lites = false;
}
else if(adcVal > 220)
{
  brake_lites = false;
  tail_lites = true;
}
else
{
  brake_lites = false;
  tail_lites = false;
}

div1(1).png

JCA79B:
With 12V on tail input, analog out will be about 1.48V, ADC value 303 with 5V AREF,
with 12V on brake input, 2.8V, ADC value 576, with 12V on both, 3.68V, ADC value 753.
div1(1).png

bool tail_lites, brake_lites;

int adcVal = analogRead(aInPin);
if(adcVal > 660)
{
  tail_lites = true;
  brake_lites = true;
}
else if(adcVal > 440)
{
  brake_lites = true;
  tail_lites = false;
}
else if(adcVal > 220)
{
  brake_lites = false;
  tail_lites = true;
}
else
{
  brake_lites = false;
  tail_lites = false;
}

thanks, how stable will the values be if the input varies between 12-14V?

can one use a comparator to achieve this?
TLC3702? LM339?

destiny2008:
thanks, how stable will the values be if the input varies between 12-14V?

Perhaps something to attempt to stabilize the inputs? I don't know. Others will comment.

What's wrong with a resistor ladder?

As it's automotive you may want to isolate it using an optocoupler. Then your crude 12V signal gets turned into a clean 5V signal.

wvmarle:
What's wrong with a resistor ladder?

As it's automotive you may want to isolate it using an optocoupler. Then your crude 12V signal gets turned into a clean 5V signal.

do you have a diagram how it would look like?

Of course.