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, ABB Circuit Breaker 10236169

ABB Circuit Breaker 10236169

US$19.53
New In stock for sale, Togami Contactor PAK-8JS22

Togami Contactor PAK-8JS22

US$120.75
New In stock for sale, HYUNDAI Contactor HMX40

HYUNDAI Contactor HMX40

US$346.15
New In stock for sale, Dynapar Encoder H220100100245

Dynapar Encoder H220100100245

US$115.38
New In stock for sale, KEYENCE Light Curtain SL-V71F

KEYENCE Light Curtain SL-V71F

Contact Us
New In stock for sale, GMCC Compressor EKTF310D43UMT

GMCC Compressor EKTF310D43UMT

US$1692.31
New In stock for sale, Sanyo Denki Fan 9GA0612H1021

Sanyo Denki Fan 9GA0612H1021

US$17.51