Electronics Project 1
For this one you will be creating the same thing as Project 0, but you will use 1 button to control the light. Before using your electronics kit build a prototype in Tinkercad.
IMPORTANT: Work slowly and carefully so you do not break or lose anything in these kits! You will need everything in this kit for other projects.
NOTES: Except for the red, green, and blue lights the color of the wire doesn't matter much for this project. However, in the real world these colors do matter. Here is a chart of common wiring colors and their use.
Make sure before you start wiring the actual device you create your prototype in Tinkercad!
To start a project from scratch go to Tinker at the top of the page and select Circuits.
Step 1
Get the breadboard.
Insert a small switch with 2 pins in the middle channel. It doesn't matter what number row you put it in, but make sure there's enough room at the top to place other components.
Step 2
Get the RGB LED. It has 4 connectors on it. Red, Ground (GND), Green, and Blue.
The ground is the longest pin and is marked with a +
Place the LED into the breadboard in a similar position as shown below.
Step 3
Get three 220 (set to 22KΩ in Tinkercad) resistors, and one 10K resistor. Be careful removing them!!
Place a 220 resistor next to the connections for R,G, and B on the light. Make sure the pins aren’t touching each other. The other end of the resistor should plug in on the other side of the channel.
Skipping one slot, place a 10K resistor next to the switch to the + rail.
Step 4
Get the Arduino board from your kit.
Step 5
Go slowly on this step! Doing 1 wire at a time.
Get 2 short jump wires (the same color).
Place one from the RGB ground to the - rail position.
Place the other from the switch to the - rail position.
Step 6
Connect a different colored jump wire from the 5v connector on the Arduino board to the + rail on the breadboard.
Connect another ground jump wire (use the same color as the others) from the ground (GND) on the Arduino board to the - rail on the breadboard.
Step 7
Connect a new jump wire (white wire in pic) from pin 3 on the arduino board to the space in between the button terminal and the resistor.
Now connect jump wires to each of the 3 LED colors (Red, Green, and Blue). Use the same colored wire for each color on the light (Red LED connects with red wire, etc.)
Connect the Red jump wire to #9 on the arduino board. Connect the Green jump wire to #10, and the Blue to #11.
View from the other side.
At this point your wiring should be complete. To test it out get the USB plug from your kit and plug it into your computer. The lights on the Arduino board should come on. Your LED may also light up and begin cycling through the colors.
If you're getting power to the device then proceed to the next stop. If there appears to be no power call the teacher over for help.
Step 8
ARDUINO SOFTWARE
Open your Arduino software (install if not already installed) and paste the code below. (delete any code that’s already there)
Under Tools select Board and set it to “Arduino Mega or Mega 2560”
Under Tools select Port and set it to “Arduino Mega or Mega 2560”
Click the check mark to verify your code for errors. This will also create a log file of the errors, you can just cancel this. If there are errors in the code you will see them in the output window at the bottom. Can you fix the errors? If there are no errors you should see a couple lines of white text.
Once you’ve fixed all errors press the arrow to upload your code. If everything was done correctly you should be able to press the button and cycle through the the 3 colors.
TINKERCAD
Copy and paste the code from below into Code are of tinkercad.
const int buttonPin = 3;
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
int counter = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
int buttonState;
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
counter++;
delay(150);
}
else if (counter == 0) {
digitalWrite(red, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
else if (counter == 1) {
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
else if (counter == 2) {
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
}
else if (counter == 3) {
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
}
else {
counter = 0;
}
}