I try to connect 3 RGB LED (common annode) to my Arduino Nano ESP32 which in theory should work because i only need 3x3 (=9) of the 13 digital pins.
But for some reason the LEDs wont work correctly with my code
i am pretty sure my build is correct, but like always not 100% certain
(sorry for the messy build :,) )
The Code should cycle through all the colors, for all 3 LEDs the same
thanks in advance
int r_pin1 = 12;
int g_pin1 = 11;
int b_pin1 = 10;
int r_pin2 = 9;
int g_pin2 = 8;
int b_pin2 = 7;
int r_pin3 = 6;
int g_pin3 = 5;
int b_pin3 = 4;
int r_val1 = 0;
int g_val1 = 255;
int b_val1 = 255;
int r_val2 = 0;
int g_val2 = 255;
int b_val2 = 255;
int r_val3 = 0;
int g_val3 = 255;
int b_val3 = 255;
void setup() {
pinMode(r_pin1,OUTPUT);
pinMode(g_pin1,OUTPUT);
pinMode(b_pin1,OUTPUT);
pinMode(r_pin2,OUTPUT);
pinMode(g_pin2,OUTPUT);
pinMode(b_pin2,OUTPUT);
pinMode(r_pin3,OUTPUT);
pinMode(g_pin3,OUTPUT);
pinMode(b_pin3,OUTPUT);
}
void loop() {
while (r_val1 != 255)
{
analogWrite(r_pin1,r_val1);
analogWrite(g_pin1,g_val1);
analogWrite(r_pin2,r_val2);
analogWrite(g_pin2,g_val2);
analogWrite(r_pin3,r_val3);
analogWrite(g_pin3,g_val3);
r_val1++;
g_val1--;
r_val2++;
g_val2--;
r_val3++;
g_val3--;
delay(10);
}
while (g_val1 != 255)
{
analogWrite(g_pin1,g_val1);
analogWrite(b_pin1,b_val1);
analogWrite(g_pin2,g_val2);
analogWrite(b_pin2,b_val2);
analogWrite(g_pin3,g_val3);
analogWrite(b_pin3,b_val3);
g_val1++;
b_val1--;
g_val2++;
b_val2--;
g_val3++;
b_val3--;
delay(10);
}
while (b_val1 != 255)
{
analogWrite(b_pin1,b_val1);
analogWrite(r_pin1,r_val1);
analogWrite(b_pin2,b_val2);
analogWrite(r_pin2,r_val2);
analogWrite(b_pin3,b_val3);
analogWrite(r_pin3,r_val3);
b_val1++;
r_val1--;
b_val2++;
r_val2--;
b_val3++;
r_val3--;
delay(10);
}
}
You are using "analogWrite(x,y); " to turn on the LEDs. Correct?
I don't know the ESP32 nano well, but the ESP32 platform doesn't have
the function "analogWrite(x,y);. The ESP 32 uses its own hardware/software
called LEDC.
See the theory of using LEDC in " esp32_technical_reference_manual "
Chapter 14 page 385
Or use a library for PWM for the ESP32.
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
PS: I find this information
" Yes, the Arduino Nano has PWM (Pulse Width Modulation) capabilities .
analogWrite() has been implemented for the ESP32 for some time. Behind the scenes it uses ledc
It certainly works for me
the code works correct as long as I only use one RGB LED but it does not work anymore as soon as I try to use 2 or 3 LEDs
What does it mean "it doesn't work anymore as soon as I try to use 2 or 3 LEDs?"
Explain more....
Hi, @starkai
Welcome to the forum.
Have you checked how much current you are drawing through each output?
Tech specs
Board
Name
Arduino® Nano ESP32 with headers
SKU
ABX00083
Microcontroller
u-blox® NORA-W106 (ESP32-S3)
USB connector
USB-C®
Pins
Built-in LED Pin
13
Built-in RGB LED pins
14-16
Digital I/O Pins
14
Analog input pins
8
PWM pins
5
External interrupts
All digital pins
Connectivity
Wi-Fi®
u-blox® NORA-W106 (ESP32-S3)
Bluetooth®
u-blox® NORA-W106 (ESP32-S3)
Communication
UART
2x
I2C
1x, A4 (SDA), A5 (SCL)
SPI
D11 (COPI), D12 (CIPO), D13 (SCK). Use any GPIO for Chip Select (CS)
Power
I/O Voltage
3.3 V
Input voltage (nominal)
6-21 V
Source Current per I/O Pin
40 mA
Sink Current per I/O Pin
28 mA
Clock speed
Processor
up to 240 MHz
Memory
ROM
384 kB
SRAM
512 kB
External Flash
128 Mbit (16 MB)
Dimensions
Width
18 mm
Length
45 mm
Check the current output limits of the Nano ESP32.
Tom..
This is the code I used for only one RGB LED
on this code I added the other 2 LEDs
(e.g. r_pin1, r_pin2, r_pin3 and r_val1++, etc...)
int r_pin = 12;
int g_pin = 11;
int b_pin = 10;
int r_val = 0;
int g_val = 255;
int b_val = 255;
void setup() {
pinMode(r_pin,OUTPUT);
pinMode(g_pin,OUTPUT);
pinMode(b_pin,OUTPUT);
}
void loop() {
while (r_val != 255)
{
analogWrite(r_pin,r_val);
analogWrite(g_pin,g_val);
r_val++;
g_val--;
delay(10);
}
while (g_val != 255)
{
analogWrite(g_pin,g_val);
analogWrite(b_pin,b_val);
g_val++;
b_val--;
delay(10);
}
while (b_val != 255)
{
analogWrite(b_pin,b_val);
analogWrite(r_pin,r_val);
b_val++;
r_val--;
delay(10);
}
}
my RGB LEDs are labeled 20mA
"Each GPIO pin is rated at 40mA for a ESP32"
"250mA is the ESP 32s max current draw"
if I understand the Tech Specs there should be no problem with connecting 3 RGB LEDs
system
Closed
October 11, 2024, 9:49pm
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.