PDA

View Full Version : Help with this!



SXRguyinMA
05-16-2010, 08:16 PM
Alright, I've got this program down pat for my servo controller:


// Controlling a servo position using a temperature sensor
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7

#include <Servo.h>
#define CONTROL 7

Servo myservo; // create servo object to control a servo

int temps = 0; // analog pin used to connect the temp sensor
int val; // variable to read the value from the analog pin

void setup()
{
pinMode (CONTROL, INPUT); // sets the control pin to input
myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop()
{
val = digitalRead(CONTROL); //read input of pin 7 and store it
if (val == HIGH){ // reads whether or not 5v is present on pin 7, if 5v present, continue:
val = analogRead(temps); // reads the value of the temp sensor (value between 0 and 1023)
val = map(val, 350, 700, 75, 105); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(25); // waits for the servo to get there
} else {
if (val == LOW); // if no voltage present on pin 7, continue
myservo.write(50); //sets servo position to 50 if no voltage is detected on pin 7
}
}

when I take power away from pin 7 the servo is to go to a preset position. It does this, but it jitters before it goes. once its there its ok. anyone have any ideas? :?

Oneslowz28
05-16-2010, 08:56 PM
Its not in the code. Is it normal servo jitter that you see on some RC servos?

SXRguyinMA
05-16-2010, 09:13 PM
it almost seems like it, but that is the ONLY time it does it. It hasn't done it once during normal operation, or even when it's parked at its base point. Only right before it goes to base

crenn
05-17-2010, 08:40 PM
Alright, I've got this program down pat for my servo controller:


// Controlling a servo position using a temperature sensor
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7

#include <Servo.h>
#define CONTROL 7

Servo myservo; // create servo object to control a servo

int temps = 0; // analog pin used to connect the temp sensor
int val; // variable to read the value from the analog pin

void setup()
{
pinMode (CONTROL, INPUT); // sets the control pin to input
myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop()
{
val = digitalRead(CONTROL); //read input of pin 7 and store it
if (val == HIGH){ // reads whether or not 5v is present on pin 7, if 5v present, continue:
val = analogRead(temps); // reads the value of the temp sensor (value between 0 and 1023)
val = map(val, 350, 700, 75, 105); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(25); // waits for the servo to get there
} else {
if (val == LOW); // if no voltage present on pin 7, continue
myservo.write(50); //sets servo position to 50 if no voltage is detected on pin 7
}
}when I take power away from pin 7 the servo is to go to a preset position. It does this, but it jitters before it goes. once its there its ok. anyone have any ideas? :?


// Controlling a servo position using a temperature sensor
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7

#include <Servo.h>
#define CONTROL 7

Servo myservo; // create servo object to control a servo

int temps = 0; // analog pin used to connect the temp sensor
int val; // variable to read the value from the analog pin

void setup()
{
pinMode (CONTROL, INPUT); // sets the control pin to input
myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop()
{
val = digitalRead(CONTROL); //read input of pin 7 and store it
if (val == HIGH){ // reads whether or not 5v is present on pin 7, if 5v present, continue:
val = analogRead(temps); // reads the value of the temp sensor (value between 0 and 1023)
val = map(val, 350, 700, 75, 105); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
}
else if (val == LOW){ // if no voltage present on pin 7, continue
myservo.write(50); //sets servo position to 50 if no voltage is detected on pin 7
}
delay(25); // waits for the servo to get there
}

SXRguyinMA
05-17-2010, 10:00 PM
no go. I see the change and it makes sense.

When I take the voltage away, it takes an average of 18 seconds before the servo starts to move to the set position, and it jiggles for about 2 seconds, then goes to its set point. once its there it's still. I'll take a vid and show you

I took a vid, and of course this time it didn't wait 18 seconds, but it did the same jitter lol. I'm uploading it now

crenn
05-17-2010, 10:06 PM
void setup()
{
pinMode (CONTROL, INPUT); // sets the control pin to input
myservo.attach(9); // attaches the servo on pin 9 to the servo object
digitalWrite(CONTROL, LOW); // ensure internal pullup resistor is disabled.
}

SXRguyinMA
05-17-2010, 10:11 PM
hasn't changed a thing - vid is processing

:EDIT:
had it twitch on me once while the 5v signal was unplugged. it shouldn't move at all :?

crenn
05-17-2010, 10:19 PM
Circuit diagram please

SXRguyinMA
05-17-2010, 10:22 PM
alright here's the vid. It's still processing so it may be a few. It starts with the signal wire unplugged. when I plug it in, the servo instantly goes to wherever the temp reading puts it. when I unplug it, the temp sensor still controls it for 10-20 seconds, then it jiggles and goes to the set position

uJ0uDS6oHBM

SXRguyinMA
05-17-2010, 10:27 PM
Circuit diagram please

as you wish :D

http://i92.photobucket.com/albums/l11/sportrider12584/Arduino%20Stuff/servo_control_wiring.png

crenn
05-17-2010, 10:36 PM
Add a 10k resistor from Pin 7 to ground.

SXRguyinMA
05-17-2010, 10:41 PM
Add a 10k resistor from Pin 7 to ground.

you my friend, are pure genious! it works perfectly! now the question...what does this do and why does it do it? :?

SXRguyinMA
05-17-2010, 10:49 PM
ok new diagram that works 100%

http://i92.photobucket.com/albums/l11/sportrider12584/servo_control_wiring.png

crenn
05-17-2010, 10:50 PM
you my friend, are pure genious! it works perfectly! now the question...what does this do and why does it do it? :?
It ties the input to ground via the resistor. When you pulled the signal out, it held it's value for a while probably due to capcitance in the line, so by adding the resistor, it quickly drains that capacitance so it reaches low (0v) quicker.

SXRguyinMA
05-17-2010, 10:58 PM
ahhh I get it. is that the same reason for putting a 10k resistor in the thermistor circuit as well?

crenn
05-17-2010, 11:05 PM
ahhh I get it. is that the same reason for putting a 10k resistor in the thermistor circuit as well?
No, the reason for putting the 10k resistor in the thermistor circuit was to set up a voltage divider, you're measuring the voltage over the resistor.

SXRguyinMA
05-17-2010, 11:13 PM
ahhh ok. theres still a ton I need to learn about circuits. I know the basics, but when it comes to voltage dividers and transistors and stuff I'm lost :?

know anywhere I can learn that stuff?

crenn
05-17-2010, 11:17 PM
http://www.electronics-tutorials.com/basics/basic-electronics.htm
This looks like a good site