did you do a basic check if your motor-controller is working at all?
You should post your actual sketch as a code-section.
How should anybody give advice if
it is unclear if your code still has a bug?
it is unclear that your motor-controller is damaged through overvoltage?
technical things like microcontroller require
detailed and precise
information
if you don't like to give detailed and precise information
go search another hobby like throwing paint bubbles on a big wall to create randomly colored pictures
if you are too lazy to write more than three sentences go snap-chattering
So here is the update. I got the motor to kind of move but I think it was by mistake. I'm using a different power source that has a changeable voltage. I set it to 7.5V and uploaded my code. At first nothing happened but then I got rid of the GND wire that goes to the Arduino and then the motor started to move. The problem is it kind of moves randomly back in forth in intervals and I don't think it is reading my code because when I deleted the part that was supposed to control the motors movement it still moved. If I plug the GND wire back in then the motor stops moving. I have replaced both the motor and the motor controller and this happens no matter what. I even tried with 6V and it still does that.
The code you are using is creating a servo-pulse with which the servo
standing still
the function call
makes the code start creating a servo-pulse but the pulse of mid-position
On a continious rotation-servo mid-possition is the middle between fullspeed forward and full-speed backwards and this middle-position is speed zero
as far as I know the servo-library a function-call
int motor(180);
does nothing at all
Without a proper connection between ground of your extra power-supply and the arduino
the control-signal is floating uncontrolled which make the servo move somehow but completely uncontrolled.
The connection between ground of extra-power-supply and ground of arduino is a must for proper operation!
You still seem to just tinker around randomly instead of learning and knowing what you are doing.
Why don't you use a well proven example-code for testing the servo?
This is a demo-code delivered with the arduino IDE
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
}
The code above should make your motor start rotating and the speed will increase
and at maximum-speed decrease until running full speed backwards
etc. etc. etc.
Can your digital voltage meter measure frequency?
If yes you could do a check if the IO-pin that shall work as the servo-control if there is a frequency of 50 Hz
If your digital multimeter can measure duty-cycle you could do a measuring if the duty-cycle is between 1% and 2%
and here the situation is: where a digital multimeter that can measure frequency and dutycycle would be very useful.
Thanks for all of this help. The vex motor actually moved. It does two spins to the right and then does two spins to the left which I believe is correct. However in my project, the motor has a gear with a belt on it. This belt has a wood rod sticking out. The program is started with a button which moves the belt down until the rod hits a limit switch. The motor switches directions making the belt with the rod go up. It then stops when it hits another limit switch. I'm not sure if this design will work with the servos since they are position based. I was thinking that I could program it to spins a certain amount of times before it switches directions since it would be going the same distance every time. I'm not sure if this is possible or the best approach.
Position based servos can only turn 90 to maximum 270 degree. which is a 3/4 rotation.
If your servo can rotate one full rotation or multiple rotations it is
not
position based.
non continious = position based servos:
servo.write(90);: turn to middle-position and hold middle-position
servo.write(0);: turn to 0 degree position and hold 0-degree position
servo.write(180);: turn to 180 degree-position and hold 180 degree-position
continous rotation servo = rotates on and on and on and on
servo.write(90); : STOP rotation
servo.write( 0);:full speed for clockwise rotation
servo.write( 180);: degrees full speed for counter-clockwise rotation
servo.write( 10); degrees: slow clockwise rotation
servo.write( 100); degrees slow counterclockwise rotation
as a general advice:
unmount your servo from your device.
you should examine in small steps:
what happens if my code uses
servo.write(90);
what happens if my code uses
servo.write(95);
what happens if my code uses
servo.write(100);
etc. etc.
what happens if my code uses
servo.write(85);
what happens if my code uses
servo.write(80);
what happens if my code uses
servo.write(75);
to collect experience what does your servo do in dependancy of the angle given inside the parentheses of the function-call
servo.write();
If you want good advice how to get a certain way of functioning the first step is to describe this functionality in
normal words
make a new attempt which shall be more precise to describe your wanted functionality
in normal words
So as I'm running the program and just using the vex motor I've noticed a few things and I just wanted to ask you about them. First off when I properly wire and plug in the motor it just starts spinning continuously. Is this normal for the vex motor since it acts like a servo. Also when I run the example program you showed me I noticed that it spins clockwise twice and then spins counter clockwise twice. Unless I'm reading the code wrong, I though that the motor was only supposed to spin once in each direction.
Here is the program I'm using currently
#include <Servo.h>
Servo servo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup() {
servo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // rotate from 0 degrees to 180 degrees
// in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // rotate from 180 degrees to 0 degrees
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
}
}
You seem to have forgotten what I have explained above in this thread about continiuous-rotation-servos
start variable with value zero
create servo-signal for "angle" zero.
On continious-rotation servos angle 0 means full speed clockwise
then the value of pos is increased
1
2
3
4
....
89 on continious-rotation servos 89 means rotate at slow speed clockwise
90
angle 90 on continious-rotation servos means rotate NOT
91 on continious-rotation servos means rotate at slow speed counterclockwise
92 on continious-rotation servos means rotate at little bit faster counterclockwise
etc.
second loop goes back from full speed countercockwise to zero and rising to full speed clockwise
You should observe what the motor is doing more carefully to discover such details as which rotational direction is the motor moving?
Maybe you should something on the motor-axle to make it easier to see
So it seems like for clockwise rotation 50-60 is the sweet spot for the fastest rpm. 120-130 seems like the spot with the best rpm for counter clockwise.
When it comes to making the motor move properly yes. But I'm still working on wring and programing a start button and limit switches. I'll try some stuff and if I get stuck I'll ask . Thanks for all your help
So I have been try to make a start button for my prgram but it is not working. I think it is my wiring but it could be my code.
Here is my program
#include <Servo.h>
Servo servo; // create servo object to control a servo
int buttonPin =8;
void setup() {
servo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(buttonPin, INPUT);
}
void loop() {
digitalRead(buttonPin);
if (digitalRead(buttonPin) == HIGH) {
servo.write(60);
} else {
servo.write(90);
}
}
And here is an image of the wiring I'm using for the button
I'm not drawing power from the Arduino for the button. I'm using the same 9v that I'm using for the motor. I'm not sure if this is causing a voltage issue.
So I changed the button and it now started to work so I guess that was the issue. Now I just need help to figure out how to make the button toggle on with a push. In my final design I need the motor to start when it is pressed and stay on I'm not sure how to do that exactly.
One look and everything is clear.
Button wired with pull-down-resistor and connected to IO-pin 3
60 seconds hand drawn.
Just showing the relevant information. Leaving away all non-relevant information.
Here is a code that demonstrates using a button to start / stop a part of the code
#define unPressed HIGH
#define pressed LOW
const byte ToggleButtonPin = 3;
boolean isActive = false;
unsigned long myTestTimer;
void setup() {
Serial.begin(115200); // change baudrate in the serial monitor to 115200
Serial.println("Setup-Start");
pinMode (LED_BUILTIN, OUTPUT); // used for indicating logging active or not
digitalWrite(LED_BUILTIN, LOW);
// wire button between IO-pin and GND
// Pull-up-resistor inverts the logic
// unpressed: IO-pin detects HIGH
// pressed: IO-Pin detects LOW
pinMode(ToggleButtonPin, INPUT_PULLUP);
}
void myCodeToRun() {
// check if 249 milliseconds time have passed by
if ( TimePeriodIsOver(myTestTimer, 249) ) {
// if really 249 milliseconds have passed by
Serial.println("running");
}
}
void wait() {
// check if 498 milliseconds time have passed by
if ( TimePeriodIsOver(myTestTimer, 498) ) {
// if really 498 milliseconds have passed by
Serial.println("waiting");
}
}
void loop() {
// code that shall be executed UN-conditional all the time
// store toggle-switch-state into variable named "isActive"
isActive = GetToggleSwitchState();
if (isActive == true) { // only in case variable isActive is true
digitalWrite(LED_BUILTIN, HIGH);
myCodeToRun();
}
else { // variable isActive holds value false
digitalWrite(LED_BUILTIN, LOW);
wait();
}
// code that shall be executed UN-conditional all the time
}
// this function cntains ALL the details to use a momentary push-button as a toggle-switch
// push-button = contact only closed as long as the button is pressed down
// first press => contact closed
// second press => conact opened
// third press => contact closed
// fourth press => conact opened
// and so on and off and on and off....
bool GetToggleSwitchState() {
// "static" makes variables persistant over function calls
static bool toggleState = false;
static bool lastToggleState = false;
static byte buttonStateOld = unPressed;
static unsigned long buttonScanStarted = 0;
unsigned long buttonDebounceTime = 50;
static unsigned long buttonDebounceTimer;
byte buttonStateNew;
if ( TimePeriodIsOver(buttonDebounceTimer, buttonDebounceTime) ) {
// if more time than buttonDebounceTime has passed by
// this means let pass by some time until
// bouncing of the button is over
buttonStateNew = digitalRead(ToggleButtonPin);
if (buttonStateNew != buttonStateOld) {
// if button-state has changed
buttonStateOld = buttonStateNew;
if (buttonStateNew == unPressed) {
// if button is released
toggleState = !toggleState; // toggle state-variable
} // the attention-mark is the NOT operator
} // which simply inverts the boolean state
} // !true = false NOT true is false
// !false = true NOT false is true
return toggleState;
}
// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}