Strange problem, sending IR control signals - not working on stand alone 328P

Hi all. I’m working on something which is really bugging me. I am trying to send a IR code to switch a device off, and I’m using the code attached. I have it working on a bread-boarded using a Nano (328P), I then started on the project and built a perf board standalone 328 which seemed successful, the blink sketch runs fine.

Here is the problem, with a IR LED connected to the perf board 328 - it doesn’t seem to switch off the device.

I started to trouble shoot - I am using the exact same code on both, same LED, same value resistor same pin numbering. I used my phone camera to verify IR is being emitted when I send the signal from the LED and it is on the bread-boarded nano, but I can’t see anything coming from the LED on the perf board 328.

I then loaded the blink sketch and once again used my camera to check and the IR LED on the perf board was indeed lighting up. I even put a 328 chip on another breadboard and set it up the same but I’m seeing exactly the same issue; LED appears working but nothing when I send the signal :frowning:

I have run out of things to try, hope somebody can come up with some ideas?

Thanks

Edit… forgot the code

// This program allows an Arduino to power on/off a Duraflame heater using infrared
//
// Usage: hook up an IR led with Annode on pin 13.  Then send serial data "POWER"
// to the arduino.  It should flash the LED code.
//
// By Rick Osgood with code borrowed from adafruit.com
//

#define IRledPin 13
#define NumIRsignals 96
      
// This is the code I determined works for my Duraflame heater
int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
	130, 34,
	130, 36,
	46, 118,
	128, 36,
	128, 36,
	46, 118,
	48, 118,
	46, 118,
	46, 118,
	46, 118,
	46, 118,
	130, 684,
	128, 36,
	130, 34,
	48, 118,
	128, 36,
	128, 36,
	46, 118,
	46, 118,
	46, 118,
	46, 120,
	46, 118,
	46, 118,
	128, 686,
	128, 36,
	128, 36,
	46, 118,
	130, 34,
	130, 36,
	46, 116,
	48, 118,
	46, 118,
	46, 118,
	46, 118,
	48, 116,
	130, 684,
	128, 36,
	130, 34,
	48, 118,
	128, 36,
	128, 36,
	46, 118,
	46, 118,
	48, 116,
	48, 118,
	46, 118,
	46, 118,
	128, 0};

void setup(void) {
  digitalWrite(IRledPin, LOW);   //Make sure LED starts "off"
  Serial.begin(9600);            //Initialize Serial port
}

void loop() {
  char data[6];
  int index = 0;

  delay(1000);  //Serial input seems to need some kind of short delay or the data gets screwed up.

  while (Serial.available() > 0) {            //Loop if there data on the serial line
    if (index < 5) {                          //Make sure we don't overflow
      data[index] = Serial.read();            //Load a character into the string
      index++;                                //Increment the index to get the next character
    }
  }
  
  data[5]='\0';  //Null terminate the string
  
  if (strcmp(data, "POWER") == 0){                //If the Arduino receives the POWER signal...
    Serial.println("SENDING SIGNAL!");
    for (int i = 0; i < NumIRsignals; i+=2) {         //Loop through all of the IR timings
      pulseIR(IRsignal[i]*10);              //Flash IR LED at 38khz for the right amount of time
      delayMicroseconds(IRsignal[i+1]*10);  //Then turn it off for the right amount of time
    }
  }                                         //Otherwise do nothing!
}

// This function allows us to PWM the IR LED at about 38khz for the sensor
// Borrowed from Adafruit!
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait
 
  cli();  // this turns off any background interrupts
 
  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
   digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
 
   // so 26 microseconds altogether
   microsecs -= 26;
  }
 
  sei();  // this turns them back on
}
]

The nano probably runs at 16MHz. A "standalone" breadboard probably runs at 1 or 8 MHz...

Sorry guys, forgot the code - added to first post.

I did wonder about the clock frequency, but the stand alone arduino is running on a 16MHz crystal too so I'm totally confused.

The blink sketch appears to run at the correct speed, but is there another way to verify its running at the correct speed? The thing is that I cant see any output from the IR LED - surely if it was running slower I would see more output from it?

Thanks

initially there are 3 likely issues. 1. The clock frequency is not set up correctly. Test using a longer blink sketch @ 10 secs (be careful to measure the on off times correctly) 2. The current going thru the IR Led is too low...place the IR Led right beside the target device when sending. 3. check your wiring! Are you confusing the pin-out. How did you figure out which pin to connect to on the 328P vs the nano

If that doesnt help, then you need to upload more details about your setup: - circuit - fuse settings etc for the standalone 328P - code

Hi, thanks for the advice.

OK, I have just tested this with a new Uno that just turned up and same problem. I don't even see pin 13 blinking with no IR LED connected when I send the code - it blinks on the nano, and I the UNO RX Led lights so I know its receiving serial data . This is baffling, so far it works on 1 Nano, but doesn't work on 2 bare 328p's and a Uno.

The original code was taken from here http://www.richardosgood.com/blog/2013/11/12/clone-infrared-signals-with-arduino/

Any other ideas what could be going on here?

Thanks

Hmm. I don’t see a “pinMode” call to set the led output pin to be an output.
It could be that the Nano has a different bootloader that just happens to leave pin13 set as an output…

Good point! Well spotted, I will try that out as soon as I get home :)

Thanks again

That was it!

Cheers westfw, I was going out of my mind with that, trying to many things but overlooked something so simple :0

Thanks again