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.
schematic
simulate this circuit – Schematic created using CircuitLab
3 Answers 3
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.
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.
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.
INPUT_PULLUP
on D2 and remove the 12v pullup parts completely?