RGB LED with different resistors

Hello, guys.
I’m doing MA project with Arduino.
I’ve started that project 10 weeks ago.
But I have got stocked and i’m still in beginning step.

I use 3 different resistor(10K, 22K, 47K) for each colour which is R, G, B.
Colour should be changed depand on resistor.

Is there anything I can try?

You're trying to make the colour of an RGB LED change depending on the value of a resistor?

How are the resistors connected?

Can you post your code?

Now it is working depand on position

I don't understand what you mean by this.

int potPin = 0; // select the input pin for the potentiometer
int ledPinBlue = 9; // select the pin for the LED
int ledPinRed = 10; // select the pin for the LED
int ledPinGreen = 11; // select the pin for the LED

int val = 0; // variable to store the value coming from the sensor

void setup() {
pinMode(ledPinBlue, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPinRed, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPinGreen, OUTPUT); // declare the ledPin as an OUTPUT
}

void loop()
{
val = analogRead(0); // read the value from the sensor

if ( 500 < val < 540 ) {
analogWrite(ledPinRed, val/4); // turn the ledPin on
}
if ( 705 < val < 710 ) {
analogWrite(ledPinGreen, val/4); // turn the ledPin on
}
if ( 848 < val ) {
analogWrite(ledPinBlue, val/4); // turn the ledPin on
}

}

That’s my code.
Problem is red colour is mixed with other colour every times and
when Red colour should work, green colour is mixed with red.

The analogWrite command will continuously write the PWM signal to each pin. It will stay at whatever you last set it. So if your red channel was 100, then you want to make green 50, you'll get red 100 and green 50. You need to set analogWrite to 0 for the channels you want to turn off.

I use 3 different resistor(10K, 22K, 47K) for each colour which is R, G, B.

What voltage are you using to drive the LEDs? If you’re using the 5V supply of the Arduino, then those resistors are much too high. You’ll need values closer to 330 Ohms, although it will be slightly different for each colour.

if ( 705 < val < 710 ) {

This isn’t going to work the way you want it to! Try this instead:

if ( ( val > 705) && (val < 710) ) {

Thank you very much.
Ican’t understand channel

“So if your red channel was 100, then you want to make green 50, you’ll get red 100 and green 50. You need to set analogWrite to 0 for the channels you want to turn off.”

Can I use “delay();” for turning off in tnat case??

I tried that code, but doesn’t work.
if ( ( val > 705) && (val < 710) ) {

This is informaition of RGB LED.

Component Red Green Blue
DC Forward current max. (mA) 50 30 30
Pulse forward current max. (mA) 100 50 50
Forward voltage max. (V) 2.4 3.6 3.6
Dominant wavelength typ. (nm) 625 525 470
(IF=20mA)
Luminous intensity typ. (mcd) 3000 4200 2180
(IF=20mA)

Reverse current max. (µA) 10
Reverse voltage max. (V) 5
Power dissipation max. (mW) 150
Half-power angle 100°
Lead soldering temperature 260°C/3s
Operating temperature range –30°C to +85°C
Storage temperature range –30°C to +100°C

If I try to change resister, what resister will be good?

if ( (val > 500) && (val < 540) ) {
analogWrite(ledPinRed, val/4); 
analogWrite(ledpinGreen, 0);
analogWrite (ledpinBlue, 0);
 }
etc...

I tried that code, but doesn’t work.
if ( ( val > 705) && (val < 710) ) {

Just saying “it doesn’t work” doesn’t tell us anything. In what way does it not work? Can you describe what you want it to do, and what it actually does, and how they differ?

As for the LED resistors, we need 50mA through the red LED and 30mA through both the green and blue. Now, 50mA is more than the Arduino can provide, so we’ll have to limit it to 40mA. The forward voltages are 2.4V, 3.6V, 3.6V for RGB respectively. Now, what power supply voltage do you want to use? Let’s assume the ordinary 5V Arduino supply. So, your resistor for red will drop (5V - 2.4V) = 2.6V at 40mA, that’s 65 Ohms. The others drop (5V - 3.6V) = 1.4V at 30mA, that’s 47 Ohms. To be safe, it’s best to choose slightly higher resistor values, so maybe 100 Ohms or 120 Ohms would be good.