0

I know there are a lot of questions about this topic, but I've tried everything and any possible guide online without success.

I want dim (increase and decrease the brightness) some leds (3.5 Watt each). To do that I'm using an Arduino Nano, a 10k potentiometer and an NPN transistor (TIP41).

I was able to drive the potentiometer as a switch: on/off. Now I want to control its brightness using the potentiometer. I don't get what I'm expecting because the led is always on except when the potentiometer is turned all the way on the right (where is connected Vcc).

This is the schematic:

dim led using transistor npn

This is my Arduino code:

int pinPotentiometer = 0;
int pinTransistor = 3;

void setup() {
  Serial.begin(9600);  
  pinMode(pinTransistor, OUTPUT);
  pinMode(pinPotentiometer, INPUT);
}

void loop() {
  int potValue = analogRead(pinPotentiometer);
  int outValue = map(potValue, 0, 1023, 0 ,255);
  Serial.println(outValue);
  digitalWrite(pinTransistor, outValue);
  delay(100);
}

The potentiometer is working fine because I read from the serial values between 0 and 255.

Am I using the wrong transistor? Or maybe I'm using it in the wrong way?

NOTE: to test my circuit I'm using a small 5mm led and not the 3.5 Watt one so I don't have any external power source.

Many thanks!

  • 1
    Use analogWrite() instead of digitalWrite(). And make sure you're using a PWM-capable pin. – Majenko Apr 24 '18 at 21:09
1

Try using analogWrite().

Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin. The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz.

Source: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

| improve this answer | |
  • Considering using a protected MOSFET, it will run much cooler then the transistor. Reason the transistor has a 0.7V collector emitter voltage drop, the MOFET will be less then 0.01 depending on choice. You are missing a resistor from the base to the Nano. Use something in the 50 to 120 Ohm for the MOSFET to keep it ultra stable. Be sure to use a seperate power supply with the high wattage LEDs. Also connect the power supply grounds. – Gil Sep 23 at 3:40
  • @Gil - The OP stated they were using a TIP41 transistor. Perhaps your comment would be useful if you added it to the question. – VE7JRO Oct 8 at 0:30
0

your transistor base should be connected to the PWM side of the Arduino and not the collector. put a 1kOhm resistor between that base and arduino too. collector to load, load to positive of battery or power source. emitter to ground.

| improve this answer | |
  • 1
    You also need a resistor on the collector side, if the load is a LED. For 3W Led you need a fat resistor (some Watts) – DataFiddler Oct 7 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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