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


3 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. 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