Problem understanting Aruino pins

I have a Arduino Uno board. My project is based on 4x 12V inputs, these inputs will be either 0V or ~4.6V( I used a 1.5M ohm resistor to reduce from 12V to under 5V), they work like a switch when one input has voltage >0 then do something. My problem is that i cannot understand the analog/digial pins very well on arduino, i tried connecting those inputs to the analog pins of arduino and without any voltage the analog reads were around ~300, but when one input was on the analog pin corresponding to it was 1023, the problem is that sometimes another pin was also 1023 even if it had no voltage on it and i didn't have my hands near the pins (i have read on the documentation that this could cause some problems). Can someone explain me what's wrong, maybe those resistors are not good for such voltage drop and if so, please give me an alternative except a step-down module ( someone told me that it's not very fast at delivering the reduced voltage and in my case i need the response as fast as possible from the arduino when one pin has voltage).

I used a 1.5M ohm resistor to reduce from 12V to under 5V)

Explain, please.

Paragraphs and sentences are your friends.

Post a diagram of how these parts are connected. Your description doesn't sound like it'll work.

How to use this forum.

Use a voltage divider, which is two resistors
12V - R1- R2 - Ground.
Input to Arduino comes from R1/R2 junction, and Ground.

With R2 = 5K ohm, and R1 = 10K, then Vout = 12V*5000/(10000 + 5000) = 4V.

Does the 12V switch between 0 and 12V?

Alternately, you can use the 12V signal to drive the base of an NPN transistor, with emitter to Ground, and the collector connected to an Arduino input with internal pull-up resistor enabled:
PinMode (pinX, INPUT_PULLUP); (small pin pinMode, darn iPad keeps autocorrecting it on me)

Then when 12V is high, the arduino pin gets pulled low, and you know the input is active.
If (digitalRead(pinX == LOW){
// input is active, do something
}

Alternately, instead of individual transistors, you can use a cd74HC4050 with the output side powered by 5V to translate the 12V inputs to 5V outputs. Each chip can handle 6 inputs. That would be my preference.

I use R1 of 18k to keep protection diode current below 1mA in case connection to R2 and GND fails and Arduino is not powered.

the problem is that sometimes another pin was also 1023 even if it had no voltage on it

For part of your question: Inputs should always be connected to something. Open (aka un connected) pins can easily pickup electrical signal even if your hands are not hear them.

Protection shown by @JCA34F is ideal for this situation, keep in mind the capacitor should be as close physically to the arduino board as possible.

ciuz99best:
I have a Arduino Uno board. My project is based on 4x 12V inputs, these inputs will be either 0V or ~4.6V( I used a 1.5M ohm resistor to reduce from 12V to under 5V), they work like a switch when one input has voltage >0 then do something. My problem is that i cannot understand the analog/digial pins very well on arduino, i tried connecting those inputs to the analog pins of arduino and without any voltage the analog reads were around ~300, but when one input was on the analog pin corresponding to it was 1023, the problem is that sometimes another pin was also 1023 even if it had no voltage on it and i didn't have my hands near the pins (i have read on the documentation that this could cause some problems). Can someone explain me what's wrong, maybe those resistors are not good for such voltage drop and if so, please give me an alternative except a step-down module ( someone told me that it's not very fast at delivering the reduced voltage and in my case i need the response as fast as possible from the arduino when one pin has voltage).

Input pins are floating (a characteristic of all CMOS logic chips), they are isolated electrically so pick up the slightest charge from anywhere, and very readily couple capacitively to nearby signals.

In input mode a pin is connected only to the gates of MOSFETs(*), and MOSFET gates are isolated due to the oxide layer. MOS = metal-oxide-semiconductor.

If you read any floating input pin expect to see any value, ie if the input isn't connected, its value is meaningless, stop worrying about it.

If you want to reduce (scale down) a signal voltage a voltage divider can be used, but megaohms is rather large for this. If you want to reduce power voltate a voltage regulator is required.

(*) Not actually true, they are also connected to protection diodes so that they cannot float higher than Vcc+0.5V or lower than -0.5V, but normally these diodes are reverse biased and thus carry no current.

Unused pins can be set to INPUT_PULLUP.