IR Remote Power and Function Control

Forum rules
Forum Rules For All Members: No posts of any kind containing offensive language or personal insults will be allowed. Also, no pictures depicting full nudity whether in a post or an individual members personal avatar are permitted. Spamming or multiple trolling posts by members in an offensive way are also not permitted. Violations of these basic guidelines will result in Admin taking action starting with a warning and up to a permanent ban from the community for repeat offending members.
Post Reply
RossW
Posts: 89
Joined: April 3rd, 2019, 1:27 pm

November 6th, 2019, 8:47 pm

If you've ever wanted to use an IR remote control for your model, here's my custom circuit/code to get you started. I wanted to be able to power on my TOS E via remote control but without going as far as using Bluetooth, so this was the easiest solution. The IR receiver is inside the neck of my custom base (clear styrene cover but painted with Tamiya Smoke to hide the diode and blend in) and you can use either the remote control to power on the model, or a momentary button in the base. I've included a connector to use the SDA/SCL pins on an Arduino to communicate between other boards with an Arduino so I can eventually use the remote control to increase the speed of the motors, for example, or adjust the brightness of the LED strips.

I'm using a Pololu A-Star 32u4 Micro board as it is fully Arduino compatible and is the smallest board I could find (there may be others, of course). You need to follow the steps in the User Guide to add the board to the Arduino IDE, but after that it's basically the same as using an Uno:
https://www.pololu.com/product/3101

The IR remote control is from SparkFun as I didn't need a ton of buttons and their hookup guide has all the command codes and sample Arduino code you need to get started:
https://www.sparkfun.com/products/14865

https://learn.sparkfun.com/tutorials/ir ... 1349392979

The 12V power in goes to the A-Star 32u4 Micro which then is monitoring for any IR command received by the receiver. For the power button, it then turns on the Pololu Mini Push Button Power Control board when outputs the 12V to any downstream circuit. This push button power control accepts either a momentary button push (there's one on the board itself but it's obviously more useful to connect an external button to A/B pins) or a logic signal from an Arduino. This lets me turn on/off the model with either the IR remote control or the momentary button in the back of the base.

https://www.pololu.com/product/2808

Custom Circuit (Schematic & Board, plus parts list & Arduino Code)
https://drive.google.com/open?id=1URDlK ... ZWszqyLX2A
IR_Remote_Pwr_Ctrl_Schematic..png
IR_Remote_Pwr_Ctrl_Board.png
Demo Videos
ImageIR Remote Power Control by Ross the Boss, on Flickr

ImageIR Remote power control wired into base of model by Ross the Boss, on Flickr

Arduino Code

1. Primary Board (this one)

Code: Select all

/*

  PARTS
  =====

  1. Pololu Mini Pushbutton Power Switch with Reverse Voltage Protection, LV
     https://www.pololu.com/product/2808

  2. Pololu A-Star 32u4 Micro
     https://www.pololu.com/product/3101

     Note: for this to work the board must have direct power connected to its Vin pin

  3. IR Receiver Diode
     https://www.sparkfun.com/products/10266?_ga=2.119035520.883295568.1567630800-1769896816.1567289089

  4. IR Remote Control
     https://www.sparkfun.com/products/14865
  
  5. LED to indicate IR receive


  PIN CONNECTIONS
  ===============

  Mini Pushbutton Power Switch
  ----------------------------
  
  +ve lead of input power                   > Vin
  -ve lead of input power                   > GND pin next to Vin
  A0 pin on A-Star 32u4 Micro               > CTRL pin
  +ve lead on downstream circuits           > Vout
  -ve lead on downstream circuits           > GND pin next to Vout
  External button                           > A & B



  Pololu A-Star 32u4 Micro
  ------------------------

  +ve lead of input power supply            > Vin
  -ve lead of input power supply            > GND
  CTRL pin on Mini Pushbutton Power Switch  > pin 18 (A0)
  +ve lead on IR receive indicator LED      > pin 8 (-ve lead on LED > appropriate resistor > GND)
  IR receiver diode pin 1 (OUT)             > pin 7 (pin 2 > GND; pin 3 > Vs [5V])
  SDA/SCL pins                              > SDA/SCL pins on slave Arduino


  i2c Synchronous Serial Protocol - Master/Slave Arduino Connections
  ==================================================================

  https://www.arduino.cc/en/Tutorial/MasterWriter

  https://www.instructables.com/id/I2C-between-Arduinos/
  

*/


#define DEBUG 0                 // Set to 0 for production

#include <IRremote.h>
#include <Wire.h>

int RECV_PIN = 7;               // Connected to IR receiver chip output pin
int CTRL_PIN = 18;              // A0 on A-Star 32u4 Micro
int LED_IND  = 8;               // LED indicator (shows when board receives IR input)

IRrecv irrecv(RECV_PIN, LED_IND); // Sets up pin 8 for blinking LED when receiving signal
decode_results results;


/*
 Sparkfun Hookup Tutorial
 https://learn.sparkfun.com/tutorials/ir-control-kit-hookup-guide?_ga=2.98764510.1343415594.1568417261-36824998.1349392979
 
 */
 
#define POWER  0x00FF629D
#define A      0x00FF22DD
#define B      0x00FF02FD
#define C      0x00FFC23D
#define UP     0x00FF9867
#define DOWN   0x00FF38C7
#define LEFT   0x00FF30CF
#define RIGHT  0x00FF7A85
#define SELECT 0x00FF18E7

//------------------------------------------------------------


void setup()
{
#ifdef DEBUG
    Serial.begin(9600);
#endif

  irrecv.blink13(1);            // enables blinking LED as set in declaration above
  irrecv.enableIRIn();          // Start the receiver

  pinMode(CTRL_PIN, INPUT);     // Configure CTRL as an input so it floats

  // Start the I2C Bus as MASTER
  Wire.begin(); 
    
}

void togglePwr() {
  int ctrlPinValue = analogRead(CTRL_PIN);
  float voltage = ctrlPinValue * (1.0 / 1023.0);

#ifdef DEBUG
  Serial.print("Voltage read off CTRL pin: ");
  Serial.println(voltage);
#endif

  if (ctrlPinValue > 0) {
    pwrOff();
  } else {
    pwrOn();
  }

  pinMode(CTRL_PIN, INPUT);     // Configure CTRL as an input so it floats.

}

void pwrOn() {
  pinMode(CTRL_PIN, OUTPUT);    // Configure the CTRL pin as an output
  digitalWrite(CTRL_PIN, HIGH); // Drive CTRL high.
  delay(50);                    // Delay 50 ms (i.e. 50 ms high pulse).
//  pinMode(CTRL_PIN, INPUT);     // Configure CTRL as an input so it floats.
}

void pwrOff() {
  pinMode(CTRL_PIN, OUTPUT);    // Configure the CTRL pin as an output
  digitalWrite(CTRL_PIN, LOW);  // Drive CTRL low.
  delay(50);                    // Delay 50 ms (i.e. 50 ms low pulse).
//  pinMode(CTRL_PIN, INPUT);     // Configure CTRL as an input so it floats.
  
}


void adjWarpSpeed(int x) {
  Wire.beginTransmission(1);  // transmit to device #1
  Wire.write(x);              // sends x 
  Wire.endTransmission();     // stop transmitting
  delay(500);
}




//------------------------------------------------------------

void loop()
{
  if (irrecv.decode(&results))
  {
    if (results.value == POWER)
    {

#ifdef DEBUG
      Serial.println("POWER BTN PUSHED");
#endif

      togglePwr();
      
    } else if (results.value == UP) {

#ifdef DEBUG
      Serial.println("INC_WARP");
#endif
      
      adjWarpSpeed(1);
      
    } else if (results.value == DOWN) {

#ifdef DEBUG
      Serial.println("DEC_WARP");
#endif

      adjWarpSpeed(-1);
      
    }
    
    // Add other cases here
    
    
    else {

#ifdef DEBUG
      Serial.println("IR RECV Code Value Not Defined or Button was Held Down");
      Serial.print("IR RECV Code = 0x ");
      Serial.println(results.value, HEX);
#endif

    }

    irrecv.resume();
  }

}
2. Secondary Board (not shown)

Code: Select all

/*

  PARTS
  =====


  PIN CONNECTIONS
  ===============


  Pololu A-Star 32u4 Micro
  ------------------------

  SDA/SCL pins                              > SDA/SCL pins on MSter Arduino


  i2c Synchronous Serial Protocol - Master/Slave Arduino Connections
  ==================================================================

  https://www.arduino.cc/en/Tutorial/MasterWriter

  https://www.instructables.com/id/I2C-between-Arduinos/
  

*/

#include <Wire.h>

//------------------------------------------------------------


void setup() {
  Wire.begin(1);                // join i2c bus with address #1
  Wire.onReceive(receiveEvent); // register event
  
  Serial.begin(9600);           // start serial for output
}

void loop() {
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();       // receive byte as an integer
  // Handle negative numbers
  if (x > 127) {
    x = 256 - x;
    x *= -1;
  }
  
  Serial.println(x);         // print the integer
}
Tshark
Posts: 38
Joined: April 3rd, 2019, 1:24 pm

November 7th, 2019, 1:50 pm

Thanks Ross! I might try this on my lighted RX-7 with pop-up headlights build that I am currently working on.
RossW
Posts: 89
Joined: April 3rd, 2019, 1:27 pm

November 7th, 2019, 2:23 pm

Tshark wrote:
November 7th, 2019, 1:50 pm
Thanks Ross! I might try this on my lighted RX-7 with pop-up headlights build that I am currently working on.
:)
Post Reply