# Need help on how to approch 12v digital read on a blinking signal

I need to have my arduino (mega) know the state of my blinker on my car. Not if the signal is high or low (whether the actual signal is high or low), but if the blinker is turned on or off. Yes i could take the signal from before it blinks but i want to take it from the blinker directly. To clarify when blinker goes +-+-+-+- i want to read +, and when it goes --------- i want to read - can i have it read - when its been that way for a certain interval? or would something else give me simpler code? and can the arduino even take a 12v input? any help would be great thanks

First thing I fought of was an optoisolator to keep the voltages safe + sperate. Code seems pretty simple.

what is an optiresistor? and edit for my original post i need it to read 1 value(possibly analog) when it is solid positive+++++++. and another when it is varriable+-+-+-+-+-+-+-+,--+--+--+--+ or ---++---++---++ etc. and the read low or 0 if its analog when its constant neg --------- can i take an average of 10 or 20 read values(or more?), and take an average(or the most often or mode)? so 111111 would yeild 1, and 101010101 would yeild 0.5, and 00000 would yeild 0? would that have errors, and how would you code that?

Did you mean optoisolator?

Here’s a couple of ways.

``````pinMode (inputPin, INPUT);
digitalWrite (inputPin, HIGH);  // turns on internal pullup

// With 2 resistors, look for a High to indicate blinker is on:
if (digitalRead (inputPin) == HIGH){
// do code for on
}
else {
// do code for off
}

// with transistors, Blinker On will bring the pin low
if (digitalRead (inputPin) == LOW){
// do code for on
}
else{
// do code for off
}
``````

that solves the input problem. thankyou can anyone explain how to code it?

Coding it - you have to explain more what the times are that correlate to the levels:
read 1 value(possibly analog) when it is solid positive+++++++.
and another when it is varriable±±±±±±±+,–±-±-±-+ or —+±–+±–++ etc.
read low or 0 if its analog when its constant neg ---------

The blinker on/off times are ages long compared to 16 MHz clock.
How long do you go before deciding it is solid positive, or negative, and can anything change outsde of those times be called variable?

sorry bout that optoisolator, don't know what i was thinking

it blinks on for about 1/2 a second then off for a tiny bit less. So i Guess if it's blinking, and doesn't come back on in 0.6 sec or something read as 0000 or -----to my var. and then only read 11111 or ++++ if it has been high for greater than 0.08 to prevent a false positive?

I see you've started another thread on this as well.

this one is about the input reading it as 3 different values. the other is in programing. once i read a pin normaly (digitalRead ) how do i get that to store as 3 different values. 2 treads-yes same project-yes same thread no that one focus on 3 vars read and changed after read. this one 3 vars stored when read. Could you help with either?

I'm thinking read the input every 100mS, have a counter for high or low. If see it high 10 times, call it solid high. If see it low 10 times, call it solid low. If see if change one way or the other after starting a count, set a possibly_variable flag. if the count then stays high or low, go back to calling it solid high or low. If the level changes a 2nd time, call it variable. Keep wathing to see that it keeps changing, and when it stops, go back to the solid high/low state.

thanks i will give it a try.

useing 2 resistors as was shown above i would need to connect the ground of my vehicle to that of the arduino right?

Yes, grounds must be connected to provide a common reference point between systems.

Grounds can be separated if using the optoisolator, light does not need a common reference.