360degree potentiometer controlling 360 degree servo

hi guys i'm trying to create a wind turbine that will react to the direction and speed of wind.

When the wind changes direction through the rotation of the potentiometer with a wind vane attached to the top i want the head of the turbine that covers the swept area to face perpendicular to the wind. As this will be automated my current program isn't up to date and am not sure how this section of code will work. Any help would be greatly appreciated

Welcome to the forum

Please post it here, using code tags when you do

Please give details of exactly which servo you are using. Is it a regular servo that can move through 360 degrees which you can control the angle of, or a continuous rotation "servo" that you can only control the speed and direction of ?

DFRobot DF9GMS 360 Degree Micro Servo (1.6Kg) is the servo motor in use.

The forum won't let me post the code file as i am a new user but here is the code i am currently working with

// Prototype program for mapping wind direction to direction turbine faces using a potentiometer and micro servo

#include <Servo.h>

Servo myServo;  

int const potPin = A0; // analog pin used to connect the potentiometer
int potVal;  // variable to repliate wind direction
int angle;   // variable to angle turbine direction

void setup() {
  myServo.attach(A1); // attaches the servo on pin A1 to the servo object
  Serial.begin(9600); 
}

void loop() {
  potVal = analogRead(potPin); // read the value which replicates the wind direction
  // print out the value to the Serial Monitor
  Serial.print("potVal: ");
  Serial.print(potVal);

  // scale the numbers from the pot
  angle = map(potVal, 0, 1023, 0, 360);

  // print out the angle for the servo motor
  Serial.print(", angle: ");
  Serial.println(angle);

  // set the servo position to face perpendicular to the wind direction
  myServo.write(angle);

  // wait for the turbine to turn and face the wind
  delay(15);
}
angle = map(potVal, 0, 1023, 0, 360);

You are mapping the pot angle to a value between 0 and 360 which is all very well, but the Servo write() function only accepts angle values of 0 to 180

Please provide details of the servo that you are using

Try the sweep example that comes with the IDE to find out what your servo does when it gets the 0-180 values @UKHeliBob mentioned.

For a 360 degree pot look here at the ones described at 1 turn, they are not cheap.
rotary potentiometers

From the page that you linked to

A 360 degree servo’s operation is more similar to a DC motor than a standard servo as only rotation direction and speed can be controlled.

You cannot control the rotation angle of this servo without adding a position detection system to its output

The term "360 degree servo" is completely inappropriate and really should not appear on that web page. The correct term is "continuous rotation servo". It has absolutely nothing to do with 360°! :roll_eyes:

It should not be described as a servo of any kind

As you point out, absolutely true; it fails the entire concept of a "servo". :face_with_raised_eyebrow:

try a rotary encoder they go 360

Good advice, but it won't fix the problem with the "servo"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.