Introduction: Arduino Led Controller
I wanted to make a box to control my led strips. I wanted it to be a hands on experiencie. So no apps!
Supplies
- 3x - 10kΩ potmeter Standaard
- 1x - Mean Well Power Supply - 5V 10A - Switching Power Supply - LRS-50-5
- 1x - 3 Way Switch On-Off-On - MTS-103
- 3x - WS2813 Digitale 5050 RGB LED Strip - 30 LEDs 1m
- 3x - Button 16mm - On-Off
- 1x - Arduino Uno
- 3x - 10kΩ Resistor
- Soldering Iron & Solder
- Case
Step 1: Schematic
I had three led strips I wanted to control. So I chose to have 3 buttons to put them on or off separately, 3 pot meters to change the colours (hue value). One echo sensor so you can change the amount of LEDs lit.
I also have a three way switch. I decided I wanted 3 modes on that switch.
1. Off
2. Fully controllable with the potentiometers and buttons
3. Static colour where the controls where bypassed.
Step 2: Soldering
The first things I soldered where the potentiometers than the buttons and the three-way switch and at last the echo sensor. After that, I built in the power supply and my Arduino.
I used a separate power supply even though my led strips where 5v. I had a total of 90 LEDs "pixels" that means I had to power 90 x 3 = 270 led. This used way more ampere than the Arduino could give it.
Step 3: Coding
//library
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include
//led strips #define NUM_LEDS_PER_STRIP 31
#define LED_TYPE WS2813 #define COLOR_ORDER GRB CRGB eenLeds[NUM_LEDS_PER_STRIP]; CRGB tweeLeds[NUM_LEDS_PER_STRIP]; CRGB drieLeds[NUM_LEDS_PER_STRIP];
//echo sensor const int TRIG_PIN = 12; const int ECHO_PIN = 13; const unsigned int MAX_DIST = 2900;
void setup() { Serial.begin(9600);
//echo sensor // The Trigger pin will tell the sensor to range find pinMode(TRIG_PIN, OUTPUT); digitalWrite(TRIG_PIN, LOW);
// fastled FastLED.addLeds(eenLeds, NUM_LEDS_PER_STRIP); FastLED.addLeds(tweeLeds, NUM_LEDS_PER_STRIP); FastLED.addLeds(drieLeds, NUM_LEDS_PER_STRIP);
//pot pinMode(A0, INPUT); pinMode(A1, INPUT); pinMode(A3, INPUT);
//three way switch pinMode (10, INPUT); pinMode (11, INPUT);
//buttons pinMode (7, INPUT); pinMode (8, INPUT); pinMode (9, INPUT); }
int echosensor() {
unsigned long t1; unsigned long t2; unsigned long pulse_width; float cm; float inches;
// Hold the trigger pin high for at least 10 us digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW);
// Wait for pulse on echo pin while ( digitalRead(ECHO_PIN) == 0 );
// Measure how long the echo pin was held high (pulse width) // Note: the micros() counter will overflow after ~70 min t1 = micros(); while ( digitalRead(ECHO_PIN) == 1); t2 = micros(); pulse_width = t2 - t1;
// Print out results // if ( pulse_width > MAX_DIST ) { // Serial.println("Out of range"); // } else { // Serial.println(pulse_width); // }
// Wait at least 60ms before next measurement delay(60);
int echovalue = map(pulse_width, 200, 1500, 0, NUM_LEDS_PER_STRIP);
// Print out results if ( pulse_width > MAX_DIST || echovalue > 31 ) { return 31; } else { return echovalue; }
}
void loop() {
echosensor();
//three way switch int switchState2 = digitalRead(10); int switchState3 = digitalRead(11);
//functies en iff if (switchState2 == 1) { FastLED.clear (); } else if (switchState2 == 0 && switchState3 == 0) { fill_rainbow( &(eenLeds[0]), 30, 1); fill_rainbow( &(tweeLeds[0]), 30, 1); fill_rainbow( &(drieLeds[0]), 30, 1); } else if (switchState2 == 0 && switchState3 == 1) { ledsControl(); }
FastLED.show(); delay(30);
}
int ledsControl() {
int NumbersOfLeds = echosensor(); Serial.println(NumbersOfLeds);
//potHue1 int valuePotHue1 = analogRead(A1); int hue1 = map(valuePotHue1, 0, 1023, 0, 255);
//potHue2 int valuePotHue2 = analogRead(A0); int hue2 = map(valuePotHue2, 0, 1023, 0, 255);
//potHue3 int valuePotHue3 = analogRead(A2); int hue3 = map(valuePotHue3, 0, 1023, 0, 255);
FastLED.clear();
//button1 int buttonState1 = digitalRead(7);
if (buttonState1 == 1) { fill_solid( eenLeds, NUM_LEDS_PER_STRIP, CHSV(hue1, 255, 0)); } else if (buttonState1 == 0) { for (int led = 0; led < NumbersOfLeds; led++) { fill_solid( eenLeds, led, CHSV(hue1, 255, 155)); } }
//button2 int buttonState2 = digitalRead(8);
if (buttonState2 == 1) { fill_solid( tweeLeds, NUM_LEDS_PER_STRIP, CHSV(hue2, 255, 0)); } else if (buttonState2 == 0) { for (int led = 0; led < NumbersOfLeds; led++) { fill_solid( tweeLeds, led, CHSV(hue2, 255, 155)); } }
//button3 int buttonState3 = digitalRead(9);
if (buttonState3 == 1) { fill_solid( tweeLeds, NUM_LEDS_PER_STRIP, CHSV(hue3, 255, 0)); } else if (buttonState3 == 0) { for (int led = 0; led < NumbersOfLeds; led++) { fill_solid( drieLeds, led, CHSV(hue3, 255, 155)); } } }