Go Down

Topic: Analog Pin Voltage With External Power Supply (Read 318 times) previous topic - next topic

mtrapuzz

May 31, 2019, 05:39 am Last Edit: May 31, 2019, 05:41 am by mtrapuzz
I have done a lot of searching and found some similar issues, but I can't quite figure this out.

I am using an Arduino Uno to control some stepper motors, and the controller works fine when plugged into my laptop with a USB cable, but when externally powered with a 5V adapter using the same USB cable, the controller doesn't work properly. I am referencing some analog pins in the code and noticed that when the controller is powered externally the analog pins have a voltage, but when powered with the laptop the analog pins have no voltage. When plugged into the laptop, the voltage in the cable is 5.07V and when plugged in externally it is 5.1V. I don't think this would make any difference. There is no serial communication or anything similar in the code. Anyone able to help me out with this? If I need to explain something further I can. Thanks in advance. 

groundFungus

How is the 5V adapter connected to the Arduino?

mtrapuzz

A USB cable that goes into an adapter like those used for iPhone chargers plugged into the wall. The controller does the same thing when connected with a barrel plug using both a 9V or a 12V adapter.

hammy

Need a wiring diagram , sounds like a wiring fault

mtrapuzz

#4
May 31, 2019, 06:28 pm Last Edit: May 31, 2019, 06:29 pm by mtrapuzz
Like I said, it works fine with the USB to PC power.

I attached the image of the diagram to this post.

Sorry it's a bit messy but hopefully you get the idea.

mtrapuzz

Code below:



const int stepPin = 5;
const int dirPin = 4;
const int sleepPin = 2;
const int resetPin = 3;
int upPin = A0;
int downPin = A1;

// setup
void setup() {
 // Sets pins as Outputs/Inputs
 pinMode(stepPin,OUTPUT);
 pinMode(dirPin,OUTPUT);
 pinMode(sleepPin,OUTPUT);
 pinMode(resetPin,OUTPUT);
 pinMode(upPin,INPUT);
 pinMode(downPin,INPUT);

digitalWrite(resetPin,HIGH);
 
}  

// code
void loop() {    

  while ((analogRead(upPin) < 660) && (analogRead(downPin) < 660)) {
   digitalWrite(sleepPin,LOW); }
 
  while (analogRead(upPin) >= 660) {
   digitalWrite(sleepPin,HIGH);
   digitalWrite(dirPin,HIGH);
   digitalWrite(stepPin,HIGH);
   delayMicroseconds(1000);
   digitalWrite(stepPin,LOW);
   delayMicroseconds(1000); }
   
     
  while (analogRead(downPin) >= 660) {
   digitalWrite(sleepPin,HIGH);
   digitalWrite(dirPin,LOW);
   digitalWrite(stepPin,HIGH);
   delayMicroseconds(1000);
   digitalWrite(stepPin,LOW);
   delayMicroseconds(1000); }

}
 

groundFungus

#6
May 31, 2019, 07:40 pm Last Edit: May 31, 2019, 07:57 pm by groundFungus
Why are the up-down switches wired to analog inputs?  Are the analog inputs flooating when the switchis open?  Have you printed the values of the readings of upPin and downPin when plugged into PC and on the external supply?

Have you measured the 3.3V output with both supplies?

mtrapuzz

It used to be digital pins but they were getting a lot of noise and randomly going high and low. Apparently it's a known issue especially with long wires.

The analog inputs read zero when the arduino is powered with the pc, but they read a voltage when the arduino is powered any other way.

I was printing the analog values when connected to the computer. Ut havent when connected to wall power.

groundFungus

#8
May 31, 2019, 08:26 pm Last Edit: May 31, 2019, 08:28 pm by groundFungus
The, probable, reason that the digital inputs were giving you noise is that they are floating.  Wire the center of the switch to ground and the upPin and downPin terminals to inputs with the pinMOdes set to INPUT_PULLUP (internal pullup, 30K to 50K).  Use digitalRead to read the switch states (digitalRead works fine on analog inputs). If the wires are short the internal pullups will stop the floating,  Longer wires require stronger pullups.  That means an external pullup resistor of lower value.    Start with 10K and go down till you get good transitions. Usually no lower than 1K.  A 0.1uF cap will help, a lot, to filter noise.

The reason that I asked about the 3.3V output is that 660 ADC counts is 3.22 volts with an analog reference of 5V.  If the 3.3V output is not above 3.22V the if statement that sleeps the driver is the only one that will run, making it look like nothing is happening.

mtrapuzz

I can try that.

The motors are supposed to do nothing until the switch is pressed in either direction. It works like when the arduino is powered with the pc via ISB but when I power the arduino any other way the motor starts acting erratically when the switch is not pressed in either direction.

hammy

I would have powered the pot from the 5v output as this is also the reference for the A/D - so if the 5v dips the input voltage A/D value stays the same . I would put say 100k pull down on the analog inputs being used too, and as a previous poster put ,  change  the switch Points  - with 5v say 600 on 100 off.

Go Up