Hello guys, I am running a project with a simple servo and my UNO arduino. I have a problem here...
here is the code
/************************************************************************
* This file was created by Tzivaras Vasilis
* it can be modified and be used for any purpose
*
* The setup() function is called when a sketch starts. Use it to initialize
* variables, pin modes, start using libraries, etc. The * setup function will
* only run once, after each powerup or reset of the Arduino board.
*
* The loop() function does precisely what its name suggests, and loops
* consecutively, allowing your program to change and respond. Use it to actively
* control the Arduino board.
************************************************************************/
#include <Servo.h>
// create servo object to control a servo
// a maximum of eight servo objects can be created
Servo myservo;
int pos = 0; // the position that the servo starts
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for(pos = 0; pos < 180; pos += 1) {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
Serial.print("Currest Position(+): ");
Serial.print(pos);
Serial.print("\n");
}
for(pos = 180; pos>=0; pos-=1) {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
Serial.print("Currest Position(-): ");
Serial.print(pos);
Serial.print("\n");
}
}
what it does is turning the servo from 0 to 180 deggres then stop then it does some crazy things...like stop for 5 sec then start for a little time then stop for 1 min start veeeery slowly etc...I am a programmer and i know how these kind of stuff works but I am sure something is missing here... yellow wire is signal red 5 V and brown is gnd...i ahve connected them directly to my arduino without resistors etc...and i connect the arduino with a cable to a usb port. Dunno if i need an external source of power like a battery. Please give me some answers
And before you make another classic mistake, that battery had better not be a 9V smoke alarm type - put yourself together some AAs that give you the voltage you need - likely 6V.
wildbill:
And before you make another classic mistake, that battery had better not be a 9V smoke alarm type - put yourself together some AAs that give you the voltage you need - likely 6V.
I was 99% sure that it was fault of the servo... Or bad programming. Really now? Its battery problem? I only have 9V battery. Um what exactly must i do? Connect 3 batteries 1.5 V? how?
You need something like this for 4x AAs to give 6V. You can get them to take 5x cells if you use rechargeables @ 1.2V each. But check your servo datasheet for the right voltage, most are 4.8-6V.
Put the pack straight to the servo's red and black, and join the black also to the Arduino ground; see attached pic.
Got it. Is there any specific reason why 9 V or even the usb cable creates the problem? I just want to learn why... Also this is the part 1. For part 2 I want to do the same but i have a bruseless motor and ESC. This the same thing i guess i just have one question. Will i give input from 0 to 180 again? How is the motor working? With degrees? Something else? I just want to know the MIN and MAX value that i can set in the write funcution. Thank you
JimboZA:
You need something like this for 4x AAs to give 6V. You can get them to take 5x cells if you use rechargeables @ 1.2V each. But check your servo datasheet for the right voltage, most are 4.8-6V.
Put the pack straight to the servo's red and black, and join the black also to the Arduino ground; see attached pic.
JimboZA:
The problem's that the Arduino 5V can't provide enough current to run a servo: forum wisdom is to allow 1Amp for each one.
Ok so i need more than 5V. Um, 1Amp how many Volts? I am newbie sry...and also if you need more than 5 when i put a 9V battery ? Whats wrong? I need more than 9V???
Does your project need to be self sufficient? If not, see if you have a wall wart lying around that provides enough power. Most folks have quite a number left over from old phones and other electronics that needed charging.
ITs my first steps to make a quadcopter. I just want to make the motor work...turn And its toooo hard damn. Now i have connected the ESC to my arduino and after the beeps. it beep for ever...every 1 second i have a beep. and i dont like this Something is going wrong.
Now i have connected the ESC to my arduino and after the beeps. it beep for ever...every 1 second i have a beep. and i dont like this smiley-neutral Something is going wrong.
I presume that you have a brushless motor attached to the ESC and it the motor that is making the beeps.
Some questions
What signals are you sending signals to the ESC ?
Does the ESC need to receive a sequence of commands to arm it ?
Is the ESC expecting an input and signalling that none is present ?
AWOL:
If you want to control an ESC (or four), what's the servo for?
Because I didnt know if the ESC is the same with servo and i am testing the servo as i am 99% sure that the example on the IDE and the connections are right. IF these will work I ll connect the ESC and do the same thing. AS i said I dont know the MIN and MAX value that i cna write to the ESC. But in the servo is 0 180.
Now i have connected the ESC to my arduino and after the beeps. it beep for ever...every 1 second i have a beep. and i dont like this smiley-neutral Something is going wrong.
I presume that you have a brushless motor attached to the ESC and it the motor that is making the beeps.
Some questions
What signals are you sending signals to the ESC ?
Does the ESC need to receive a sequence of commands to arm it ?
Is the ESC expecting an input and signalling that none is present ?
I have no idea man. I am running this one now and nothing happen whne i give 10-20 50 340 54 12 53 lol fire g h t etc...
/*
* This code is in the public domain.
* (Do whatever you want with it.)
*/
// Need the Servo library
#include <Servo.h>
// This is our motor.
Servo myMotor;
// This is the final output
// written to the motor.
String incomingString;
// Set everything up
void setup()
{
// Put the motor to Arduino pin #9
myMotor.attach(9);
// Required for I/O from Serial monitor
Serial.begin(9600);
// Print a startup message
Serial.println("initializing");
}
void loop()
{
// If there is incoming value
if(Serial.available() > 0)
{
// read the value
char ch = Serial.read();
/*
* If ch isn't a newline
* (linefeed) character,
* we will add the character
* to the incomingString
*/
Serial.print(ch);
Serial.print("\n");
if (ch != 10){
// Print out the value received
// so that we can see what is
// happening
Serial.print("I have received: ");
Serial.print(ch, DEC);
Serial.print('\n');
// Add the character to
// the incomingString
incomingString += ch;
}
// received a newline (linefeed) character
// this means we are done making a string
else
{
// print the incoming string
Serial.println("I am printing the entire string");
Serial.println(incomingString);
// Convert the string to an integer
int val = incomingString.toInt();
// print the integer
Serial.println("Printing the value: ");
Serial.println(val);
/*
* We only want to write an integer between
* 0 and 180 to the motor.
*/
if (val > -1 && val < 181)
{
// Print confirmation that the
// value is between 0 and 180
Serial.println("Value is between 0 and 180");
// Write to Servo
myMotor.write(val);
}
// The value is not between 0 and 180.
// We do not want write this value to
// the motor.
else
{
Serial.println("Value is NOT between 0 and 180");
// IT'S a TRAP!
Serial.println("Error with the input");
}
// Reset the value of the incomingString
incomingString = "";
}
}
}
Before you try making the motor move using Serial inputs, how about trying it with the Sweep example from the Servo library ? That way you will know that the ESC and motor work.
Fellow "big bang theory" fan ( IT'S A TRAP!),
are you positive your servo can go 0 to 180 ? I would check the data sheet.
I looks as you servo "stalled" and pulled the source down for the processor to misbehave / or reset.
BTW you last post has no "wait" for the hardware provision.
I am not sure 15 ms is long enough when the refresh rate is nominally 20 ms , just saying.