Low current

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Low current

Postby rawrdino » Fri Jun 01, 2012 2:39 am

So yesterday i wrote this little skecth :
Code: Select all
const int LeftSensor = A1;
int SensorLeft;

void setup(){
  pinMode(LeftSensor, INPUT);
  digitalWrite(12, LOW);
  digitalWrite(A1, HIGH);
  Serial.begin(9600);
}
void loop(){
  SensorLeft = analogRead(LeftSensor);
  Serial.println("LeftSensor = ");
  Serial.println(SensorLeft);
  delay(100);
  if (SensorLeft = 30 || SensorLeft < 30){
    digitalWrite(12, HIGH);
  }
    else
    {
    digitalWrite(12, LOW);
    }
  }


And it seems that when i power LED from 12th pin it like receives 1mA only. (By the way the LED should light up from the laser but it always stays on.) Thanks for help
rawrdino
 
Posts: 1
Joined: Fri Jun 01, 2012 2:34 am

Re: Low current

Postby adafruit_support_bill » Fri Jun 01, 2012 5:06 am

How is your led connected? Post a wiring diagram.
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am

Re: Low current

Postby JamesC4S » Fri Jun 01, 2012 10:39 pm

Pin 12 is never set as an OUTPUT.
User avatar
JamesC4S
 
Posts: 114
Joined: Sun Sep 26, 2010 10:49 pm
Location: Austin, TX

Re: Low current

Postby philba » Sat Jun 02, 2012 10:56 am

Same with A1.

But there is also a newbee bug in the if statement. It will never execute the else code.

This leads to the question of what are the defaults on I/O pins. I think they default to input but, in true arduino form, this doesn't seem to be documented. If they do default to input, then the bug in the code causes a digitalwrite(high) to the input pin which turns on the internal pullup and, viola!, a small amount of current will flow.
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 5:59 pm

Re: Low current

Postby adafruit_support_bill » Sat Jun 02, 2012 11:14 am

I think they default to input but, ...

That is right. They do default to input.
http://arduino.cc/en/Tutorial/DigitalPins
Arduino (Atmega) pins default to inputs
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am

Re: Low current

Postby Stephanie » Sat Jun 02, 2012 11:18 am

The digitalWrite to set A1 high will set the internal pullup on that pin too, and ensure analogReads on A1 only return 1023.
User avatar
Stephanie
 
Posts: 286
Joined: Sat Dec 11, 2010 12:17 am
Location: Canada

Re: Low current

Postby JamesC4S » Sat Jun 02, 2012 11:48 am

philba wrote: I think they default to input but, in true arduino form, this doesn't seem to be documented.

http://arduino.cc/en/Tutorial/DigitalPins
"Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs with pinMode()"
User avatar
JamesC4S
 
Posts: 114
Joined: Sun Sep 26, 2010 10:49 pm
Location: Austin, TX


Return to Arduino

Who is online

Users browsing this forum: No registered users and 7 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]