Go Down

Topic: help with my first arduino project (Read 860 times) previous topic - next topic

alvinpenworth

Jun 22, 2011, 06:09 pm Last Edit: Jun 24, 2011, 04:57 pm by alvinpenworth Reason: 1
this is my first arduino project, it's my first electronics project, it's my first led project.  everything i know has been pieced together from forums and instructables, so bear with me please.  i'm determined to learn.

i am helping a friend with his sculpture project.  i have RGB led's that i want to put in one part of the sculpture, and have arcade-style buttons that viewers will be able to push to light up the led's.  three buttons, one for each color, so that a variety of colors can be created.

so let's say i've got 5 led's wired in parallel, with one button to trigger each RGB.  so when none of the buttons are pushed down, there are no lights.  i modified the code of the "button" example that comes with the arduino software to have three buttons instead of one.  

but it doesn't work.  sometimes lights will go on randomly, or when i hold down one button for more than a second all the lights will turn on.   does it look like there's a big problem with the code?  or have i wired it all wrong?  or is there a bigger problem that i don't even know about?

again i'm a beginner, any advice, or links to tutorials, or even a book i could read, would be helpful.  the code i am using is below:



Code: [Select]
// set pin numbers:
const int blackbuttonPin = 2;     // the number of the pushbutton pin
const int blueledPin =  13;      // the number of the LED pin
const int yellowbuttonPin = 3;
const int greenledPin = 12;
const int redbuttonPin = 4;
const int redledPin = 11;

// variables will change:
int blackbuttonState = 0;         // variable for reading the pushbutton status
int yellowbuttonState = 0;
int redbuttonState = 0;


void setup() {
 // initialize the LED pin as an output:
 pinMode(blueledPin, OUTPUT);      
 // initialize the pushbutton pin as an input:
 pinMode(blackbuttonPin, INPUT);    
 
 pinMode(yellowbuttonPin, INPUT);
 pinMode(redbuttonPin, INPUT);
 pinMode(redledPin, OUTPUT);
 pinMode(greenledPin, OUTPUT);
 
   }

void loop(){
 // read the state of the pushbutton value:
 blackbuttonState = digitalRead(blackbuttonPin);
 yellowbuttonState = digitalRead(yellowbuttonPin);
 redbuttonState = digitalRead(redbuttonPin);

 // check if the pushbutton is pressed.
 // if it is, the blackbuttonState is HIGH:
 if (blackbuttonState == HIGH) {    
   // turn LED on:    
   digitalWrite(blueledPin, HIGH);  
 }
 else {
   // turn LED off:
   digitalWrite(blueledPin, LOW);
 }
 
 if (yellowbuttonState == HIGH) {
   digitalWrite(greenledPin, HIGH);
 }
 else {
   digitalWrite(greenledPin, LOW);
 }
 if (redbuttonState == HIGH) {
   digitalWrite(redledPin, HIGH);
 }
 else {
   digitalWrite (redledPin, LOW);
 }
}

Grumpy_Mike

#1
Jun 22, 2011, 06:36 pm Last Edit: Jun 22, 2011, 06:43 pm by Grumpy_Mike Reason: 1
Welcome I hope it all works out.
First off go back and modify that code so it is in a box. Select modify the post. Select the code bit and hit the # icon, then save.

Quote
have i wired it all wrong?]have i wired it all wrong?

I suspect you have, especially if you follow instructables which are from what I have seen 90% wrong on LED projects.

Quote
so let's say i've got 5 led's wired in parallel,

That rings alarm bells, you can't just wire LEDs in parallel, and you make no mention of resistors, you need them.
Please post a schematic of how you have wired it up, we can look at the software when we know it is right.

focalist

#2
Jun 22, 2011, 06:38 pm Last Edit: Jun 22, 2011, 06:40 pm by focalist Reason: 1
Well, first, you are drawing far too much connecting those LED's to a pin directly. You need a transistor...

I usually avoid using pin 13 if I can, the oboard LED uses that, and can confuse things.



When the testing is complete there will be... cake.

alvinpenworth

ok thanks for the replies guys.  first of all, mike

Quote
Please post a schematic


is there freeware to download, or a website that makes drawing schematics easy?  i don't have any experience with this.  or do people generally just draw lines and triangles in photoshop for their schematics?

i have been using this website http://www.hebeiltd.com.cn/?p=zz.led.resistor.calculator to determine resistance.  plugging in 5V with a voltage drop of 1.9 and 20mA  (all figures i derived from stumbling around forums like this) the resistor calculator told me to use a 33 Ohm resistor.  the smallest i had on hand was 100 Ohm so I have been using that, having read that going too high with your resistor, though limiting brightness, is not harmful to the project.

focalist, could you explain this
Quote
You need a transistor...

because I don't know how or where to put a transistor in this project.

thanks again for the help.  i know i sound clueless but the dialogue helps me understand things better.


Grumpy_Mike

Anything from drawing in on paper and photographing it to a dedicated layout program like Eagle, just as long as we see the picture.

If you need a transistor wire it up like this but with a LED and resistor in place of the motor.
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

dumle29

#5
Jun 28, 2011, 03:36 pm Last Edit: Jun 29, 2011, 02:12 am by dumle29 Reason: 1
Why do you want to use an arduino for this?.

its not needed at all :)

you could do it like this:

http://snuletek.com/ting/Untitled%20Sketch%202_schem.png

made in fritzing

!!--EDIT--!!
!!--THE LINK NOW SHOWS ANOTHER PICTURE--!!

the first schematic was ugly (i was in a REAL hurry)

the schematics are made in a program called Fritzing. its awesome.

in this schematic i only used one RGB LED though

Go Up