Go Down

Topic: USB device drawing too much power (beginner ques.) (Read 4130 times) previous topic - next topic

PeteAJ

Hi! New to Arduino and psyched. However..I've been trying to do simple 'use a pushbutton to a LED' but I get this message when I press the button

Because a USB device was drawing too much power from your computer, one or more of your USB devices have been disabled.
To prevent damaging your computer, the USB device drawing too much power has been disabled. Other devices may have also been disabled...

I'm using an iMac Mac OSX 10.6.4

I'd appreciate any advice. New to this..

Thanks

RuggedCircuits

It sounds like your pushbutton is connected to the wrong pins, perhaps between 5V and GND?

Where did you connect your pushbutton?

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

Jonathan Oxer

Sounds like you've connected it so that the button shorts out the power supply! Could you post details of how you've connected everything together? A sketch or a photo would make it much easier for people to help you.
--
Jon
Practical Arduino: www.practicalarduino.com

Jonathan Oxer

SNAP! We even used the same words and came to the same conclusion, only 3 seconds apart   ;-)

RuggedCircuits

Arduino Hive Mind?

--
The Quick Shield: breakout all 28 pins to quick-connect terminals


RuggedCircuits

Yup, definitely wrong wiring. Connect one side of the switch to GND. Connect the other side of the switch to pin 7 (red wire). Get rid of the resistor and other yellow wire (to 5V).

In your sketch, enable the pullup on pin 7:

Code: [Select]
void setup() {
pinMode(7, INPUT);
digitalWrite(7, HIGH);
}


Then, when the button is pushed, pin 7 will read LOW, else it will read HIGH.

--
Need a custom shield? Let us design and build one for you.

PeteAJ

Thanks! Good news is I no longer get that USB power message. This is new photo http://datavisual.tumblr.com/#1202980891 and my code.. light still doesn't go on tho..

#define LED 13
#define BUTTON 7

int val = 0;

int state = 0;

void setup() {
pinMode(7, INPUT);
digitalWrite(7, HIGH);
}


void loop() {
 val = digitalRead(BUTTON);
 
 if (val ==HIGH) {
   state = 1 - state;
 }
 
 if (state == 1) {
   digitalWrite(LED, HIGH);
 } else {
   digitalWrite(LED,LOW);
 }
 
}

Jeremy1998

^^^^^^^^^^
Or you can leave the code as is, and swap the wires for ground and signal. ust move the right yellow wire over, and the red wire to thw contact on the pushbutton.

PeteAJ

Thanks Jeremy. Liked your suggestion but still can't get the light to go with the wires switched as you said (and the original code). Tried restarting program and computer just for good measure as well. Guess I'm a little stumped here..

Jonathan Oxer

I'm a bit confused about what you're trying to achieve. It *looks* like what you're wanting to do is have the LED change state on a button press, but what you've written won't achieve that. If you just want a simple "on while pressed" behavior, you could simplify your sketch to this (untested):

Code: [Select]
#define LED 13
#define BUTTON 7

void setup() {
 pinMode(BUTTON, INPUT);
 digitalWrite(BUTTON, HIGH);
 pinMode(LED, OUTPUT);
}

void loop() {
if (digitalRead(BUTTON) == LOW) {
  digitalWrite(LED, HIGH);
} else {
  digitalWrite(LED,LOW);
}
}


It may seem like the logic is inverted, but what's happening is that the internal pull-up on the BUTTON pin will hold that input high unless the button is pressed. So a LOW value on the button corresponds to a press, which is then used to set a HIGH value (illuminated) for the LED.
--
Jon

Graynomad

Or even simpler (but inverted)

Code: [Select]
void loop() {
digitalWrite(LED, digitalRead(BUTTON)
}
Rob Gray aka the GRAYnomad www.robgray.com

Jonathan Oxer

#12
Sep 28, 2010, 09:02 am Last Edit: Sep 28, 2010, 09:24 am by jonoxer Reason: 1
Hey @Graynomad, spot on. Or to be just a little bit trickier:

Code: [Select]
void loop() {
digitalWrite(LED, !digitalRead(BUTTON))
}


@PeteAJ: What Graynomad's suggestion does is set the LED output pin level to match the BUTTON input pin level. Very simple and clear.

The "!" you see in my trivially modified version is a logical "NOT" operator, which reverses the logic so that instead of setting the LED output to the same level as the BUTTON input, it sets it to the *opposite* value. Since the button is "low" while pressed that'll give the effect of turning on the LED when the button is pressed, and off when released.
--
Jon

Edit: Added in the second closing bracket that was missing from the copied / pasted code

Graynomad

And you even got the syntax right with two closing parens.
Rob Gray aka the GRAYnomad www.robgray.com

Grumpy_Mike

Quote
And you even got the syntax right with two closing parens.


but missed the semicolon off the end.

Go Up