Hello all, I've recreated a circuit that uses a HC-SR04 Ultrasonic sensor (and Arduino Mega) to successively glow 3 LEDs depending on the distance of the object it is measuring. However I notice that my LEDs glow in varying degrees of brightness like below. The LEDs are 3mm in diameter and I'm using 220 Ohm resistors. I've checked each LED separately and they glow bright by themselves but in this circuit two LEDs are barely glowing while one LED is extremely bright. I've made sure to declare each LED using pinMode(LED, OUTPUT) too.
I'm following the circuit design as shown in this image below:
The tutorial link is: https://create.arduino.cc/projecthub/codernoob/rgb-led-based-on-distance-ba94f8
That's quite a bit too low.
10 Ohm is way too low.. i guess you draw down the output to just a few volts..
Depending on the kind of Leds i shoud use 220-470 Ohms instead..
With 10 Ohms it is quite likely you fry your leds or outputs..
Thanks @anon73444976 yes I see what you mean. I initially used 220Ohm resistors and I still saw the same issue with some LEDs glowing very dim when in this circuit…so that’s why I thought maybe I’ll reduce the resistance. Do you think it some other issue?
Thanks @TechGraphix ! I initially used 220 Ohm resistors and faced the same issue with some resistors glowing very dim in this circuit. I just changed the details in my post again. Do you think it’s some other issues causing this?
Maybe you forgot the pinMode for those pins in that code.
Does your sketch look like the one below? The Red, Green, and Blue functions are turning one LED on AND TURNING OFF THE OTHER TWO. This is happening very rapidly so each LED is only on about 1/3 of the time.
Note: Pin 4 is NOT a PWM output pin on an UNO or Nano. What Arduino is this sketch for?!?
const int redPin = 3;
const int greenPin = 4;
const int bluePin = 5;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
Red(255);
Green(255);
Blue(255);
}
void Red(int VAL)
{
analogWrite(redPin, VAL);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
}
void Green(int VAL)
{
analogWrite(redPin, 0);
analogWrite(greenPin, VAL);
analogWrite(bluePin, 0);
}
void Blue(int VAL)
{
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, VAL);
}
Place a delay(1000); after Red(255); Green(255); and Blue(255);
like this:
void loop()
{
Red(255); delay(1000);
Green(255);delay(1000);
Blue(255);delay(1000);
}
And see what happens.... And indeed Pin 4 is not PWM:
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
I use 1K to 2K for my LED resistors. 220Ω is bright enough to light up the room.
@johnwasser yes the code looks similar. Should I be connecting the LEDs to only PWM pins?
@TechGraphix thank you! I will try this out. Appreciate your help!!