Pages: [1]   Go Down
Author Topic: How to connect LED Power Strip to Arduino Uno  (Read 2432 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I am trying to connect my Arduino Uno to an LED Strip (non RGB, just white).
In short I just want the LED strip to light up, but I can't seem to get the LED strip working when connected to arduino (UNO).
 
I am using  digitalWrite(8, HIGH); to activate the pin...

I was given the Hardware all setup for me, but the actual code is gone.
Basicly there is a power supply going directly into my arduino Uno. There is then a Eithernet shield on top of the Uno board. The USB is connect from my computer into the UNO (for dev purpose). There is a cable connected directly into the Eithernet Board, and this works (confirmed by twitter example I am receiving the LED on)

There are two wires coming out of the Arduino (GND and Pin smiley-cool. Both of these wires go into a mini "rayexelec" breadboard. There is then a bigger wire coming from the "rayexelec" which connects directly to the LED power Strip.

On one final front, there is an LED power Supply which connects into the "rayexelec" chip. ( I am assuming this is for Additional power & protection) .

In short, what code do I use to tell pin8 to send voltage to the led strip - currently using  digitalWrite(8, HIGH);



Maybe this will make it easier ?



Here is the code I am testing with.

I am using the TWITTER code but modified it to turn on led 8 when the program connects to Twitter.

Code:
/*
  Twitter Client with Strings
 
 This sketch connects to Twitter using an Ethernet shield. It parses the XML
 returned, and looks for <text>this is a tweet</text>
 
 You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield,
 either one will work, as long as it's got a Wiznet Ethernet module on board.
 
 This example uses the DHCP routines in the Ethernet library which is part of the
 Arduino core from version 1.0 beta 1
 
 This example uses the String library, which is part of the Arduino core from
 version 0019.  
 
 Circuit:
  * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 21 May 2011
 by Tom Igoe
 
 This code is in the public domain.
 
 */
#include <SPI.h>
#include <Ethernet.h>


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xBA, 0x44};
IPAddress ip(10,11,0,62); //<<< ENTER YOUR IP ADDRESS HERE!!!

// initialize the library instance:
EthernetClient client;

const int requestInterval = 60000;  // delay between requests

char serverName[] = "api.twitter.com";  // twitter URL

boolean requested;                   // whether you've made a request since connecting
long lastAttemptTime = 0;            // last time you connected to the server, in milliseconds

String currentLine = "";            // string to hold the text from server
String tweet = "";                  // string to hold the tweet
boolean readingTweet = false;       // if you're currently reading the tweet

int mainPower=8;

void setup() {
  
  pinMode(2, OUTPUT);
  pinMode(8, OUTPUT); // FOR THE LED STRIP
  
  // reserve space for the strings:
  currentLine.reserve(256);
  tweet.reserve(150);

// initialize serial:
  Serial.begin(9600);
  // attempt a DHCP connection:
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Ethernet.begin(mac, ip);
  }
  // connect to Twitter:
  connectToServer();
}



void loop()
{
  if (client.connected()) {
    if (client.available()) {
      // read incoming bytes:
      char inChar = client.read();

      // add incoming byte to end of line:
      currentLine += inChar;

      // if you get a newline, clear the line:
      if (inChar == '\n') {
        currentLine = "";
      }
      // if the current line ends with <text>, it will
      // be followed by the tweet:
      if ( currentLine.endsWith("<text>")) {
        // tweet is beginning. Clear the tweet string:
        readingTweet = true;
        tweet = "";
      }
      // if you're currently reading the bytes of a tweet,
      // add them to the tweet String:
      if (readingTweet) {
        if (inChar != '<') {
          tweet += inChar;
        }
        else {
          // if you got a "<" character,
          // you've reached the end of the tweet:
          readingTweet = false;
          Serial.println(tweet);
          
          if(tweet == ">Hello Cruel World"){
           digitalWrite(2, HIGH);

           digitalWrite(8, HIGH); // TURN ON LED STRIP

           Serial.println("LED ON!");
          
          }
          if(tweet != ">Hello Cruel World"){
           digitalWrite(2, LOW);
           Serial.println("LED OFF!");
          }
          
          // close the connection to the server:
          client.stop();
        }
      }
    }  
  }
  else if (millis() - lastAttemptTime > requestInterval) {
    // if you're not connected, and two minutes have passed since
    // your last connection, then attempt to connect again:
    connectToServer();
  }
}

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.println("connecting to server...");
  if (client.connect(serverName, 80)) {
    Serial.println("making HTTP request...");
  // make HTTP GET request to twitter:
    client.println("GET /1/statuses/user_timeline.xml?screen_name=RandyMcTester&count=1 HTTP/1.1");
    client.println("HOST: api.twitter.com");
    client.println();
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
}  

« Last Edit: October 09, 2012, 03:06:47 am by daragh_c » Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you been able to get the 'rayexelec' to turn on the LED Power Strip without involving the Arduino?  If you have then tell us how you did so, otherwise we need more information about the 'rayexelec'.

Have you been able to get the Arduino to turn on a single LED, perhaps the one on pin 13, when it receives a Tweet?  If not then your sketch needs some work and it is pretty hard to read as it stands right now.  Go back to your original post and use the 'Modify' option.  Highlight the portion of that post that is code and press the 'Code' button (which looks like a # sign).


Don
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Floresta.

Thanks a million for that. I have indeed been able to get the LED working when a Tweet comes in. Thats why I am so confused, as the code seems to be ok (unless I need special code for the Light strip)

Any other ideas at all would be great.

Cheers
Daragh
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Floresta.

Forgot about the first part of your post. I have not been able to get the light strip to work at all unless connected directly into the plug. I have got information about the 'rayexelec' from another form (johnwasser) and apparently the 'rayexelec' could be a simple relay box ?. Not sure what the purpose of the relay box is though.

Thanks a million for your help

Daragh
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Not sure what the purpose of the relay box is though.
A traditional relay is an electromagnetic device that allows you to control a device, typically one that requires a lot of power one such as lights, a motor, or a heater, with a much device that uses a much smaller amount of power.  Your low power circuit controls an electromagnet.  The electromagnet operates a switch that controls the current to the high power device.

A solid state relay uses an LED in it's low power circuit.  This LED controls a transistor (or other similar device) which in turn controls the current to the high power device.

We need to know what kind of signal the 'rayexelec' expects to find at it's input (the low power side) and then use the Arduino to generate this signal.

Have you ever heard of a device called a Powerswitch Tail?  This may be just what you need.


Don
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey All,
I managed to get the light strip working, by simply taking everything apart and putting it all back together again. The blink program makes the entire board flash so that's working as expected YAY !. Annoying that I waited until the last idea to dismantle, but sure glad it works.

I ended up using pin 8, as the eithernet sheild uses pins 10-13

Thanks a mill for everyone's help !!!

For the record the twitter code is here , But I have removed my MAC and Ip address for obvious reasons...

Code:
/*
  Twitter Client with Strings
 
 This sketch connects to Twitter using an Ethernet shield. It parses the XML
 returned, and looks for <text>this is a tweet</text>
 
 You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield,
 either one will work, as long as it's got a Wiznet Ethernet module on board.
 
 This example uses the DHCP routines in the Ethernet library which is part of the
 Arduino core from version 1.0 beta 1
 
 This example uses the String library, which is part of the Arduino core from
 version 0019. 
 
 Circuit:
  * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 21 May 2011
 by Tom Igoe
 
 This code is in the public domain.
 
 */
 
int led=8;
 
#include <SPI.h>
#include <Ethernet.h>


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX};
IPAddress ip(XX,XX,XX,XXX); //<<< ENTER YOUR IP ADDRESS HERE!!!

// initialize the library instance:
EthernetClient client;

const int requestInterval = 10000;  // delay between requests

char serverName[] = "api.twitter.com";  // twitter URL

boolean requested;                   // whether you've made a request since connecting
long lastAttemptTime = 0;            // last time you connected to the server, in milliseconds

String currentLine = "";            // string to hold the text from server
String tweet = "";                  // string to hold the tweet
boolean readingTweet = false;       // if you're currently reading the tweet



void setup() {
 
  pinMode(led, OUTPUT);
 
   //reserve space for the strings:
 currentLine.reserve(256); 
 tweet.reserve(150);

//initialize serial:
 Serial.begin(9600);
 //attempt a DHCP connection:
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Ethernet.begin(mac, ip);
  }
  // connect to Twitter:
 
  connectToServer();
}



void loop()
{

 
   
  if (client.connected()) {
    if (client.available()) {
      // read incoming bytes:
      char inChar = client.read();

      // add incoming byte to end of line:
      currentLine += inChar;

      // if you get a newline, clear the line:
      if (inChar == '\n') {
        currentLine = "";
      }
      // if the current line ends with <text>, it will
     // be followed by the tweet:
      if ( currentLine.endsWith("<text>")) {
        // tweet is beginning. Clear the tweet string:
        readingTweet = true;
        tweet = "";
      }
      // if you're currently reading the bytes of a tweet,
      // add them to the tweet String:
      if (readingTweet) {
        if (inChar != '<') {
          tweet += inChar;
        }
        else {
          // if you got a "<" character,
          // you've reached the end of the tweet:
          readingTweet = false;
          Serial.println(tweet);
         
          if(tweet == ">Hello Cruel World"){
           Serial.println("LED ON!");
           flashLight();
           delay(3000);
           
          }
          if(tweet != ">Hello Cruel World"){
          digitalWrite(led, LOW);
           Serial.println("LED OFF!");
          }
         
          // close the connection to the server:
          client.stop();
          Serial.println("Closed Connection");
        }
     }
    }   
  }
  else if (millis() - lastAttemptTime > requestInterval) {
    // if you're not connected, and two minutes have passed since
    // your last connection, then attempt to connect again:
    connectToServer();
  }
}


void flashLight(){
 
  Serial.println("Turning on Light");
 digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000); 
 
}

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.println("connecting to server...");
  if (client.connect(serverName, 80)) {
    Serial.println("making HTTP request...");
  // make HTTP GET request to twitter:
    client.println("GET /1/statuses/user_timeline.xml?screen_name=RandyMcTester&count=1 HTTP/1.1");
    client.println("HOST: api.twitter.com");
    client.println();
    digitalWrite(led, HIGH);
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
}   




Logged

Pages: [1]   Go Up
Jump to: