user-1: Adruino nano powered by 12v through VIN pin. 
Normally I expect ~12v on digital output pin, when i write HIGH to this pin, and ~0v when i write LOW. But what I have instead
digitalWrite(pin, HIGH); // I have 1.5v on pin
digitalWrite(pin, LOW);  // I have 0.5v

Algorithm is quite simple - On push button toggle output pin state.
Connections:

VIN - +12v
GND - ground
d2 - input pin (0 0, 12 - 1, button);
d3 - output pin (we change state of this pin)

Input works as expected. 

simulate this circuit – Schematic created using CircuitLab

user21074: The arduino is powered by 12v but regulates down to 5v or 3v for the microcontroller. Then your output pin current is important. Anything over 20mA will result in a large voltage droop due to the ESR of the pin. Highly depends on your circuit and your full code.

user7508: As others have said, you should not pull d2 to 12 V. You are
sending about (12 V − 5 V) ÷ 100 Ω
= 70 mA into the high-side diode that protects that input pin.
This diode is only rated for 1 mA, thus you will likely fry it in a
short time.
To avoid the damage, you could increase the value of R1 in order to
lower that current to a safe value, but it would be simpler and safer to
completely remove the resistor and use the internal pullup instead, as
in
pinMode(2, INPUT_PULLUP);

As for the measured output on d3, you expect 5 V when the pin is
written HIGH. Your 1.5 V reading is suspicious. My guess is that
you forgot to
pinMode(3, OUTPUT);

In this case, writing the pin to HIGH does not have the expected
effect. Instead, it activates the internal pullup, which should make the
pin read 5 V, but then even a very small load (about 0.1 mA)
can make the voltage drop to 1.5 V.
If you are really getting 1.5 V while the pin mode is set to
OUTPUT, then you are really pulling far too much current from the pin.
My guess would be around 130 mA (a 26 Ω output resistance is
typical). The absolute maximum rating for the pin is 40 mA, so
again, you are going to fry something.

user1498: The microcontoller in an Arduino operates on 5 Volts (or perhaps 3.3 Volts).  An on-board voltage regulator reduces the 12 Volt input to 5 volts for the ICs on the board.
Connecting the pull-up resistor (R1 in your drawing) to 12 Volts may damage the microcontroller (especially if it is really 100 Ohms as your drawing shows).  The pullup resistor must be connected to the 5 Volt pin on the Arduino board.
The output voltage of an Arduino pin should be near 5 Volts, but may be less if you place a heavy (high-current) load on it.

-1: <p>Adruino nano powered by 12v through <strong>VIN</strong> pin. </p>

<p>Normally I expect ~12v on digital output pin, when i write HIGH to this pin, and ~0v when i write LOW. But what I have instead</p>

<pre><code>digitalWrite(pin, HIGH); // I have 1.5v on pin
digitalWrite(pin, LOW);  // I have 0.5v
</code></pre>

<p>Algorithm is quite simple - On push button toggle output pin state.
Connections:</p>

<ul>
<li><strong>VIN</strong> - +12v</li>
<li><strong>GND</strong> - ground</li>
<li><strong>d2</strong> - input pin (0 0, 12 - 1, button);</li>
<li><strong>d3</strong> - output pin (we change state of this pin)</li>
</ul>

<p>Input works as expected. </p>



<p><img src="https://i.stack.imgur.com/35iul.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2f35iul.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>
 21074: <p>The arduino is powered by 12v but regulates down to 5v or 3v for the microcontroller. Then your output pin current is important. Anything over 20mA will result in a large voltage droop due to the ESR of the pin. Highly depends on your circuit and your full code.</p>
 7508: <p>As others have said, you should not pull d2 to 12&nbsp;V. You are
sending about (12&nbsp;V −&nbsp;5&nbsp;V) ÷&nbsp;100&nbsp;Ω
=&nbsp;70&nbsp;mA into the high-side diode that protects that input pin.
This diode is only rated for 1&nbsp;mA, thus you will likely fry it in a
short time.</p>

<p>To avoid the damage, you could increase the value of R1 in order to
lower that current to a safe value, but it would be simpler and safer to
completely remove the resistor and use the internal pullup instead, as
in</p>



<pre class="lang-c++ prettyprint-override"><code>pinMode(2, INPUT_PULLUP);
</code></pre>

<p>As for the measured output on d3, you expect 5&nbsp;V when the pin is
written <code>HIGH</code>. Your 1.5&nbsp;V reading is suspicious. My guess is that
you forgot to</p>

<pre class="lang-c++ prettyprint-override"><code>pinMode(3, OUTPUT);
</code></pre>

<p>In this case, writing the pin to <code>HIGH</code> does not have the expected
effect. Instead, it activates the internal pullup, which should make the
pin read 5&nbsp;V, but then even a very small load (about 0.1&nbsp;mA)
can make the voltage drop to 1.5&nbsp;V.</p>

<p>If you are really getting 1.5&nbsp;V while the pin mode is set to
<code>OUTPUT</code>, then you are really pulling far too much current from the pin.
My guess would be around 130&nbsp;mA (a 26&nbsp;Ω output resistance is
typical). The <strong>absolute maximum rating</strong> for the pin is 40&nbsp;mA, so
again, you are going to fry something.</p>
 1498: <p>The microcontoller in an Arduino operates on 5 Volts (or perhaps 3.3 Volts).  An on-board voltage regulator reduces the 12 Volt input to 5 volts for the ICs on the board.</p>

<p>Connecting the pull-up resistor (R1 in your drawing) to 12 Volts may damage the microcontroller (especially if it is really 100 Ohms as your drawing shows).  The pullup resistor must be connected to the 5 Volt pin on the Arduino board.</p>

<p>The output voltage of an Arduino pin should be near 5 Volts, but may be less if you place a heavy (high-current) load on it.</p>
