









INFRARED (IR) SPEED sensor module
KES 400.00
- Stock: In Stock
- Model: IR Speed Sensor Module
- Weight: 8.00g
- Dimensions: 32.00mm x 14.00mm x 7.00mm
- SKU: 3751
<h2 style="line-height: 1.2; word-break: break-word; margin-bottom: 0.5rem;"><span style="color: rgb(51, 55, 69); font-family: Arial; font-size: 22px; font-weight: 600; letter-spacing: 0.6px;">Introduction</span></h2><p style="margin-bottom: 1rem; font-size: 15px; letter-spacing: 0px; color: rgb(51, 55, 69); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";"><span style="font-family: Arial;">The Infrared Speed Sensor Module is an IR counter that has an IR transmitter and receiver. If any obstacle is placed between these sensors, a signal is sent to the microcontroller. The module can be used in association with a microcontroller for motor speed detection, pulse count, position limit, etc.</span></p><p style="margin-bottom: 1rem; font-size: 15px; letter-spacing: 0px; color: rgb(51, 55, 69); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";"><span style="font-family: Arial; letter-spacing: 0px;">Speed-sensing is very important in industrial applications in which process control require precise speed control of production belts to control the rate of manufacturing and also in robotics and autonomous system to determine the exact position of the arm or the tool and its movement. In industry, we use two types of speed sensors: magnetic induction and infrared. This 4 Pin Infrared Speed Sensor Module is used in speed control applications where you need to read the rotation of a disk. It is powered by any of the 3.3V or 5V supplies and gives digital output, which you can easily read with the help of the interrupt function on your microcontroller or development board. </span></p><ul style="padding-left: 2rem; margin-bottom: 1rem; list-style-position: inside; color: rgb(33, 37, 41); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; font-size: 10px; letter-spacing: 0.6px;"><li style="font-size: 15px; letter-spacing: 0px; color: rgb(51, 55, 69); list-style: inherit;"><span style="font-family: Arial;">LM393 Compa</span><span style="font-family: Arial;">rator</span><span style="font-family: Arial;"> onboard to give digital output</span></li><li style="font-size: 15px; letter-spacing: 0px; color: rgb(51, 55, 69); list-style: inherit;"><span style="font-family: Arial;">Low power requirement</span></li><li style="font-size: 15px; letter-spacing: 0px; color: rgb(51, 55, 69); list-style: inherit;"><span style="font-family: Arial;">Sensor output is High when the object is detected in the groove; otherwise, Low</span></li><li style="font-size: 15px; letter-spacing: 0px; color: rgb(51, 55, 69); list-style: inherit; margin-bottom: 0px;"><span style="font-family: Arial;">4 Pins VCC, GND, Dout and Aout</span></li></ul><ul style="-webkit-font-smoothing: antialiased; scroll-margin-top: 200px; scrollbar-width: thin; margin-right: 0px; margin-bottom: 0px; margin-left: 18px; padding: 0px; list-style: none; outline: none; color: rgb(0, 0, 0); font-family: "Basic Commercial", sans-serif; font-size: 15px;"><li style="-webkit-font-smoothing: antialiased; scroll-margin-top: 200px; scrollbar-width: thin; outline: none; position: relative; margin-bottom: 5px;"><span style="font-family: Arial;">Working Voltage: 3.3 to 5 VDC</span></li><li style="-webkit-font-smoothing: antialiased; scroll-margin-top: 200px; scrollbar-width: thin; position: relative;"><br></li></ul><p style="-webkit-font-smoothing: antialiased; scroll-margin-top: 200px; scrollbar-width: thin; position: relative;"><span style="color: inherit; font-size: 24px; font-weight: 700; background-color: rgb(252, 252, 252); font-family: Arial;">Principle</span><a class="headerlink" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/components_basic/18-component_speed.html#principle" title="Link to this heading" style="background-color: rgb(252, 252, 252); font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-variant-emoji: normal; font-stretch: normal; font-size: 14px; line-height: 1; font-family: FontAwesome; color: rgb(41, 128, 185); cursor: pointer; display: inline-block; text-rendering: auto; -webkit-font-smoothing: antialiased; opacity: 0; margin-left: 0.5em;"><span style="font-family: Arial;"></span></a></p><section id="principle" style="font-family: Verdana; color: rgb(64, 64, 64); font-size: 16px; background-color: rgb(252, 252, 252);"><p style="line-height: 24px; margin-bottom: 24px;"><span style="font-family: Arial;">The speed sensor module is mainly used to detect changes in rotational speed or velocity. When an object passes by the H2010 sensor, it generates a pulse signal. The integrated LM393 comparator inside the module compares this pulse signal with a preset threshold, producing a stable high-level output signal.</span></p><p style="line-height: 24px; margin-bottom: 24px;"><span style="font-family: Arial;">The Infrared Speed Sensor Module has 1 H2010 photocell, which consists of a phototransistor and an infrared light emitter packaged in a 10 cm wide black plastic housing.</span></p><a class="reference internal image-reference" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_LM393_module_2.png" style="color: rgb(41, 128, 185); cursor: pointer;"><img alt="../_images/18_LM393_module_2.png" class="align-center" src="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_LM393_module_2.png" style="max-width: 100%; height: auto; margin: auto; display: block; width: 200px;"></a><p style="line-height: 24px; margin-bottom: 24px;"><span style="font-family: Arial;">When operating, the infrared light-emitting diode continuously emits infrared light (invisible light), and the photosensitive triode will conduct if it receives it.</span></p><a class="reference internal image-reference" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_LM393_module_3.png" style="color: rgb(41, 128, 185); cursor: pointer;"><img alt="../_images/18_LM393_module_3.png" class="align-center" src="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_LM393_module_3.png" style="max-width: 100%; height: auto; margin: auto; display: block; width: 900px;"></a></section><section id="module-schematic-diagram" style="font-family: Verdana; color: rgb(64, 64, 64); font-size: 16px; background-color: rgb(252, 252, 252);"><h2 style="font-family: "Roboto Slab", ff-tisa-web-pro, Georgia, Arial, sans-serif; font-weight: 700; font-size: 24px; margin-bottom: 24px;"><span style="font-family: Arial;">Module Schematic Diagram</span><a class="headerlink" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/components_basic/18-component_speed.html#module-schematic-diagram" title="Link to this heading" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-variant-emoji: normal; font-weight: normal; font-stretch: normal; font-size: 14px; line-height: 1; font-family: FontAwesome; color: rgb(41, 128, 185); cursor: pointer; display: inline-block; text-rendering: auto; -webkit-font-smoothing: antialiased; opacity: 0; margin-left: 0.5em;"><span style="font-family: Arial;"></span></a></h2><a class="reference internal image-reference" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_speed_sensor_module_schematic.png" style="color: rgb(41, 128, 185); cursor: pointer;"><img alt="../_images/18_speed_sensor_module_schematic.png" class="align-center" src="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_speed_sensor_module_schematic.png" style="max-width: 100%; height: auto; margin: auto; display: block; width: 696.469px;"></a><br></section><section id="usage" style="font-family: Verdana; color: rgb(64, 64, 64); font-size: 16px; background-color: rgb(252, 252, 252);"><h2 style="font-family: "Roboto Slab", ff-tisa-web-pro, Georgia, Arial, sans-serif; font-weight: 700; font-size: 24px; margin-bottom: 24px;"><span style="font-family: Arial;">Usage</span><a class="headerlink" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/components_basic/18-component_speed.html#usage" title="Link to this heading" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-variant-emoji: normal; font-weight: normal; font-stretch: normal; font-size: 14px; line-height: 1; font-family: FontAwesome; color: rgb(41, 128, 185); cursor: pointer; display: inline-block; text-rendering: auto; -webkit-font-smoothing: antialiased; opacity: 0; margin-left: 0.5em;"><span style="font-family: Arial;"></span></a></h2><p style="line-height: 24px; margin-bottom: 24px;"><span style="font-weight: 700; font-family: Arial;">Hardware components</span></p><ul class="simple" style="margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px;"><li style="list-style: disc; margin-left: 24px;"><p style="line-height: 24px; margin-bottom: 0px;"><span style="font-family: Arial;">Arduino Uno R4 or R3 board * 1</span></p></li><li style="list-style: disc; margin-left: 24px;"><p style="line-height: 24px; margin-bottom: 0px;"><span style="font-family: Arial;">Infrared Speed Sensor Module * 1</span></p></li><li style="list-style: disc; margin-left: 24px;"><p style="line-height: 24px; margin-bottom: 0px;"><span style="font-family: Arial;">Jumper Wires</span></p></li></ul><p style="line-height: 24px; margin-bottom: 24px;"><span style="font-weight: 700; font-family: Arial;">Circuit Assembly</span></p><a class="reference internal image-reference" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_LM393_module_circuit.png" style="color: rgb(41, 128, 185); cursor: pointer;"><img alt="../_images/18_LM393_module_circuit.png" class="align-center" src="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/_images/18_LM393_module_circuit.png" style="max-width: 100%; height: auto; margin: auto; display: block; width: 600px;"></a><br><br><section id="code"><h3 style="font-family: "Roboto Slab", ff-tisa-web-pro, Georgia, Arial, sans-serif; font-weight: 700; font-size: 20px; margin-bottom: 24px;"><span style="font-family: Arial;">Code</span><a class="headerlink" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/components_basic/18-component_speed.html#code" title="Link to this heading" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-variant-emoji: normal; font-weight: normal; font-stretch: normal; font-size: 14px; line-height: 1; font-family: FontAwesome; color: rgb(41, 128, 185); cursor: pointer; display: inline-block; text-rendering: auto; -webkit-font-smoothing: antialiased; opacity: 0; margin-left: 0.5em;"></a></h3><iframe src="https://create.arduino.cc/editor/sunfounder01/abcd3502-1ea8-49e5-8254-5652448f06b1/preview?embed" frameborder="0" style="height: 510px; width: 696.469px; margin: 10px 0px;"></iframe><video loop="" autoplay="" muted="" style="max-width: 100%;"></video><br><br></section><section id="code-explanation"><h3 style="font-family: "Roboto Slab", ff-tisa-web-pro, Georgia, Arial, sans-serif; font-weight: 700; font-size: 20px; margin-bottom: 24px;"><span style="font-family: Arial;">Code explanation</span><a class="headerlink" href="https://docs.sunfounder.com/projects/ultimate-sensor-kit/en/latest/components_basic/18-component_speed.html#code-explanation" title="Link to this heading" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-variant-emoji: normal; font-weight: normal; font-stretch: normal; font-size: 14px; line-height: 1; font-family: FontAwesome; color: rgb(41, 128, 185); cursor: pointer; display: inline-block; text-rendering: auto; -webkit-font-smoothing: antialiased; opacity: 0; margin-left: 0.5em;"><span style="font-family: Arial;"></span></a></h3><ol class="arabic" style="margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px;"><li style="list-style: decimal; margin-left: 24px;"><p style="line-height: 24px; margin-bottom: 12px;"><span style="font-family: Arial;">Setting up the pins and initializing variables. Here, we define the pins for the motor and the speed sensor. We also initialize variables that will be used to measure and calculate the speed of the motor.</span></p><div class="highlight-arduino notranslate" style="margin: 1px 0px 24px; border: 1px solid rgb(225, 228, 229); overflow-x: auto;"><div class="highlight" style="background: rgb(248, 248, 248); position: relative; border: none; overflow-x: auto; margin: 0px; padding: 0px;"><pre id="codecell0" style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace; line-height: 1.4; margin-bottom: 0px; padding: 12px;"><span style="font-family: Verdana !important;"></span><span class="c1" style="color: rgb(61, 123, 123); font-style: italic; font-family: Verdana !important;">// Define the sensor and motor pins</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">const</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">int</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">sensorPin</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">11</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">const</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">int</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">motorB_1A</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">9</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">const</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">int</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">motorB_2A</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">10</span><span class="p" style="font-family: Verdana !important;">;</span><span class="c1" style="color: rgb(61, 123, 123); font-style: italic; font-family: Verdana !important;">// Define variables for measuring speed</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">unsigned</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">long</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">start_time</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">0</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">unsigned</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">long</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">end_time</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">0</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">int</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">0</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">float</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps_old</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">0</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">float</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">temp</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">0</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">float</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">rps</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">0</span><span class="p" style="font-family: Verdana !important;">;</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell0" style="font-size: 16px; vertical-align: baseline; line-height: normal; position: absolute; display: flex; top: 0.3em; right: 0.3em; width: 1.7em; height: 1.7em; opacity: 0; transition: opacity 0.3s, border 0.3s, background-color 0.3s; user-select: none; padding: 0px; outline: none; border-radius: 0.4em; border-width: 1px; border-style: solid; border-color: rgba(27, 31, 36, 0.15); background-color: rgb(246, 248, 250); color: rgb(87, 96, 106); font-family: Verdana !important;"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><rect x="8" y="8" width="12" height="12" rx="2"></rect><path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path></svg></button></div></div></li><li style="list-style: decimal; margin-left: 24px;"><p style="line-height: 24px; margin-bottom: 12px;"><span style="font-family: Arial;">Initialization in the </span><code class="docutils literal notranslate" style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace; font-size: 12px; max-width: 100%; background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); padding-right: 5px; padding-left: 5px; color: rgb(231, 76, 60); overflow-x: auto;"><span class="pre" style="font-family: Verdana !important;">setup()</span></code><span style="font-family: Arial;"> function. This section sets up the serial communication, configures the pins’ modes, and sets the initial motor speed.</span></p><div class="highlight-arduino notranslate" style="margin: 1px 0px 24px; border: 1px solid rgb(225, 228, 229); overflow-x: auto;"><div class="highlight" style="background: rgb(248, 248, 248); position: relative; border: none; overflow-x: auto; margin: 0px; padding: 0px;"><pre id="codecell1" style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace; line-height: 1.4; margin-bottom: 0px; padding: 12px;"><span style="font-family: Verdana !important;"></span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">void</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nb" style="color: rgb(0, 128, 0); font-family: Verdana !important;">setup</span><span class="p" style="font-family: Verdana !important;">()</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">{</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">Serial</span><span class="p" style="font-family: Verdana !important;">.</span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">begin</span><span class="p" style="font-family: Verdana !important;">(</span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">9600</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">pinMode</span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">sensorPin</span><span class="p" style="font-family: Verdana !important;">,</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">INPUT</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">pinMode</span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">motorB_1A</span><span class="p" style="font-family: Verdana !important;">,</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">OUTPUT</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">pinMode</span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">motorB_2A</span><span class="p" style="font-family: Verdana !important;">,</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">OUTPUT</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">analogWrite</span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">motorB_1A</span><span class="p" style="font-family: Verdana !important;">,</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">160</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">analogWrite</span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">motorB_2A</span><span class="p" style="font-family: Verdana !important;">,</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">0</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="p" style="font-family: Verdana !important;">}</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell1" style="font-size: 16px; vertical-align: baseline; line-height: normal; position: absolute; display: flex; top: 0.3em; right: 0.3em; width: 1.7em; height: 1.7em; opacity: 0; transition: opacity 0.3s, border 0.3s, background-color 0.3s; user-select: none; padding: 0px; outline: none; border-radius: 0.4em; border-width: 1px; border-style: solid; border-color: rgba(27, 31, 36, 0.15); background-color: rgb(246, 248, 250); color: rgb(87, 96, 106); font-family: Verdana !important;"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><rect x="8" y="8" width="12" height="12" rx="2"></rect><path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path></svg></button></div></div></li><li style="list-style: decimal; margin-left: 24px;"><p style="line-height: 24px; margin-bottom: 12px;"><span style="font-family: Arial;">Measuring the motor’s speed in the </span><code class="docutils literal notranslate" style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace; font-size: 12px; max-width: 100%; background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); padding-right: 5px; padding-left: 5px; color: rgb(231, 76, 60); overflow-x: auto;"><span class="pre" style="font-family: Verdana !important;">loop()</span></code><span style="font-family: Arial;"> function. In this segment, the motor’s steps are measured for a duration of 1 second. These steps are then used to calculate the revolutions per second (rps), which is then printed to the serial monitor.</span></p><p style="line-height: 24px; margin-top: 12px; margin-bottom: 12px;"><code class="docutils literal notranslate" style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace; font-size: 12px; max-width: 100%; background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); padding-right: 5px; padding-left: 5px; color: rgb(231, 76, 60); overflow-x: auto;"><span class="pre" style="font-family: Arial;">millis()</span></code><span style="font-family: Arial;"> returns the number of milliseconds passed since the Arduino board began running the current program.</span></p><div class="highlight-arduino notranslate" style="margin: 1px 0px 24px; border: 1px solid rgb(225, 228, 229); overflow-x: auto;"><div class="highlight" style="background: rgb(248, 248, 248); position: relative; border: none; overflow-x: auto; margin: 0px; padding: 0px;"><pre id="codecell2" style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace; line-height: 1.4; margin-bottom: 0px; padding: 12px;"><span style="font-family: Verdana !important;"></span><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">void</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nb" style="color: rgb(0, 128, 0); font-family: Verdana !important;">loop</span><span class="p" style="font-family: Verdana !important;">()</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">{</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">start_time</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">millis</span><span class="p" style="font-family: Verdana !important;">();</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">end_time</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">start_time</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">+</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">1000</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="k" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">while</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">(</span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">millis</span><span class="p" style="font-family: Verdana !important;">()</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;"><</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">end_time</span><span class="p" style="font-family: Verdana !important;">)</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">{</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="k" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">if</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">(</span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">digitalRead</span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">sensorPin</span><span class="p" style="font-family: Verdana !important;">))</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">{</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">+</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">1</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="k" style="color: rgb(0, 128, 0); font-weight: bold; font-family: Verdana !important;">while</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">(</span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">digitalRead</span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">sensorPin</span><span class="p" style="font-family: Verdana !important;">))</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">}</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">}</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">temp</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">-</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps_old</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps_old</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">steps</span><span class="p" style="font-family: Verdana !important;">;</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="n" style="font-family: Verdana !important;">rps</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">=</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="p" style="font-family: Verdana !important;">(</span><span class="n" style="font-family: Verdana !important;">temp</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="o" style="color: rgb(102, 102, 102); font-family: Verdana !important;">/</span><span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="mi" style="color: rgb(102, 102, 102); font-family: Verdana !important;">20</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">Serial</span><span class="p" style="font-family: Verdana !important;">.</span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">print</span><span class="p" style="font-family: Verdana !important;">(</span><span class="s" style="color: rgb(186, 33, 33); font-family: Verdana !important;">"rps:"</span><span class="p" style="font-family: Verdana !important;">);</span>
<span class="w" style="color: rgb(187, 187, 187); font-family: Verdana !important;"> </span><span class="nf" style="color: rgb(0, 0, 255); font-family: Verdana !important;">Serial</span><span class="p" style="font-family: Verdana !important;">.</span><span class="nf" style="color: rgb(0, 0, 255); fo


