Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Pololu Mini Pushbutton Power Switch with Reverse Voltage Protection, LV

Is it possible to use the Mini Pushbutton Power Switch with Reverse Voltage Protection, LV together with an IR remote? In other words, I want to be able to toggle the power to my downstream circuit via the pushbutton *OR via an IR remote. Is that possible?

Hello.

The power switch provides advanced control options through the ON, OFF, and CTRL pins, so you could make an interface system that reads your IR remote and then uses those pins to turn on the switch. If you do implement something like that, we’d be interested to hear more about it!

-Patrick

Thanks Patrick! Is the CTRL pin kind of a combination of the ON/OFF pins? In other words, can I toggle the power on/off with just the CTRL pin?

Also, the product description page says to use a pulse for these pins, so is that like a serial out Arduino command?

Yes, the power switch’s CTRL pin can be used by itself to toggle power on and off. There is more information about how to use the CTRL pin in the “Using the Pushbutton Power Switch” section of the product page description.

You should not use serial commands to pulse the CTRL, ON, or OFF pins. Pulsing just means driving the pin high or low for a brief period. For example, you might use something like the following Arduino code to send a high pulse to the CTRL pin:

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.

Note that you would need to define CTRL_PIN to be the Arduino pin connected to CTRL.

-Patrick

Excellent, thanks very much Patrick. I did read the product page but found it a bit confusing:

This pin directly determines the state of the switch. A high pulse (> 1 V) on this pin turns on the switch; a low pulse (e.g. driving the pin low with a microcontroller output line or pushing a button connected from this pin to ground) turns the switch off. Leave this pin disconnected or floating when not trying to set the switch state. Note that this pin should not be driven high at the same time the “OFF” pin is driven high.

Does this mean I can use the same code to turn off the switch, or would I need to use this:

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 high pulse).
pinMode(CTRL_PIN, INPUT);		// Configure CTRL as an input so it floats.

If it’s the latter, then I would first need to know the state of the switch (on or off) before using this code in the case where it has been turned on (or off) via the momentary switch on the board, for example. Is that right?

To turn off the power switch with the CTRL pin you need to pulse it low instead of high as shown with the code you posted.

Whether or not you need to know the state of the switch before you use the CTRL pin depends on your objective. If your goal is to change the state of the switch from whatever it currently is to the opposite state, then yes, you need to know the state of the switch before you pulse the CTRL pin. However, if your goal is to set the state of the switch regardless of the state it is currently in, then you do not need to know the state of the switch. For example, if you want to set the switch to the off state, then you can send a low pulse to the CTRL pin. If the switch is already off, sending the low pulse will not change anything.

-Patrick

Thanks again. If I use the same button on the remote to toggle on/off the switch, and if there is a momentary pushbutton on the base of the model which does the same thing (connected to pins A & B), then I think I need to know the state of the switch. If that’s the case, is there an easy way to do that or should I just do an analog read on the Vout pin to see if it is > 0V?

Measuring VOUT with one of our Arduino’s analog inputs (through an appropriate voltage divider, of course!) is certainly one option. However, you can also determine the state of the switch by reading the voltage on the CTRL pin. When the switch is off, the CTRL pin will be at 0 V, and when the switch is on, the CTRL pin can range from around 500 mV to 1 V, depending on VIN.

-Patrick

Got it! I can set the pin on the Arduino to INPUT and read it, then decide if I need to send a HIGH or LOW output. Or would it be better to connect a second Arduino pin (analog) and keep that as an input?

I do not think there would be any benefit to connecting a second Arduino pin. The analog inputs on an Arduino can also act as digital outputs, so you can use one pin to both control the CTRL pin and read its state.

-Patrick

Got my Mini Pushbutton Power Switch with Reverse Voltage Protection, LV today and thanks to PatrickM, I got this up and running on the first attempt!

#include <IRremote.h>

int RECV_PIN = 7;               // Connected to IR receiver chip
int CTRL_PIN = 18;              // A0 on A-Star Micro 32u4

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

#define POWER 0x00FD00FF        // Using old generic remote

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

void setup()
{
  Serial.begin(9600);
  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

  
}

void togglePwr() {
  int ctrlPinValue = analogRead(CTRL_PIN);
  float voltage = ctrlPinValue * (1.0 / 1023.0);
  Serial.print("Voltage read off CTRL pin: ");
  Serial.println(voltage);

  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 loop()
{
  if (irrecv.decode(&results))
  {
    if (results.value == POWER)
    {
      Serial.println("POWER BTN PUSHED");

      togglePwr();
    }
    else {
      Serial.println("IR RECV Code Value Not Defined or Button was Held Down");
      Serial.print("IR RECV Code = 0x ");
      Serial.println(results.value, HEX);
    }

    irrecv.resume();
  }

}
1 Like

Q: are the 4 GND pins on the power switch connected internally? I’m going to use this as a master/slave setup and I need to ensure the GND pin on the Arduino board used in this IR remote control (A-Star 32u4 Micro) is connected to the GND pin on the slave Arduino, which will be powered by the Vout & GND pins on the right-hand side of the board.

Yes, all of the GND pins are connected internally. If you are ever in doubt about something like that, you could always check that using a multimeter.

-Patrick

Thanks Patrick.

1 Like