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

Arduino-Controlled RGB LED Strip with Hall Effect Sensor and MOSFET Dimming

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled RGB LED Strip with Hall Effect Sensor and MOSFET Dimming

Circuit Documentation

Summary

The circuit in question is designed to control an RGB LED strip using an Arduino UNO microcontroller. It includes a Hall effect sensor for detecting magnetic fields, a power MOSFET for controlling high-current loads, a rectifier diode for protecting against reverse polarity, and an electrolytic capacitor for voltage smoothing. The circuit is powered by an external power supply and includes a resistor for current limiting or pull-up purposes.

Component List

Electrolytic Capacitor

1N4007 Rectifier Diode

WS2812 RGB LED Strip

Hall Sensor (Magnetic)

STP16NF06 N-Channel Power MOSFET

Arduino UNO

Power Supply

Resistor

Wiring Details

Electrolytic Capacitor

1N4007 Rectifier Diode

WS2812 RGB LED Strip

Hall Sensor (Magnetic)

STP16NF06 N-Channel Power MOSFET

Arduino UNO

Power Supply

Resistor

Documented Code

Arduino UNO Code (sketch.ino)

#include <Adafruit_NeoPixel.h>

#define SENSOR_PIN 2      // Sensor input pin (Reed Switch or Hall Effect Sensor)
#define LED_PIN 6         // LED strip control pin
#define MOSFET_PIN 9      // MOSFET control pin
#define NUM_LEDS 60       // Number of LEDs in the strip

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

volatile unsigned long lastDebounceTime = 0;
volatile unsigned int pulseCount = 0;
unsigned long previousMillis = 0;

void setup() {
  pinMode(SENSOR_PIN, INPUT_PULLUP);
  pinMode(MOSFET_PIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(SENSOR_PIN), countPulse, FALLING);

  strip.begin();
  strip.show();  // Initialize all pixels to 'off'
}

void loop() {
  unsigned long currentMillis = millis();
  
  // Calculate speed based on pulse count
  if (currentMillis - previousMillis >= 1000) {
    previousMillis = currentMillis;

    int speed = pulseCount;
    pulseCount = 0;

    // Map speed to brightness (0-255)
    int brightness = map(speed, 0, 50, 0, 255);
    brightness = constrain(brightness, 0, 255);
    
    // Control the brightness of the LEDs
    strip.setBrightness(brightness);
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(255, 0, 0));  // Set color to red (can be changed)
    }
    strip.show();

    // Control the MOSFET (if needed)
    analogWrite(MOSFET_PIN, brightness);
  }
}

void countPulse() {
  if ((millis() - lastDebounceTime) > 50) {  // Debounce
    pulseCount++;
    lastDebounceTime = millis();
  }
}

Note: The code provided for the microcontroller with instance ID b23d5d2a-02ba-4f89-99c2-8dda9a2b75b1 is empty and thus not included in the documentation.