Arduino IR sensor and remote control

hi all
i'm trying to control my LID via remote control
i want to 2 options
1/ on and off switch
2/ dim the light

I found a video on youtube that helped me -->- YouTube

The problem is when i program the arduino my remote changes its code :frowning:

the code

// NewIRcon.ino
#include "IRremote.h"
#include "IRremoteInt.h"

#define MAX_BRIGHT 255
#define RECV_PIN 8
#define LED_PIN 11

byte ledState;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(LED_PIN, OUTPUT);

}

void loop() {
if(irrecv.decode(&results))
{
switch (results.value) {
case 11346143:
ledState = 125;
digitalWrite(LED_PIN, LOW);

break;
case 4294967295:
digitalWrite(LED_PIN, ledState);
break;
case 11340023:
if(ledState < MAX_BRIGHT)
{
ledState +=10;
}
analogWrite(LED_PIN, ledState);
break;
case 11356343:
ledState -= 10;
if(ledState > 0)
{
analogWrite(LED_PIN, ledState);
}
break;

default:
Serial.println("greska!");

}
delay(200);
irrecv.resume();
}

}

in order to work out what codes your remote device is throwing out with each button you will need to test it by making a small sketch to read the code and echo it to the serial monitor so you can confirm the codes to insert into the switch case statement.

if you have done this already i have mis understood your problem

i have the codes ... and they work
i can turn on and off the light but when i try to dim the light all codes change
its like a changed the remote :frowning:

have you tried using different buttons on the remote, perhaps the button you have used for dimming the lights is like a vcr button on a tv remote and is changing the output codes by design?

i would hack the sketch you have to repeat the code returned by results.value to the serial monitor at every press so you can map the change

If first press gives code X and 2nd AND subsequent presses give Y consistently, then you could modify the code to opperate on that instance to
Case (X And first press) or (Y and Not 1st press)

i would also try a second remote,

looking at your utube link, a resistor was added to the IR receiver circuit to limit noise, have you also done this??

tnx for the replay :slight_smile:

Yes i have added a resistor to the sensor .
And i tried a different remote control but the same problem continues ...

i'm gonna try what you suggested i hope it works :slight_smile:

It's no use... i tried to map all the codes
And it just freezes the sensor starts to pick up just one code

4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295
4294967295

try pulling the call
irrecv.resume();
out to the end of the void loop function.

         }
         delay(200);
       
      }
        irrecv.resume();
}

Well it definitely changed the end result but it still ends bugged ...
My code must be the problem

// NewIRcon.ino
#include "IRremote.h"
#include "IRremoteInt.h"


#define MAX_BRIGHT 255
#define RECV_PIN 8
#define LED_PIN 11 

byte ledState;
IRrecv irrecv(RECV_PIN);
decode_results results;



void setup() {
	Serial.begin(9600);
  	irrecv.enableIRIn(); 
 	 pinMode(LED_PIN, OUTPUT);

}

void loop() {
	if(irrecv.decode(&results))
		{	
			Serial.println(results.value, DEC);
			
			switch (results.value) {
			    case 16620133:
			    	ledState = 50;
			    	digitalWrite(LED_PIN, LOW);
			      
			    break;
			    case 4294967295:
			    	digitalWrite(LED_PIN, ledState);
			    break;
			    case 16626253:
			    	if(ledState < MAX_BRIGHT)
			    	{
			    		ledState +=10;
			    	}
			    break;
			    case 334548453:
			    	if(ledState < MAX_BRIGHT)
			    	{
			    		ledState +=10;
			    	}
			    break;
			    case 11356343:
			    	ledState -= 10;
			    	if(ledState	> 0)
			    	{
			    		analogWrite(LED_PIN, ledState);
			    	}
			    break;
			    case 16616053:
			    	ledState -= 10;
			    	if(ledState > 0)
			    	{
			    		analogWrite(LED_PIN, ledState);
			    	}
			    break;
			    default:
			    	Serial.println("bug!");
			    delay(500);
			}
			
			irrecv.resume();
		}

}

i'm using a vivax remote control could that be the problem ??