I'm new to arduino and I'm trying to use analogWrite(). I'm using a 3.7 V battery, but when I try to use analogWrite() to send 100% of this voltage to an LED, I get about half of that voltage consistently (~1.8 V) when measuring with a multimeter. Sure enough, the LED stays at about half its brightness. I'm sure I'm just missing something obvious. Any help would be greatly appreciated.
int redPin = 12;
int redPin2 = 10;
int redPin3 = 9;
int redVal = 0;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(redPin2, OUTPUT);
pinMode(redPin3, OUTPUT);
}
void loop() {
redVal = 255;
analogWrite(redPin, redVal);
analogWrite(redPin2, redVal);
analogWrite(redPin3, redVal);
}
1.8V is about right for an LED. LEDs are "current driven". You should have a series resistor to limit the current and then the voltage "falls into place".
Connecting an LED without a resistor will result in excess current it that can potentially fry the LED or the Arduino. The voltage is getting "dragged down" because you are "pulling" too much current from the output pin.
Thanks for the help! I'm using a pretty beefy LED that is normally used directly with a 3.7 V battery without first going to a circuit board. When I've used it without a circuit board, sending the full 3.7 volts gives it its "maximum brightness," and going through the board, it's significantly more dim.
Is that the 5V or 3.3V version? I guess it is the 3.3V because you are powering with a li-ion or li-po battery.
I don't think that will help, and may not even compile. The itsy bitsy 32u4 is an AVR based board with 8-bit PWM resolution. Other itsy bitsy models are 32-bit and may have 10-bit PWM. In those cases your suggestion would be appropriate.
No, I'm sorry, didn't mean to imply any criticism. @pd_spine did not reveal what board was being used until the following post, so at the time, your suggestion was a good guess which might have helped explain the readings.