External power supply trouble

Hello guyz,

I decided to develop my own board based on a Atmega328P.

I load the bootloader to the chip, and after that load my program throught the USB2SERIAL arduino board.

My program only works when the 5V power supply comes from my computer (USB).
When I want to give 5V with an external power supply nothing happens. I check the current limit and try with different power supply and the result is always the same.

So I don't know why it doesn't work?

For information : I tried with the "Blink" example program. It works fine both with USB 5V and external power supply.

But nothing happens with my program when using external power supply.

The program control a 5V DC motor.

Does anybody has an idea?

Thanks

Let's see a schematic of what you have wired up. Maybe you're missing a ground connection, maybe the motor needs more current than your supply can provide.

CrossRoads:
Let's see a schematic of what you have wired up.

And the rogue code, of course!

Hello,

Find below my code :

#include <AccelStepper.h>

// Define some steppers and the pins the will use
//AccelStepper stepper1(8, 8, 9, 10, 11);
//AccelStepper stepper1(8, 7, 8, 9, 10);
AccelStepper stepper1(8, 4, 5, 6, 7);


int value = 0;
int Signal = A0;  
long int pos = 0;
int previous = 0;

//int angle_deviation = 3072;                 // Angle de déviation = angle*4096/360

int homeButton_A1 = A1;

//byte hBval;
int hBval;

float x = 0;
int i = 0;

void setup()
{  
  pinMode (Signal,INPUT);                     // Analog Input signal (0 to 5V)
  pinMode (homeButton_A1,INPUT);              // Analog Input for home position
  
  pinMode(13, OUTPUT);
  
  stepper1.setMaxSpeed(2000.0);               // Max speed of the first motor - modify if you want to
  stepper1.setAcceleration(2000.0);           // Rate at which the first motor accelerate -
  
  motorHome();                                // Do only one time to find the 0 position (switch or photoresistor mode)
  stepper1.setCurrentPosition(0);             // Initialize the step counter to 0  
}

void loop()
{    
  
  value = analogRead(Signal); 
//  pos = (value*2390)/1024L;  

//  x = 2.5;
  x = 2795.0/1024.0;    // 2795 pour 240° de déviation
   
  pos = (value*x);  
  
  if (stepper1.distanceToGo() == 0)
  {
    stepper1.moveTo(float(pos));  
    delayMicroseconds(0.5);      // 500 µs
  }
  stepper1.run();
}

void motorHome()
{    
  hBval = analogRead(homeButton_A1);
    while (hBval <= 950)
    {
      if (stepper1.distanceToGo() == 0)
      {
        stepper1.move(-2795);  
        hBval = analogRead(homeButton_A1);
      }    
      stepper1.run();
    }  
  stepper1.setCurrentPosition(0);             // Initialize the step counter to 0  
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  
}

For the ATMEGA328P.

Summary of my connection :

Pin 7 and 20 : 5V
Pin 8 and 22 : GND
Pin 1 : To 5V through 10K resistor

I connected my motor driver to :

pin 6, pin 11, pin 12 and pin 13

And I connected my two analog inputs to pin 23 and 24.

When I Give 5V to the µC with the USB2SERIAL board it works well, but nothing happen with an external power supply.

My power supply is an Agilent E3631A and I can put 5V/5A current limit.

The consumption is arround 300mA maximum for my motor

I have no idea wh it doesn't work with external supply.

Maybe the problem comes from the bootloader.

For information to loard my code I used the USB2SERIAL board. Parameters on arduino IDE :

Board : Arduino UNO
Programmer : AVR ISP

OK, we can wait for the photo/ schematic.
:roll_eyes:

Find attach the schematic of my app

When the 5V is provided by USB it works, when it's an external power supply it won't.

SimonR:
Find attach the schematic of my app

Why do you have a pushbutton connected to +5 V and no pull-down?

Firstly, it should go to ground, then either a pull-up resistor or enable the internal pull-up.

Not necessarily the fault (but it could well be) but a point of engineering design.

ULN2003 are essentially obsolete, very poor performance at 5V as you lose about 1.5V in them.

More useful to use a TPIC6B595 and load the data serially. In fact, this has the advantage that all outputs are updated simultaneously whereas if you use digitalWrite commands on individual pins, there is some - albeit minor - delays between updates.

Hello Paul,

The pushbutton is a home position. During the setup, the motor goes backward, when it hits the pussbutton, it wiil stop. That's why it is connected to 5V. When analog input detects high level, the motor stop and we know the home position of the motor

I used ULN2003A according to all the example I was ble to find for my motor.

The point is that the program and my components works fine when I did it with the Arduino Uno. No troubles.

Now I tried to do my own board (I don't have a lot of space on my box) so I just want the ATMEGA328P and my driver.
But It works only with USB 5V. And even with that there are some functionning troubles.

SimonR:
The point is that the program and my components works fine when I did it with the Arduino Uno. No troubles.

that is just random luck. there seems to be lack of understanding how io and push buttons work. unconnected floating inputs may appear high or low depending on noise. best use mcu built in pull up. i suggest paying attention to the good advice from paul.

switching to a modern motor driver will make life much easier. specially considering cost is similar to old 2003 and programming is 10x simpler. i find a4988 modules best because they are more efficient than others, better performance, safety features, and complete ready to go modules only cost a buck or so:

Try this, I think you will see big improvement.
Change this
pinMode (homeButton_A1,INPUT); // Analog Input for home position
to
pinMode (homeButton_A1,INPUT_PULLUP); // Analog Input for home position
and wire the button to connect to GND when pressed.

Then fix this code to wait for a LOW to let you know the button is pressed. You're connected to an analog input pin, but it can be used as a digital input also, so you can test for a LOW vs an analogRead value.
Or, add a 10K pulldown resistor to GND as suggested, so the pin is either firmly LOW or HIGH and not floating.

void motorHome()
{    
  hBval = analogRead(homeButton_A1);
    while (hBval <= 950)                          << change these two lines to: while ((digitalRead(homeButton_A1) ==HIGH) 
    {
      if (stepper1.distanceToGo() == 0)
      {
        stepper1.move(-2795);  
        hBval = analogRead(homeButton_A1);
      }    
      stepper1.run();
    }  
  stepper1.setCurrentPosition(0);             // Initialize the step counter to 0  
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  
}

Thanks guyz for your answers,

I tried both solution (pull-down and the digitalRead). Both solution improve the program and digitalRead seems to be the better one.

john1993:
switching to a modern motor driver will make life much easier. specially considering cost is similar to old 2003 and programming is 10x simpler. i find a4988 modules best because they are more efficient than others, better performance, safety features, and complete ready to go modules only cost a buck or so:

For the moment I will keep the ULN2003A because I only want to develop one app. But if you have some arduino code to deal with these component will be great.

Moreover, major probem is still here. The program works fine with the 5V providing by my USB2SERIAL board. But doesn't with an external power supply.

What is the output voltage and current rating of your external supply?

It's an Agilent E3631A 5V / 5A

I got nothing. You could use a couple 0.1uF caps on the VCC and AVCC pins.
Have you measured the Agilent output with a meter? Good, solid 5V?
If you put your meter on AC mode, does that show a very small number, so there is little ripple on the DV level?

SimonR:
if you have some arduino code to deal with these component will be great.

heres a sketch that will run stepper motor with module "step" signal connected to pin 13:

void setup() {
   pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH); delay(100);
  digitalWrite(13, LOW); delay(100);
}

works with nearly all modern driver chips. somewhat simpler than equivalent uln2003 code.

this is probably the first time motor setup runs fine off usb serial power but misbehaves with high power external supply. usually the other way around.

The 5V is good, very less noise, and good stability.

Effectively it's the first times I see something working fine with USB power supply but doesn't with an external power supply. That's really weird.

For information, it seems that my power supply consumes 155mA, but nothing happens.

I don't have 100nF available today. I will try it tomorrow and let you know.

Do you think that the problem comes from the bootloader and how I load the program to the chip?

No. If it runs with USB, it will be the same code running from external.

SimonR:
I don't have 100nF available today. I will try it tomorrow and let you know.

Which is to say, you did not have the essential bypass capacitors fitted.

Note that the value is not critical - anything upward of 0.047 µF will be just fine as long as it is ceramic (or "blob" tantalum, but people are suspicious of them) and not electrolytic, so 1 µF would do also.

The problem is I suspect that using the USB feed, you are using a proper cable with the power wires adjacent, whereas with the lab supply, you are using two separate flying leads, which means that you have effectively put an inductor in series with your power supply. "Lead dress" is a very common cause of such problems here, especially with relays - so motors would also apply. All interconnection leads should always be grouped tightly together for digital electronics (but run separately for power and signal).

HEllo guyz, I added couple capacitors and everything is going well.

Thanks for your help. I let you know if I have other troubles.