Thursday, July 7, 2022

tinkercad pwm + servo


 Servo motor works on PWM (Pulse width modulation) principle, means its angle of rotation is controlled by the duration of applied pulse to its Control PIN. Basically servo motor is made up of DC motor which is controlled by a variable resistor (potentiometer) and some gears. High speed force of DC motor is converted into torque by Gears. We know that WORK= FORCE X DISTANCE, in DC motor Force is less and distance (speed) is high and in Servo, force is High and distance is less.

Servo checks the pulse in every 20 milliseconds. The pulse of 1 ms (1 millisecond) width can rotate the servo to 0 degrees, 1.5ms can rotate to 90 degrees (neutral position) and 2 ms pulse can rotate it to 180 degree.

-------------------
int value = 0;
int angle = 0;

void setup()
{
   pinMode(11, OUTPUT);
   TCCR2A = _BV(COM2A1) | _BV(WGM20);
   TCCR2B = _BV(CS22)| _BV(CS22);
   OCR2A = 255;
}

void loop()
{
   value = analogRead(A0);
   angle = map(value, 0, 1023, 60, 255);
   OCR2A = angle;
}

reference:

pmw

No comments:

Post a Comment