[SOLVED] Analog pin not outputting a LOW

Hello everyone! I was looking at a blog post recently for my first arduino project and I wanted to try the same thing the original poster did, which is basically turn a lamp on and off with my voice (blog post: http://jacksondolan.com/blag/2013/10/16/bringing-jarvis-home/). I have the same code as him, and I'm using the same pins as him. However, the red light on the powertail switch does not light up, for whatever reason.

The light only turns on when I connect "-in" to ground instead of A0. This makes sense, since ground only outputs 0. However, the light does not turn on when I connect it to the predefined negative pin.

Is it the pins? Is it the tail? Or am I doing something stupid? Why doesn't the blog poster have anything connected to pin 13?

I'll post the void action() code and a picture of my connections. Let me know if you want to see the whole thing.

(Sorry if I posted in the wrong spot. I'm new here and this seemed mostly a hardware issue.)
Thanks.

The code (powerPin is A0 on the board):

void action()
{
    switch (group)
    {
    case GROUP_0:
      switch (idx)
      {
      case G0_ARDUINO:
      group=GROUP_1;
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    case GROUP_1:
      switch (idx)
      {
      case G1_LIGHT:
      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);
      }
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_THANK_YOU:
      group=GROUP_0;
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    }
}

I'm not seeing the full picture here, like which pins are which.

http://snippets-r-us.com/

Well, D13 should be the positive input, and A0 should be the negative input. I find it weird, however, that in the blog the author never puts anything in the D13 pin, so for now I've put positive (+in) there instead of 5V, because unless I'm wrong, 5V cannot be switched on and off.

Regardless, the thing only works when I put (-in) to ground, not A0, which suggests that maybe there's some sort of current flow in the negative wire even though it's supposed to be LOW.

If you want the full code, here it is:

#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_ARDUINO = 0,
};

enum Group1 
{
  G1_LIGHT = 0,
  G1_THANK_YOU = 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_ARDUINO:
      group=GROUP_1;
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    case GROUP_1:
      switch (idx)
      {
      case G1_LIGHT:
      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);
      }
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_THANK_YOU:
      group=GROUP_0;
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    }
}

I'll throw in a picture too, in case it helps (I know nothing's plugged in right now, I just took it apart for the night. The yellow wire goes to pin 13).

Let me know if I've made a silly mistake somewhere, because I honestly did not expect this much difficulty in the project.

sorry, the picture was too large to upload. here's the link:
Imgur

Digital I/O point 13 is just an on-board LED on all of my Arduino boards. It's just something to use if you don't have a spare LED, and has no special significance or internal function. Is it different on your board?

   case G0_ARDUINO:
      group=GROUP_1;
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }

Your code does nothing at all when the command is found as you have yet to write it!

PS are there are no -ve pins on your arduino!

Mark

Your code does nothing at all when the command is found as you have yet to write it!

The purpose of the code there is simply to jump to the commands in group 1. It is basically a "password" to be able to continue to the next commands.

PS are there are no -ve pins on your arduino!

I am talking about the PowerSwitch Tail, not the Arduino. Sorry for the confusion. Link: http://www.powerswitchtail.com/Pages/default.aspx

Digital I/O point 13 is just an on-board LED on all of my Arduino boards.

I think it's linked to an LED, which tells you the status of the pin (like if it's sending a 1 or 0). Regardless, I still get the same result when I try pin 12 instead of 13. It's only stable when I connect it to 5V, but I don't think I can switch that on and off like the digital pins.

Since my circuit only worked when I connected negative to ground (which would send 0 all the time), I tried only controlling pin 13. I thought that, if both positive and negative were LOW, then the lamp should still not turn on. Is there a reason why that didn't work?

I presume the powertail has an opto-coupler input, so you'd be correct to connect the -ve
input to ground and the +ve input to a pin (which then should be high to activate(*) the thing).
The must be current flow in both wires for the thing to work of course, you seem to be confused by this.

You could just as easily connect +ve input to +5V and -ve input to a pin, which would then
work with negative logic.

opto-coupled inputs are simply an LED and resistor electrically.

(*) activate will of course mean different things for a NO and NC switch...

UPDATE: I fixed it!

Aparrently, you can't address pin A0 as A0; you have to address it as pin 14 in the code. I changed only that and everything else was good.

Thanks for the help :slight_smile:

To turn the light on, you need to see the arduino output/powertail control input to high ( or, at least, to 3 volts ). To turn it off, you need to set it low.

Your code seems to do the opposite of this.

skahri1429:
Aparrently, you can't address pin A0 as A0; you have to address it as pin 14 in the code. I changed only that and everything else was good.

Are you sure you didn't change anything else?

Try this:

const byte ppin = A0;

void setup() {
  Serial.begin (115200);
  Serial.println (ppin);
}

void loop() {
  // put your main code here, to run repeatedly: 
}