Connection between Arduino and servo motor

The connection of the servo motor using Arduino is as follows:

Connect the black wires on the two servo motors to the GND on the Arduino

Connect the red wires on the two servo motors to the 5V pin on the Arduino

Connect the yellow wire on the first motor to pin 8 on the Arduino

Connect the yellow wire on the second motor to pin 9 on the Arduino

servo motor,servo motor price list, servo motor online store

Sample source code:

#include "Servo.h"

#define PIN_SERVO 9

#define PIN_KNOB A0

Servo servo; // creates servo object to control the SG90 servo

int value_knob = 0; // will be used to store the value of the potentiometer/knob

int value_servo = 0; // will be used to control the servo => should be between 5 and 175 degrees

void setup()

{

  servo.attach(PIN_SERVO); // assigns pin 9 to the servo object

}

void loop()

{

  value_knob = analogRead(PIN_KNOB); // reads value of the knob/potentiometer. Return value will be between 0 and 1023.

  value_servo = map(value_knob, 0, 1023, 5, 175); // will map knob value range to servo value range

  servo.write(value_servo); // shaft of servo will start to rotate. value_servo is interpreted as an absolute position.

  delay(20); // give servo some time to rotate

}

 

Recent related posts

Customers frequently viewed

New In stock for sale, IWAYA DENKI Water Pump 25CJT0752

IWAYA DENKI Water Pump 25CJT0752

US$2307.69
New In stock for sale, ROTEN Mechanical Seal 8E5K-22-X

ROTEN Mechanical Seal 8E5K-22-X

US$384.62
New In stock for sale, NSK Bearing 16020

NSK Bearing 16020

US$184.62
New In stock for sale, Moog Servo Valve D663Z703F

Moog Servo Valve D663Z703F

Contact Us
New In stock for sale, CKD Air Cylinder SRL3-00-32B-820

CKD Air Cylinder SRL3-00-32B-820

Contact Us
New In stock for sale, Fans-tech Fan R2S175-AB56-01

Fans-tech Fan R2S175-AB56-01

Contact Us
New In stock for sale, Omron PLC CS1W-AD081-V1

Omron PLC CS1W-AD081-V1

US$2300.00
New In stock for sale, HYSEIKO Linear Guideway RM30FA

HYSEIKO Linear Guideway RM30FA

US$33.98
New In stock for sale, Beckhoff Module ES3702

Beckhoff Module ES3702

US$561.54