Hello, I'm doing a project with a arduino mega, where I use 20 of the digital pins as output.
When I set the 20 pins pinMode to output and set one to high, I only get 0.013v.
When I don't set a pinMode, but just set one high, I also only get 0.013v. Only when I only set one of the pins to output, and set that one to high, it outputs about 5v.
I've tried both with a USB connection and with a 12v, 1a power supply.
What could cause this?
Until you specify a given pin as an output with pinMode(), it will be an input ( the default on power-up) and will not output a logic level.
Allan
What do you have attached to the outputs?
APersonH:
When I set the 20 pins pinMode to output and set one to high, I only get 0.013v.
Just to make sure, you set (i.e., dont know all the digital pins on the mega)
pinMode(5,OUTPUT);
pinMode(5,OUTPUT);
...
pinMode(25,OUTPUT);
and then
digitalWrite(5,HIGH);
you measure on pin 5 then, right?
It wasn't clear to me which Pin you set HIGH and which pin you perform the measurement on. maybe some code?
In fact even if a pin set to INPUT mode is written HIGH to, a multimeter should measure 5V on that pin (thanks to the built-in pull-up resistor).
My preferred sketch to check the working of a pin: blink. Just set the pin to test as LED pin, upload the sketch, connect your multimeter, and you should see the voltage go from 0V to 5V.
When I set the 20 pins pinMode to output and set one to high, I only get 0.013v.
An you post the code for that please. Use the select all the copy for forum on the computer and paste the result into the reply.
You know how to measure a voltage?
Are you sure that your sketch uploaded properly and is running?
wvmarle:
In fact even if a pin set to INPUT mode is written HIGH to, a multimeter should measure 5V on that pin (thanks to the built-in pull-up resistor).
Surely not unless you specified pinMode( , INPUT_PULLUP) ?
Allan
allanhurst:
Surely not unless you specified pinMode( , INPUT_PULLUP) ?Allan
Instead you can write:
pinMode(pin, INPUT);
digitalWrite(pin, HIGH);
Which would be the case if OP forgot to set the pinMode to OUTPUT, but does digitalWrite HIGH to the pin. A multimeter will read 5V. A connected LED would light up very dimly. Switching a MOSFET would probably not work at all.
One of the odd and confusing Arduino things... Look at how the underlying registers work to really understand this
The digitalWrite() to an input pin is an AVR hack, works only on specific controllers. For compatibility the mode INPUT_PULLUP should be used.
MOSFETs need no special current for switching, unlike BJT do. If 5V is too low for turning a MOSFET on, it's regardless of input or output mode.
OP uses a Mega, so ATmega. It'll work on that processor.
MOSFETs commonly have a 10k resistor connected between gate and source, forming a voltage divider with the internal pull-up resistor. In that case it will not work with INPUT_PULLUP, even if it would switch fine with a proper 5V output.