0

I'm new to Arduino and building circuits, and was wondering if there is a type of component, or some other way to do the following task:

I want to control the resistance of a circuit from my computer linked to my Arduino, presumably using an output analog PIN.

Basically what I have is an LED whose brightness I want to control from my computer. I want to be able to control the resistance of the circuit to limit the electricity going to the LED, and I want to be able to do this from my computer (not physically, with a potentiometer) (unless a potentiometer's resistance can also be controlled from a PIN?).

How can I do this?

closed as off-topic by MichaelT, sempaiscuba, VE7JRO, MatsK, Avamander Mar 18 at 0:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – MichaelT, sempaiscuba, VE7JRO, MatsK, Avamander
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Possibly off topic. Better suited to Electrical Engineering SE? – MichaelT Mar 14 at 7:55
  • you can tape an LDR to the LED to make a crude digipot. I would low-pass the PWM and drive it at as high a frequency as possible to allow the smallest resistor possible, as even though LDRs are slow, some ripple (caused by PWM) will leak through. – dandavis Mar 14 at 16:32
1

The easiest way to drive an LED with variable brightness is to use one of the pulse width modulation (PWM) output pins on an Arduino.

A PWM pin takes an input value from 0 to 255 (or is it 0/1023? I don't remember.) and converts it to a ratio of on-time to off-time. At the highest value, the output pin is in the on state, 100% of the time. At the halfway point, the output pin is HIGH 50% of the time, and LOW 50% of the time.

Our eyes average out the flashes and see a variable brightness. It works very well.

If you absolutely must have a variable resistance controlled by a digital value, there are devices known as digital potentiometers. These are variable resistors controlled by digital inputs. For an Arduino, you should think about an I2C or SPI potentiometer, which is controlled by serial port commands. You tell it the resistance you want, and it sets itself to that resistance.

As CrossRoads points out in their comment below, you still need a current limiting resistor to drive an LED from a logic pin, to protect both the LED and the output driver on the Arduino. You want to limit the current to the max current for your LED, and then use PWM to lower the brightness from the absolute max set by the current limiting resistor. CrossRoads explains how to calculate the resistor value.

  • I'll try all of this, thanks for the help! – Aidan Mar 14 at 1:32
  • See this example: arduino.cc/en/tutorial/fading – Michel Keijzers Mar 14 at 1:35
  • Cool, thankyou for that – Aidan Mar 14 at 1:39
  • A PWM pin takes an input value from 0 to 255. (analogRead() returns 0-1023). Don't forget a current limit resistor so you don't damage the IO pin, or the LED. (5V - Vf)/.02A = resistor. Say the LED has 2.5V across it when on (measure it, or read its data sheet), then (5V - 2.5V)/20mA = 125 ohm. 20mA with current LEDs will be really bright. 250 ohm or 270 ohm may be plenty bright for the max brightness. – CrossRoads Mar 14 at 12:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.