Let's Make Robots!

(Solved!) Low current from Arduino Output (Arduino Start Here robot)

 

EDIT: LED problem solved thanks to RobotFreak. I forgot to set the pins to output mode using the pinMode command. As RobotFreak points out, the Arduino sets all pins as inputs by default. I added a For loop to set all the pins to outputs, and everything worked great.

void setup() {
  pinMode(13, OUTPUT);  
  for (int pinindex = 0; pinindex < 14; pinindex++) {
     pinMode(pinindex, OUTPUT);  // set pins 0 to 13 as outputs
  }

I have updated the attached code with the working version.

Note that the USB still resets when the board is not connected to external power and the servo is commanded to move. I suspect the servo draws close to 500mA or whatever my laptop's USB port can support.


I'm working on an Arduino version of the Start Here robot. I haven't got all the hardware yet, but I'm testing out the code on my Arduino Mega clone. I've got an LED that I'm using on different outputs to test their state during program operation.

Here's the weird thing. The LED is running really dim. I can barely see it. At first I thought maybe my cheap Chinese knock-off copy of the Mega was having a problem. I had previously tested all the outputs and they were fine. However, when I download the standard "Blink" program to the Mega with the the output pin changed to my LED pin, it works fine.

So now I suspect something in my code is weird. This is where you come in, my friends. ; j

I've attached my code and would appreciate a quick review to see if I've done something foolish. Here's some info on my setup and things I've tried so far.

Setup

  • LED and 150 ohm resistor on Output 7 (one of the motor outputs), with other side going to ground
  • Arduino connected to USB port
  • Arduino powered by external wall wart: 12VDC, 2A
  • Dagu mini servo connected to pin 9 (plus power and ground, of course)
  • Sharp GP2Y0A21YK IR sensor connected to Analog pin 0 (pin 54 on Arduino Mega)
  • Attached code pulls all unused Analog ports to HIGH using internal pullups
  • Built in board LEDs are lit up nice and bright

Observations/Symptoms

  • LED dim when running on pin 7 or 5 (motor outputs that are high during normal operation)
  • LED lights up bright if I connect to pin 9 in parallel to servo, or directly to board 5V supply
  • Running attached code, if I disconnect the external 12V supply, my computer keeps dropping the USB connection. I suspect I'm drawing more than the 500mA the USB is rated for. Works find with the external supply.
  • Running standard Arduino 'Blink' program with output on pin 8, LED lights up nice and bright.
  • Servo and Sharp sensor seem to work fine.

Stuff I've tested

  • I've tried commenting out the For loop that sets all the internal pullup resistors: no effect
  • I've tried commenting out all the servo commands: no effect
  • I've tried commenting out the Serial.begin command: no effect
  • I've tried phyically disconnecting power to the servo and to the Sharp: no effect
  • I've tried adding a digitalWrite command to set an unused output to HIGH and moved the LED to that output: LED lights dimly
  • I've tried asking for help from you guys: Effect to be determined ; j

If there's a problem with my code, I can't see it. I'm going to try to wire up the SN754410NE motor driver and see if outputs 7,6,5,4 are providing enough current to drive the logic. I'll post an update when I have some results. In the meantime, can anyone check over my code?

I'm also open to any suggestions to changes in my code. I'm pretty new to the Arduino. I'm not trying to do anything fancy with this one yet. Just trying to replicate the posted Start Here robot. I'll elaborate on the code and physical robot design later.

 

AttachmentSize
starthere_-_working_now.pde3.41 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I was going to say that perhaps you missed to declare the pin Output, but I see you already got that advice and that was the problem. The good part about this forums is that you don't have to wait for one person to get back from work or wake up to help you out, there are so many other knowledgeable people online almost all the time. I really love it.

Cheers!

BTW, one of my motors is running faster than the other. I use PWM to slow it down so the robot drives straight. Look at my code to see how that works.

I had a quick look at your code, looks ok at a glance.

Considering the USB drops out with external power removed I suspect you have a short somewhere. Is the ATmega1280 getting hot. If any of it's pins are shorted it will get unusually warm.

Did you do CTC's trick and get the power connections to the sharp sensor backwards?

Until you can get it to work fine with USB power only I would not proceed any further.

The board came pre-assembled and has none of my own soldering. It works fine for other programs, and has been since I got it.

The ATmega1280 is cool as a cucumber, but thanks for that tip. It is good to know.

The Sharp is wired correctly and working fine.

BTW, when I download the Blink program and it works, I'm not disconnecting the Sharp or servo or doing any rewiring. That's why I suspected something weird in the code instead of a hardware issue. I appreciate your taking a crack at it. Another pair of eyes is often helpful when you are stuck.

Your advice about not proceding further until I understand what is going on is very sound. I will keep digging.