DIY Servo Motor 360° high torque w Arduino code

preview_player
Показать описание
Uses a 20V printer motor geared down using an old record player transmission. Motor is controlled via an L293 driver using the Arduino code pinned in the comment section. A ten-turn potentiometer is attached to the final drive shaft with flexible tubing and acts as the position sensor.
Рекомендации по теме
Комментарии
Автор

//CODE

// PWM pins to L293 Driver
const int PWMpinCW = 10;
const int PWMpinCCW = 11;
const int enablePin = 3;

//analog speed pins

const int wiperControlPin= A7;
const int wiperSensePin = A6;

// LED Indicator Outputs
const int ledCW = 8;
const int ledCCW = 9;





void setup()
{
Serial.begin (9600);

pinMode (wiperSensePin, INPUT_PULLUP);
pinMode (wiperControlPin, INPUT_PULLUP);

pinMode (enablePin, OUTPUT); //for PWM speed via enable pin
pinMode(PWMpinCW, OUTPUT);
pinMode(PWMpinCCW, OUTPUT);
pinMode (ledCW, OUTPUT);
pinMode (ledCCW, OUTPUT);
}

//direction
void CW()
{
digitalWrite(PWMpinCW, HIGH);
digitalWrite(PWMpinCCW, LOW );
digitalWrite (ledCW, HIGH);
digitalWrite (ledCCW, LOW);
}
void CCW()
{
digitalWrite(PWMpinCW, LOW);
digitalWrite(PWMpinCCW, HIGH);
digitalWrite (ledCW, LOW);
digitalWrite (ledCCW, HIGH);
}
void allStop()
{
analogWrite (enablePin, 0);
digitalWrite(PWMpinCW, LOW);
digitalWrite(PWMpinCCW, LOW );
digitalWrite (ledCW, LOW);
digitalWrite (ledCCW, LOW);
}


volatile int controlVal = 0;
volatile int senseVal = 0;
volatile int error = 0;

void loop()
{

controlVal = analogRead (wiperControlPin);
senseVal = analogRead (wiperSensePin);
error = map((controlVal - senseVal), 0, 1023, 0, 70); // (lower "70" value if oscillation occurs)
error = min(error, 55);

for (int i = 0; i < 200; i++) // accelerate
{
analogWrite(enablePin, (i + error));
}
for (int i = 199; i >= 0; i--) //decelerate
{
analogWrite(enablePin, (i + error));
}
if(controlVal > senseVal && error >abs(1))

{
CW();
}
else if ( controlVal < senseVal)

{
CCW();
}

else if (error < abs(1))
{
allStop();
//delay(10);
}
Serial.println (senseVal);


}

andrewferg
Автор

Looks great, your work is so neat and tidy 😊👍

GrandadsOtherChannel
Автор

Please tell me more information about each device and how to connect it.

majareboom
Автор

How to control that using digital signals.

shubhamankush