January 11, 2015

Driving a LED strip with Arduino




Do you know those cheap LED strips?

These are often called "analog" LED strips because you cannot control each pixel individually like you do with "digital" strips.


Today we want to drive them using our Arduino board.



Hardware

  • Arduino Board
  • MOSFET
  • White LED strip

As MOSFET i have used I have used the IRF520 that comes with the Arduino starter kit but you can use any general purpose MOSFET (for example the popular STP16NF06).

Schematic









Code


#define PIN 11      // control pin
#define DELAY 10    // 20ms internal delay; increase for slower fades

void setup() {
  pinMode(PIN, OUTPUT);
}

void loop() {
  // fade in
  for(int i=0; i<255; i++) {
    analogWrite(PIN, i);
    delay(DELAY);
  }

  // fade out
  for(int i=0; i<255; i++) {
    analogWrite(PIN, 255-i);
    delay(DELAY);
  }
}

This is the code if you prefer a "strobo effect".

#define PIN 11      // control pin
#define DELAY 20    // 20ms internal delay; increase for slower pulse

void setup() {
  pinMode(PIN, OUTPUT);
}

void loop() {
  digitalWrite(PIN, HIGH);  // turn on
  delay(DELAY);             // wait few milliseconds
  digitalWrite(PIN, LOW);   // turn off
  delay(DELAY*10);          // wait some more time
}


References


Dimming a 12V LED Strip With an Arduino
RGB LED Strips
RGB Led Strip Controlled by an Arduino


9 comments:

  1. Thank you for posting such a great article! I found your website perfect for my needs. It contains wonderful and helpful posts. Keep up the good work!
    RGB LED STRIP

    ReplyDelete
  2. can it be done without a mosfet?

    ReplyDelete
    Replies
    1. Works well, even with a 12V white LED strip. Thank you

      Delete
    2. Hi, yes it is perfect .....but I need help please, with code settup...
      My idea is 12 hours LED light OFF and after 12 hours LED light ON, if is possible? please.
      Thank u. Ondrej

      Delete
  3. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us


    LED robots party service

    ReplyDelete
  4. I appreciate you for this blog post really good. Thank for sharing information.
    As you want Programmable LED Controller then contact our manufacturer who give you bet products............................................................... Read More

    ReplyDelete
  5. Magnificent beat ! I wish to apprentice while you amend your site, how could i subscribe for a blog site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear concept beta afp browser

    ReplyDelete
  6. Wonderful Post. This is a very helpful post. These are the useful tips for Solar Garden Lights.Good and useful information. Thanks for sharing the blog.

    ReplyDelete

Note: Only a member of this blog may post a comment.