Stumped!!! so close, yet so far away

howdy,

I am trying to make a project where I can turn other instruments on/off at school by just sending a open/close(on/off) signal to a relay to control the power source (see pic). The code was written to make the ardruino do this so many times in a loop, then stop. My code worked when I was just turning LEDs on/off, then I replaced the LEDs with the PowerSwitch Tail II's to conrol the power and I can't get them to work.

my next guess is the problem is with the powerswitch tails a.k.a., the relays:
the PowerSwitch Tail II requires an actuating signal between 3vdc(3ma) to 12vdc(30ma) to reliably energize the ac circuit. Do I need an external driver circuit? has anyone set one of those up before?

any input would be great, thanks

(I'll post pics of what I got and what I'm using: Arduino Uno, Brick Chassis v1.1, 10 wire bus cable, LCD 16x2, buckled 3 wire cable, empty box to attach the stuff too, etc..)
ps. The red LED on the powerswitches: when lit up, AC circuit is energized.

the code:

// include the library code:
#include <LiquidCrystal.h>

//Each of these are associated with the arduino pin numbers
int LED9 = 9;      // D9
int LED11 = 11;   // D11
int LED17 = 17;   // A3 

//time delays to make it easy to keep track of minutes and hours
int minute = 60000;       //1000ms/sec * 60 sec (60000)
int hour = minute*60;    //60 minutes in an hour

//number of loops & stop execution after # of loops.
int MAX_CYCLES = 99;
int countLoop = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10,11,12,13,14,15,16);

void setup() //setup is run once and is used as an init.
{
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(1,2);
  lcd.display();
 
  //set the LED's to output mode for each corresponding pin.
  pinMode(LED9, OUTPUT);
  pinMode(LED11, OUTPUT);
  pinMode(LED17, OUTPUT);
  
  //turn off the led's
  digitalWrite(LED9, LOW);
  digitalWrite(LED11, LOW);
  digitalWrite(LED17, LOW);
}

void cycleLED(int ledPin, int state, int timeDelay)
{
  digitalWrite(ledPin, state);
  delay(timeDelay);
}

void loop()                              //this gets looped the entire time it has power.
{
  if(countLoop<MAX_CYCLES)     //make a conditional statement which will be false and not be executed after 6 loops
  {
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("Beginning");
  lcd.setCursor(1,2);
  lcd.display();
  delay(1000);
  
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("1");
  lcd.setCursor(1,2);
  lcd.display();
  delay(1000);
    cycleLED(LED9, HIGH, 50);          //loop 1. first loop.
    cycleLED(LED9, LOW, 50);
   
    
lcd.begin(16, 2);
  lcd.clear();
  lcd.print("2");
  lcd.setCursor(1,2);
  lcd.display();
  delay(1000);
    cycleLED(LED11, HIGH, 50);      //loop  2  
    cycleLED(LED11, LOW, 50);
   
    
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("3");
  lcd.setCursor(1,2);
  lcd.display();
  delay(1000);
    cycleLED(LED17, HIGH, 50);    //loop   3
    cycleLED(LED17, LOW, 50);
    
   
    
  lcd.begin(16, 2);                     //   loop finished, but will continue    
  lcd.clear();
  lcd.print("End of Process");
  lcd.setCursor(1,2);
  lcd.display();
  delay(1000);
    
  }
  if(countLoop<MAX_CYCLES+1)    //prevent the device from counting forever.
    countLoop++;
}

lcd.begin(16, 2);                        //   loops finished. no more loops. will not continue.    
  lcd.clear();
  lcd.print("Finished");
  lcd.setCursor(1,2);
  lcd.display();
  delay(1000);

Just a heads up - you will be asked to put code inside a code block - the number sign button just above this edit window, makes you post easier to read.

Not having worked with those devices - are you using any kind of pull-up/pull-down resistor on the pin going t those devices? it looks like they use a very low current, and if the signal line going to the PowerSwitch is floating they may not turn off.

thanks for the heads up.

well, since I just googled pull up/pull down resisters, I did not knowingly use any; unless they are built in or can my code somehow act like them?

floating=not grounded? I did attached a ground to the powerswitches via the ardruino. there are three wires going to each powerswitch(+,-,ground), unless there is more needed to make them work....

Since the Arduino should have no problem providing the required signal, the most likely problem is your wiring is wrong. You only need two connections; 1 Connect ground on the Arduino to the - signal on the Powerswitch (not the ground, although you can connect Arduino Gnd to both if your Arduino is earth grounded), and the LED pin to the + connection

You also have a declaration problem

This

int minute = 60000;       //1000ms/sec * 60 sec (60000)
int hour = minute*60;    //60 minutes in an hour

should be

unsigned long minute = 60000;       //1000ms/sec * 60 sec (60000)
unsigned long hour = minute*60;    //60 minutes in an hour

since the largest positive integer that an int can store 32767, when you cause it to type cast 60000 to an int you get a negative number, probably not what you wanted.

Did you test the PowerSwitch Tail II manually? I mean wiring to +5V and GND to see if its working?
A schematic of you connections will help understand the problem.
By the way, you are giving the connections just 50ms high. Maybe the relays or the load connected to it are not that fast. Seen the PwrSwitch datasheet says that the relays need only 15ms to actuate, maybe the load needs more. What is your load?
Relays make a notorious CLICK when they are actuated. Try to listen to this sound.
Hope this helps.

ooo00OO00oooOOhhhhh These are all great suggestions, that I have not tried! I will try them ASAP. I didn't bring my setup to work :slight_smile:

I think I have tried different times (to avert the 50ms high issue), but I can't remember. Eventually, the final times that I will want to use are like minimum: 1 sec. and the max: 10 min. I want to use this to turn on/off three devices: a shaker and two different pumps. I'll post a pic later if curious

ok, so I did some tests tonight.

my first impression was that the relay is a "normally ON" relay, but then it confused me when I give it power and its just on all the time, regardless of the code running.

I made a pic to show whats going on. notice: Just looking at one relay/powerswitch tail(the bottom one of three in the pic), I labeled the things that I was looking at. Also, for more reference, when the powerswitch is plugged into the wall outlet, the Adruino is strong enough to trip/click the relay on, a 9v battery could too, but a 1.5v (AA) battery could not.

Which pin are you using to turn the relay on and off? How are you wiring it to the Powerswitch? It should be Pin to +, GND to -
Do you hear the relay clicking??
Is it me or you are using pin 11 for the LCD and a relay??

since I am using the brick Chassis v1.1, the pins I am using for on/off commands are:

//Each of these are associated with the arduino pin numbers
int LED9 = 9;      // D9
int LED11 = 11;   // D11
int LED17 = 17;   // A3

I put the D9, D11, and A3 in there because that is how the Chassis v1.1 labels its quick connects. I put it in the code because the last one is LED17 to A3 not easy LED3 to connect A3. should I not use the language LED# since I'm not using LEDs anymore? i figured it doesnt make a difference.

and if so, maybe I should use some language other than this to command the relays? like not OUTPUT?

//set the LED's to output mode for each corresponding pin.
  pinMode(LED9, OUTPUT);
  pinMode(LED11, OUTPUT);
  pinMode(LED17, OUTPUT);
  
  //turn off the led's
  digitalWrite(LED9, LOW);
  digitalWrite(LED11, LOW);
  digitalWrite(LED17, LOW);

when I wire it to the relays, the 3wire bundles and the relays both have +-gnd labeled to they are wired +to+, -to-, and ground to ground.

I can hear the clicking when the relay is on, but I also plug it into a lamp to make sure by seeing the light come on.

with pin 11, yes I think that is the case. I am using pin 11 for the LCD because it was used that way on the LCD's mft website, and pin 11 in the code because I had it working with LEDs, before using the relays.

I put the D9, D11, and A3 in there because that is how the Chassis v1.1 labels its quick connects. I put it in the code because the last one is LED17 to A3 not easy LED3 to connect A3. should I not use the language LED# since I'm not using LEDs anymore? i figured it doesnt make a difference.

How yo label your variables, is just a matter of taste :slight_smile:

Don't use a Pin for the LCD and controlling a Relay. This is just going to give you headaches. Choose another one.

You have tree wires coming out of the Chassis v1.1 connectors: GND, VCC and Signal. You have to wire only GND and Signal to the PowerSwitch Tail II: GND to Pin 1 and Signal to pin 2, leaving pin 3 not connected . Don't use VCC (or you will just leave the relay always ON).

its alive!!!! its works!

with this code:

// include the library code:
#include <LiquidCrystal.h>

//Each of these are associated with the arduino pin numbers
int LED9 = 9;     // D9
int LED11 = 11;   // D11
int LED17 = 17;   // A3 

//time delays to make it easy to keep track of minutes and hours
unsigned long minute = 60000;       //1000ms/sec * 60sec equals 60000ms or 1 minute
unsigned long hour = minute*60;    //60 minutes in an hour

//number of loops & stop execution after # of loops.
int MAX_CYCLES = 99;
int countLoop = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10,11,12,13,14,15,16);

void setup() //setup is run once and is used as an init.
{
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(1,2);
  lcd.display();
 
  //set the LED's to output mode for each corresponding pin.
  pinMode(LED9, OUTPUT);
  pinMode(LED11, OUTPUT);
  pinMode(LED17, OUTPUT);
  
  //turn off the led's
  digitalWrite(LED9, LOW);
  digitalWrite(LED11, LOW);
  digitalWrite(LED17, LOW);
}

void cycleLED(int ledPin, int state, int timeDelay)
{
  digitalWrite(ledPin, state);
  delay(timeDelay);
}

void loop()                     //this gets looped the entire time it has power.
{
  if(countLoop<MAX_CYCLES)     //make a conditional statement which will be false and not be executed after 6 loops
  {
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("Beginning");
  lcd.setCursor(1,2);
  lcd.display();
  delay(1000);
  
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("1");
  lcd.setCursor(1,2);
  lcd.display();
    cycleLED(LED9, HIGH, 2000);    //loop 1. first loop.
    cycleLED(LED9, LOW, 2000);
   
    
lcd.begin(16, 2);
  lcd.clear();
  lcd.print("2");
  lcd.setCursor(1,2);
  lcd.display();
    cycleLED(LED11, HIGH, 2000);      //loop  2  
    cycleLED(LED11, LOW, 2000);
   
    
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("3");
  lcd.setCursor(1,2);
  lcd.display();
    cycleLED(LED17, HIGH, 2000);    //loop   3
    cycleLED(LED17, LOW, 2000);
    
   
   
  lcd.begin(16, 2);           //   loop finished, but will continue    
  lcd.clear();
  lcd.print("End of Process");
  lcd.setCursor(1,2);
  lcd.display();
  delay(2000);
    
  }
  
{
  if(countLoop<MAX_CYCLES+1)//prevent the device from counting forever.
    countLoop++;
}

lcd.begin(16, 2);           //   At this time, loops are finished. No more loops. Will not continue.    
  lcd.clear();
  lcd.print("Finished");
  lcd.setCursor(1,2);
  lcd.display();
}

the Solution:
rewired the Chassis to the relays (powerswitch tails). it works with or without the VCC to Ground.
Must have Signal(chassis) to "+"(relay), and Ground(chassis) to "-"(relay) connections.

Thanks everyone!

Congratulations.
Enjoy it!