RGB LED Controller Using ATtiny85

I got a LED strip with a piece a drawer set and the controller that came with it was dead on arrival.  Now, this was a probably $5 – $10 set of LEDs – but I was excited about them and figured this could be a fun project.  So I designed a LED controller with two knobs (color and brightness) and used only parts-bin parts.  The brightness control pot even has a switch so when turned fully counter-clockwise it turns cuts power entirely.  Note: I didn’t add the switch on the diagram.

Transistors are MPSA42 and MPSA13 but could be anything similar as long as they can carry at least a couple hundred ma.

9v DC booster is DFR Robot DFR0952 set to 9v

C1 – 0.1uF
C2 – 2.2uF

R1, R2, R3 – 510ohm
R4, R5, R6, R7 – 10k ohm

Diagram for ATtiny85 RGB LED controller, designed in DIYLC.

Diagram for ATtiny85 RGB LED controller, designed in DIYLC.

I did all of the coding in Arduino IDE.

int ledR = PB0; // Output ping for red LED pin 5
int ledG = PB1; // Output ping for green LED pin 6
int ledB = PB4; // Output ping for blue LED pin 3

int brightness = A3; // Input pin for brightness potentiometer
int color = A1; // Input pin for color change potentiometer

int colorVal = 0; // Store value of color potentiometer
int brightnessVal = 0; // Store value of brightness potentiometer

int red = 0; // Set default to off

int green = 0; // Set default to off

int blue = 0; // Set default to off

int brightnessOutput = 2; // Set default brightness to 2

void setup() {

// Set led pins to low before setting as output:
digitalWrite(ledR, LOW);
digitalWrite(ledG, LOW);
digitalWrite(ledB, LOW);

// Set led pins to be an output:
pinMode(ledR, OUTPUT);
pinMode(ledG, OUTPUT);
pinMode(ledB, OUTPUT);

// Set inputs as inputs
pinMode(color, INPUT);
pinMode(brightness, INPUT);
}

void loop() {

analogWrite(ledR, ((red * brightnessOutput) / 100) * 1); // Red brightness based on color, brightness, and calibration for white (1 = max full power)
analogWrite(ledG, ((green * brightnessOutput) / 100) * 1); // Green brightness based on color, brightness, and calibration for white (1 = max full power)
analogWrite(ledB, ((blue * brightnessOutput) / 100) * 1); // Blue brightness based on color, brightness, and calibration for white (1 = max full power)

colorVal = analogRead(color); // Read value of color change potentiometer
brightnessVal = analogRead(brightness); // Read value of brightness potentiometer

if (brightnessVal > 1000) { // Top of potentiometer, set to full brightness
brightnessOutput = 100;
} else if (brightnessVal > 25) {
brightnessOutput = brightnessVal / 10; // Calculate level of brightness
} else {
brightnessOutput = 2;
}

// Read colorVal and assign RGB values
if (colorVal > 910) { // Set to white (full RGB) if at top of potentiometer, total of 510 so things stay fairly even
red = 170;
green = 170;
blue = 170;

} else if (colorVal > 895) {
red = 85;
green = 85;
blue = 85;

} else if (colorVal > 750) {
red = 255;
green = 255 - ((colorVal - 750) * 1.7); //ramp green up from 0-255 in the 1000 to 750 zone
blue = 0;

} else if (colorVal > 600) {
red = (colorVal - 600) * 1.7; //ramp red down from 255-0 in the 750 to 600 zone - multiply by 1.7 to get range of 255
green = 255;
blue = 0;

} else if (colorVal > 450) {
red = 0;
green = 255;
blue = 255 - ((colorVal - 450) * 1.7); //ramp blue up from 0-255 in the 600 to 450 zone - multiply by 1.7 to get range of 255

} else if (colorVal > 300) {
red = 0;
green = (colorVal - 300) * 1.7; //ramp green down from 255-0 in the 450 to 300 zone - multiply by 1.7 to get range of 255
blue = 255;

} else if (colorVal > 150) {
red = 255 - ((colorVal - 150) * 1.7); //ramp red up from 0-255 in the 300 to 150 zone - multiply by 1.7 to get range of 255
green = 0;
blue = 255;

} else {
red = 255;
green = 0;
blue = colorVal * 1.7; //ramp blue down from 255-0 in the 150 to 0 zone - multiply by 1.7 to get range of 255
}

}

Posted in Circuits and Electronics, Hobbies, Projects | Leave a comment

Cool site for making custom gauge faces!

While thinking about a project making a custom clock using the automotive gauge stepper motor from Adafruit, I tripped across this site for making custom gauge faces – perfect!

This is my first attempt – pretty happy with it.

Posted in Circuits and Electronics, Ideas, Web/Internet | Comments Off on Cool site for making custom gauge faces!

Manually control servo with ATtiny85

If you find yourself wanting to control a servo with an ATtiny85, you will find very few libraries available.  Those that are available, I was unable to get to work properly for full 180 degree rotation of my SG92R servo.  Here is what I did that worked great:

int servoControlMaster = 2400; // SG92R uses 600 for 0 degrees, 2400 for 180 degrees, move in increments of 5
int servoControlRemain = 17600; // servoControlMaster + servoControlRemain must equal 20000 Microseconds

int servoChange = 30; // Change in microseconds
int servoChangeCalc = 20000-servoControlMaster; // calculate remainder of 20000 microseconds

void setup() {

}

void loop() {

// manually send position to servo
for(int i = 0; i<20; ++i) {
digitalWrite(2, HIGH);
delayMicroseconds(servoControlMaster);
digitalWrite(2, LOW);
delayMicroseconds(servoControlRemain);
}

delay (1000);

if (servoControlMaster > (600)) {
servoControlMaster = servoControlMaster-servoChange;
servoControlRemain = servoChangeCalc;
} else {
// reset to beginning position
servoControlMaster = 2400;
servoControlRemain = 17600;
}

}

Posted in Circuits and Electronics | Comments Off on Manually control servo with ATtiny85

Manjaro – Rebuild Chrome browser

Since Chrome won’t update properly in Manjaro, you need to rebuild it when there is a new version.  Thankfully, using yay makes this super easy.

yay -Sy google-chrome
 

Or if you want to do the same but with no bothersome questions asked in Terminal:

yay -Sy google-chrome --noconfirm

Posted in Computers and Hardware | Comments Off on Manjaro – Rebuild Chrome browser

Manjaro Linux Fails To Add Printer

If your printer fails to load in Manjaro Linux, use the old CUPS interface: http://localhost:631/admin

The username and password will be the same as the admin on the computer.

Posted in Computers and Hardware | Comments Off on Manjaro Linux Fails To Add Printer