Go Down

Topic: Why would it not accept DC jack as power supply (Read 4942 times) previous topic - next topic

ashmita_chatterjee

Jul 11, 2014, 01:17 pm Last Edit: Jul 12, 2014, 06:59 am by ashmita_chatterjee Reason: 1
i have been making a 2WD obstacle avoding robot. the code is pretty simple. it works when i connect it to USB but when i use dc power supply it does not run the code. this is schall project of DEADLINE 14 JULY 2014. help ASAP.
Code: [Select]

#include <Servo.h>

//Define Pins
int enableA = 10;
int pinA1 = 2;
int pinA2 = 3;
int enableB = 11;
int pinB1 = 4;
int pinB2 = 5;

Servo myservo;

int leftDistance, rightDistance;

boolean run;

long int inches;

//Define Run variable
void setup() {
 
 myservo.attach(9);  // attaches the servo on pin 9 (SERVO_2 on the Motor Drive Shield to the servo object
 myservo.write(90); // tells the servo to position at 90-degrees ie. facing forward.
 delay(1000); // delay for one seconds

pinMode(enableA, OUTPUT);
pinMode(pinA1, OUTPUT);
pinMode(pinA2, OUTPUT);

pinMode(enableB, OUTPUT);
pinMode(pinB1, OUTPUT);
pinMode(pinB2, OUTPUT);


 pinMode (8,OUTPUT);//attach pin 2 to vcc
 pinMode (6,OUTPUT);//attach pin 5 to GND
 // initialize serial communication:


}



//command sequence
void loop() {
 digitalWrite(8, HIGH);
 // establish variables for duration of the ping,
 // and the distance result in inches and centimeters:
 long duration, inches, cm;

 // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
 // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
 pinMode(13, OUTPUT);// attach pin 3 to Trig
 digitalWrite(13, LOW);
 delayMicroseconds(2);
 digitalWrite(13, HIGH);
 delayMicroseconds(5);
 digitalWrite(13, LOW);

 // The same pin is used to read the signal from the PING))): a HIGH
 // pulse whose duration is the time (in microseconds) from the sending
 // of the ping to the reception of its echo off of an object.
 pinMode (12, INPUT);//attach pin 4 to Echo
 duration = pulseIn(12, HIGH);

 // convert the time into a distance
 inches = microsecondsToInches(duration);


if( inches <= 14)
{
delay(1000);



changePath();    
 

}
else{
run = true;
enableMotors();
 
forward() ;   }




}

//Define Low Level H-Bridge Commands

//enable motors
void motorAOn()
{
digitalWrite(enableA, HIGH);
}

void motorBOn()
{
digitalWrite(enableB, HIGH);
}

//disable motors
void motorAOff()
{
digitalWrite(enableB, LOW);
}

void motorBOff()
{
digitalWrite(enableA, LOW);
}

//motor A controls
void motorAForward()
{
digitalWrite(pinA1, HIGH);
digitalWrite(pinA2, LOW);
}

void motorABackward()
{
digitalWrite(pinA1, LOW);
digitalWrite(pinA2, HIGH);
}

//motor B contorls
void motorBForward()
{
digitalWrite(pinB1, HIGH);
digitalWrite(pinB2, LOW);
}

void motorBBackward()
{
digitalWrite(pinB1, LOW);
digitalWrite(pinB2, HIGH);
}

//coasting and braking
void motorACoast()
{
digitalWrite(pinA1, LOW);
digitalWrite(pinA2, LOW);
}

void motorABrake()
{
digitalWrite(pinA1, HIGH);
digitalWrite(pinA2, HIGH);
}

void motorBCoast()
{
digitalWrite(pinB1, LOW);
digitalWrite(pinB2, LOW);
}

void motorBBrake()
{
digitalWrite(pinB1, HIGH);
digitalWrite(pinB2, HIGH);
}

//Define High Level Commands

void enableMotors()
{
motorAOn();
motorBOn();
}

void disableMotors()
{
motorAOff();
motorBOff();
}

void forward()
{
motorAForward();
motorBForward();
delay(100);
}

void backward()
{
motorABackward();
motorBBackward();
delay(500);
}

void turnLeft(int time)
{
motorABackward();
motorBForward();
delay(500);
}

void turnRight(int time)
{
motorAForward();
motorBBackward();
delay(500);
}

void coast()
{
motorACoast();
motorBCoast();
delay(500);
}

void brake()
{
motorABrake();
motorBBrake();
delay(500);
}
long microsecondsToInches(long microseconds)
{
 
 return microseconds / 74 / 2;
}

void changePath() {
run = false;
disableMotors;



 myservo.write(36);  // check distance to the right
   delay(500);
   rightDistance = inches; //set right distance
   delay(500);
   myservo.write(144);  // check distace to the left
   delay(700);
   leftDistance = inches; //set left distance
   delay(500);
   myservo.write(90); //return to center
   delay(100);
   compareDistance();
 }
void compareDistance() {
 
 {
 if (leftDistance>rightDistance) //if left is less obstructed
 {
   run = true;
   enableMotors();
   turnLeft(2000);
   forward();
 }
 else if (rightDistance>leftDistance) //if right is less obstructed
 {
   run = true;
   enableMotors();
   turnRight(2000);
   forward();
 }
 else {
       run = true;
   enableMotors();

 backward();
 turnRight(3000);
forward();
 
 }
}
 }


the power supply that i am using is 9v transistor battery soldered to a dc plug so that it fits in the jack. it perfectly powers the arduino but does not run the code
i dont think description of the assembly of the bot has to do anything with it as it powers up when connected through USB

spycatcher2k

Please supply ALL the information required to answer your query. Think that you are asking someone who does not know what you have built and describe everything you can.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

Jantje


i have been making a 2WD obstacle avoding robot. the code is pretty simple. it works when i connect it to USB but when i use dc power supply it does not run the code. this is schall project of DEADLINE 14 JULY 2014. help ASAP.

Whats in it for the one who is helping you out?
I think a picture of the setup may be required. If "the code doesn't run" the code is very unlikely to help identify the problem  ]:D.
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

steinie44

#3
Jul 11, 2014, 11:35 pm Last Edit: Jul 12, 2014, 12:12 pm by steinie44 Reason: 1
A 9 Volt DC , 1 Amp adapter works best. Center pin positive.

One 9 volt battery is less power then the USB port.
You need 2 or 3 in parallel to provide enough current.

zoomkat

Quote
but when i use dc power supply it does not run the code.


You need to provide details on the DC power supply being used.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

ashmita_chatterjee

Hey everyone i have posted additional details as well if there is anything u think is so also relevant pls  just ask for it

JimboZA

Quote
it perfectly powers the arduino but does not run the code


If it powered the Arduino perfectly it would run the code, so it's not perfect.

Quote
i dont think description of the assembly of the bot has to do anything with it as it powers up when connected through USB


You're trying to out-think anything that anyone might suggest. You should indeed provide connection details.

Have you powered the motors separately or is it all powered from the Arduino? If so, that's asking for trouble.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

steinie44

One 9 volt battery is less power then the USB port.
You need 2 or 3 in parallel to provide enough current.

rameses32

#8
Jul 12, 2014, 04:54 pm Last Edit: Jul 12, 2014, 04:59 pm by rameses32 Reason: 1
As Steinie mentioned a couple of times already, your problem is the 9v battery, I have a small robot that uses two 9g servos, it's controlled via bluetooth with a Wii controller, a new alkaline 9v works perfectly for 5 minutes and then drops the Bluetooth  connection. It looks like you are using one servo to look around and two motors to drive your robot, a 9v will not supply the current needed, your voltage drops too low, and the arduino won't initialise.

zoomkat

I'd suggest going to radio shack and getting a 8 AA battery holder like below and get 8 rechargeable AA batteries/charger at walmart to provide external power to the project. RC equipment vendors also supply batteries/chargers.

http://www.radioshack.com/product/index.jsp?productId=2062251

http://www.radioshack.com/product/index.jsp?productId=2062242

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


spycatcher2k

Quote
the power supply that i am using is 9v transistor battery soldered to a dc plug so that it fits in the jack. it perfectly powers the arduino but does not run the code
i dont think description of the assembly of the bot has to do anything with it as it powers up when connected through USB



This tells us nothing - let me put it like this :

I have a box that when I turn it on only makes a squeaking noise, but when I press the green button it works perfectly : tell me is it the blue wire or the orange led thats faulty?

I havent told you ANYTHING that you can use to resolve the fault, and I've told you more than you told us.

1 - what should it do & what IS it doing?
2 - Post your code
3 - post a diagram or photo of your setup
4 - what have you tried already (so we don't cover things you have already tried)
5 - if you don't know something, don't guess, it's better to get the correct information than to assume an incorrect fault/solution

Don't add to an older post either, add a reply, it makes following the thread easier.

This is not a 'I'm better than you RANT' - it's a 'please respect the help offered & put a bit of thought into your post RANT'
We can't see your project, we don't know what or how you have done something.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

retrolefty

As simple test will prove to yourself that a 9 volt transistor battery won't cut it for you project. Just take you multimeter and measure voltage between the Vin pin and ground when trying to power using the battery. Tell us what voltage you measure.


zoomkat

Quote
This is not a 'I'm better than you RANT' - it's a 'please respect the help offered & put a bit of thought into your post RANT'
We can't see your project, we don't know what or how you have done something.


Please stop using "we" in your postings.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up