Pages: 1 [2]   Go Down
Author Topic: USB device drawing too much power (beginner ques.)  (Read 3658 times)
0 Members and 1 Guest are viewing this topic.
Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I'll probably get this wrong as well but I'll give it another go   ;-)

Code:
void loop() {
 digitalWrite(LED, !digitalRead(BUTTON));
}

Better?

Hmmm, here we are talking among ourselves and don't even know if the original poster has had any success.

@PeteAJ: are we helping, or just making you more confused?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops, looks like Jon and I both go to the back of the C 101 class   :-[
Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Jon, Mike, Graynomad.. thanks for the input. I've tried your code versions and the code itself and the suggestions/mods make sense..

I'm new to this. Working on the second example in the Massimo's 'Getting Started with Arduino' book. Controlling an LED with a pushbutton.

I went back to my original setup with the second yellow and red wires flipped in relation to the resistor 'cause that got rid of my USB power warning error as per Jeremy's suggestion.

This is what I have:  http://datavisual.tumblr.com/#1204687027

Also went back to the original code in the book:

#define LED 13
#define BUTTON 7

int val = 0;

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

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


Replugged the USB
changed by LED ..just in case
Compile, save, upload in Arduino, and my LED still doesn't turn on.

The 2nd orange light on the Arduino board (marked L) responds to the button press (which must be a good sign).


This is only my second thing but not giving up until I figure this out.

Does it look like I have the right 10K ohm? There are 1K and 10K ones in the MakerShed starter kit and I wasn't completely convinced I'm telling them apart.

  

Logged

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are trying to do a:
*press*
led on
*press*
led off
(repeat)
Then I have some code that is tested and working. Just let me know and I'll post it...
Logged

UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LED connected backwards? Or blown?

If the on-board LED (L) is responding correctly to your button then the code is almost certainly fine.

Edit: and yeah, that looks like a 10k resistor to me. To be honest, I cheat most of the time and use a free Resisitor Color Code app on my phone. smiley-wink
« Last Edit: September 28, 2010, 02:06:40 pm by Eight » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Jeremy.. could I try your code? Not sure what else to try. Might rewire off the arduino.cc version of this task ..
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey.. just wanted to say thanks guys! Totally learnin'. And in business.  
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the on board LED is responding to the button press your code is OK.
The external LED must be connected through a resistor somewhere between 300R (that's ohms) and 1K. If you use 10K it will not light up bright enough for you to see.
You must use an external resistor, those books that say there is an on board resistor are out of date and wrong.
Logged

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This uses the internal pull up resistor. Just connect the button to ground and the other side to digital pin 12. You don't NEED an led for this, because the board has  one built on to it, but you can use one if you want to. It would go on digital pin 13.

This code SHOULD work. I tested it a long time ago, and I can't remember if I modified it or not...

Code:
int ledPin = 13;
int buttonPin = 12;

int currentState;
int previousState;

int counter;

void setup(){
 pinMode(ledPin, OUTPUT);
 pinMode(buttonPin, INPUT);
 digitalWrite(buttonPin, HIGH);
}

void loop(){
 currentState = digitalRead(buttonPin);
 if(currentState == LOW && previousState == HIGH){
  counter ++;
  digitalWrite(ledPin, HIGH);
 }  
 else if(currentState == HIGH){
  digitalWrite(ledPin, LOW);
 }  
 if(counter >= 2){
  counter = 0;
 }  
}
« Last Edit: September 30, 2010, 10:01:49 am by Jeremy1998 » Logged

Pages: 1 [2]   Go Up
Jump to: