2

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

6
  • Code: pastebin.com/77hqTuWA
    – Neka
    Mar 23 '17 at 3:38
  • 5
    You put 12V on an input pin? You likely fried something. ATMega are 5V max devices.
    – cde
    Mar 23 '17 at 3:40
  • USB powered with LED instead of Voltmeter is working fine. R1 is 47k BTW
    – Neka
    Mar 23 '17 at 3:46
  • 1
    With 47k as the pullup to 12 V you probably have not fried your AVR. It's only 100 uA into the protection diodes in the processor. But you do need to change that ....it's definitely not a good thing to do. You can either turn on the internal pullup or add one to the 5 V rail (say 1K or higher). For the output pin I'd posit you have some load you are driving and it's too heavy for the port. Restrict your output current to 20 mA or less (either source or sink). The processor stands up well to too a high a sink current, but you can blow the internal rails in the chip if you source too much. Mar 23 '17 at 5:11
  • why not just use INPUT_PULLUP on D2 and remove the 12v pullup parts completely?
    – dandavis
    Mar 23 '17 at 6:38
5

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

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.

1

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.