<h1 class="title is-3 is-size-4-mobile" style="box-sizing: inherit; margin: 50px 0px 1.5rem; padding: 0px; word-break: break-word; color: #363636; line-height: 1.125; letter-spacing: -1.4px; font-family: &quot;Gowun Batang&quot;, Ubuntu, Roboto, &quot;Open Sans&quot;, &quot;Microsoft YaHei&quot;, sans-serif; background-color: #ffffff;">esp32 서보모터 PWM제어</h1>
<div class="content" style="box-sizing: inherit; margin-bottom: 1.5rem; overflow-wrap: break-word; font-size: 1.3rem; line-height: 1.75em; letter-spacing: -0.3px; color: #5d686f; margin-top: 20px; font-family: &quot;Gowun Batang&quot;, Ubuntu, Roboto, &quot;Open Sans&quot;, &quot;Microsoft YaHei&quot;, sans-serif; background-color: #ffffff;">
   <h3 id="SG90-MG90S-MG966R-서보모터" style="box-sizing: inherit; margin: 0px 0px 0.6666em; padding: 0px; font-size: 1.5em; font-weight: 400; color: #363636; line-height: 1.125; scroll-margin: 1em;"><a href="https://stemwith.github.io/2020/10/19/ESP32-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0-%EC%A0%9C%EC%96%B4/#SG90-MG90S-MG966R-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0" class="headerlink" title="SG90, MG90S,  MG966R 서보모터" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"></a>SG90, MG90S, MG966R 서보모터</h3>
   <h4 id="datasheet" style="box-sizing: inherit; margin: 0px 0px 0.8em; padding: 0px; font-size: 1.25em; font-weight: 400; color: #363636; line-height: 1.125; scroll-margin: 1em;"><a href="https://stemwith.github.io/2020/10/19/ESP32-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0-%EC%A0%9C%EC%96%B4/#datasheet" class="headerlink" title="datasheet" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"></a>datasheet</h4>
   <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;"><a class="gallery-item" href="https://stemwith.github.io/image/SG90_Datasheet.jpg" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"><img src="https://stemwith.github.io/image/SG90_Datasheet.jpg" style="box-sizing: inherit; height: auto; max-width: 100%; margin-top: 30px;" /></a></p>
   <br style="box-sizing: inherit;" />
   <h4 id="사용법" style="box-sizing: inherit; margin: 0px 0px 0.8em; padding: 0px; font-size: 1.25em; font-weight: 400; color: #363636; line-height: 1.125; scroll-margin: 1em;"><a href="https://stemwith.github.io/2020/10/19/ESP32-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0-%EC%A0%9C%EC%96%B4/#%EC%82%AC%EC%9A%A9%EB%B2%95" class="headerlink" title="사용법" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"></a>사용법</h4>
   <ol style="box-sizing: inherit; margin: 1em 0px 1em 2em; padding: 0px; list-style-position: outside;">
      <li style="box-sizing: inherit; margin: 0px; padding: 0px;">
         <p style="box-sizing: inherit; padding: 0px;">ESP32는 16개의 PWM채널이 있으므로, 최대 16개의 서보모터를 동시에 제어할 수 있다.</p>
         </li>
      <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
         <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">서보모터 데이터 시트의 스펙상으로는…</p>
         <ul style="box-sizing: inherit; margin: 1em 0px 0px 2em; padding: 0px; list-style: outside disc;">
            <li style="box-sizing: inherit; margin: 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">대부분의 서보모터(<span style="box-sizing: inherit; color: #363636; font-weight: 700;">SG90, MG90S, MG966R</span>&nbsp;등 포함)는 위의 그림처럼 20ms가 1주기가 되므로, PWM frequency를 50Hz로 설정한다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">20ms가 1주기이고, HIGH 펄스가 2ms 지속될 때 180º 회전을 한다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">그러므로, 전체 펄스 폭의 1/10만큼 HIGH 펄스가 주어지면 180º 회전을 한다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">Resolution이 16비트라면 65535의 1/10에 해당하는&nbsp;<del style="box-sizing: inherit;">6554</del>의 값이 duty값으로 주어지면 서보모터는 180º 회전을 한다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;"><del style="box-sizing: inherit;">데이터 시트에 나온 스펙에 따라서, 16비트 해상도에서 duty값에 따른 회전 각도</del></p>
               <ul style="box-sizing: inherit; margin: 0.5em 0px 0px 2em; padding: 0px; list-style: outside circle;">
                  <li style="box-sizing: inherit; margin: 0px; padding: 0px;">
                     <p style="box-sizing: inherit; padding: 0px;"><del style="box-sizing: inherit;">PWM 5% : 3277 → 0º</del></p>
                     </li>
                  <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
                     <p style="box-sizing: inherit; padding: 0px;"><del style="box-sizing: inherit;">PWM 7.5% : 4915 → 90º</del></p>
                     </li>
                  <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
                     <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;"><del style="box-sizing: inherit;">PWM 10% : 6554 → 180º</del></p>
                     <p style="box-sizing: inherit; padding: 0px;">라고 생각했으나, 실제로는 이와 달랐다.</p>
                     </li>
                  </ul>
               </li>
            </ul>
         </li>
      <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
         <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;"><span style="box-sizing: inherit; color: #363636; font-weight: 700;">MG90S</span></p>
         <ul style="box-sizing: inherit; margin: 1em 0px 0px 2em; padding: 0px; list-style: outside disc;">
            <li style="box-sizing: inherit; margin: 0px; padding: 0px;">
               <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">16비트 해상도(0~65535)에서 duty값에 따른 회전 각도는</p>
               <ul style="box-sizing: inherit; margin: 0.5em 0px 0px 2em; padding: 0px; list-style: outside circle;">
                  <li style="box-sizing: inherit; margin: 0px; padding: 0px;">PWM 2.5% : 1639 → 0º</li>
                  <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">PWM 7.5% : 4915 → 90º</li>
                  <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">PWM 12.5% : 8191 → 180º</li>
                  </ul>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">즉, 각도에 따른 PWM값은 다음과 같이 지정한다.<br style="box-sizing: inherit;" /><span class="MathJax_Preview" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: inherit;"></span><span class="mjx-chtml MJXc-display" style="box-sizing: inherit; display: block; line-height: 0; text-align: center; font-size: 18.2px; letter-spacing: normal; overflow-wrap: normal; word-spacing: normal; text-wrap: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; margin: 1em 0px; padding: 0px;"><span id="MathJax-Element-1-Frame" class="mjx-chtml MathJax_CHTML" tabindex="0" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;><mi>P</mi><mi>W</mi><mi>M</mi><mo>=</mo><msup><mn>2</mn><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mn>16</mn></mrow></msup><mo>&amp;#x00D7;</mo><mn>0.1</mn><mo>&amp;#x00D7;</mo><mfrac><mrow><mi>a</mi><mi>n</mi><mi>g</mi><mi>l</mi><mi>e</mi></mrow><mn>180</mn></mfrac><mo>+</mo><msup><mn>2</mn><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mn>16</mn></mrow></msup><mo>&amp;#x00D7;</mo><mn>0.025</mn><mo>=</mo><msup><mn>2</mn><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mn>16</mn></mrow></msup><mo>&amp;#x00D7;</mo><mn>0.1</mn><mo>&amp;#x00D7;</mo><mo stretchy=&quot;false&quot;>(</mo><mfrac><mrow><mi>a</mi><mi>n</mi><mi>g</mi><mi>l</mi><mi>e</mi></mrow><mn>180</mn></mfrac><mo>+</mo><mn>0.25</mn><mo stretchy=&quot;false&quot;>)</mo></math>" role="presentation" style="box-sizing: inherit; display: inline-block; line-height: 0; font-size: 18.2px; overflow-wrap: normal; word-spacing: normal; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; margin: 0px; padding: 1px 0px; position: relative;"><span id="MJXc-Node-1" class="mjx-math" aria-hidden="true" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; display: inline-block; border-collapse: separate; border-spacing: 0px;"><span id="MJXc-Node-2" class="mjx-mrow" style="font-style: inherit; font-weight: inherit; display: inline-block; text-align: left; box-sizing: content-box !important;"><span id="MJXc-Node-3" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.442em; padding-bottom: 0.277em; padding-right: 0.109em; box-sizing: content-box !important;">P</span></span><span id="MJXc-Node-4" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.442em; padding-bottom: 0.277em; padding-right: 0.104em; box-sizing: content-box !important;">W</span></span><span id="MJXc-Node-5" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.442em; padding-bottom: 0.277em; padding-right: 0.081em; box-sizing: content-box !important;">M</span></span><span id="MJXc-Node-6" class="mjx-mo MJXc-space3" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.278em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.058em; padding-bottom: 0.332em; box-sizing: content-box !important;">=</span></span><span id="MJXc-Node-7" class="mjx-msubsup MJXc-space3" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.278em; box-sizing: content-box !important;"><span class="mjx-base" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-8" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.332em; box-sizing: content-box !important;">2</span></span></span><span class="mjx-sup" style="font-style: inherit; font-weight: inherit; display: inline-block; font-size: 12.8674px; vertical-align: 0.591em; padding-left: 0px; padding-right: 0.071em; box-sizing: content-box !important;"><span id="MJXc-Node-9" class="mjx-texatom" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-10" class="mjx-mrow" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-11" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">16</span></span></span></span></span></span><span id="MJXc-Node-12" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.223em; padding-bottom: 0.332em; box-sizing: content-box !important;">×</span></span><span id="MJXc-Node-13" class="mjx-mn MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">0.1</span></span><span id="MJXc-Node-14" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.223em; padding-bottom: 0.332em; box-sizing: content-box !important;">×</span></span><span id="MJXc-Node-15" class="mjx-mfrac MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-box MJXc-stacked" style="font-style: inherit; font-weight: inherit; display: inline-block; height: 0px; position: relative; width: 2.573em; padding: 0px 0.12em; box-sizing: content-box !important;"><span class="mjx-numerator" style="font-style: inherit; font-weight: inherit; display: block; text-align: center; position: absolute; width: 2.573em; top: -1.431em; box-sizing: content-box !important;"><span id="MJXc-Node-16" class="mjx-mrow" style="font-style: inherit; font-weight: inherit; display: inline-block; text-align: left; box-sizing: content-box !important;"><span id="MJXc-Node-17" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.277em; box-sizing: content-box !important;">a</span></span><span id="MJXc-Node-18" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.277em; box-sizing: content-box !important;">n</span></span><span id="MJXc-Node-19" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.497em; padding-right: 0.003em; box-sizing: content-box !important;">g</span></span><span id="MJXc-Node-20" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.497em; padding-bottom: 0.277em; box-sizing: content-box !important;">l</span></span><span id="MJXc-Node-21" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.277em; box-sizing: content-box !important;">e</span></span></span></span><span class="mjx-denominator" style="font-style: inherit; font-weight: inherit; display: block; text-align: center; position: absolute; width: 2.573em; bottom: -0.733em; box-sizing: content-box !important;"><span id="MJXc-Node-22" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; text-align: left; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">180</span></span></span><span class="mjx-line" style="font-style: inherit; font-weight: inherit; display: block; position: absolute; height: 0px; border-bottom: 1.3px solid; top: -0.284em; width: 2.573em; box-sizing: content-box !important;"></span></span><span class="mjx-vsize" style="font-style: inherit; font-weight: inherit; display: inline-block; width: 0px; height: 2.164em; vertical-align: -0.733em; box-sizing: content-box !important;"></span></span><span id="MJXc-Node-23" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.277em; padding-bottom: 0.442em; box-sizing: content-box !important;">+</span></span><span id="MJXc-Node-24" class="mjx-msubsup MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-base" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-25" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.332em; box-sizing: content-box !important;">2</span></span></span><span class="mjx-sup" style="font-style: inherit; font-weight: inherit; display: inline-block; font-size: 12.8674px; vertical-align: 0.591em; padding-left: 0px; padding-right: 0.071em; box-sizing: content-box !important;"><span id="MJXc-Node-26" class="mjx-texatom" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-27" class="mjx-mrow" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-28" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">16</span></span></span></span></span></span><span id="MJXc-Node-29" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.223em; padding-bottom: 0.332em; box-sizing: content-box !important;">×</span></span><span id="MJXc-Node-30" class="mjx-mn MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">0.025</span></span><span id="MJXc-Node-31" class="mjx-mo MJXc-space3" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.278em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.058em; padding-bottom: 0.332em; box-sizing: content-box !important;">=</span></span><span id="MJXc-Node-32" class="mjx-msubsup MJXc-space3" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.278em; box-sizing: content-box !important;"><span class="mjx-base" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-33" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.332em; box-sizing: content-box !important;">2</span></span></span><span class="mjx-sup" style="font-style: inherit; font-weight: inherit; display: inline-block; font-size: 12.8674px; vertical-align: 0.591em; padding-left: 0px; padding-right: 0.071em; box-sizing: content-box !important;"><span id="MJXc-Node-34" class="mjx-texatom" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-35" class="mjx-mrow" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-36" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">16</span></span></span></span></span></span><span id="MJXc-Node-37" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.223em; padding-bottom: 0.332em; box-sizing: content-box !important;">×</span></span><span id="MJXc-Node-38" class="mjx-mn MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">0.1</span></span><span id="MJXc-Node-39" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.223em; padding-bottom: 0.332em; box-sizing: content-box !important;">×</span></span><span id="MJXc-Node-40" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.442em; padding-bottom: 0.607em; box-sizing: content-box !important;">(</span></span><span id="MJXc-Node-41" class="mjx-mfrac" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-box MJXc-stacked" style="font-style: inherit; font-weight: inherit; display: inline-block; height: 0px; position: relative; width: 2.573em; padding: 0px 0.12em; box-sizing: content-box !important;"><span class="mjx-numerator" style="font-style: inherit; font-weight: inherit; display: block; text-align: center; position: absolute; width: 2.573em; top: -1.431em; box-sizing: content-box !important;"><span id="MJXc-Node-42" class="mjx-mrow" style="font-style: inherit; font-weight: inherit; display: inline-block; text-align: left; box-sizing: content-box !important;"><span id="MJXc-Node-43" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.277em; box-sizing: content-box !important;">a</span></span><span id="MJXc-Node-44" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.277em; box-sizing: content-box !important;">n</span></span><span id="MJXc-Node-45" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.497em; padding-right: 0.003em; box-sizing: content-box !important;">g</span></span><span id="MJXc-Node-46" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.497em; padding-bottom: 0.277em; box-sizing: content-box !important;">l</span></span><span id="MJXc-Node-47" class="mjx-mi" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.223em; padding-bottom: 0.277em; box-sizing: content-box !important;">e</span></span></span></span><span class="mjx-denominator" style="font-style: inherit; font-weight: inherit; display: block; text-align: center; position: absolute; width: 2.573em; bottom: -0.733em; box-sizing: content-box !important;"><span id="MJXc-Node-48" class="mjx-mn" style="font-style: inherit; font-weight: inherit; display: inline-block; text-align: left; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">180</span></span></span><span class="mjx-line" style="font-style: inherit; font-weight: inherit; display: block; position: absolute; height: 0px; border-bottom: 1.3px solid; top: -0.284em; width: 2.573em; box-sizing: content-box !important;"></span></span><span class="mjx-vsize" style="font-style: inherit; font-weight: inherit; display: inline-block; width: 0px; height: 2.164em; vertical-align: -0.733em; box-sizing: content-box !important;"></span></span><span id="MJXc-Node-49" class="mjx-mo MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.277em; padding-bottom: 0.442em; box-sizing: content-box !important;">+</span></span><span id="MJXc-Node-50" class="mjx-mn MJXc-space2" style="font-style: inherit; font-weight: inherit; display: inline-block; margin-left: 0.222em; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.387em; padding-bottom: 0.387em; box-sizing: content-box !important;">0.25</span></span><span id="MJXc-Node-51" class="mjx-mo" style="font-style: inherit; font-weight: inherit; display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-main-R" style="font-style: inherit; font-weight: inherit; display: block; white-space-collapse: preserve; font-family: MJXc-TeX-main-R, MJXc-TeX-main-Rw; padding-top: 0.442em; padding-bottom: 0.607em; box-sizing: content-box !important;">)</span></span></span></span><span class="MJX_Assistive_MathML MJX_Assistive_MathML_Block" role="presentation" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; top: 0px; left: 0px; clip: rect(1px, 1px, 1px, 1px); user-select: none; width: 561.609px; position: absolute !important; padding: 1px 0px 0px !important; border: 0px !important; height: 1px !important; overflow: hidden !important; display: block !important;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>�</mi><mi>�</mi><mi>�</mi><mo>=</mo><msup><mn>2</mn><mrow class="MJX-TeXAtom-ORD"><mn>16</mn></mrow></msup><mo>×</mo><mn>0.1</mn><mo>×</mo><mfrac><mrow><mi>�</mi><mi>�</mi><mi>�</mi><mi>�</mi><mi>�</mi></mrow><mn>180</mn></mfrac><mo>+</mo><msup><mn>2</mn><mrow class="MJX-TeXAtom-ORD"><mn>16</mn></mrow></msup><mo>×</mo><mn>0.025</mn><mo>=</mo><msup><mn>2</mn><mrow class="MJX-TeXAtom-ORD"><mn>16</mn></mrow></msup><mo>×</mo><mn>0.1</mn><mo>×</mo><mo stretchy="false">(</mo><mfrac><mrow><mi>�</mi><mi>�</mi><mi>�</mi><mi>�</mi><mi>�</mi></mrow><mn>180</mn></mfrac><mo>+</mo><mn>0.25</mn><mo stretchy="false">)</mo></math></span></span></span></p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">그리고, 이 서보모터 스펙상 180도 회전을 하지만 PWM 값을 조절하면 최대 190도 정도까지는 회전한다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">그러므로, map 함수를 사용하여 다음과 같이 각도를 조절한다.</p>
               <p style="box-sizing: inherit; padding: 0px;">duty = map(deg, 0, 180, 1638, 8191);</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">이에 따라, 12비트 해상도(0~4095)에서 duty값에 따른 회전 각도는</p>
               <ul style="box-sizing: inherit; margin: 0.5em 0px 0px 2em; padding: 0px; list-style: outside circle;">
                  <li style="box-sizing: inherit; margin: 0px; padding: 0px;">PWM 2.5% : 103 → 0º</li>
                  <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">PWM 7.5% : 307 → 90º</li>
                  <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">PWM 12.5% : 511 → 180º</li>
                  </ul>
               </li>
            </ul>
         </li>
      <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
         <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">MG996R</p>
         <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">duty = map(deg, 0, 180, 2720, 8191);</p>
         <p style="box-sizing: inherit; padding: 0px;">가 가장 적당한 값을 나타내었다. (4.15% ~ 12.5%) (이유는 잘 모르겠음)</p>
         </li>
      <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
         <p style="box-sizing: inherit; padding: 0px;">이런 내용을 종합해 볼때,&nbsp;<span style="box-sizing: inherit; color: #363636; font-weight: 700;">기기 데이터시트의 스펙과는 관계없이, 테스트를 통해 경험적으로 값을 찾아야 하는 듯…</span></p>
         </li>
      <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
         <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">delay( );</p>
         <ul style="box-sizing: inherit; margin: 1em 0px 0px 2em; padding: 0px; list-style: outside disc;">
            <li style="box-sizing: inherit; margin: 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">서보 회전 속도를 조절하며, 숫자가 작을 수록 빠르게 회전한다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">이동하는 각도만큼 돌아갈 수 있는 충분한 시간을 주어야한다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">(전류가 약하면) delay( ) 값이 너무 작을 경우 원하는 각도의 회전을 완성하지 못할 수도 있다.</p>
               </li>
            <li style="box-sizing: inherit; margin: 0.25em 0px 0px; padding: 0px;">
               <p style="box-sizing: inherit; padding: 0px;">전류가 충분하면 delay값을 줄여도 됨.</p>
               </li>
            </ul>
         </li>
      </ol>
   <br style="box-sizing: inherit;" /><br style="box-sizing: inherit;" />
   <h3 id="Servo-라이브러리를-이용하지-않는-경우" style="box-sizing: inherit; margin: 1.3333em 0px 0.6666em; padding: 0px; font-size: 1.5em; font-weight: 400; color: #363636; line-height: 1.125; scroll-margin: 1em;"><a href="https://stemwith.github.io/2020/10/19/ESP32-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0-%EC%A0%9C%EC%96%B4/#Servo-%EB%9D%BC%EC%9D%B4%EB%B8%8C%EB%9F%AC%EB%A6%AC%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%98%EC%A7%80-%EC%95%8A%EB%8A%94-%EA%B2%BD%EC%9A%B0" class="headerlink" title="Servo 라이브러리를 이용하지 않는 경우" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"></a>Servo 라이브러리를 이용하지 않는 경우</h3>
   <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">일반적으로 아두이노에서 서보모터를 사용하는 경우 아두이노 IDE에 기본적으로 포함되어 있는 &lt;Servo.h&gt; 라이브러리를 사용하면 되지만 이 라이브러리는 ESP32에서 사용할 수 없다. 그러므로 ESP32에 맞는 별도의 Servo.h 라이브러리를 다운로드 받아 사용해야하는 불편함이 있다. 또한 ESP32servo와 같은 ESP32용 라이브러리를 사용할 경우, 라이브러리에 따라 ledcWrite를 사용할 수 없는 경우도 있다.</p>
   <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;">그러므로, 여기서는 라이브러리를 사용하지 않고 PWM을 사용하여 ESP32로 MG90 서보모터를 제어해보고자 한다.</p>
   <h4 id="schematic" style="box-sizing: inherit; margin: 0px 0px 0.8em; padding: 0px; font-size: 1.25em; font-weight: 400; color: #363636; line-height: 1.125; letter-spacing: -0.3px; scroll-margin: 1em;">schematic</h4>
   <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px; font-size: 18.2px; letter-spacing: -0.3px;"><a class="gallery-item" href="https://stemwith.github.io/image/SG90.png" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"><img src="https://stemwith.github.io/image/SG90.png" style="box-sizing: inherit; height: auto; max-width: 100%; margin-top: 30px;" /></a></p>
   <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;"><br style="box-sizing: inherit; font-size: 18.2px; letter-spacing: -0.3px;" /></p>
   <h4 id="sketch" style="box-sizing: inherit; margin: 0px 0px 0.8em; padding: 0px; font-size: 1.25em; font-weight: 400; color: #363636; line-height: 1.125; letter-spacing: -0.3px; scroll-margin: 1em;"><a href="https://stemwith.github.io/2020/10/19/ESP32-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0-%EC%A0%9C%EC%96%B4/#sketch" class="headerlink" title="sketch" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"></a>sketch</h4>
   <figure class="highlight c hljs" id="code-1687869426605667" style="box-sizing: inherit; margin-top: 2em; margin-bottom: 2em; padding: 0px; overflow: hidden; background: rgb(39, 40, 34); color: #dddddd; max-width: 100%; text-align: center; width: 867px; position: relative; border-radius: 4px; font-size: 18.2px; letter-spacing: -0.3px; margin-right: 0px !important; margin-left: 0px !important;">
      <figcaption class="level is-mobile" style="box-sizing: inherit; align-items: center; justify-content: space-between; display: flex; background: rgba(200, 200, 200, 0.15); padding: 0.3em 0em 0.3em 0.75em; font-size: 0.8em; margin-bottom: 1.5rem; overflow: auto; margin-top: 0px !important; margin-right: 0px !important; margin-left: 0px !important;">
         <div class="level-left" style="box-sizing: inherit; flex: 0 0 auto; align-items: center; justify-content: flex-start; display: flex; color: inherit;"><span class="fold" style="box-sizing: inherit; font-style: inherit; color: inherit; font-family: &quot;Source Code Pro&quot;, monospace, &quot;Microsoft YaHei&quot;; cursor: pointer;"><span class="fas fa-angle-down" style="box-sizing: inherit; -webkit-font-smoothing: antialiased; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; text-rendering: auto; line-height: inherit; font-family: &quot;Font Awesome 5 Free&quot;; font-weight: 900; color: inherit;"></span></span></div>
         <div class="level-right" style="box-sizing: inherit; flex: 0 0 auto; align-items: center; justify-content: flex-end; display: flex; color: inherit; margin-top: 0px;"><a class="copy" title="Copy" data-clipboard-target="#code-1687869426605667 .code" style="box-sizing: inherit; color: inherit; cursor: pointer; opacity: 0.7; padding: 0em 0.75em;"><span class="fas fa-copy" style="box-sizing: inherit; -webkit-font-smoothing: antialiased; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; text-rendering: auto; line-height: inherit; font-family: &quot;Font Awesome 5 Free&quot;; font-weight: 900; color: inherit;"></span></a></div>
         </figcaption>
      <div class="highlight-body" style="box-sizing: inherit; overflow: auto;">
         <table style="box-sizing: inherit; border-spacing: 0px; width: auto;">
            <tbody style="box-sizing: inherit;">
               <tr style="box-sizing: inherit;">
                  <td class="gutter" style="box-sizing: inherit; padding: 0.5em 0.75em; vertical-align: top; text-align: right; border-style: none; border-color: initial; border-top-width: initial; border-right-width: initial; border-bottom-width: 0px; border-left-width: initial; background: rgba(200, 200, 200, 0.15);">
                     <pre style="box-sizing: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px; -webkit-font-smoothing: auto; font-family: &quot;Source Code Pro&quot;, monospace, &quot;Microsoft YaHei&quot;; background: transparent; color: inherit; font-size: 0.85em; overflow: visible; overflow-wrap: normal; max-width: 100%;"><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">1</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">2</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">3</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">4</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">5</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">6</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">7</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">8</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">9</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">10</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">11</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">12</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">13</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">14</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">15</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">16</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">17</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">18</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">19</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">20</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">21</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">22</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">23</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">24</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">25</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">26</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">27</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">28</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">29</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">30</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">31</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">32</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">33</span><br style="box-sizing: inherit;" /></pre>
                     </td>
                  <td class="code" style="box-sizing: inherit; padding: 0.5em 0.75em; vertical-align: top; border-style: none; border-color: initial; border-top-width: initial; border-right-width: initial; border-bottom-width: 0px; border-left-width: initial;">
                     <pre style="box-sizing: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px; -webkit-font-smoothing: auto; font-family: &quot;Source Code Pro&quot;, monospace, &quot;Microsoft YaHei&quot;; background: transparent; color: inherit; font-size: 0.85em; overflow: visible; overflow-wrap: normal; max-width: 100%;"><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">int</span> ledPin = <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">15</span>;  <span class="hljs-comment" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #75715e;">// corresponds to GPIO 15</span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-comment" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #75715e;">// setting PWM properties</span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">int</span> ledChannel = <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">0</span>;</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">int</span> freq = <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">50</span>;</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">const</span><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">int</span> resolution = <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">16</span>;</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">int</span> deg, duty;</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-function" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #a6e22e;">setup</span><span class="hljs-params" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">()</span></span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-function" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;"></span>{</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-comment" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #75715e;">// PWM Setup</span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">  ledcSetup(ledChannel, freq, resolution);  <span class="hljs-comment" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #75715e;">// PWM CH0, Frequncy 50 Hz, 16bit resolution</span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">  ledcAttachPin(ledPin, ledChannel);        <span class="hljs-comment" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #75715e;">// PWM CH0을 GPIO 15번으로 출력</span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">}</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-function" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #a6e22e;">loop</span><span class="hljs-params" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">()</span></span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-function" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;"></span>{</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">for</span> (deg = <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">0</span>;deg &lt;= <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">180</span>; deg++) {</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">  servoWrite(ledChannel, deg);</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">  }</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">for</span> (deg = <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">180</span>;deg &gt;= <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">0</span>; deg--) {</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">  servoWrite(ledChannel, deg);</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">  }</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">}</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-comment" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #75715e;">// deg는 0~180도 까지</span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-function" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;"><span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">void</span><span class="hljs-title" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #a6e22e;">servoWrite</span><span class="hljs-params" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">(<span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">int</span> ch, <span class="hljs-keyword" style="box-sizing: inherit; font-style: inherit; font-weight: bold; color: #f92672;">int</span> deg)</span></span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;"><span class="hljs-function" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;"></span>{</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">    duty = <span class="hljs-built_in" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #a6e22e;">map</span>(deg, <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">0</span>, <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">180</span>, <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">1638</span>, <span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">8192</span>);</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">    ledcWrite(ch, duty);</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">    delay(<span class="hljs-number" style="box-sizing: inherit; font-style: inherit; font-weight: inherit;">15</span>);                             <span class="hljs-comment" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; color: #75715e;">// delay를 줄이면 180도가 완전히 돌지 않음</span></span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">}</span><br style="box-sizing: inherit;" /></pre>
                     </td>
                  </tr>
               </tbody>
            </table>
         </div>
      </figure>
   <p style="box-sizing: inherit; margin-bottom: 1em; padding: 0px;"><br style="box-sizing: inherit; font-size: 18.2px; letter-spacing: -0.3px;" /></p>
   <h4 id="sketch-시리얼-모니터에-입력한-문자로-서보모터-회전시키기" style="box-sizing: inherit; margin: 0px 0px 0.8em; padding: 0px; font-size: 1.25em; font-weight: 400; color: #363636; line-height: 1.125; letter-spacing: -0.3px; scroll-margin: 1em;"><a href="https://stemwith.github.io/2020/10/19/ESP32-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0-%EC%A0%9C%EC%96%B4/#sketch-%EC%8B%9C%EB%A6%AC%EC%96%BC-%EB%AA%A8%EB%8B%88%ED%84%B0%EC%97%90-%EC%9E%85%EB%A0%A5%ED%95%9C-%EB%AC%B8%EC%9E%90%EB%A1%9C-%EC%84%9C%EB%B3%B4%EB%AA%A8%ED%84%B0-%ED%9A%8C%EC%A0%84%EC%8B%9C%ED%82%A4%EA%B8%B0" class="headerlink" title="sketch: 시리얼 모니터에 입력한 문자로 서보모터 회전시키기" style="box-sizing: inherit; color: #363636; cursor: pointer; text-decoration-line: none;" target="_blank"></a>sketch: 시리얼 모니터에 입력한 문자로 서보모터 회전시키기</h4>
   <figure class="highlight c hljs" id="code-1687869426606974" style="box-sizing: inherit; margin-top: 2em; margin-bottom: 2em; padding: 0px; overflow: hidden; background: rgb(39, 40, 34); color: #dddddd; max-width: 100%; text-align: center; width: 867px; position: relative; border-radius: 4px; font-size: 18.2px; letter-spacing: -0.3px; margin-right: 0px !important; margin-left: 0px !important;">
      <figcaption class="level is-mobile" style="box-sizing: inherit; align-items: center; justify-content: space-between; display: flex; background: rgba(200, 200, 200, 0.15); padding: 0.3em 0em 0.3em 0.75em; font-size: 0.8em; margin-bottom: 1.5rem; overflow: auto; margin-top: 0px !important; margin-right: 0px !important; margin-left: 0px !important;">
         <div class="level-left" style="box-sizing: inherit; flex: 0 0 auto; align-items: center; justify-content: flex-start; display: flex; color: inherit;"><span class="fold" style="box-sizing: inherit; font-style: inherit; color: inherit; font-family: &quot;Source Code Pro&quot;, monospace, &quot;Microsoft YaHei&quot;; cursor: pointer;"><span class="fas fa-angle-down" style="box-sizing: inherit; -webkit-font-smoothing: antialiased; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; text-rendering: auto; line-height: inherit; font-family: &quot;Font Awesome 5 Free&quot;; font-weight: 900; color: inherit;"></span></span></div>
         <div class="level-right" style="box-sizing: inherit; flex: 0 0 auto; align-items: center; justify-content: flex-end; display: flex; color: inherit; margin-top: 0px;"><a class="copy" title="Copy" data-clipboard-target="#code-1687869426606974 .code" style="box-sizing: inherit; color: inherit; cursor: pointer; opacity: 0.7; padding: 0em 0.75em;"><span class="fas fa-copy" style="box-sizing: inherit; -webkit-font-smoothing: antialiased; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; text-rendering: auto; line-height: inherit; font-family: &quot;Font Awesome 5 Free&quot;; font-weight: 900; color: inherit;"></span></a></div>
         </figcaption>
      <div class="highlight-body" style="box-sizing: inherit; overflow: auto;">
         <table style="box-sizing: inherit; border-spacing: 0px; width: auto;">
            <tbody style="box-sizing: inherit;">
               <tr style="box-sizing: inherit;">
                  <td class="gutter" style="box-sizing: inherit; padding: 0.5em 0.75em; vertical-align: top; text-align: right; border-style: none; border-color: initial; border-top-width: initial; border-right-width: initial; border-bottom-width: 0px; border-left-width: initial; background: rgba(200, 200, 200, 0.15);">
                     <pre style="box-sizing: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px; -webkit-font-smoothing: auto; font-family: &quot;Source Code Pro&quot;, monospace, &quot;Microsoft YaHei&quot;; background: transparent; color: inherit; font-size: 0.85em; overflow: visible; overflow-wrap: normal; max-width: 100%;"><span class="line" style="box-sizing: inherit; font-style: inherit; font-weight: inherit; line-height: 1.5rem;">1</span><br style="box-sizing: inherit;" /><span class="line" style="box-sizing: inheri