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
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);
}
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
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°!