Arduino project
Schematic (Below):
|
We only had a Digital Input and Output: The PBNO(input) and the RGB LED (output)
When the PBNO is pressed the colour is supposed to change form blue to red Here is our Code (bold): const int RED_PIN = 9; //declare the pin of each colour input// const int GREEN_PIN = 10; //declare the pin of each colour input// const int BLUE_PIN = 11; //declare the pin of each colour input// const int PBNO = 2; //declare the pin of the PBNO// int buttonState = 0; void setup () { pinMode(RED_PIN, OUTPUT); //declare the colours as outputs// pinMode(GREEN_PIN, OUTPUT); //declare the colours as outputs// pinMode(BLUE_PIN, OUTPUT); //declare the colours as outputs// pinMode(PBNO, INPUT); //declare the PBNO as an input// } void loop() //never ends// { buttonState = digitalRead(PBNO); if (buttonState == LOW) { digitalWrite(BLUE_PIN, HIGH); //the blue colour will show first// digitalWrite(RED_PIN, LOW); //this colour will not show once connected with code// digitalWrite(GREEN_PIN, LOW); //this colour will not show once connected with code// } else { digitalWrite(BLUE_PIN, LOW); //this colour will not show once the PBNO is pressed// digitalWrite(RED_PIN, HIGH); //the red colour will show second once the PBNO is pressed// digitalWrite(GREEN_PIN, LOW); //this colour will not show once the PBNO is pressed// } } CREDIT TO: http://arduino.cc/en/Tutorial/Button?action=sourceblock&num=1 Troubleshooting Guide: -Make sure the RGB LED's 4 metal wires are in the correct order and place (matching up with the appropriate colours). -Make sure the Jumper Wires are connecting from the right PIN/source, and connects to the correct place on the Arduino Breadboard. -Make sure the PBNO is inserted in the correct way; if it doesn't work flip it 180 degrees and try again. -Make sure the colours of the light source are in the correct pin and connects correctly with the RGB LED. -Make sure the resistors and the GND Jumper Wire is lined up correctly when close to the LED. Instructions: -Connect two jumper wires to 5V and GND on the power side, then you connect the 5V to the positive and the GND to the negative on the bottom right side. - Next, you will connect to jumper wire to the PBNO. The wire will be connected to pin 2 and h1. - Next, you connect the jumper wires to the RGB LED. The red wire should be on pin 9 connected to j8, green on 10 connected to j10, and blue on 11 connected to j11. - You need to connect the wire to the LED with three resistors. The red resistor should be on i8 and e8. The green resistor should be on i10 and e10. The blue resistor should be on i11 and e11. -There should be a jumper wire connect to a e9 and a negative. - The placement of the LED has to be perfect if you miss place it, it wont work. The red metal wire has to be on b8, the GND metal wire has to be on b9, the green metal wire has to be on b10, and the blue metal wire has to be on b11. -You need to add one more resistor for the PBNO on i1 and a positive. - You also need to add on more jumper wire for the PBNO connected to g3 and a negative. -The PBNO should be placed in c1, c3, f1, and f3. |