Help with PowerSwitch Tail and Arduino

Has anyone used the powerswitch tail 2 with arduino uno? I'm trying to turn a lamp on and off with it but the red light won't light up.
I tested to see if the thing actually works by connecting ground to the negative pin, and the red light turned on. But, when I connect the wire I'm trying to use for negative, it doesn't work, even though I'm using digitalWrite(13, LOW). Can someone help me fix this?

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);
#endif


#include "EasyVR.h"
EasyVR easyvr(port);

//Groups and Commands
enum Groups
{
  GROUP_0  = 0,
  GROUP_1  = 1,
};

enum Group0 
{
  G0_SAMOSA = 0,
};


enum Group1 
{
  G1_LAMP = 0,
  G1_GOODNIGHT = 1,
  
};


EasyVRBridge bridge;

int8_t group, idx;

const int powerPin = A0;
boolean powerOn = false;

void setup()
{
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }
  // run normally
  Serial.begin(9600);
  port.begin(9600);

  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(0);

  group = EasyVR::TRIGGER; //<-- start group (customize)
  
  pinMode(powerPin, OUTPUT);
  digitalWrite(powerPin, HIGH);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void action();

void loop()
{
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)

  Serial.print("Say a command in Group ");
  Serial.println(group);
  easyvr.recognizeCommand(group);

  do
  {
    // can do some processing while waiting for a spoken command
  }
  while (!easyvr.hasFinished());
  
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

  idx = easyvr.getWord();
  if (idx >= 0)
  {
    // built-in trigger (ROBOT)
    // group = GROUP_X; <-- jump to another group X
    return;
  }
  idx = easyvr.getCommand();
  if (idx >= 0)
  {
    // print debug message
    uint8_t train = 0;
    char name[32];
    Serial.print("Command: ");
    Serial.print(idx);
    if (easyvr.dumpCommand(group, idx, name, train))
    {
      Serial.print(" = ");
      Serial.println(name);
    }
    else
      Serial.println();
    easyvr.playSound(0, EasyVR::VOL_FULL);
    // perform some action
    action();
  }
  else // errors or timeout
  {
    if (easyvr.isTimeout())
      Serial.println("Timed out, try again...");
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);
    }
  }
}

void action()
{
    switch (group)
    {
    case GROUP_0:
      switch (idx)
      {
      case G0_SAMOSA:
        // write your action code here
        group = GROUP_1;
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    case GROUP_1:
      switch (idx)
      {
      case G1_LAMP:
      /*Serial.println("In Light");
      powerOn = !powerOn;
      if (powerOn) {
        Serial.println("Power On");
        digitalWrite(powerPin, LOW);
        digitalWrite(13, HIGH);
      }
      else {
        Serial.println("Power Off");
        digitalWrite(powerPin, HIGH);
        digitalWrite(13, LOW);
      }
      */group = GROUP_1;
      digitalWrite(powerPin, LOW);
      digitalWrite(13, HIGH);
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_GOODNIGHT:
        
        digitalWrite(powerPin, HIGH);
        digitalWrite(13, LOW);
        group = GROUP_0;
         
        
        
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    }
}

you only really need to see the last part, void loop()

Are you doing something like this blog?

That shows Arduino GND to PowerTail -ve, Arduino signal to PowerTail +ve and set the signal pin high for on.

This is a very good example of how it would save loads of hassle if you had posted your circuit and code.... 8)

I updated the post with the full code. As for the circuit, well, I have an EasyVR Shield connected to an arduino uno.

5V -> +in
A0 -> -in
GND -> ground

I think it's supposed to be Arduino GND to -ve and Arduino signal to +ve and the PowerTail ground is empty.

EDIT.... test it by itself with simpler code like in that blog?

I copied the code from the bottom of the post, but now I'm getting errors. I'll jump right to the case structure below:

case GROUP_1:
      switch (idx)
      {
      case G1_LAMP:
      if (Serial.available()) {
        incoming_char = Serial.read();
        if(incoming_char=='1') {
          digitalWrite(13, HIGH);
          Serial.println("Switch On");
        }
        if(incoming_char=='0') {
          digitalWrite(13, LOW);
          Serial.println("Switch OFF");
        }
      }
group = GROUP_1;
      }

And here are the errors I'm getting:

revision_jan_7.cpp: In function 'void action()':
revision_jan_7:180: error: duplicate case value
revision_jan_7:146: error: previously used here
revision_jan_7:192: error: break statement not within loop or switch
revision_jan_7.cpp: At global scope:
revision_jan_7:194: error: expected declaration before '}' token

Thanks for the help.

Good example of how it's easiest to test a concept by itself so you don't have other crap getting in the way.

My advice is make a new minimal sketch, perhaps just use the blog one?, that does nothing but test the PowerSwitch. Wire it like the blog. Then known good sketch and known good wiring should drive the thing.

I took off the easyVR Shield and connected it to the arduino, and the powerswitch lit up, but only when I put it on 5V, not pin 13. The lamp turns on, but that's only because it turns on every time it's plugged in. It never turns off when I throw a 0 in the code.

Maybe I should just get a new lamp...

At the risk of sounding like a Boring Old Fart... I repeat...

My advice is make a new minimal sketch, perhaps just use the blog one?, that does nothing but test the PowerSwitch. Wire it like the blog.

Have you tried that?

  • If so, what happened
  • If not, I'm out

That's exactly what I did. The light stayed on but never turned off or responded to any other commands.

skahri1429:
That's exactly what I did. The light stayed on but never turned off or responded to any other commands.

Hmmmm.... can you post a schematic ... or a cell phone photo that shows the connections?- of your setup?

And the code... post it as you have it in your ide, just in case something's gone wobbly

My code is exactly the same as it is on the blog. I have attached a picture of the setup.

Going back to my original question, I think the biggest problem is that I'm using GND for "-in", which does the same thing an output connection with a LOW signal would do. The powerswitch light doesn't go on if I use an output wire instead of ground. However, ground is always LOW; it doesn't have the ability to pull HIGH like an output switch can. That's what prevents the lamp (or whatever's connected to it, really; I've tried an LED as well) from switching on and off. My problem would be immediately resolved if I could get the powerswitch to recognize an output switch (A0 in my case) instead of a ground connection.

Well that pic clearly doesn't match the code of the blog...

I'm out....