Control a hobby servo motor’s angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.
Drive Servo Motor using PWM on GLYPH-C6
Introduction
What is a Servo Motor and its Working PricipleA Servo Motor is a rotary or linear actuator designed for precise control of angular or linear position, velocity, and acceleration. It consists of a DC or AC motor, a position sensor (usually a potentiometer or encoder), and a control circuit.The motor’s position is controlled by varying the width of a Pulse Width Modulated (PWM) signal.A Servo Motor consists of a Motor (DC or AC), a potentiometer, gear assembly, and a controlling circuit. First of all, we use gear assembly to reduce RPM(Revolutions Per Minute) and to increase torque of the motor. Say at initial position of servo motor shaft, the position of the potentiometer knob is such that there is no electrical signal generated at the output port of the potentiometer. Now an electrical signal is given to another input terminal of the error detector amplifier. Now the difference between these two signals, one comes from the potentiometer and another comes from other sources, will be processed in a feedback mechanism and output will be provided in terms of error signal. This error signal acts as the input for motor and motor starts rotating. Now motor shaft is connected with the potentiometer and as the motor rotates so the potentiometer and it will generate a signal. So as the potentiometer’s angular position changes, its output feedback signal changes. After sometime the position of potentiometer reaches at a position that the output of potentiometer is same as external signal provided. At this condition, there will be no output signal from the amplifier to the motor input as there is no difference between external applied signal and the signal generated at potentiometer, and in this situation motor stops rotating.This guide will help you interface a Servo Motor with GLYPH-C6 board using PWM to control its angular position.Key Features of Servo Motors:
Closed-loop Control: Uses feedback from the position sensor to adjust movement for high accuracy.
High Torque & Precision: Can maintain a set position accurately.
Controlled via PWM: Typically controlled using a Pulse Width Modulation (PWM) signal in hobby applications.
Gearing System: Often includes a gearbox to reduce speed and increase torque.
Types of Servo Motors:
AC Servo Motors: Used in industrial automation, robotics, and CNC machines. High efficiency and accuracy.
DC Servo Motors: Common in robotics, RC cars, and consumer electronics. Cheaper but require more maintenance.
Stepper-based Servo Motors: Combine stepper motor principles with closed-loop feedback.
Linear Servo Motors: Provide linear motion rather than rotational.
Applications of Servo Motors:✅Robotics – Used for arm movement, humanoid robots, and industrial automation.
✅CNC Machines – Provide precise positioning for cutting, milling, and machining.
✅Drones & RC Vehicles – Control steering, flaps, and other movable parts.
✅Medical Equipment – Used in surgical robots and precision medical devices.
Step 1: Hardware Required
GLYPH C6
Servo Motor (e.g., SG90 or MG995)
External Power Source (if required by the servo)
Male-to-Male Jumper Wires
Breadboard (optional)
Male to Male Jumper Wires (If you use just the servo motor)
Step 2: Circuit Diagram
Connect the servo motor to the GLYPH-C6 as follows
VCC (Red wire) → Connect to 3.3V or 5V of the GLYPH-C6 (depending on servo power requirements).
GND (Black/Brown wire) → Connect to GND of the GLYPH-C6.
Signal (Yellow/Orange wire) → Connect to GPIO6 (or any PWM-capable pin on GLYPH-C6).
Step 3: Code Setup
Open Arduino IDE
Install the Necessary Libraries
Open Arduino IDE and navigate to Sketch > Include Library > Manage Libraries. Search for ESP32Servo and install the library by Kevin Harrington.
Enter the following code into the Arduino IDE
Arduino Code
CircuitPython Code
#include <ESP32Servo.h> // Include the ESP32 Servo libraryServo myServo; // Create a Servo object#define SERVO_PIN 6 // Use any PWM-capable GPIO on GLYPH-C6void setup() { Serial.begin(115200); // Start serial communication myServo.attach(SERVO_PIN); // Attach the servo to the defined pin}void loop() { // Move servo from 0° to 180° for (int pos = 0; pos <= 180; pos += 5) { myServo.write(pos); Serial.print("Servo Position: "); Serial.println(pos); delay(15); // Adjust delay for smoother motion } // Move servo from 180° back to 0° for (int pos = 180; pos >= 0; pos -= 5) { myServo.write(pos); Serial.print("Servo Position: "); Serial.println(pos); delay(15); }}
Connect the servo signal to GPIO6. Supply the servo from a suitable external source if it draws more current than the board can provide, and connect the supply ground to GLYPH GND.Follow the CircuitPython setup guide and save this example as code.py on the board.
Select the Board and Port
Do the following settings in your Arduino IDE,
Do the following settings in your Arduino IDE,
Tools > Board > esp32 > Pcbcupid GLYPH C6
For the Pcbcupid GLYPH C6 to appear under Tools > Board > esp32, the esp32 board version installed in the Arduino IDE should be greater than or equal to 3.1.0.
Tools > Port and select the port connected to your GLYPH.
Tools > USB CDC on Boot >Enabled
If USB CDC on BOOT not enabled, you won’t be seeing any serial data on Arduino IDE.
Upload the Code
Click the upload button (➡️ icon) or use the shortcut CTRL + U in Arduino IDE to upload the code to the board.
Step 5: Observe the Output
After uploading the code, open the Serial Monitor (Tools > Serial Monitor) and set the baud rate to 115200.You should see the servo motor moving back and forth from 0° to 180° and back, with the position being printed on the Serial Monitor.(If your servo does not move, check the wiring and ensure your power supply is sufficient for the servo’s requirements).
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"PCB Cupid","colors":{"primary":"#0D9373"},"favicon":"https://mintcdn.com/pcbcupid-bae3761c/4dXNuJjZhqL5zqVd/images/favicon_PCBcupid.png?fit=max\u0026auto=format\u0026n=4dXNuJjZhqL5zqVd\u0026q=85\u0026s=697c4189e0a983e1722bddbedde79f61","appearance":{"strict":true},"background":{"decoration":"gradient"},"navbar":{"links":[{"href":"https://spell.pcbcupid.com","label":"Circuit Spell"},{"href":"https://shop.pcbcupid.com","label":"Shop"},{"href":"/","label":"Learn"},{"href":"https://events.pcbcupid.com","label":"Events"},{"href":"https://forum.pcbcupid.com","label":"Forum"},{"href":"https://pcbcupid.com/articles","label":"Articles"},{"href":"https://pcbcupid.com/tools","label":"Tools"}]},"seo":{"indexing":"all"},"fonts":{"family":"Space Grotesk","weight":400},"icons":{"library":"lucide"},"styling":{"eyebrows":"breadcrumbs","latex":true},"contextual":{"options":["copy","chatgpt","claude","cursor","vscode","mcp"],"display":"toc"},"thumbnails":{"appearance":"dark"},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"pcbcupid-bae3761c","hasAudioNarration":false,"actualSubdomain":"pcbcupid-bae3761c","customDomains":["learn.pcbcupid.com"],"gitSource":{"type":"github","owner":"pcbcupid","repo":"pcbcupid-docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"feedback":{"thumbs":true,"edits":true,"issues":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6ae268427b458a5c875a9a81","clientVersion":"0.0.4177","searchFilterCounts":[{"language":"default","tag":"Documentation","count":77},{"language":"default","tag":"Modules","count":67},{"language":"default","tag":"PCB Design","count":45},{"language":"default","tag":"Examples","count":32},{"language":"default","tag":"Glyph","count":25},{"language":"default","tag":"G-Mod","count":17},{"language":"default","tag":"KiCad","count":16},{"language":"default","tag":"Basic","count":15},{"language":"default","tag":"Welcome","count":9},{"language":"default","tag":"G-Sense","count":8}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":true},"customCss":[],"page":{"pagePath":"guides/servo-motor-with-glyph-c6","slug":"/guides/servo-motor-with-glyph-c6","pageMetadata":{"description":"Control a hobby servo motor's angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.","title":"Servo Motor Control with Glyph C6","sidebarTitle":"Servo Motor","href":"/guides/servo-motor-with-glyph-c6"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Control a hobby servo motor’s angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,img:`img`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,OptimizedFrame,Tab,Tabs,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!OptimizedFrame)_missingMdxReference(`OptimizedFrame`,true);if(!Tab)_missingMdxReference(`Tab`,true);if(!Tabs)_missingMdxReference(`Tabs`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(OptimizedFrame,{className:`mint-w-full mint-aspect-video mint-rounded-xl`,src:`https://www.youtube.com/embed/UuSVqxvMGNs?si=Mtn2T2f0mXFZXjZJ`,title:`YouTube video player`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:true}),`\n`,_jsx(Heading,{level:`1`,id:`drive-servo-motor-using-pwm-on-glyph-c6`,children:`Drive Servo Motor using PWM on GLYPH-C6`}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/servo_motor/PCBCUPID_servomotor2.avif`,alt:`pcbcupid_servo_motor2`})}),`\n`,_jsx(Heading,{level:`2`,id:`introduction`,children:`Introduction`}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`What is a Servo Motor and its Working Priciple`})}),`\n`,_jsxs(_components.p,{children:[`A `,_jsx(_components.strong,{children:`Servo Motor`}),` is a rotary or linear actuator designed for precise control of angular or linear position, velocity, and acceleration. It consists of a DC or AC motor, a position sensor (usually a potentiometer or encoder), and a control circuit.The motor’s position is controlled by varying the width of a Pulse Width Modulated (PWM) signal.`]}),`\n`,_jsx(_components.p,{children:`A Servo Motor consists of a Motor (DC or AC), a potentiometer, gear assembly, and a controlling circuit. First of all, we use gear assembly to reduce RPM(Revolutions Per Minute) and to increase torque of the motor. Say at initial position of servo motor shaft, the position of the potentiometer knob is such that there is no electrical signal generated at the output port of the potentiometer. Now an electrical signal is given to another input terminal of the error detector amplifier. Now the difference between these two signals, one comes from the potentiometer and another comes from other sources, will be processed in a feedback mechanism and output will be provided in terms of error signal. This error signal acts as the input for motor and motor starts rotating. Now motor shaft is connected with the potentiometer and as the motor rotates so the potentiometer and it will generate a signal. So as the potentiometer’s angular position changes, its output feedback signal changes. After sometime the position of potentiometer reaches at a position that the output of potentiometer is same as external signal provided. At this condition, there will be no output signal from the amplifier to the motor input as there is no difference between external applied signal and the signal generated at potentiometer, and in this situation motor stops rotating.`}),`\n`,_jsxs(_components.p,{children:[`This guide will help you interface a Servo Motor with `,_jsx(_components.a,{href:`https://shop.pcbcupid.com/product/gd002/`,children:`GLYPH-C6`}),` board using PWM to control its angular position.`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Key Features of Servo Motors:`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Closed-loop Control: Uses feedback from the position sensor to adjust movement for high accuracy.`}),`\n`,_jsx(_components.li,{children:`High Torque \u0026 Precision: Can maintain a set position accurately.`}),`\n`,_jsx(_components.li,{children:`Controlled via PWM: Typically controlled using a Pulse Width Modulation (PWM) signal in hobby applications.`}),`\n`,_jsx(_components.li,{children:`Gearing System: Often includes a gearbox to reduce speed and increase torque.`}),`\n`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Types of Servo Motors:`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`AC Servo Motors: Used in industrial automation, robotics, and CNC machines. High efficiency and accuracy.`}),`\n`,_jsx(_components.li,{children:`DC Servo Motors: Common in robotics, RC cars, and consumer electronics. Cheaper but require more maintenance.`}),`\n`,_jsx(_components.li,{children:`Stepper-based Servo Motors: Combine stepper motor principles with closed-loop feedback.`}),`\n`,_jsx(_components.li,{children:`Linear Servo Motors: Provide linear motion rather than rotational.`}),`\n`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Applications of Servo Motors:`})}),`\n`,_jsx(_components.p,{children:`✅Robotics – Used for arm movement, humanoid robots, and industrial automation.\n✅CNC Machines – Provide precise positioning for cutting, milling, and machining.\n✅Drones \u0026 RC Vehicles – Control steering, flaps, and other movable parts.\n✅Medical Equipment – Used in surgical robots and precision medical devices.`}),`\n`,_jsx(Heading,{level:`2`,id:`step-1-hardware-required`,children:`Step 1: Hardware Required`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`GLYPH C6`}),`\n`,_jsx(_components.li,{children:`Servo Motor (e.g., SG90 or MG995)`}),`\n`,_jsx(_components.li,{children:`External Power Source (if required by the servo)`}),`\n`,_jsx(_components.li,{children:`Male-to-Male Jumper Wires`}),`\n`,_jsx(_components.li,{children:`Breadboard (optional)`}),`\n`,_jsx(_components.li,{children:`Male to Male Jumper Wires (If you use just the servo motor)`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`step-2-circuit-diagram`,children:`Step 2: Circuit Diagram`}),`\n`,_jsx(_components.p,{children:`Connect the servo motor to the GLYPH-C6 as follows`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`VCC (Red wire)`}),` → Connect to 3.3V or 5V of the GLYPH-C6 (depending on servo power requirements).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`GND (Black/Brown wire)`}),` → Connect to GND of the GLYPH-C6.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Signal (Yellow/Orange wire)`}),` → Connect to GPIO6 (or any PWM-capable pin on GLYPH-C6).`]}),`\n`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/servo_motor/PCBCUPID_servomotor_circuitdiagram.avif`,alt:`pcbcupid_servo_motor_circuit`})}),`\n`,_jsx(Heading,{level:`2`,id:`step-3-code-setup`,children:`Step 3: Code Setup`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Open Arduino IDE`})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Install the Necessary Libraries`}),`\nOpen Arduino IDE and navigate to `,_jsx(_components.code,{children:`Sketch > Include Library > Manage Libraries`}),`. Search for `,_jsx(_components.code,{children:`ESP32Servo`}),` and install the library by Kevin Harrington.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Enter the following code into the Arduino IDE`})}),`\n`]}),`\n`]}),`\n`,_jsxs(Tabs,{children:[_jsx(Tab,{title:`Arduino Code`,id:`arduino-code`,children:_jsx(CodeBlock,{filename:``,numberOfLines:`29`,language:`cpp`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`cpp`,children:_jsxs(_components.code,{language:`cpp`,numberOfLines:`29`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#include`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \u003cESP32Servo.h>`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Include the ESP32 Servo library`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`Servo myServo;`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Create a Servo object`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`#define`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#569CD6`},children:` SERVO_PIN`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 6`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Use any PWM-capable GPIO on GLYPH-C6`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` setup`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`begin`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`115200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Start serial communication`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` myServo`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`attach`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(SERVO_PIN);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Attach the servo to the defined pin`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`void`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` loop`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Move servo from 0° to 180°`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pos `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; pos `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u003c=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 180`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; pos `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` myServo`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`write`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(pos);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Servo Position: \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`println`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(pos);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` delay`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`15`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Adjust delay for smoother motion`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Move servo from 180° back to 0°`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pos `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 180`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; pos `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; pos `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` myServo`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`write`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(pos);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Servo Position: \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Serial`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`println`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(pos);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` delay`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`15`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`]})})})}),_jsxs(Tab,{title:`CircuitPython Code`,id:`circuitpython-code`,children:[_jsx(_components.p,{children:`Connect the servo signal to GPIO6. Supply the servo from a suitable external source if it draws more current than the board can provide, and connect the supply ground to GLYPH GND.`}),_jsxs(_components.p,{children:[`Follow the `,_jsx(_components.a,{href:`/documentation/welcome/prerequisites/circuitpython-setup-guide`,children:`CircuitPython setup guide`}),` and save this example as `,_jsx(_components.code,{children:`code.py`}),` on the board.`]}),_jsx(CodeBlock,{filename:``,numberOfLines:`19`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`19`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` time`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` microcontroller`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pwmio`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`servo `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pwmio.PWMOut(microcontroller.pin.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`GPIO6`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`frequency`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`50`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` set_angle`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`angle`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pulse_us `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` angle `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` //`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 180`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` servo.duty_cycle `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pulse_us `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`*`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 65535`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` //`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 20000`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`while`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` angle `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` range`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`181`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` set_angle(angle)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Servo Position:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, angle)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` time.sleep(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0.05`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` angle `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` range`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`180`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` set_angle(angle)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Servo Position:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, angle)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` time.sleep(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0.05`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`step-4-upload-the-code`,children:`Step 4: Upload the Code`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.strong,{children:`Connect the Board`})}),`\n`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Connect your GLYPH board to your computer`}),`\n`]}),`\n`,_jsxs(_components.ol,{start:`2`,children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Select the Board and Port`}),`\nDo the following settings in your Arduino IDE,\nDo the following settings in your Arduino IDE,`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.code,{children:`Tools > Board > esp32 > Pcbcupid GLYPH C6`})}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`For the `,_jsx(_components.code,{children:`Pcbcupid GLYPH C6 `}),` to appear under `,_jsx(_components.code,{children:`Tools > Board > esp32`}),`, the esp32 board version installed in the Arduino IDE should be greater than or equal to 3.1.0.`]})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`Tools > Port`}),` and select the port connected to your GLYPH.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`Tools > USB CDC on Boot >`}),` `,_jsx(_components.em,{children:_jsx(_components.strong,{children:`Enabled`})})]}),`\n`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`If `,_jsx(_components.code,{children:`USB CDC on BOOT`}),` not enabled, you won’t be seeing any serial data on Arduino IDE.`]})}),`\n`,_jsxs(_components.ol,{start:`3`,children:[`\n`,_jsx(_components.li,{children:_jsx(_components.strong,{children:`Upload the Code`})}),`\n`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Click the upload button (➡️ icon) or use the shortcut `,_jsx(_components.code,{children:`CTRL + U`}),` in Arduino IDE to upload the code to the board.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`step-5-observe-the-output`,children:`Step 5: Observe the Output`}),`\n`,_jsx(_components.p,{children:`After uploading the code, open the Serial Monitor (Tools > Serial Monitor) and set the baud rate to 115200.`}),`\n`,_jsx(_components.p,{children:`You should see the servo motor moving back and forth from 0° to 180° and back, with the position being printed on the Serial Monitor.(If your servo does not move, check the wiring and ensure your power supply is sufficient for the servo’s requirements).`}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/servo_motor/PCBCUPID_servomotor_turn_compressed.gif`,alt:`pcbcupid_servo_motor_turn`})}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/servo_motor/PCBCUPID_servo_motor_serialmon_low_angle.avif`,alt:`pcbcupid_servo_motor_serialmon_lowangle`})}),`\n`,_jsx(_components.p,{children:_jsx(_components.img,{src:`https://files.pcbcupid.com/Documentation/Boards/Examples/servo_motor/PCBCUPID_servo_motor_serialmon_high_angle.avif`,alt:`pcbcupid_glyph_intro-led_changebrightnesswithPot`})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"description":"Control a hobby servo motor's angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.","title":"Servo Motor Control with Glyph C6","sidebarTitle":"Servo Motor","href":"/guides/servo-motor-with-glyph-c6"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Drive Servo Motor using PWM on GLYPH-C6","slug":"drive-servo-motor-using-pwm-on-glyph-c6","depth":1,"children":[]},{"title":"Introduction","slug":"introduction","depth":2,"children":[]},{"title":"Step 1: Hardware Required","slug":"step-1-hardware-required","depth":2,"children":[]},{"title":"Step 2: Circuit Diagram","slug":"step-2-circuit-diagram","depth":2,"children":[]},{"title":"Step 3: Code Setup","slug":"step-3-code-setup","depth":2,"children":[]},{"title":"Step 4: Upload the Code","slug":"step-4-upload-the-code","depth":2,"children":[]},{"title":"Step 5: Observe the Output","slug":"step-5-observe-the-output","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"dynamicCss":".mint-aspect-video {\n aspect-ratio: 16 / 9\n}\n.mint-w-full {\n width: 100%\n}\n.mint-rounded-xl {\n border-radius: 0.75rem\n}","subdomain":"pcbcupid-bae3761c","siteName":"PCB Cupid","title":"Servo Motor Control with Glyph C6 - PCB Cupid","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-17T08:18:02.758Z","originalFileLocation":"guides/servo-motor-with-glyph-c6.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Control a hobby servo motor\u0026#x27;s angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.\">\u003cmeta data-mint-head name=\"application-name\" content=\"PCB Cupid\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Servo Motor Control with Glyph C6 - PCB Cupid\">\u003cmeta data-mint-head property=\"og:description\" content=\"Control a hobby servo motor\u0026#x27;s angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"PCB Cupid\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://pcbcupid-bae3761c.mintlify.site/_mintlify/api/og/v2?division=Basic\u0026amp;title=Servo+Motor+Control+with+Glyph+C6\u0026amp;description=Control+a+hobby+servo+motor%27s+angle+using+PWM+on+the+Glyph+ESP32-C6+development+board+with+the+ESP32Servo+Arduino+library+and+wiring+diagram.\u0026amp;theme=2c7e3818cca0f9e7f4434aa9\u0026amp;signature=789aaa7ba0fde35a69d8a64ee7431cb858295d919ef35ad3a4047a1b5cf7cca6\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Servo Motor Control with Glyph C6 - PCB Cupid\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Control a hobby servo motor\u0026#x27;s angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://pcbcupid-bae3761c.mintlify.site/_mintlify/api/og/v2?division=Basic\u0026amp;title=Servo+Motor+Control+with+Glyph+C6\u0026amp;description=Control+a+hobby+servo+motor%27s+angle+using+PWM+on+the+Glyph+ESP32-C6+development+board+with+the+ESP32Servo+Arduino+library+and+wiring+diagram.\u0026amp;theme=2c7e3818cca0f9e7f4434aa9\u0026amp;signature=789aaa7ba0fde35a69d8a64ee7431cb858295d919ef35ad3a4047a1b5cf7cca6\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/pcbcupid-bae3761c/TFd0Eu1csuxrLpjH/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"PCB Cupid\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#0D9373\">\u003clink data-mint-head rel=\"canonical\" href=\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/guides/servo-motor-with-glyph-c6.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://learn.pcbcupid.com/#organization\",\"name\":\"PCB Cupid\",\"url\":\"https://learn.pcbcupid.com\"},{\"@type\":\"WebSite\",\"@id\":\"https://learn.pcbcupid.com#website\",\"name\":\"PCB Cupid\",\"url\":\"https://learn.pcbcupid.com\",\"publisher\":{\"@id\":\"https://learn.pcbcupid.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6#webpage\",\"url\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6\",\"name\":\"Servo Motor Control with Glyph C6\",\"description\":\"Control a hobby servo motor's angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.\",\"dateModified\":\"2026-10-17T08:18:02.758Z\",\"isPartOf\":{\"@id\":\"https://learn.pcbcupid.com#website\"},\"breadcrumb\":{\"@id\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Basic\",\"item\":\"https://learn.pcbcupid.com/guides/arduino-ide-blink-led\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Servo Motor Control with Glyph C6\",\"item\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6#article\",\"headline\":\"Servo Motor Control with Glyph C6\",\"name\":\"Servo Motor Control with Glyph C6\",\"description\":\"Control a hobby servo motor's angle using PWM on the Glyph ESP32-C6 development board with the ESP32Servo Arduino library and wiring diagram.\",\"url\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6\",\"mainEntityOfPage\":{\"@id\":\"https://learn.pcbcupid.com/guides/servo-motor-with-glyph-c6#webpage\"},\"dateModified\":\"2026-10-17T08:18:02.758Z\",\"publisher\":{\"@id\":\"https://learn.pcbcupid.com/#organization\"},\"isPartOf\":{\"@id\":\"https://learn.pcbcupid.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"PCB Cupid\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"PCB Cupid\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/guides/servo-motor-with-glyph-c6.md","siteName":"PCB Cupid","nav":{"global":null,"tabs":[{"tab":"Documentation","pages":[{"title":"Documentation","href":""}]},{"tab":"Examples","pages":[{"group":"Basic","pages":[{"title":"Blink LED","sidebarTitle":"Blink LED","href":"/guides/arduino-ide-blink-led"},{"title":"Analog Input and Output","sidebarTitle":"Reading Analog Input","href":"/guides/reading-analoginput"},{"title":"Battery Voltage Measurement","sidebarTitle":"Battery Measurement","href":"/guides/battery-measurement"},{"title":"I2C Scanner","sidebarTitle":"I2C Scanner","href":"/guides/i2c-scan-test"},{"title":"BH1750 Adafruit Sensor","sidebarTitle":"BH1750 Sensor","href":"/guides/bh1750adafruit-compatibility"},{"title":"Parallel LCD Display","sidebarTitle":"Parallel LCD","href":"/guides/lcd"},{"title":"I2C LCD Display","sidebarTitle":"I2C LCD","href":"/guides/lcd-i2c"},{"description":"Read direction, position, and button presses from a rotary encoder on the Glyph ESP32-C6 board using interrupts and example Arduino code.","title":"Rotary Encoder with Glyph ESP32-C6","sidebarTitle":"Rotary Encoder","href":"/guides/rotor-encoder-with-glyph-c6"},{"title":"Servo Motor Control with Glyph C6","sidebarTitle":"Servo Motor","href":"/guides/servo-motor-with-glyph-c6"},{"description":"Drive a bipolar stepper motor at variable speeds using the DRV8833 motor driver and a Glyph ESP32 board with example Arduino code and wiring.","title":"Stepper Motor","sidebarTitle":"Stepper Motor","href":"/guides/stepper-motor-with-drv8833"},{"title":"OpenWeatherMap REST API","sidebarTitle":"REST API Weather","href":"/guides/temperature-monitoring-using-glyph"},{"title":"OLED Display Test","sidebarTitle":"OLED Display","href":"/guides/display-test"},{"title":"REST API Weather on SH1106 OLED","sidebarTitle":"REST API Weather with OLED","href":"/guides/temperaturemonitoring-glyph+sh1106oled"},{"title":"DHT Sensor One-Wire Communication","sidebarTitle":"DHT Sensor One-Wire","href":"/guides/dht-onewire-communication"},{"title":"Unipolar Stepper Motor (28BYJ-48)","sidebarTitle":"Unipolar Stepper Motor","href":"/guides/unipolar-stepper-motor"}]},{"group":"Kits","pages":[{"title":"Beginner Kit with GLYPH-C6","sidebarTitle":"Beginner Kit","href":"/guides/kits/beginner-kit"},{"title":"GLYPH Voice Kit","sidebarTitle":"GLYPH Voice Kit","href":"/guides/kits/glyph-voice"},{"title":"GLYPH MIDI Controller Kit","sidebarTitle":"GLYPH MIDI Controller","href":"/guides/kits/glyph-midi-controller"},{"title":"GLYPH Tank Kit","sidebarTitle":"GLYPH Tank Kit","href":"/guides/kits/glyph-tank"}]},{"group":"AI","pages":[{"title":"ESP32-C3 Voice Chatbot","sidebarTitle":"Voice Chatbot","href":"/guides/ai/esp32-c3-voice-chatbot"},{"title":"Z-Claw AI","sidebarTitle":"Z-Claw AI","href":"/guides/ai/z-claw"},{"title":"Edge Impulse Gesture Recognition","sidebarTitle":"Edge Impulse","href":"/guides/ai/edge-impulse"}]},{"group":"Basic Sensors","pages":[{"title":"HC-SR04 Ultrasonic Sensor","sidebarTitle":"Ultrasonic Sensor","href":"/guides/basic-sensors/ultrasonic-sensor"},{"title":"Flame Sensor Test","sidebarTitle":"Flame Sensor","href":"/guides/basic-sensors/flame-sensor"},{"title":"IR Sensor","sidebarTitle":"IR Sensor","href":"/guides/basic-sensors/infrared-sensor"},{"title":"LDR Light Sensor","sidebarTitle":"LDR Light Sensor","href":"/guides/basic-sensors/ldr"},{"title":"MQ2 Gas Sensor","sidebarTitle":"MQ2 Gas Sensor","href":"/guides/basic-sensors/mq2-sensor"},{"title":"Touch Sensor (TTP223)","sidebarTitle":"Touch Sensor","href":"/guides/basic-sensors/touch-sensor"}]},{"group":"Bluetooth","pages":[{"title":"BLE Server Demo","sidebarTitle":"BLE Server","href":"/guides/bluetooth/bluetoothglyph"}]},{"group":"WiFi","pages":[{"title":"Control a Dual Relay over Wi-Fi","sidebarTitle":"Wi-Fi Dual Relay","href":"/guides/wifi/local-webserver-to-control-relay"},{"title":"Create a Wi-Fi Access Point on Glyph","sidebarTitle":"Wi-Fi Access Point","href":"/guides/wifi/wifiaccess-point"}]},{"group":"Zigbee","pages":[{"title":"Arduino Zigbee Blink: C6 to H2","sidebarTitle":"Zigbee Blink","href":"/guides/zigbee/arduino-zigbee-blink"}]}]},{"tab":"PCB Design","pages":[{"title":"PCB Design","href":"/pcb-design/design/kicad/introduction-on-kicad"}]}]},"basePath":"","title":"Servo Motor Control with Glyph C6 - PCB Cupid","deploymentId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","buildId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","dynamics":["a74be98ba7"],"chunks":["zoom-image-lightbox-DQG3o8Eu.js","lightbox-handle-r17bVUz3.js"]}