Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Monday, April 9, 2012

PowerSwitch Tail II and Arduino


Summary
Example of controlling the PowerSwitch Tail II, using an Arduino.

Description
This is an example of controlling the PowerSwitch Tail II, using an Arduino.  The PowerSwitch Tail II is a relay that is enclosed in a case.


Why?
Because we can easily control physical devices.

Before We Begin

PowerSwitch Tail II
This example uses using the PowerSwitch Tail II, you can find the product here:
http://www.sparkfun.com/products/10747

Arduino
This example uses the Arduino Duemilanove version of the Arduino board.  This board has been replaced by the Arduino Uno.  All Arduino stuff can be found:
http://arduino.cc/en/


Upload Code to Arduino
If you don't have the Arduino environment, download it from the Arduino site  (http://arduino.cc/en/Main/Software).  From here, copy the code from the bottom section labeled "The Code".  Paste this into your sketch and upload it to your Arduino.  Finally, from the menu, select "Tools > Serial Monitor".  With the code uploaded already, enter 1 or 0 to turn the device on or off.

Hooking it up
Simply enough here's how this works.

  1. In my example, pin 13 of the Arduino is connected (by the orange line) to the PowerSwitch "1: +in"
  2. In my example, Gnd of the Arduino is connected (by the black line) to the PowerSwitch "2: -in" 

Figure 1 - Arduino and Powerswitch Tail II

Figure 2 - Arduino 

Figure 3 - Powerswitch Tail II



The Code

char incoming_char=0;

void setup() {              
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  //pinMode(7, OUTPUT);
  Serial.begin(9600);
  pinMode(13, OUTPUT);  
  Serial.println("Setup has ended, entering loop()");
}

void loop() {
  if (Serial.available())
  {
 
 
    incoming_char=Serial.read(); // Get the incoming char
    if(incoming_char == '1')
    {
      digitalWrite(13, HIGH); // Turn the Powertail on
      Serial.println("Switch ON");
    }

    if(incoming_char == '0')
    {
      digitalWrite(13, LOW);    // turn the Powertail off
      Serial.println("Switch OFF");
    }
  }
}