Hi everyone !
I am developing a project to change the intensity of three led strips and create environments for my modell railroad layout. The idea is to use an IR remote control and pressing each number change the intensity of the LEDs (warm- cold-blue) and the ambient atmosphere.
I use the module IRF520 N-Channel Power MOSFET PWM to control the LEDs and this IR Receiver.
To control leds I follow the last droneboxworkshop example, but instead potentiometers I use de IR receiver.
My test sketch for IR receiver works perfect !! and the MOSFET works right as well !!
BUT... When I put all together something is wrong.
This is a piece of my final sketch over Arduino Uno
// Include Libraries
// -------------------------------------------
#include <IRremote.h>
// IR Sensor
// -------------------------------------------
const int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
// Variables
// -------------------------------------------
// Pines
int pin_cold = 3;
int pin_warm = 5;
int pin_blue = 6;
// Current values for each strip
int state_cold;
int state_warm;
int state_blue;
// Values to go for each strip
int value_cold;
int value_warm;
int value_blue;
// State sistem on = true ; off = false
bool state_sistem;
void setup(){
Serial.begin(9600);
// Enable the IR Receiver
irrecv.enableIRIn();
// Pines
pinMode(pin_cold, OUTPUT);
pinMode(pin_warm, OUTPUT);
pinMode(pin_blue, OUTPUT);
// First leds states
state_cold = 0;
state_warm = 0;
state_blue = 0;
// Sistem Off
state_sistem = false;
// Values to go at setup
value_cold = 0;
value_warm = 0;
value_blue = 0;
}
void loop(){
if (irrecv.decode(&results)){
// Read Hex code and switch case
switch (results.value) {
// On button
case 0xFF08F7:
if(!state_sistem) {
value_cold = 50;
value_warm = 50;
value_blue = 50;
state_sistem = true;
Serial.println("sistem ON");
} else {
value_cold = 0;
value_warm = 0;
value_blue = 0;
state_sistem = false;
Serial.println("sistem OFF");
}
break;
// Rest of the IR sender values
}
// Write values to go
if(state_sistem) {
analogWrite(pin_cold, value_cold);
analogWrite(pin_warm, value_warm);
analogWrite(pin_blue, value_blue);
}
irrecv.resume();
}
}
The problem is in the line where code says: irrecv.enableIRIn();
When this line exists I can read IR codes, by nothing is written in analogWrite.
If I delete the line, of course I cannot read IR codes, but analogWrite runs perfect.
Need some Help to solve it !!! Thanks in advance.