Using the TSMP96000 IR Receiver Breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller and running the provided example code. The code is compatible with AVR (ATmega328, ATmega32u4, etc) and RP2040 boards.
You'll need an infrared emitter to use this example with the breakout, such as an IR remote or IR LED:
This breakout is for advanced IR remote receiving projects. You don't get the demodulated output, so it is not good for most IR decoding firmware.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the demodulator using a JST PH cable.
-
Board 5V to breakout JST PH V+ (red wire)
-
Board GND to breakout JST PH GND (black wire)
- Board pin 2 to breakout JST PH Sig (white wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
- Board pin 2 to breakout SIG (white wire)
No additional libraries are needed for this example code.
// SPDX-FileCopyrightText: 2024 ladyada for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Arduino.h> #define IROUT 9 #define IRIN 2 volatile unsigned long pulseCount = 0; #if defined(ARDUINO_RASPBERRY_PI_PICO) #include "hardware/pwm.h" void countPulse() { pulseCount++; } #else void countPulse() { pulseCount++; } #endif void setup() { Serial.begin(115200); pinMode(IRIN, INPUT); // Assuming the input signal is connected to pin 2 attachInterrupt(digitalPinToInterrupt(IRIN), countPulse, RISING); pinMode(IROUT, OUTPUT); } bool testFreq(uint32_t freq) { uint32_t temp = 0; Serial.print(freq); Serial.println(" Hz"); setFrequency(freq); // Set the initial frequency to the specified value pulseCount = 0; delay(100); temp = pulseCount; Serial.print("\tCounted "); Serial.print(temp); Serial.println(" pulses"); if ((temp > (freq / 10) + (freq / 100)) || (temp < (freq / 10) - (freq / 100))) { return false; } return true; } void loop() { Serial.println("----------------------"); if (!testFreq(30000)) return; if (!testFreq(40000)) return; if (!testFreq(50000)) return; if (!testFreq(60000)) return; } void setFrequency(unsigned long frequency) { #if defined(__AVR__) unsigned long ocrValue; byte csBits = 0; // Disable interrupts noInterrupts(); // Reset Timer1 Control Registers TCCR1A = 0; TCCR1B = 0; TCNT1 = 0; // Reset counter // Set Timer1 to CTC mode (Clear Timer on Compare Match) TCCR1B |= (1 << WGM12); // Determine best prescaler and OCR1A value for the desired frequency if (frequency > 4000) { // Can use no prescaler if frequency is high enough csBits = (1 << CS10); // No prescaler ocrValue = 16000000 / (2 * frequency) - 1; } else if (frequency > 500) { csBits = (1 << CS11); // Prescaler 8 ocrValue = 2000000 / (2 * frequency) - 1; } else if (frequency > 60) { csBits = (1 << CS11) | (1 << CS10); // Prescaler 64 ocrValue = 250000 / (2 * frequency) - 1; } else { csBits = (1 << CS12); // Prescaler 256 ocrValue = 62500 / (2 * frequency) - 1; } // Handle boundary conditions for OCR1A if (ocrValue > 65535) ocrValue = 65535; // Cap at maximum for 16-bit timer if (ocrValue < 1) ocrValue = 1; // Ensure OCR1A is at least 1 OCR1A = ocrValue; TCCR1B |= csBits; // Set the prescaler TCCR1A |= (1 << COM1A0); // Toggle OC1A on Compare Match // Re-enable interrupts interrupts(); #elif defined(ARDUINO_RASPBERRY_PI_PICO) // Set PWM frequency for the RP2040 gpio_set_function(IROUT, GPIO_FUNC_PWM); uint slice_num = pwm_gpio_to_slice_num(IROUT); pwm_set_wrap(slice_num, 125000000 / frequency); pwm_set_chan_level(slice_num, PWM_CHAN_A, 125000000 / (2 * frequency)); pwm_set_enabled(slice_num, true); #endif }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. As you send IR signals to the breakout, you'll see the frequency and pulse count print to the Serial Monitor.
Going Further
Chris Young has an excellent guide detailing how he built an IR Transmitter and Receiver that utilizes a similar code learning module (the TSMP58000). This guide demonstrates how you would utilize one of these receivers to decode IR messages.
Also noted in the guide is Chris' IRLib2 Arduino library. The frequency example measures frequency modulation from an IR signal and prints it to the Serial Monitor.
Text editor powered by tinymce.