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, AirTAC Air Cylinder SGC250X225S

AirTAC Air Cylinder SGC250X225S

US$661.08
New In stock for sale, WALRUS Water Pump TPHK4T6-3

WALRUS Water Pump TPHK4T6-3

US$1000.00
New In stock for sale, CKD Air Cylinder CMK2-00-20-80

CKD Air Cylinder CMK2-00-20-80

Contact Us
New In stock for sale, IDEC Relay RJ1S-CLD-D12

IDEC Relay RJ1S-CLD-D12

US$7.33
New In stock for sale, Eaton Contactor CN15BN3R1B

Eaton Contactor CN15BN3R1B

Contact Us
New In stock for sale, SUNX Sensor EQ-501

SUNX Sensor EQ-501

US$1025.00
New In stock for sale, IVZ Bearing 61840 Iron cage

IVZ Bearing 61840 Iron cage

Contact Us
New In stock for sale, Littelfuse Fuse JTD30

Littelfuse Fuse JTD30

US$34.50