Show Posts
Pages: 1 2 [3] 4 5 ... 10
31  Using Arduino / Programming Questions / reading SPST button on: March 09, 2013, 11:31:58 am
Hello,

I have this button from radioshack: http://www.radioshack.com/product/index.jsp?productId=2909787&locale=en_US

I want the LED to always be on, am powering it through the arduino.

I have it turning on a 5V relay (https://www.sparkfun.com/products/11042) and doing PWM on a separately powered LED array through a TIP120.

So you press the button,  relay goes on, a speaker makes some noise, a for() { conditional runs x amount of times (for say, 10 minutes) to make some LEDs fade in and out.

This is working just fine, just one problem.
If the button is pressed once, the relay turns on, lights are on, etc, all for 10 minutes as the LEDs do PWM in the for conditional.
Problem is, if the button is pressed again, one time, three times, five times, during the PWM in the for conditional, the whole program will start again because the button state will be different from before (this doesn't happen if the button is pressed an even amount of times making the button state the same as before)

So my question is, is how can I make it so no matter how many times someone presses the button while the lights are doing PWM the program will stop after running once? Here is my code:

Code:
//BUTTON CONFIG:
//1 - 5v in arduino (red)
//2 - 10k pull up resistor and to PIN 2 (orange)
//3 - GND (brown)

int speaker = 13;
int relay = 12;
int led = 10;
int button = 2;

int buttonState = 0;
int lastButtonState = 0;

int brightness = 0;
int fadeAmount = 3;

int debouncer = 0;

void setup() {
  Serial.begin(9600);
  pinMode(button, INPUT);
  pinMode(speaker, OUTPUT);
  pinMode(relay, OUTPUT);
  pinMode(led, OUTPUT);
}

void loop() {
 
buttonState = digitalRead(button);
 
if (buttonState != lastButtonState) {
  delay(50);
  debouncer = 1;
}

if (debouncer == 1) {
  tone(speaker, 500, 1000);
  tone(speaker, 500, 500);
  delay(500);
  digitalWrite(relay, HIGH);

//write a loop that fades an array of 12V LEDs on tip120s for 15 min
//and meanwhile the button is deactivated

for (int i = 0; i<33; i++){ //was 33 for 10 sec...30k is 15min
  analogWrite(led, brightness);
  brightness = brightness + fadeAmount;
 
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount;
  }
  delay(30);
}
//turn off relay and wait for another push
  digitalWrite(relay, LOW);
  digitalWrite(led, LOW);
  debouncer = 0;
}

else {
debouncer = 0;
}

lastButtonState = buttonState;

}
32  Using Arduino / General Electronics / Re: help reading diagram for button on: February 27, 2013, 11:41:05 am
ah good idea hahaha. i'm so dumb. already fried a chip before using multimeter...but yeah it's working fine with multimeter.
so i think what the problem is, is that when the button is HIGH it's giving 12V to the arduino pin....how can i not do this?
33  Using Arduino / General Electronics / help reading diagram for button on: February 27, 2013, 11:32:20 am
hello,

i found this button in a drawer and it fits perfectly in the hole I want to install it in...I think I got it at RadioShack years ago. I googled it and all I found was this diagram:

http://www.sci.com.tw/PRODUCTS/AUTO%20ACCESSORIES/(R13)%20Car%20Switch/(A3)%20PUSH/R13-553.html

I can't really make sense of it. Right now I have pin 3 (LED pin) through a 1k resistor and in ground, pin 2 to the arduino and pin 1 in 12V. The arduino also shares the 12V ground.

The arduino isn't recognizing the button. i want the LED in the button to stay on all the time which it is now, but no pin reading. Any idea how I could rig this up to work with an arduino? i'm so bad at switches...

Thanks for any help!
34  Using Arduino / General Electronics / Re: anyone use these super strong LEDs? on: January 31, 2013, 03:49:20 pm
thanks so much everyone for all the responses! looks like i've got some stuff to learn!
35  Using Arduino / General Electronics / anyone use these super strong LEDs? on: January 31, 2013, 11:31:16 am
Hello,

A photographer friend gave me a few of these:
http://www.ebay.com/itm/1pcs-10W-Round-Base-LED-Cool-White-High-Power-800LM-LED-Lamp-Chip-DC-9-12V-EM-28-/140888002499?_trksid=p5197.m1992&_trkparms=aid%3D111000%26algo%3DREC.CURRENT%26ao%3D1%26asc%3D14%26meid%3D5203636072474398295%26pid%3D100015%26prg%3D1006%26rk%3D1%26sd%3D140888002499%26

I am having a hard time figuring out what the forward current would be so I can't figure out what size resistor to use.

Also...do you think it would be okay to control these through an arduino and a TIP120? so i'd have the LED cathode grounding controlled through the TIP 120, the anode would have a resistor on it, going into 12v as well as the tip120 would have a 1k resistor going to arduino pin

anyone know much about these? the info on instructables i've found didn't seem to be exactly what I wanted...
and also...anyone know where to get good heatsinks for them?
thanks for any help!
36  Using Arduino / General Electronics / Re: timing and decoupling on: October 12, 2012, 12:18:44 pm
yeah oddly enough the startup code was the only thing I had to adjust by 2 seconds and then everything worked better than ever. I have no idea why that is. Anyone have any ideas?
37  Using Arduino / General Electronics / Re: timing and decoupling on: October 12, 2012, 10:21:40 am
hey thanks for all the replies. ok so i fixed the timing...but i don't understand why it works. basically the startup time changed by 2 seconds after I put in the decoupling capacitors. in the startup() i had a delay of 5500 to allow a digital video frame to boot up....now i changed that 5500 to 3500 and everything is rock solid.

but i'm timing this all based on how the atmega circuit is in sync with a digital video frame. it's very cold in my studio now...could the cold have anything to do with startup time? maybe it was the video frame that started up faster and the arduino was actually the same the whole time? unlikely i know....but just thought i'd ask. anyway...everything seems to be running very smoothly now. here is a terrible fritzing of my circuit...i still haven't got down the schematics view section of fritzing:

http://www.jeremycouillard.com/circuit2.jpg

2 of the .1 caps next to the motors are actually soldered onto the body of the motor. i got that idea from here: http://www.pololu.com/docs/0J15/9
38  Using Arduino / General Electronics / timing and decoupling on: October 12, 2012, 08:58:05 am
hello,

i think i just successfully decoupled my first circuit but am still trying to wrap my head around the whole thing. I put a 47uf polarized cap on the + and - rails and some .1uf caps on the atmega328p and 3 .1uf caps each on two DC motors. Everything seems to be working great except the timing of everything is a little bit off from how it originally was. (I know there are still a few more things I could do to decouple it better as well and I might do those things later)

So my question is...will the off timing be consistent? So I can just adjust the code accordingly? My loop probably takes about half a second longer now or so it seems. Or would it be less predictable? I assume it's because of the 47uf cap on the power rails...it's taking a bit of time to charge/decharge. Would the .1uf caps also need to be considered?

Thanks for any advice
39  Using Arduino / General Electronics / Re: circuit dying or acting bizarre on: October 10, 2012, 06:17:42 pm
i really am trying to understand this decoupling thing. i've read and reread grumpy mike's tutorial. i don't have any inductors laying around to try out but do you think it'd be enough to decouple a couple motors with a .1uf and a 47uf capacitor?

am i doing this correctly? it feels wrong:

http://jeremycouillard.com/decouple_breadboard.jpg

is that motor decoupled? i'm just putting a couple caps in its path on the way to power?

thanks so much for the replies. i ordered a 5A psu so hopefully that will help also.
40  Using Arduino / General Electronics / Re: circuit dying or acting bizarre on: October 09, 2012, 09:10:44 pm
the 7805 has two capacitors on it and that's the only power to the IC. also the atmega has the capacitors on the crystal pins. is that sufficient? the 12v that goes to the motors and LED power wouldn't need to be decoupled, correct? or should i put a big capacitor on the motors? i've looked at grumpy mikes de-coupling page but it's really hard for me to understand everything totally i think....what is a choke or inductor? just a resistor? what size resistor would you know to use? would i do something like he shows at the bottom of his tutorial? http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

do you think decoupling or more amperage is the main problem? i will try both anyway once i wrap my head around how to decouple this circuit....

thanks so much for all the replies!
41  Using Arduino / General Electronics / Re: circuit dying or acting bizarre on: October 09, 2012, 07:33:41 pm
man...i so with i knew how to do both those things but unfortunately i don't know how to get amperage readings off my multimeter and i'm still trying to learn the schematic part in fritzing. might take another couple days. i was thinking this was an amperage issue also. i can hopefully find another wall wart with more amperage. but 1.7 already seems like more than enough to run 6 LEDs, some transistors, 2 relays and an IC, no?

also now i am noticing it's mostly the timing that is off. this program i wrote is a very time specific thing (timed to be in sync to a video) and currently the circuit has been running for awhile but the timing is changing a lot. could this mean something is off with the crystal?
42  Using Arduino / General Electronics / circuit dying or acting bizarre on: October 09, 2012, 07:03:36 pm
hello,

i just learned fritzing so here is a poor attempt to show you the circuit i am working with. i hope you get the idea:

http://www.jeremycouillard.com/circuit.jpg (it's actually an atmega 328p but the pin config is the same)

the relays are not the ones i have but they are an spst relay that is turning the motors on and off and a dpdt relay that is reversing the polarity. the spst is 5v, powered by the arduino with a nominal current of 20mA. there is a diode across the coils. the dpdt is 12v and controlled through a tip120 transistor (with a diode). everything is powered through a 12v 1.7amp wall wort.

the leds are 12v, huge things and also are being powered separately and controlled through tip120s. the leds have a forward voltage of 3.5.

the code, pasted below, is very very simple. just starts the motors in one polarity, stops them, blinks some lights, then starts them again in a different polarity.
The problem is as follows: The program starts up and everything runs fine for about 2-3 cycles and then it either 1) just stops or 2) the relays and lights start turning on and off in a continuous loop...about 2 seconds on, two off. it is very strange....i've never had a circuit do something that wasn't in the code. Is there anything in my circuit that is suspect? any help/guidance would be so so appreciated!!!


Code:
void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(5, OUTPUT);
  digitalWrite(13, LOW);
  digitalWrite(13,LOW);
  delay(5500);
}

void loop() {

 
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  delay(35000);
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);

  //light show needs to be 11 seconds exactly
  //22 loops
////////////////////////////////////////////////
  for (int i = 0; i<22;i++){
    digitalWrite (11, HIGH);
    delay(100);
    digitalWrite(10, HIGH);
    delay(100);
    digitalWrite(5, HIGH);
    delay(100);
    digitalWrite(11, LOW);
    delay(100);
    digitalWrite(10, LOW);
    delay(100);
    digitalWrite(5, LOW);
  }
///////////////////////////////////////////////

  //delay(11000);

  digitalWrite(13, LOW);
  digitalWrite(12, HIGH);
  delay(36000);
  digitalWrite(13,LOW);
  digitalWrite(12,LOW);
  delay(2000);



}



43  Using Arduino / General Electronics / Re: strange diode reading with 5v relay on: October 06, 2012, 05:13:00 pm
thanks so much for the responses...but do you have any idea why this could be happening? or any other trouble shooting approaches? i've tried different relays, different diodes...it's just any time the diode is connected to the relay on both ends it stops working...if i just have the anode connected to he coil, it works...if just the cathode is connected...it works...but as soon as both are connected...it stops working...but in the same breadboarded circuit..no problems.
44  Using Arduino / General Electronics / Re: strange diode reading with 5v relay on: October 06, 2012, 05:09:38 pm
oh shoot...i was looking at it wrong. the diode stops working on the side of the relay that goes to the arduino. is there an order of the pins? like relay pin connects to diode, diode to arduino? or some other order?
45  Using Arduino / General Electronics / Re: strange diode reading with 5v relay on: October 06, 2012, 05:02:59 pm
so all my grounds are connected....do you have any idea why the coil is shorting out the diode in one circuit and not the other?
Pages: 1 2 [3] 4 5 ... 10