<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chris Hio on Medium]]></title>
        <description><![CDATA[Stories by Chris Hio on Medium]]></description>
        <link>https://medium.com/@chrishio?source=rss-438178630707------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZUjqtwrJYYMprxzKKiQm4Q.jpeg</url>
            <title>Stories by Chris Hio on Medium</title>
            <link>https://medium.com/@chrishio?source=rss-438178630707------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:15:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chrishio/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Basics: Reading DC Motor Encoder Values with Arduino]]></title>
            <link>https://medium.com/@chrishio/basics-reading-dc-motor-encoder-values-with-arduino-2c185f3601ef?source=rss-438178630707------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c185f3601ef</guid>
            <category><![CDATA[arduino-ide]]></category>
            <category><![CDATA[encoder]]></category>
            <category><![CDATA[dc-motor]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[tinkercad]]></category>
            <dc:creator><![CDATA[Chris Hio]]></dc:creator>
            <pubDate>Thu, 07 Sep 2023 17:08:00 GMT</pubDate>
            <atom:updated>2023-09-07T17:08:00.761Z</atom:updated>
            <content:encoded><![CDATA[<p>This basic example comes from teaching myself how to monitor motor encoder values. I started with <a href="https://www.electroniclinic.com/arduino-dc-motor-speed-control-with-encoder-arduino-dc-motor-encoder/">https://www.electroniclinic.com/arduino-dc-motor-speed-control-with-encoder-arduino-dc-motor-encoder/</a> but noticed that in their example to motor did not actually turn and they scale a digital read value as if it were an analog A2D value.</p><p>I am new to Arduino and wanted to make sure that I really understood every step of this process. Below is my update to the tutorial.</p><p>First, the goods. You can run this for yourself (for free) at:</p><p><a href="https://www.tinkercad.com/things/6tR4w82wnAd">Circuit design DC Motor with Encoder + Arduino | Tinkercad</a></p><figure><img alt="Layout for an Arduino Uno with a DC Motor with Encoder" src="https://cdn-images-1.medium.com/max/888/1*ayIrSGoPNdqCT2CjfIp1-A.png" /><figcaption><em>An externally powered DC Motor with Encoder connected to an Arduino Uno R3.</em></figcaption></figure><p><strong>Layout Overview:</strong></p><ul><li><em>Motor Power Wires: </em>The red and black wires from the motor are connected to a 12V power supply. The simulated motor needs a simulated 12V to run at full speed.</li><li><em>Ground for Encoder</em>: The encoder’s ground is the green wire.</li><li><em>Encoder Outputs</em>: The purple and yellow wires serve as the digital outputs from the encoder, sending pulses to the Arduino based on the motor’s position. There is nothing special about pins 7 &amp; 8. Those are just the ones I chose to use.</li><li><em>Encoder Power</em>: The orange wire supplies 5V to power the encoder.</li></ul><pre>// Define pins for encoder channels<br>#define encoder_ChA 7  // Channel A of the encoder connected to Digital Pin 7<br>#define encoder_ChB 8  // Channel B of the encoder connected to Digital Pin 8<br><br>// Variables to store the current state of encoder channels<br>int encoder_ChA_value;<br>int encoder_ChB_value;<br><br>void setup() {<br>   Serial.begin(9600); // Initialize serial communication at 9600 baud rate<br><br>   // Set encoder pins as inputs with internal pull-up resistors <br>   // to avoid floating states and provide stable readings<br>   pinMode(encoder_ChA, INPUT_PULLUP); <br>   pinMode(encoder_ChB, INPUT_PULLUP);<br>}<br><br>void loop() {<br>    // Read the current state of encoder channels<br>   encoder_ChA_value = digitalRead(encoder_ChA); <br>   encoder_ChB_value = digitalRead(encoder_ChB); <br> <br>    // Print the encoder values to the serial monitor<br>   Serial.print(encoder_ChA_value); <br>   Serial.print(&quot; &quot;);  // Separate the values with a space<br>   Serial.println(encoder_ChB_value);  // Print the second value and move to a new line<br>}</pre><p><strong>Code Overview:</strong></p><p><em>Defining Encoder Channels</em>: At the beginning of the code, we define two constants for our encoder channels, encoder_ChA and encoder_ChB. This makes our code more readable and allows easy modification if we ever need to switch pins. Again, there is nothing special about pins 7 &amp; 8. They are just the ones I decided to use.</p><ol><li>Initializing Variables: The variables encoder_ChA_value and encoder_ChB_value are used to store the current digital readings (either 0 or 1) from each encoder channel.</li><li>Setup Function: Inside the setup() function, we initialize the serial communication, which allows us to print the encoder readings to the Arduino IDE&#39;s serial monitor. We also set our encoder pins as input with the INPUT_PULLUP mode. Using pull-up resistors is essential to avoid &#39;floating&#39; pins which can lead to erratic or unpredictable readings.</li><li>Main Loop: The core of our program lies in the loop() function. We continuously read the values from our encoder channels using the digitalRead() function. These values are then printed to the serial monitor, allowing us to see the encoder&#39;s output in real-time.</li></ol><p>That’s it. If you run the simulation you will see that as the motor turns the 2 digital pins return values of 0 or 1. Once you have this encoder data you can analyze it to do things like motor direction detection, position tracking, and speed measurement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c185f3601ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>