NEW my brains r fried on code/see Entry #6 below

Hello, and thank you for your input.

All I am trying to do is light an LED on pin 9 when a button is pressed on my remote control to activate the servo (and capacitor) i.e. BT_UP_PRESSED…I will be remarking out all the BT_TOUCH code.
I’ve tried to use digitalWrite , but to no avail. Help please :confused:

The code is courtesy of Ricardo Caratti PU2CLR:
#include <IRremote.h>
#include <Servo.h>

#define IR_RECEIVER_PIN 6
#define SERVO_PIN 7
#define FULL_CLOSED_RED_LED_PIN 5
#define FULL_OPEN_BLUE_LED_PIN 3
#define CENTER_PULSE_PIN 4
#define SIGNAL_LED_PIN 9

// Arduino IR remote control
#define BT_RIGHT_PRESSED 2640 // right button keep pressed
#define BT_RIGHT_TOUCH 16 // right button single touch
#define BT_LEFT_PRESSED 2704 // left button keep pressed
#define BT_LEFT_TOUCH 17 // left button single touch
#define BT_UP_PRESSED 144 // up button keep pressed
#define BT_UP_TOUCH 2192 // up button single touch
#define BT_DOWN_PRESSED 1168 // down button keep pressed
#define BT_DOWN_TOUCH 3216 // down button single touch
#define BT_MENU_PRESSED 112 // capacitor 90 degrees
#define BT_MENU_TOUCH 112 // capacitor 90 degrees
#define BT_AV_TV_PRESSED 2059 // AV/TV button keep pressed
#define BT_AV_TV_TOUCH 11 // AV/TV button sigle touch
#define BT_3_PRESSED 1040 // 30 m tune
#define BT_2_PRESSED 2064 // 20 m tune
#define BT_7_PRESSED 1552 // 17 m tune

IRrecv irrecv(IR_RECEIVER_PIN);
decode_results results;

#define MIN_PULSE 510
#define MAX_PULSE 2500

#define CENTER_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) / 2)

#define THIRTY_M_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) /1.80)
#define TWENTY_M_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) /3.15)
#define SEVENTEEN_M_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) /6.00)

#define FINE_TUNE_STEP 1
#define NORMAL_TUNE_STEP 15

int capacitorPosition = CENTER_PULSE; // The capacitor starts in the closed position;

int tuneStep = NORMAL_TUNE_STEP; // The tune mode start in normal steps

Servo capacitor;
int increment = 0;

void setup() {

// declare output pins
pinMode(SERVO_PIN, OUTPUT);
pinMode(FULL_CLOSED_RED_LED_PIN, OUTPUT);
pinMode(FULL_OPEN_BLUE_LED_PIN, OUTPUT);
pinMode(CENTER_PULSE_PIN, OUTPUT);
pinMode(SIGNAL_LED_PIN, OUTPUT;

irrecv.enableIRIn(); // enable IR reading

capacitor.attach(SERVO_PIN,MIN_PULSE,MAX_PULSE); // attaches the servo

capacitor.writeMicroseconds( CENTER_PULSE );
delay(1000);

Serial.begin (9600);
}

void loop() {

increment = 0;

// check infrared
if (irrecv.decode(&results)) {

Serial.println(results.value);

switch (results.value) {
case BT_RIGHT_PRESSED:
case BT_RIGHT_TOUCH:
increment = (tuneStep * .0685);
break;
case BT_LEFT_PRESSED:
case BT_LEFT_TOUCH:
increment = (-tuneStep * .0685 );
break;
case BT_UP_PRESSED:
case BT_UP_TOUCH:
increment = (tuneStep * -.10);
break;
case BT_DOWN_PRESSED:
case BT_DOWN_TOUCH:
increment = (tuneStep * .10);
break;
case BT_MENU_PRESSED:
//case BT_ON_OFF_TOUCH:
capacitorPosition = CENTER_PULSE;
capacitor.writeMicroseconds( capacitorPosition );
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(4,LOW);

break;
case BT_AV_TV_PRESSED:
case BT_AV_TV_TOUCH:
break;
case BT_3_PRESSED:
capacitorPosition = THIRTY_M_PULSE;
capacitor.writeMicroseconds( capacitorPosition );
break;
case BT_2_PRESSED:
capacitorPosition = TWENTY_M_PULSE;
capacitor.writeMicroseconds( capacitorPosition );
break;
case BT_7_PRESSED:
capacitorPosition = SEVENTEEN_M_PULSE;
capacitor.writeMicroseconds( capacitorPosition );

break;
default:
break;
}

irrecv.resume(); // Recebe o proximo valor
}

if ( increment ) {
capacitorPosition += increment;
if ( capacitorPosition < MIN_PULSE) {
capacitorPosition = MIN_PULSE;

digitalWrite(5,HIGH);
delay(1000);
digitalWrite(5,LOW);

}
else if ( capacitorPosition > MAX_PULSE ) {
capacitorPosition = MAX_PULSE;

digitalWrite(3,HIGH);
delay(1000);
digitalWrite(3,LOW);

}
else {
capacitor.writeMicroseconds(capacitorPosition);
delay(10);
}
}

}

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

That way our brains will be less fried :slight_smile:

…R

All I am trying to do is light an LED on pin 9

In the code that you posted : Where is pin 9 set as an output ? Where is pin 9 written to ?

you are absolutely right, Robin2...I will try to delete post.

tnx

Can't delete, however I reset the code.

marco18

Hello, and thank you for your input.

All I am trying to do is light an LED on pin 9 when a button is pressed on my remote control to activate the servo (and capacitor) i.e. BT_UP_PRESSED…I will be remarking out all the BT_TOUCH code.
I’ve tried to use digitalWrite , but to no avail. Help please :confused:

The code is courtesy of Ricardo Caratti PU2CLR:
#include <IRremote.h>
#include <Servo.h>

#define IR_RECEIVER_PIN 6
#define SERVO_PIN 7
#define FULL_CLOSED_RED_LED_PIN 5
#define FULL_OPEN_BLUE_LED_PIN 3
#define CENTER_PULSE_PIN 4
#define SIGNAL_LED_PIN 9

// Arduino IR remote control
#define BT_RIGHT_PRESSED 2640 // right button keep pressed
#define BT_RIGHT_TOUCH 16 // right button single touch
#define BT_LEFT_PRESSED 2704 // left button keep pressed
#define BT_LEFT_TOUCH 17 // left button single touch
#define BT_UP_PRESSED 144 // up button keep pressed
#define BT_UP_TOUCH 2192 // up button single touch
#define BT_DOWN_PRESSED 1168 // down button keep pressed
#define BT_DOWN_TOUCH 3216 // down button single touch
#define BT_MENU_PRESSED 112 // capacitor 90 degrees
#define BT_MENU_TOUCH 112 // capacitor 90 degrees
#define BT_AV_TV_PRESSED 2059 // AV/TV button keep pressed
#define BT_AV_TV_TOUCH 11 // AV/TV button sigle touch
#define BT_3_PRESSED 1040 // 30 m tune
#define BT_2_PRESSED 2064 // 20 m tune
#define BT_7_PRESSED 1552 // 17 m tune

IRrecv irrecv(IR_RECEIVER_PIN);
decode_results results;

#define MIN_PULSE 510
#define MAX_PULSE 2500

#define CENTER_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) / 2)

#define THIRTY_M_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) /1.80)
#define TWENTY_M_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) /3.15)
#define SEVENTEEN_M_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) /6.00)

#define FINE_TUNE_STEP 1
#define NORMAL_TUNE_STEP 15

int capacitorPosition = CENTER_PULSE; // The capacitor starts in the closed position;

int tuneStep = NORMAL_TUNE_STEP; // The tune mode start in normal steps

Servo capacitor;
int increment = 0;

void setup() {

// declare output pins
pinMode(SERVO_PIN, OUTPUT);
pinMode(FULL_CLOSED_RED_LED_PIN, OUTPUT);
pinMode(FULL_OPEN_BLUE_LED_PIN, OUTPUT);
pinMode(CENTER_PULSE_PIN, OUTPUT);
pinMode(SIGNAL_LED_PIN, OUTPUT;

irrecv.enableIRIn(); // enable IR reading

capacitor.attach(SERVO_PIN,MIN_PULSE,MAX_PULSE); // attaches the servo

capacitor.writeMicroseconds( CENTER_PULSE );
delay(1000);

Serial.begin (9600);
}

void loop() {

increment = 0;

// check infrared
if (irrecv.decode(&results)) {

Serial.println(results.value);

switch (results.value) {
case BT_RIGHT_PRESSED:
case BT_RIGHT_TOUCH:
increment = (tuneStep * .0685);
break;
case BT_LEFT_PRESSED:
case BT_LEFT_TOUCH:
increment = (-tuneStep * .0685 );
break;
case BT_UP_PRESSED:
case BT_UP_TOUCH:
increment = (tuneStep * -.10);
break;
case BT_DOWN_PRESSED:
case BT_DOWN_TOUCH:
increment = (tuneStep * .10);
break;
case BT_MENU_PRESSED:
//case BT_ON_OFF_TOUCH:
capacitorPosition = CENTER_PULSE;
capacitor.writeMicroseconds( capacitorPosition );
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(4,LOW);

break;
case BT_AV_TV_PRESSED:
case BT_AV_TV_TOUCH:
break;
case BT_3_PRESSED:
capacitorPosition = THIRTY_M_PULSE;
capacitor.writeMicroseconds( capacitorPosition );
break;
case BT_2_PRESSED:
capacitorPosition = TWENTY_M_PULSE;
capacitor.writeMicroseconds( capacitorPosition );
break;
case BT_7_PRESSED:
capacitorPosition = SEVENTEEN_M_PULSE;
capacitor.writeMicroseconds( capacitorPosition );

break;
default:
break;
}

irrecv.resume(); // Recebe o proximo valor
}

if ( increment ) {
capacitorPosition += increment;
if ( capacitorPosition < MIN_PULSE) {
capacitorPosition = MIN_PULSE;

digitalWrite(5,HIGH);
delay(1000);
digitalWrite(5,LOW);

}
else if ( capacitorPosition > MAX_PULSE ) {
capacitorPosition = MAX_PULSE;

digitalWrite(3,HIGH);
delay(1000);
digitalWrite(3,LOW);

}
else {
capacitor.writeMicroseconds(capacitorPosition);
delay(10);
}
}

}
[code][code][/code][/code]

You missed it by about | that much!

Take the remote out of the equation and test the code that lights the led when a btn is pressed on your micro (if you have one) if that works then go to the next part which would be to make sure the micro is receiving valid data from your remote.

You should always use Tools > Auto Format on your code, which would make it obvious where an error was in your setup():

void setup()  {

  // declare output pins
  pinMode(SERVO_PIN, OUTPUT);
  pinMode(FULL_CLOSED_RED_LED_PIN, OUTPUT);
  pinMode(FULL_OPEN_BLUE_LED_PIN, OUTPUT);
  pinMode(CENTER_PULSE_PIN, OUTPUT);
  pinMode(SIGNAL_LED_PIN, OUTPUT;

          irrecv.enableIRIn();             // enable IR reading

          capacitor.attach(SERVO_PIN, MIN_PULSE, MAX_PULSE); // attaches the servo

          capacitor.writeMicroseconds( CENTER_PULSE );
          delay(1000);

          Serial.begin (9600);
}