TinyRemoteXL - 12-Button IR Remote Control based on ATtiny13A

Overview

TinyRemoteXL - 12-Button IR Remote Control based on ATtiny13A

TinyRemoteXL is a 12-button IR remote control based on an ATtiny13A powered by a CR2032 or LIR2032 coin cell battery.

pic1.jpg pic2.jpg

Hardware

The basic hardware is similar to the 5-button TinyRemote. The main difference is that the ATtiny13 has to query 12 buttons here. There are various options for using a larger number of buttons with just a few pins. However, most of them do not meet the following conditions:

  • there are only four pins available for twelve buttons,
  • a keystroke must trigger an asynchronous interrupt to wake the ATtiny from deep sleep mode,
  • the circuit must not consume any electricity as long as no button is pressed.

A combination of voltage dividers and a couple of diodes does the trick:

wiring.png

If, for example, button 4 is pressed, pin PB0 is pulled to ground via the corresponding diode and a pin change interrupt is triggered, which wakes up the ATtiny. The diodes prevent the 4k7 resistors of the voltage divider from shorting out. The voltage that can be measured at PB2 via the ADC results from the supply voltage divided by the 10k resistor on the upper side and two 4k7 resistors (= 9k4) on the lower side. This value depends on the key pressed.

Software

IR Protocol Implementation

The implementation for the NEC, SAMSUNG, SONY and RC-5 protocol is taken from TinyRemote. Refer to this project for a complete explanation.

Setting the IR Codes

Before compiling you have to define the IR commands for each button. Different protocols and device addresses can be used. Several codes can also be assigned to a single key, separated by semicolons.

#define KEY1  NEC_sendCode(0x04,0x08)     // LG TV Power: addr 0x04, cmd 0x08
#define KEY2  RC5_sendCode(0x00,0x0B)     // Philips TV Power: addr 0x00, cmd 0x0B
#define KEY3  SON_sendCode(0x01,0x15,12)  // Sony TV Power: addr 0x01, cmd 0x15, 12-bit version
#define KEY4  SAM_sendCode(0x07,0x02)     // Samsung TV Power: addr: 07, cmd: 02
#define KEY5  NEC_sendCode(0xAB04,0x08);SON_sendCode(0xE401,0x15,20)
[...]

Button Detection

If a key has been pressed, a pin change interrupt is triggered and the ATtiny is brought out of sleep mode. The pressed key is then identified via the voltage divider between the individual keys using the ADC of the ATtiny.

// Pin assignments
#define BINT1_PIN   PB0       // interrupt pin for buttons 1..6
#define BINT2_PIN   PB3       // interrupt pin for buttons 7..12
#define BADC1_AP    1         // ADC port for buttons 1..6
#define BADC2_AP    2         // ADC port for buttons 7..12

// Button ADC thresholds
const uint8_t THRESHOLDS[] PROGMEM = {217, 173, 158, 136, 103, 41, 0};

// ADC read button row and return button number
uint8_t readButtonRow(uint8_t port) {
  PRR     = 0;                            // power on ADC
  ADMUX   = (1<// set port, Vcc as reference, 8-bit sample
  ADCSRA |= (1<1<// enable ADC and start sampling
  while (ADCSRA & (1<// wait until sampling complete
  uint8_t raw = ADCH;                     // read sampling result (8 bits)
  ADCSRA &= ~(1<// disable ADC
  PRR     = 1<// shut down ADC
  uint8_t  button = 0;                    // figure out button number
  while (raw < pgm_read_byte(&THRESHOLDS[button])) button++;
  return button;                          // return button number
}

// Read and return button number (0 = no button)
uint8_t readButton(void) {
  uint8_t  button = 0;                    // start with number 0
  if (~PINB & (1<readButtonRow(BADC1_AP);
  else if (~PINB & (1<readButtonRow(BADC2_AP);
    if (button) button += 6;
  }
  return button;                          // return button number
}

// Main function
int main(void) {
  [...]  
  // Setup ADC to read button values
  ADCSRA = (1<1<// set ADC prescaler 8
  [...]
  // Main loop
  while(1) {
    sleep_mode();                       // sleep until button is pressed
    _delay_ms(1);                       // debounce
    uint8_t button = readButton();      // read button number
    switch (button) {                   // send corresponding IR code
      case  1:  KEY1;  break;
      case  2:  KEY2;  break;
      [...]
      default: break;
    }
  }
}

// Pin change interrupt service routine
EMPTY_INTERRUPT (PCINT0_vect);          // nothing to be done here, just wake up from sleep

Power Saving

The code shuts down unused peripherals and utilizes the sleep mode power down function. It wakes up on every button press by pin change interrupt. The device will work several months on a CR2032 battery.

// Disable unused peripherals and prepare sleep mode to save power
ACSR  =  1<// disable analog comperator
DIDR0 = ~BT_MASK & 0x1F;              // disable digital intput buffer except button INT
PRR   =  1<// shut down ADC
GIMSK =  1<// turn on pin change interrupts
PCMSK =  BT_MASK;                     // turn on interrupt on button pins
sei();                                // enable global interrupts
set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // set sleep mode to power down

Timing Accuracy

The accuracy of the internal oscillator of the ATtiny13 is +/-10% with the factory calibration. Usually this is sufficient for an infrared remote control. Slight deviations in timing are tolerated by the receiver, since cheap remote controls are usually not more accurate. Nevertheless, it is recommended to manually calibrate the internal oscillator and set the corresponding OSCCAL value at the beginning of the code.

// oscillator calibration value (uncomment and set if necessary)
#define OSCCAL_VAL  0x48

Compiling and Uploading

Since there is no ICSP header on the board, you have to program the ATtiny either before soldering using an SOP adapter, or after soldering using an EEPROM clip. The AVR Programmer Adapter can help with this.

If using the Arduino IDE

  • Make sure you have installed MicroCore.
  • Go to Tools -> Board -> MicroCore and select ATtiny13.
  • Go to Tools and choose the following board options:
    • Clock: 1.2 MHz internal osc.
    • BOD: BOD disabled
    • Timing: Micros disabled
  • Connect your programmer to your PC and to the ATtiny.
  • Go to Tools -> Programmer and select your ISP programmer (e.g. USBasp).
  • Go to Tools -> Burn Bootloader to burn the fuses.
  • Open the TinyRemoteXL sketch and click Upload.

If using the precompiled hex-file

  • Make sure you have installed avrdude.
  • Connect your programmer to your PC and to the ATtiny.
  • Open a terminal.
  • Navigate to the folder with the hex-file.
  • Execute the following command (if necessary replace "usbasp" with the programmer you use):
    avrdude -c usbasp -p t13 -U lfuse:w:0x2a:m -U hfuse:w:0xff:m -U flash:w:tinyremotexl.hex
    

If using the makefile (Linux/Mac)

  • Make sure you have installed avr-gcc toolchain and avrdude.
  • Connect your programmer to your PC and to the ATtiny.
  • Open the makefile and change the programmer if you are not using usbasp.
  • Open a terminal.
  • Navigate to the folder with the makefile and sketch.
  • Run "make install" to compile, burn the fuses and upload the firmware.

References, Links and Notes

  1. TinyRemote
  2. TinyRemote RF
  3. IR remote control explanations by San Bergmans
  4. IR remote control by Christoph Niessen (german)
  5. IR remote control detective by David Johnson-Davies
  6. Infrared communication concepts (altium.com)
  7. NEC decoder based on ATtiny13A
  8. OSC Calibrator
  9. ATtiny13A datasheet

License

license.png

This work is licensed under Creative Commons Attribution-ShareAlike 3.0 Unported License. (http://creativecommons.org/licenses/by-sa/3.0/)

You might also like...
Digispark attiny85 code to smack the big button!

dave-o-rec The big button what records the trucks! Requires the DigiKeyboard.h library, which is included in the Arduino IDE's DigiStump package. Setu

Control Heidelberg Wallbox Energy Control over WiFi using ESP8266 and configure your own local load management
Control Heidelberg Wallbox Energy Control over WiFi using ESP8266 and configure your own local load management

scroll down for English version and additional information wbec WLAN-Anbindung der Heidelberg WallBox Energy Control über ESP8266 Die Heidelberg W

Azure Outlook Command & Control (C2) - Remotely control a compromised Windows Device from your Outlook mailbox. Threat Emulation Tool for North Korean APT InkySquid / ScarCruft / APT37. TTP: Use Microsoft Graph API for C2 Operations. Automatic street light control using LDR as the sensor and an LED as an example of a street light. Performed a small simulation of an Arduino board along with LDR and LED to simulate the automatic street light control in TinkerCAD.
Budgie Control Center is a fork of GNOME Control Center for the Budgie 10 Series.

Budgie Control Center Budgie Control Center is a fork of GNOME Settings / GNOME Control Center with the intent of providing a simplified list of setti

Remote Arduino Uno-based TFT graphical display for VSR Mini Mega Alternator Regulator

VSMMAR_Remote_Display Remote Arduino Uno-based TFT graphical display for VSR Mini Mega Alternator Regulator This project is an optional accessory for

2.4 GHz LORA based telemetry and radio link for remote controlled vehicles

mLRS This is the mLRS project. The goal is an open source 2.4 GHz LORA-based high-performance long-range radio link, which provides fully transparent

A line follower simulation created in CoppeliaSim, with a C++ interface for CoppeliaSim's Remote API
A line follower simulation created in CoppeliaSim, with a C++ interface for CoppeliaSim's Remote API

Wall-E-Sim A line follower simulation created in CoppeliaSim, with a C++ interface for CoppeliaSim's Remote API This is a simuation of SRA's Wall-E bo

PoC for CVE-2021-28476 a guest-to-host
PoC for CVE-2021-28476 a guest-to-host "Hyper-V Remote Code Execution Vulnerability" in vmswitch.sys.

CVE-2021-28476: a guest-to-host "Microsoft Hyper-V Remote Code Execution Vulnerability" in vmswitch.sys. This is a proof of concept for CVE-2021-28476

Owner
Stefan Wagner
Stefan Wagner
A push-button control panel for Zoom

Zoom Control Panel A push-button control panel for Zoom This repo contains files for building a push-button control panel for Zoom.

Elena Long 48 Nov 15, 2022
Bluetooth Gateway for Phantom Remote Control based on ESP32

Phantom remote control Bluetooth gateway An ESP3232 firmware for the gateway of Phantom remote control, which can push the temperature and humidity data of Phantom remote control through LAN, and also support to control Phantom remote control to send and receive IR data through LAN.

George Zhao 14 Nov 3, 2022
Remote control for your QMK-powered keyboard

QMK RC QMK RC is a project that aims to bring the same convenience to controlling your QMK keyboard from your computer, as QMK did to programming keyb

Maciej Małecki 46 Sep 22, 2022
Use Arduino to realize IR remote control of equipment supporting Onkyo RI

OnkyoIRRemote 使用红外遥控控制支持OnkyoRI的设备 可用ArduinoNano制作 ID列表(这是我自己测试出来的我的安桥收音机的代码) 3072 列表下一个电台(全组切换) 3073 列表上一个电台(全组切换) 3080 SLEEP 90 3081 FM 3082 AM 3088

null 1 Oct 24, 2021
Hide skip button in cutscenes in Max Payne 3

MaxPayne3.FusionFix This is a small project intended to add ability to hide button in Max Payne 3. Additionally, added an option to increase the size

Sergey P. 26 Sep 29, 2022
Turns the button on the Lamy Pen into an eraser on the reMarkable.

RemarkableLamyEraser Standalone tool that turns the button on the Lamy Pen into an eraser on the reMarkable. Also confirmed to work with these other s

null 129 Nov 21, 2022
If the button pressed esp will reset and App mode will on. App mode will on then led will on, network is connected led will off.

DHT22-to-Google-sheet-Reset-Using-ESP8266-LED-Switch If button pressed esp will reset and App mode will on. App mode will on then led will on, network

Md. Harun-Or-Rashid 3 Aug 17, 2022
MFD Button Switches for Flight Simulators. Arduino *.ino and PCB Gerber files and a picture. Now with FalconBMS specific firmwares.

MFD-Switches Use at your own risk. I am not accepting responsiblity for anything. Copyright Ron Lyttle 2021. I have to copyright because of some of th

Ron Lyttle 10 Jul 10, 2022
Turing-ring is a simple Turing Machine using just a Nano, a NeoPixel ring and a rotary encoder+push-button The ring is the tape and the UI.

Turing-ring Turing-ring is a simple Turing Machine using just a Nano, a NeoPixel ring and a rotary encoder+push-button The ring is the tape and the UI

Mark Wilson 2 Dec 26, 2021
L'iconico Button di YouTube rivisitato e reso Smart con un contatore di iscritti in tempo reale!

Smart Youtube Button with Subscribers Counter ESP32 L'iconico Button di Youtube rivisitato e "smartizzato" con un contatore di iscritti in tempo reale

Luca Barsanti 2 Dec 28, 2021