Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mkr Zero Battery-Powered RGB LED Strip with Button Control and Sound Feedback

View and Edit Project In Cirkit DesignerImage of Arduino Mkr Zero Battery-Powered RGB LED Strip with Button Control and Sound Feedback

Circuit Documentation

Summary

This circuit consists of an Arduino Mkr Zero microcontroller, a WS2812 RGB LED strip, a black momentary switch, a piezo speaker, and a 3.7V battery. The circuit is designed to control the LED strip and the piezo speaker based on the state of the momentary switch. When the switch is pressed, the LED strip toggles between on and off states, and the piezo speaker emits different tones.

Component List

  1. Arduino Mkr Zero

    • Description: A microcontroller board based on the SAMD21 microcontroller.
    • Pins: 5V, Vin, VCC, GND, Reset, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, A6, A5, A4, A3, A2, A1, A0, AREF
  2. WS2812 RGB LED strip

    • Description: An addressable RGB LED strip.
    • Pins: DIN, 5V, GND, DO
  3. Black momentary switch 32 mm

    • Description: A momentary push button switch.
    • Pins: In, Out
  4. Piezo Speaker

    • Description: A piezoelectric speaker.
    • Pins: pin1, pin2
  5. 3.7V battery

    • Description: A rechargeable lithium-ion battery.
    • Pins: +, -

Wiring Details

Arduino Mkr Zero

WS2812 RGB LED strip

Black momentary switch 32 mm

Piezo Speaker

3.7V battery

Code Documentation

Arduino Code

#include <Adafruit_NeoPixel.h>

#define LED_PIN 6
#define BUTTON_PIN 7
#define SPEAKER_PIN 8
#define NUM_LEDS 30 // Adjust based on your LED strip length

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

bool ledState = false;
bool lastButtonState = LOW;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(SPEAKER_PIN, OUTPUT);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  bool buttonState = digitalRead(BUTTON_PIN);

  if (buttonState == LOW && lastButtonState == HIGH) {
    ledState = !ledState;
    if (ledState) {
      strip.fill(strip.Color(255, 0, 0), 0, NUM_LEDS); // Turn on LEDs (red color)
      strip.show();
      tone(SPEAKER_PIN, 1000, 200); // Play a tone for 200ms
    } else {
      strip.clear();
      strip.show();
      tone(SPEAKER_PIN, 500, 200); // Play a different tone for 200ms
    }
  }

  lastButtonState = buttonState;
}

This code initializes the WS2812 RGB LED strip and sets up the button and speaker pins. In the main loop, it checks the state of the button. When the button is pressed, it toggles the state of the LED strip and plays a tone on the speaker.