Description:
For this challenge, we needed to design a night light using an RGB LED. As an extension to the challenge, we chose to add the ability to granularly select the hue of the LED; Three knobs control the Red, Green, and Blue values of the RGB LED. In addition, we have chosen to 3d print a chassis to hold the components and give structure to the light, while looking aesthetically pleasing.
Schematic:
Code:
/*
RGB Colour selector Nightlight
by Elvin and Oliver, created March 4, 2022
This program will read the values of three potentiometers,
and map those values to the R, G, and B channels of an RGB LED,
if the ambient light level is low enough
*/
void setup() {
Serial.begin(9600); //initialize serial for debugging
//analog inputs 0-3 receive the 3 pots and photoresistor value
pinMode (A0, INPUT);
pinMode (A1, INPUT);
pinMode (A2, INPUT);
pinMode (A3, INPUT);
// PWM outputs 9, 5, 6 go to R, G, B LED diodes
pinMode (9, OUTPUT);
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
}
// Values that will be assigned LED brightness output values
int redVal;
int grnVal;
int bluVal;
int lightVal;
//Nice names for LED output pins
const int redPin = 9;
const int grnPin = 5;
const int bluPin = 6;
//Nice names for pot/photoresistor input pins
byte photoPin = A3;
byte redInPin = A2;
byte grnInPin = A1;
byte bluInPin = A0;
void loop() { //Run forever:
//Set RGB output values as maps of the pots (value 0-1023), to the RGB LEDs (value 0-255)
redVal = map(analogRead(redInPin), 0, 1023, 0, 255);
grnVal = map(analogRead(grnInPin), 0, 1023, 0, 255);
bluVal = map(analogRead(bluInPin), 0, 1023, 0, 255);
//set the lightVal to the value of the photoresistor
lightVal = analogRead(photoPin);
//Print all the RGB values, and photoresistor value, for debugging
Serial.println(redVal);
Serial.print(" ");
Serial.print(grnVal);
Serial.print(" ");
Serial.print(bluVal);
Serial.print(" ");
Serial.print(lightVal);
Serial.print(" ");
if (lightVal <= 1000) { //If the light level is less than a set threshold,
analogWrite(redPin, redVal); //set the LEDs to their set values
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
} else { //Otherwise, turn them off
analogWrite(redPin, 0);
analogWrite(grnPin, 0);
analogWrite(bluPin, 0);
}
delay(10);
}
A Photo of the Circuit:
A Video of the Circuit, mounted in the case:
Reflection:
Partner 1:
I would say the easiest aspect of this challenge was making the paper box for the top of the night light, and the most difficult part for me was probably making sure everything was wired correctly and setting up the mess of jumpers. Throughout this challenge I learned that you could connect resistors between 2 jumpers and it will work fine. My goal for the next challenge is to make the wiring better.
Partner 2:
I think the easiest aspect of this challenge was coming up with a cool design to extend the scope of the project. Within 2 minutes of reading the challenge, we had decided on adding 3 potentiometers to manually control the light, and planned to print a housing for the electronics, to make the whole thing look more polished. The most difficult part of the project was working inside the very cramped interior of the housing we printed; we had to remove the majority of the breadboards involved to fit the electronics inside, and that resulted in a lot of less-than-robust connections. Multiple times while assembling the design, we accidentally disconnected some wire, and figuring out which one was, as you can guess from the above image, a nightmare. In this challenge, I learned more about how to 3d print things effectively and efficiently; How to make a design that doesn’t require support, how to minimize the amount of filament and time used for printing, and how to 3d model in an efficient way. My goals for the next challenge are to make another interesting and useful product, and to improve the wiring design for ease of assembly and debugging.
Comentarios