IR object detection with a-star prime

I have attached a very simple IR circuit that I have used with an UNO. When I hook this up to the Astar LV prime it does not work. The code I’ve used and the attachment is from parallax for Arduino.

[code]void setup() // Built-in initialization block
{
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone

pinMode(10, INPUT); pinMode(9, OUTPUT); // Left IR LED & Receiver

Serial.begin(9600); // Set data rate to 9600 bps
}

void loop() // Main loop auto-repeats
{
int irLeft = irDetect(9, 10, 38000); // Check for object

Serial.println(irLeft); // Display 1/0 no detect/detect

delay(100); // 0.1 second delay
}

// IR Object Detection Function

int irDetect(int irLedPin, int irReceiverPin, long frequency)
{
tone(irLedPin, frequency, 8); // IRLED 38 kHz for at least 1 ms
delay(1); // Wait 1 ms
int ir = digitalRead(irReceiverPin); // IR receiver → ir variable
delay(1); // Down time before recheck
return ir; // Return 1 no detect, 0 detect
}

][/code]
I set the circuit up on a breadboard and it works fine on the UNO but will not detect using the Astar.
I use these for detection a lot because it is easy to point them in the direction you want and I really like the Astar prime boards so I’m asking if you might know what I’m doing wrong here.


As noted on the tone() Arduino page, if you want to play different pitches on multiple pins, you need to call noTone() on one pin before calling tone() on the next pin. Could you try adding noTone(4); after the one second delay in setup() and see if that fixes the issue.

- Jeremy

OK it’s working. You people are good. To save on pins I don’t use the buzzer and it is not in my code. I had loaded this code only to test the circuit and had not thought about the buzzer. It doesn’t answer why this works fine on an UNO without adding noTone but adding noTone fixed what I was trying to do.
Thanks again