1 led 2 different pins to drive it

Hello,

1 want to use 1 led in the lower light range and the same led in the upper light range.

1 pin 100 ohm resistor to the led
1 pin 500 ohm resistor to the same led (thus more dimmed)

I thougt that
analogwrite ( some pin, 0 )
analogwrite ( the other pin, range 1-255 )

would do the case, however it is not. Looks like the pin with the 0 value is providing a path to ground?

Anyone willing to enlighten me and maybe give a hint how to solve this? I tried adding a diode for each pin , that works but the voltage drop over the diode is too high to get the maximum led output.

Post a schematic and an image of your setup.

Why not just use one pin?

PWM of 0 is dim and PWM of 255 is brighter. One could just send out on one pin either a PWM of 0 or 255 for the thing do.

You have set the pin to 0. So now it is connected to ground indeed...

The inactive pin should not be analogWrite anything, but should be pinMode INPUT. Then it will be high impedance, and will neither source nor sink current. But Idahowalker is right. AnalogWrite is designed to give you variable average voltage, so it seems one pin should be enough.

The spread is not enough. The light is used to drive a photoresistor and if I play the whole range on 1 pin eighter i'm missing range in the lower end or on the upper range. That is why i thought about 2 pins with different current limiting resistors. This works wel if I do 1 led per pin.

100 Ohm is a bit low for the average led, but you, probably, have a high-current led...
Anyway: a output can deliver enough current to drive a LED (not a 3W type :wink: )
analogWrite(PWM_PIN,PWM_Value) will drive the LED correct if you connect the anode of the led to the PWM_PIN with a resistor of 3V/LED-current (220 Ohm is normal) and the kathode to Ground.
Check if the output is capable to output PWM signals, not every processor or output supports that.

Have you tried different values of analogWrite.
You don't have to count down or up to your PWM duty cycle values.
Just

analogWrite(LEDPin, 30):
then a delay.
analogWrite(LEDPin, 120);

You have a range from 0 to 255.

What do you mean, you have 0 which is OFF to 255 which is FULL brightness.

Don't forget the Arduino pins can really only have 40mA or less load current.

What is your project, there may be easier ways to do your project.

Tom... :smiley: :+1: :coffee: :australia:

Yes; I use the whole range from 1-255. But a (my) photoresistor is not regular to the value of analogwrite. From 0 to 100 the resistance value of the PR goes up like a rocket and after 100 to 255 is flattens out. Bij putting a different resistor (I said 100 and 500 but in reality I use a variable register (1-1000 ohm)) and different code in the range 0-100 and 100-255. This way I can smoothen it out. This works very well with 1 led / pin but if I put the same led connected to 2 pins and toggle one of these pins, it doesn't work as expected. If I regulate 1 resister it regulates the current for both. I'm gonna try to create kind of a relay to the led.

The Arduino should be able to do 16 bit PWM. I don't know if there is a simple way. You may try to look here:
https://www.teachmemicro.com/generate-arduino-16-bit-pwm/

Can you please post a drawing of your circuit, including the LDR?
A hand drawn image will be fine.
An image of your project would be of help too.
A copy of your code will be appreciated.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Precisely as you would expect. You refer to an LDR - its response is anything but linear and a 2.5:1 ratio really makes quite little difference in the resistance just as it corresponds to only a minor change in perceived brightness.

You do realise do you not, that if you have a resistor connected to each of two pins and the same LED, when you pull one of those pins LOW as an an output, it will sink current and there will be less for the LED?

You need to not write such a pin LOW, but set it to INPUT to disable it.

Yes, I didn't know this when I started this topic but in reply 4 [ShermanP] wrote this allready. However it didn't work when I tested it ...

So wrong answer? No, correct answer but I had to learn that you have to set the pin, after it has become an input, explicitely to output again before the next analogwrite. I thought that analogwrite took care of these things itself but it does not (I actually use an esp8266 d1)

It is working now. Thanks !

Well, in fact, the Arduino reference entry for analogWrite() says:

" You do not need to call pinMode() to set the pin as an output before calling analogWrite()."

So maybe that's just wrong, or it may be wrong just for the ESP8266.

it may be correct for the first call to analogWrite, but not subsequent calls.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.