Kontrol Led Strip Rgb Neopixel Dengan Arduino Lengkap

9:29 AM

 

Kontrol Led Strip Rgb Neopixel Dengan Arduino

Pasti kalian sering melihat led strip dipinggir pinggri jalan atau pada dekorasi ruangan, nah untuk merubah warna dari atau kombinasi gerakan warna led diatur oleh sebuah kontroler, kali ini akan dijelaskan bagaimana cara mengontrol led tersebut dengan menggunakan arduino, penasaran kan, yuk simak penjelasan berikut ini

Pada led rgb neopixel terdapat 3 buah pin yang tersedia yakni pin +5V, pin Din dan pin GND, nah ketiga pin itulah yang gunanya untuk mengatur warna dari led tersebut, pin titu dihubungkan ke kontroller, kali ini menggunakan arduino sebagai kontrollernya, untuk komponen yang erlu kalian siapkan yaitu :

  • Arduino
  • Led rgb neopixel
  • Kabel secukupnya untuk menyambung dari pin led ke arduino
  • Elco 1000 uF
  • Resistor 470 / 330 ohm
  • Jack socket untuk power Led

Untuk rangkaiannya dapat dilihat pada gambar dibawah ini

Kontrol Led Strip Rgb Neopixel Dengan Arduino Lengkap

Keterangan :

  • Pin +5V pada led strip hubungkan ke pin + pada jack power
  • Pin GND led strip hubungkan ke pin – pada jack power
  • Kaki kutub – pada elco hubungkan ke pin – jack power
  • Kaki kutub + elco hubungkan ke pin + pada jack power
  • Pin Din pada led strip hubungkan ke resistor 470 atau 330 ohm kemudian kaki resistor lainnya hubungkan ke pin d2 pada arduino
  • Setelah semua tersambung selanjutnya mengupload program ke arduino
  • Buka arduino ide kalian dan hubungkan board arduino ke laptop atau komputer
  • Setting port yang terhubung dibagain menu tools >port
  • Setting juga board arduino yang kalian pakai di menu tools > board
  • instal library adafruit neopixel dnegan cara ke menu tools > manage libraries dan cari pada kotak pencarian dengan nama neopixel seperti gambar dibawah ini dan instal

  • Copy program dibawah ini dan paste ke project arduino ide kalian
[program]

// NeoPixel test program showing use of the WHITE channel for RGBW
// pixels only (won't look correct on regular RGB NeoPixel strips).

#include 
#ifdef __AVR__
 #include  // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN     6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT  60

// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255)

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

void setup() {
  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(BRIGHTNESS);
}

void loop() {
  // Fill along the length of the strip in various colors...
  colorWipe(strip.Color(255,   0,   0)     , 50); // Red
  colorWipe(strip.Color(  0, 255,   0)     , 50); // Green
  colorWipe(strip.Color(  0,   0, 255)     , 50); // Blue
  colorWipe(strip.Color(  0,   0,   0, 255), 50); // True white (not RGB white)

  whiteOverRainbow(75, 5);

  pulseWhite(5);

  rainbowFade2White(3, 3, 1);
}

// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
  for(int i=0; i= strip.numPixels()) whiteLength = strip.numPixels() - 1;

  int      head          = whiteLength - 1;
  int      tail          = 0;
  int      loops         = 3;
  int      loopNum       = 0;
  uint32_t lastTime      = millis();
  uint32_t firstPixelHue = 0;

  for(;;) { // Repeat forever (or until a 'break' or 'return')
    for(int i=0; i= tail) && (i <= head)) ||      //  If between head & tail...
         ((tail > head) && ((i >= tail) || (i <= head)))) {
        strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
      } else {                                             // else set rainbow
        int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
        strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
      }
    }

    strip.show(); // Update strip with new contents
    // There's no delay here, it just runs full-tilt until the timer and
    // counter combination below runs out.

    firstPixelHue += 40; // Advance just a little along the color wheel

    if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
      if(++head >= strip.numPixels()) {      // Advance head, wrap around
        head = 0;
        if(++loopNum >= loops) return;
      }
      if(++tail >= strip.numPixels()) {      // Advance tail, wrap around
        tail = 0;
      }
      lastTime = millis();                   // Save time of last movement
    }
  }
}

void pulseWhite(uint8_t wait) {
  for(int j=0; j<256 0="" 255="" at="" brightness="" delay="" entire="" fill="" for="" from="" gamma-corrected="" int="" j="" level="" ramp="" strip.color="" strip.fill="" strip.gamma8="" strip.show="" strip="" to="" up="" wait="" white="" with="">=0; j--) { // Ramp down from 255 to 0
    strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
    strip.show();
    delay(wait);
  }
}

void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
  int fadeVal=0, fadeMax=100;

  // Hue of first pixel runs 'rainbowLoops' complete loops through the color
  // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to rainbowLoops*65536, using steps of 256 so we
  // advance around the wheel at a decent clip.
  for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
    firstPixelHue += 256) {

    for(int i=0; i= ((rainbowLoops-1) * 65536)) { // Last loop,
      if(fadeVal > 0) fadeVal--;                             // fade out
    } else {
      fadeVal = fadeMax; // Interim loop, make sure fade is at max
    }
  }

  for(int k=0; k=0; j--) { // Ramp down 255 to 0
      strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
      strip.show();
    }
  }

  delay(500); // Pause 1/2 second
}

  • Upload program dengan klik icon centang pada pojok kiri atas arduino ide
  • Hubungkan socket jack ke adaptor 5v jika kalian menggunakan led strip 5v

Itulah bagaimana cara mengontrol led strip neopixel menggunakan arduino

 

 

Next Article
« Prev Post
Previous Article
Next Post »
Disqus
Tambahkan komentar Anda

No comments