** Instructions
** An Arduino
** All Jumper cables
** Breadboard
** 3 Leds
** 1 Resistor
** A Light Dependent Resistor (LDR)
** The paper lamp cover
** Stickers
** Arduino Code ( Which I typed out and made it super simple for you to copy and paste in the sketchbook.)
Breadboard |
Resistors/LEDS/ jumpers |
My DIY Power supply now up and running. Check BLOG for Step by Step build. |
Gather materials and place LED's onto the breadboard. The longer leg (of the led's facing towards you.
(Diode and LED Polarity. Diodes only allow current to flow in one direction, and they're always polarized. A diode has two terminals. The positive side is called the anode, and the negative one is called the cathode.
STEP 2: Placing the Resistors
Now take your resistor and LDR and connect those to the breadboard as shown. ** Make sure
that the two get connected on the same rail as shown in the picture.
Step 3: Connecting the LEDS/ Resistors
Now we will begin by taking the 3 mini jumpers and connecting the led's. We do this by attaching the cathodes of the leds to the negative rail (blue) on the breadboard. Once they are all connected and you sit back and admire your progress then we move on.
As with connecting the cathodes (-) we must also connect the anodes(+). We do this by attaching the wires to the respected leds making sure we don't connect to the same rails. As you can see from the photos the breadboard is now coming alive.
The resistors also need to be connected to the breadboard as well. Run a jumper wire like I have from one end of the resistor and connect it to the 5v rail (red). Next you need to complete the circuit by now attaching the free end of the LDR to the ground rail on the breadboard (blue)
after this has all been arranged you now have finished the trickiest part. Looks amazing doesn't it. Next step is setting up the arduino on your laptop or pc.
Step 4: Connecting to the Arduino
Step 5: Hooking up the Arduino and Code

So once in the sketch window all you now need to do is copy the following code and place it in a blank sketch. Click upload and bammm you should be up and running.
*******CODE:
int pulseSpeed = 5; // how fast lamp runs
int ldrPin = 0; // LDR in Analog input 0
int redLed = 11; // red led in digital pin 11
int greenLed = 10; // green led in digital pin 10
int blueLed = 9; // blue LED in digital pin9
int ambientLight; // stores the value of the light in the room
int power = 150; // brightness 2-255
float RGB[3]; // this is an array
float CommonMathVariable = 180/PI;
void setup () {
pinMode(redLed,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(blueLed,OUTPUT);
digitalWrite (redLed,LOW);
digitalWrite (greenLed,LOW);
digitalWrite (blueLed,LOW);
// this sets all the outputs to off
}
void loop (){
for (float x = 0; x < PI; x = x + 0.00001){
RGB[0] = power * abs(sin(x * (CommonMathVariable)));
// Red
RGB[1] = power * abs(sin((x + PI/3) * (CommonMathVariable)));
// green
RGB[2] = power * abs(sin((x + (2 * PI)/3)*(CommonMathVariable)));
ambientLight = analogRead(ldrPin);
// reads light and stores
if (ambientLight > 600) {
// makes the light only turn on if dark
analogWrite (redLed,RGB[0]);
analogWrite (greenLed,RGB[1]);
analogWrite (blueLed,RGB[2]);
}
else {
digitalWrite (redLed,LOW);
digitalWrite (greenLed,LOW);
digitalWrite (blueLed,LOW);
}
for (int i = 0; i < 3; i++) {
if (RGB[i] < 1) {
delay (20 * pulseSpeed);
}
else if (RGB[i] < 5) {
delay (10 * pulseSpeed);
}
else if (RGB[i] < 10) {
delay (2 * pulseSpeed);
}
else if (RGB[1] < 100){
delay (1 * pulseSpeed);
}
else {}
}
delay(1);
}
}
Finished:
Check back soon for next months build.
}
Finished:
No comments:
Post a Comment