<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-8566775542304208489</atom:id><lastBuildDate>Tue, 09 Jun 2026 00:17:22 +0000</lastBuildDate><category>Simple Mode</category><category>Okay I’m Hooked</category><title>VN4000</title><description>How to Build a Robot from Scratch</description><link>https://vn4000.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-4918589308999219277</guid><pubDate>Tue, 09 Jun 2026 00:00:01 +0000</pubDate><atom:updated>2026-06-08T17:17:22.667-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Okay I’m Hooked</category><title>Adding Eyes to the Robot with Pi Camera and OpenCV — Part 15: The Robot Learns to Look</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;New here?&lt;/strong&gt; This part adds a Pi Camera to the C101 robot and runs live object detection and obstacle awareness using OpenCV — no heavy AI model required. The setup builds on the Raspberry Pi environment from Part 12. &lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If remote connection via SSH or VNC feels unfamiliar, Part 12 has the full walkthrough. Otherwise, let&#39;s go.&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Where We Are in the Loop&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A quick reminder of the five-step framework we keep coming back to:&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-[hsl(var(--border-300)/0.1)] pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Learn to Move → Perception → Localization → Planning → Control → [repeat from Perception]&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-pre-wrap leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Part 13: ✅ Learn to Move — the robot drives on its own.
Part 14: ✅ Perception (touch) — HC-SR04 detects obstacles and the robot reacts.
Part 15: ✅ Perception (vision) — the robot gets eyes.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The HC-SR04 did a solid job in Part 14. But let&#39;s be honest about what it can and can&#39;t do.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Imagine walking down a sidewalk with your eyes closed. You extend both arms to feel for obstacles ahead — if nothing&#39;s there, you keep walking; if something is, you step around it. Reasonable enough, until the moment you step off the curb and a silent electric car coming the wrong way is suddenly three feet away. Your hands told you the path was clear. They just couldn&#39;t see the drop.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That&#39;s exactly the situation our C101 is in. HC-SR04 says &quot;something is 25cm ahead&quot; — useful. But it has no idea whether that something is a wall, a chair leg, or the edge of a table. And it has absolutely no opinion about what&#39;s to the left or right.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot needs eyes. That means a camera.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;A Quick Note on Hardware Choices&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This project was supposed to use a Pi Camera Module v2. Then it met the edge of a desk at speed and that was the end of that.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;So we&#39;re running on a Pi Camera Module 1 — the original, 5MP, discontinued, &quot;why do you still have this&quot; version. Combined with a Raspberry Pi 3B that the rest of the world has largely moved on from, the whole setup feels a bit like installing twenty apps on an iPhone 6 while everyone around you is talking about the iPhone 18.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;It works. That&#39;s the point.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhL3FR-qeuephXnRR9aHom5LiFThUHxVstk_Ee4kBJOk3z0HR_UmWDsoseA3D_SRjjfOoS7Mqvcp_Q40Y9BfCkccMAdr5AS1rtrQyWQ7nswMeyA-ClsvXjEoii5b5Q0I7KdVCoe07oSh2Y2-iG5YeQqWWW-5zdrWsPTLnP8kMzbAn7KJ9ciPjc9pY-f45c&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;1500&quot; data-original-width=&quot;1500&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhL3FR-qeuephXnRR9aHom5LiFThUHxVstk_Ee4kBJOk3z0HR_UmWDsoseA3D_SRjjfOoS7Mqvcp_Q40Y9BfCkccMAdr5AS1rtrQyWQ7nswMeyA-ClsvXjEoii5b5Q0I7KdVCoe07oSh2Y2-iG5YeQqWWW-5zdrWsPTLnP8kMzbAn7KJ9ciPjc9pY-f45c=w640-h640&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Connecting the Pi Camera&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Power off the Pi first&lt;/strong&gt; — always, before touching the camera connector. The CSI port doesn&#39;t forgive hot-plugging.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiVgRgoxs_lv7unZa0hXpN4XYzFObOc3GU8yXDlKGenfqzbxt4Agof-GwsoMdrqtvvFXZya94q8U5s67fe0EYzYLhW-j305HgAWyz8IVY9elmSLX_vDWjeS9pN5apxTZXpm450zxt2xFogAOUzRm7w4LHDEnMDCC6v1frMTUoMo8AmwG2rBytLPQ77tHKQ&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiVgRgoxs_lv7unZa0hXpN4XYzFObOc3GU8yXDlKGenfqzbxt4Agof-GwsoMdrqtvvFXZya94q8U5s67fe0EYzYLhW-j305HgAWyz8IVY9elmSLX_vDWjeS9pN5apxTZXpm450zxt2xFogAOUzRm7w4LHDEnMDCC6v1frMTUoMo8AmwG2rBytLPQ77tHKQ=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The camera ribbon cable connects to the CSI port on the Pi 3B — the small slot between the HDMI port and the 3.5mm audio jack.&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Pull the two black locking tabs straight up gently — about 2–3mm&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Insert the ribbon cable — &lt;strong&gt;silver contacts facing toward the USB ports&lt;/strong&gt;, blue side facing toward HDMI&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Press the locking tabs back down firmly until they click&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Power the Pi back on and verify the camera is detected:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;bash code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-bash&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;rpicam-still -o test.jpg&lt;/i&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you see &quot;&lt;em&gt;Still capture image received&quot;&lt;/em&gt;&amp;nbsp;— camera is working. If the command isn&#39;t found, you&#39;re on an older OS version; try &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;raspistill -o test.jpg&lt;/code&gt; instead.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjrDLxl4UuXySsLgl2VYWTKxgrdxWCg_UhK-DhikTlKbAvcj60MdT7akvVe7VLKJyPGPqqKLZVOZlZCdD4C3pxtjxVkagIK2Pd-hDoI3F22m915d6MaK5vEMjPU7VuYm8WodstubOPSnu6MOVrALdAMIM6iyFOG3H0qunBWlOFKnVrpEqnIUuZQbYedBqg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjrDLxl4UuXySsLgl2VYWTKxgrdxWCg_UhK-DhikTlKbAvcj60MdT7akvVe7VLKJyPGPqqKLZVOZlZCdD4C3pxtjxVkagIK2Pd-hDoI3F22m915d6MaK5vEMjPU7VuYm8WodstubOPSnu6MOVrALdAMIM6iyFOG3H0qunBWlOFKnVrpEqnIUuZQbYedBqg=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Remote Connection Recap&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Pi is a tiny computer. To work with it, we borrow the laptop&#39;s keyboard and screen — but wirelessly, so no cables trail behind the robot.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;SSH&lt;/strong&gt; gives you a command line on the Pi from your laptop terminal:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;bash code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-bash&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Windows: use PuTTY → Host Name = Pi&#39;s IP → SSH → port 22&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# macOS/Linux:&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;ssh&lt;/span&gt; pi3@192.168.1.42&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;VNC&lt;/strong&gt; gives you the full Pi desktop — mouse, icons, Thonny IDE — streamed to your laptop screen. Before using VNC Viewer on the laptop, enable VNC on the Pi first:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;bash code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-bash&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;sudo&lt;/span&gt; raspi-config&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;→ Interface Options → VNC → Yes → Finish&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then open RealVNC Viewer on the laptop, enter the Pi&#39;s IP address, log in. The Pi desktop appears on screen as if you were sitting in front of a monitor plugged into it.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Full details in Part 12 if needed.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhb3RARsNXJo7rz4UwynMry238LLRK-qJdLHg3kTmUbRHNwsXWO0PoKFC58UKEcXgmwmEOobZnMjU6-0k1osnisF6HASSZ44MVPM_q0CBYBRxrzMChM5yhW8SpuLv6Q-Pn0ri-0pKQD_iHoLF80SjgHlArsTVotZ0ZGIjGSbxof20QdZR2mKbZySf9KzoI&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhb3RARsNXJo7rz4UwynMry238LLRK-qJdLHg3kTmUbRHNwsXWO0PoKFC58UKEcXgmwmEOobZnMjU6-0k1osnisF6HASSZ44MVPM_q0CBYBRxrzMChM5yhW8SpuLv6Q-Pn0ri-0pKQD_iHoLF80SjgHlArsTVotZ0ZGIjGSbxof20QdZR2mKbZySf9KzoI=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Why Not YOLO? Why Not TFLite?&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Phase 1, we used YOLOv8 on the laptop without a second thought. The laptop has the CPU headroom for it.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Pi 3B does not.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The original plan for this part used &lt;strong&gt;TFLite&lt;/strong&gt; (TensorFlow Lite) — Google&#39;s lightweight AI framework designed for embedded devices. One install attempt later:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ERROR: No matching distribution found for tflite-runtime&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;TFLite has no official build for 32-bit ARM. The Pi 3B runs a 32-bit OS. Dead end.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;PyTorch — same story. No 32-bit ARM build. Install attempt downloads 426MB, crashes halfway through. Every time.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;So we do what this blog has always done: find what&#39;s already there and use it well. &lt;strong&gt;Haar Cascade&lt;/strong&gt; is built into OpenCV, requires no model download, no GPU, no 500MB dependency chain. It runs at a perfectly respectable speed on the Pi 3B. And combined with &lt;strong&gt;edge density detection&lt;/strong&gt;, it gives the robot everything it needs for Part 16.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Setting Up the Environment&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Install picamera2 — the official camera library for modern Raspberry Pi OS:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;bash code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-bash&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;apt&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;install&lt;/span&gt; -y python3-picamera2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then recreate the virtual environment with system-site-packages access (this is the flag that prevents the &quot;&lt;em&gt;No module named libcamera&quot;&lt;/em&gt;&amp;nbsp;error):&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;bash code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-bash&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;deactivate
&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;cd&lt;/span&gt; ~
&lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;mv&lt;/span&gt; my_project_env my_project_env_backup
python3 -m venv my_project_env --system-site-packages
&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;source&lt;/span&gt; my_project_env/bin/activate&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Verify everything is in order:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;bash code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-bash&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;python3 -c &quot;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;from picamera2 import Picamera2; import cv2; import RPi.GPIO as GPIO; print(&#39;All OK&#39;)&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you see &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;All OK&lt;/code&gt; — ready to write code.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Code&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open Thonny via VNC Viewer (Menu → Programming → Thonny Python IDE). Create a new file, save it as &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;PicameraDetectV1.py&lt;/code&gt;, and paste this in:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2
&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; numpy &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; np
&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; picamera2 &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; Picamera2

&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Load Haar Cascade detectors&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
face_cascade &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;CascadeClassifier&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;haarcascades &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;haarcascade_frontalface_default.xml&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
body_cascade &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;CascadeClassifier&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;haarcascades &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;haarcascade_upperbody.xml&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Init camera&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
picam2 &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; Picamera2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
picam2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;preview_configuration&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;format&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;RGB888&#39;&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
picam2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;preview&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
picam2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;Object detection running. Press Ctrl+C to stop.&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        frame &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; picam2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;capture_array&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# If your camera image appears upside down, uncomment the line below:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# frame = cv2.flip(frame, -1)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        frame_bgr &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;cvtColor&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;COLOR_RGB2BGR&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        gray &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;cvtColor&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;frame_bgr&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;COLOR_BGR2GRAY&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Detect faces/people using Haar Cascade&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        faces &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; face_cascade&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;detectMultiScale&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;gray&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; minSize&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; y&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; w&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; h&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; faces&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;rectangle&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;frame_bgr&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; y&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; y&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;putText&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;frame_bgr&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;Person&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; y&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
                       cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;FONT_HERSHEY_SIMPLEX&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0.6&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token string-interpolation&quot; style=&quot;color: green;&quot;&gt;f&quot;Detected: Person at x=&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #14181f;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token token string-interpolation&quot; style=&quot;color: green;&quot;&gt;, y=&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #14181f;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Measure edge density on left vs right half of frame&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        edges &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;Canny&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;gray&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;150&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        h&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; w &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; edges&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;shape
        left_density &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; np&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;edges&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        right_density &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; np&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;edges&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; w&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Draw center dividing line&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;frame_bgr&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; h&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Determine which side is clearer&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; left_density &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; right_density&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            direction &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;LEFT is clearer&quot;&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            color &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;elif&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; right_density &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; left_density&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            direction &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;RIGHT is clearer&quot;&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            color &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            direction &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;Both sides equal&quot;&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            color &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;putText&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;frame_bgr&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; direction&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
                   cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;FONT_HERSHEY_SIMPLEX&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; color&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
        cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;putText&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;frame_bgr&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token string-interpolation&quot; style=&quot;color: green;&quot;&gt;f&quot;L:&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #14181f;&quot;&gt;left_density&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation format-spec&quot; style=&quot;color: #14181f;&quot;&gt;.0f&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token token string-interpolation&quot; style=&quot;color: green;&quot;&gt; R:&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #14181f;&quot;&gt;right_density&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation format-spec&quot; style=&quot;color: #14181f;&quot;&gt;.0f&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
                   &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;FONT_HERSHEY_SIMPLEX&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0.6&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;Robot Vision&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; frame_bgr&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

        &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;waitKey&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0xFF&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #14181f;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;ord&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;q&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;except&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt; KeyboardInterrupt&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;Stopped.&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
    picam2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;
    cv2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #14181f;&quot;&gt;destroyAllWindows&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Press &lt;strong&gt;F5&lt;/strong&gt; to run.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Two Things That Might Go Wrong (And How to Fix Them)&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Problem 1: &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;module &#39;cv2&#39; has no attribute &#39;data&#39;&lt;/code&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;OpenCV version too old. Fix:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;bash code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-bash&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;install&lt;/span&gt; --upgrade opencv-python&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Problem 2: The camera image is upside down&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This one is actually funny. Due to the tight packing of components on the C101 chassis, the camera ribbon exits the CSI port and naturally hangs facing downward at the front of the car — which means the image is flipped 180°. The fix is exactly one line, added right after &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;capture_array()&lt;/code&gt;:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;frame &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; picam2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;capture_array&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
frame &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;flip&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;frame&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Flip 180° if camera is mounted upside down&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;-1&lt;/code&gt; flips both horizontally and vertically. If only one axis is wrong: &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;0&lt;/code&gt; for vertical flip only, &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;1&lt;/code&gt; for horizontal only.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What the Code Actually Does&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Haar Cascade face detection:&lt;/strong&gt; The same algorithm from Part 8A, now running on the Pi. When a face appears in frame, a green bounding box appears with the label &#39;Person&quot; and the coordinates are printed to the terminal.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Edge density comparison:&lt;/strong&gt; &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;cv2.Canny&lt;/code&gt; detects edges in the grayscale image — the outlines of objects, walls, furniture. The frame is split down the middle, and the total edge count on each side is compared. More edges = more stuff = less clear path. The result — &quot;&lt;em&gt;LEFT is clearer&quot;&lt;/em&gt;&amp;nbsp;or &quot;&lt;em&gt;RIGHT is clearer&quot;&lt;/em&gt;&amp;nbsp;— is displayed on screen.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A blue vertical line divides the frame in half so you can see exactly what the algorithm is comparing. The numbers &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;L:xxx R:xxx&lt;/code&gt; show the raw density values in real time.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This direction signal is exactly what Part 16 will use to replace the &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;random.choice([&#39;left&#39;, &#39;right&#39;])&lt;/code&gt; from Part 14. Instead of guessing, the robot will look, measure, and decide.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We Just Built&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot now has two senses working independently:&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;✅ &lt;strong&gt;HC-SR04&lt;/strong&gt; — tells it something is in the way
✅ &lt;strong&gt;Pi Camera + OpenCV&lt;/strong&gt; — tells it which direction has more room&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Part 16, these two come together. The HC-SR04 triggers the stop. The camera picks the turn. The robot navigates.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up: Part 16 — Everything combined. The robot sees, senses, decides, and moves.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;br /&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/06/adding-eyes-to-robot-with-pi-camera-and.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhL3FR-qeuephXnRR9aHom5LiFThUHxVstk_Ee4kBJOk3z0HR_UmWDsoseA3D_SRjjfOoS7Mqvcp_Q40Y9BfCkccMAdr5AS1rtrQyWQ7nswMeyA-ClsvXjEoii5b5Q0I7KdVCoe07oSh2Y2-iG5YeQqWWW-5zdrWsPTLnP8kMzbAn7KJ9ciPjc9pY-f45c=s72-w640-h640-c" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-8769678383358332756</guid><pubDate>Fri, 05 Jun 2026 20:08:15 +0000</pubDate><atom:updated>2026-06-08T17:17:11.155-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Okay I’m Hooked</category><title>Obstacle Avoidance Robot with HC-SR04 and Raspberry Pi — Part 14: Stop Before You Crash</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt;New here?&lt;/strong&gt;&lt;span style=&quot;background-color: white; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt;This part adds an HC-SR04 ultrasonic sensor to the C101 robot from Part 13 — the car now stops, backs up, and steers around obstacles automatically. The wiring builds on the Raspberry Pi + L298N setup from Part 13. If the GPIO connections feel unfamiliar, a quick skim of Part 13 will help. Otherwise, let’s go.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-loop-gets-its-second-step&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part14.md#the-loop-gets-its-second-step&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Loop Gets Its Second Step&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Part 13, the robot learned to move. That was Step 1 of the five-step autonomous loop:&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Learn to Move → Perception → Localization → Planning → Control&amp;nbsp;[repeat from Perception]&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Today we add Step 2: &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Perception&lt;/strong&gt; — the ability to sense the environment and react to it.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Until now, our C101 was essentially a very confident toddler: walking forward with complete disregard for whatever was in front of it. Wall? Doesn’t care. Chair leg? Doesn’t care. Expensive equipment on the floor? Definitely doesn’t care.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Time to give it some awareness.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We’ll keep everything from Part 13 exactly as it is — same car, same wiring, same Python base — and add one sensor: the HC-SR04. Same sensor we met in Part 11, but this time it’s mounted on a moving robot, and the Python brain actually &lt;em style=&quot;box-sizing: border-box;&quot;&gt;responds&lt;/em&gt; to what it reports.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The goal: the car drives forward autonomously, detects any obstacle within 30cm, backs up, picks a random direction (left or right), steers clear, and keeps going. Repeat until you press Ctrl+C — or set a timer and let it run for exactly 20 seconds.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhD8NHqEWSLIYulztcN1uv7OB1FMCc8mwvXGZNTejlQ7Seipti1e1Amy0AbF_-q6za91ktoHbPVenIduTARgnSAXXOf8oxRC0uqw7kVWZHnMHY48bQNpJvhujO9bFtTub6N71Q-oFVoFoQ-Z8jpt8BkAD7dG0ghJPM9RitiPzJabBPPvrXyxS85j7-nyY0&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;3000&quot; data-original-width=&quot;4512&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhD8NHqEWSLIYulztcN1uv7OB1FMCc8mwvXGZNTejlQ7Seipti1e1Amy0AbF_-q6za91ktoHbPVenIduTARgnSAXXOf8oxRC0uqw7kVWZHnMHY48bQNpJvhujO9bFtTub6N71Q-oFVoFoQ-Z8jpt8BkAD7dG0ghJPM9RitiPzJabBPPvrXyxS85j7-nyY0=w640-h426&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;wiring-the-hc-sr04-to-the-raspberry-pi&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part14.md#wiring-the-hc-sr04-to-the-raspberry-pi&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Wiring the HC-SR04 to the Raspberry Pi&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Four connections, same as Part 11 — with one important difference: the ECHO pin needs a &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;voltage divider&lt;/strong&gt; to protect the Pi.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The HC-SR04 runs on 5V and its ECHO pin outputs 5V signals. The Raspberry Pi’s GPIO pins are only 3.3V tolerant. Feed 5V directly into a GPIO pin and you risk damaging the Pi permanently. The voltage divider steps it down to a safe ~3.3V.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;The circuit&lt;/strong&gt; (using 1kΩ and 2kΩ resistors):&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ECHO (5V) ──── 1kΩ ──── GPIO 25 (Pi)
                    │
                   2kΩ
                    │
                   GND
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Result: &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;5V × 2/(1+2) = 3.33V&lt;/code&gt; ✅ Safe for the Pi.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You can twist the wire ends around the resistor legs for a quick test — it works. Soldering makes it permanent and reliable.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Full wiring summary:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; color: #2b2b2f; display: block; letter-spacing: 0.2px; margin: 1rem 0px; max-width: 100%; overflow-x: auto; width: max-content;&quot;&gt;&lt;thead style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-SR04 Pin&lt;/span&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Connect To&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;VCC&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Pi 5V&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GND&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Pi GND&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;TRIG&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 17 (direct)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ECHO&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 25 (via 1kΩ + 2kΩ voltage divider)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The TRIG pin is fine connected directly — the Pi outputs 3.3V on GPIO pins, and that’s enough to trigger the HC-SR04.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;mounting-the-sensor&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part14.md#mounting-the-sensor&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Mounting the Sensor&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Fitting the HC-SR04 onto the front of the C101 chassis is a small but satisfying puzzle. The cleanest solution: cut an ice cream stick to about 4 inches, slide it under the 7.4V battery pack (the battery’s weight holds it in place), mount the L298N on top, and attach the HC-SR04 to the front of the stick pointing forward.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjHylaojwWPiUF35vFAzwkm3z6Fsscz8Bg1hkctLVzMID2iBHmZ0qiR8DY2v0Z7cnINUDC0VsLbm4hsUr5mzdb7ewUEMpnib7MP3TEJPFFQqosO_Gp2RK6R73PeqeQSXmDJQR1YGNYyIk1IEQ820hZTPS8wHlhImACsFSG2jC0Be3p7DUaPSzfUs10GQeE&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;3000&quot; data-original-width=&quot;4512&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjHylaojwWPiUF35vFAzwkm3z6Fsscz8Bg1hkctLVzMID2iBHmZ0qiR8DY2v0Z7cnINUDC0VsLbm4hsUr5mzdb7ewUEMpnib7MP3TEJPFFQqosO_Gp2RK6R73PeqeQSXmDJQR1YGNYyIk1IEQ820hZTPS8wHlhImACsFSG2jC0Be3p7DUaPSzfUs10GQeE=w640-h426&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The sensor needs a clear line of sight ahead — no wires hanging in front of it, no components blocking the beam. A few minutes of rearranging now saves a lot of confusing distance readings later.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj1Zx7JqaEt1codtUSoILsvrwSk-s2tu9eN2PAuvd4dyxagvNskbz0BrxqzGdxkNErL9Tk_1vjGgP_A04dOP1wwa5LyokXde_VCiyA8KRVP8INURCyUWgIDYMy_n5qferuHfLO91HX9LREdyDIxZtIjGkL94UtYWIEcPt5rcwo7LMlBzmt9ie9iKwElK20&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;3000&quot; data-original-width=&quot;4512&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj1Zx7JqaEt1codtUSoILsvrwSk-s2tu9eN2PAuvd4dyxagvNskbz0BrxqzGdxkNErL9Tk_1vjGgP_A04dOP1wwa5LyokXde_VCiyA8KRVP8INURCyUWgIDYMy_n5qferuHfLO91HX9LREdyDIxZtIjGkL94UtYWIEcPt5rcwo7LMlBzmt9ie9iKwElK20=w640-h426&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-python-code--version-1-runs-until-you-stop-it&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part14.md#the-python-code--version-1-runs-until-you-stop-it&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Python Code — Version 1: Runs Until You Stop It&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This builds directly on the Part 13 code. New additions: TRIG and ECHO pin declarations, the &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;get_distance()&lt;/code&gt; function, and the obstacle avoidance logic in the main loop.&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; RPi.GPIO &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;as&lt;/span&gt; GPIO
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; time
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; random

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(&lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;False&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# L298N motor pins&lt;/span&gt;
ENA = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;18&lt;/span&gt;; IN1 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;27&lt;/span&gt;; IN2 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;22&lt;/span&gt;
IN3 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;23&lt;/span&gt;; IN4 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;24&lt;/span&gt;; ENB = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;13&lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# HC-SR04 pins&lt;/span&gt;
TRIG = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;17&lt;/span&gt;
ECHO = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;25&lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Configure pins&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; pin &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; [ENA, ENB, IN1, IN2, IN3, IN4, TRIG]:
    GPIO.setup(pin, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# PWM setup&lt;/span&gt;
pwm_A = GPIO.PWM(ENA, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;)
pwm_B = GPIO.PWM(ENB, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;)
pwm_A.start(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)
pwm_B.start(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;get_distance&lt;/span&gt;():
    GPIO.output(TRIG, &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;)
    time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.00001&lt;/span&gt;)
    GPIO.output(TRIG, &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;False&lt;/span&gt;)

    start_time = time.time()
    stop_time = time.time()

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; GPIO.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;input&lt;/span&gt;(ECHO) == &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;:
        start_time = time.time()
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; GPIO.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;input&lt;/span&gt;(ECHO) == &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;:
        stop_time = time.time()

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Speed of sound ~34300 cm/s, divide by 2 for one-way distance&lt;/span&gt;
    distance = (stop_time - start_time) * &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;34300&lt;/span&gt; / &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;return&lt;/span&gt; distance

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;set_motor&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;in1, in2, pwm, speed&lt;/span&gt;):
    GPIO.output(in1, GPIO.HIGH &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; speed &amp;gt;= &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt; GPIO.LOW)
    GPIO.output(in2, GPIO.LOW &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; speed &amp;gt;= &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt; GPIO.HIGH)
    pwm.ChangeDutyCycle(&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;abs&lt;/span&gt;(speed))

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;forward&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;speed&lt;/span&gt;):
    set_motor(IN1, IN2, pwm_A, speed)
    set_motor(IN3, IN4, pwm_B, speed)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;backward&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;speed&lt;/span&gt;):
    set_motor(IN1, IN2, pwm_A, -speed)
    set_motor(IN3, IN4, pwm_B, -speed)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;turn_left&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;speed&lt;/span&gt;):
    set_motor(IN1, IN2, pwm_A, -speed)
    set_motor(IN3, IN4, pwm_B, speed)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;turn_right&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;speed&lt;/span&gt;):
    set_motor(IN1, IN2, pwm_A, speed)
    set_motor(IN3, IN4, pwm_B, -speed)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;stop_car&lt;/span&gt;():
    set_motor(IN1, IN2, pwm_A, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)
    set_motor(IN3, IN4, pwm_B, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;try&lt;/span&gt;:
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Moving. Press Ctrl+C to stop.&quot;&lt;/span&gt;)
    speed = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;70&lt;/span&gt;

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
        dist = get_distance()
        &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;Distance: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{dist:&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;.2&lt;/span&gt;f}&lt;/span&gt; cm&quot;&lt;/span&gt;)

        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; dist &amp;lt; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;:
            &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Obstacle detected! Stopping and reversing...&quot;&lt;/span&gt;)
            stop_car()
            backward(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;)
            time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;)
            stop_car()

            direction = random.choice([&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;left&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;right&#39;&lt;/span&gt;])
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; direction == &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;left&#39;&lt;/span&gt;:
                &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Steering left...&quot;&lt;/span&gt;)
                turn_left(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;75&lt;/span&gt;)
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt;:
                &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Steering right...&quot;&lt;/span&gt;)
                turn_right(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;75&lt;/span&gt;)
            time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.8&lt;/span&gt;)
            stop_car()
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt;:
            forward(speed)

        time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.1&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;except&lt;/span&gt; KeyboardInterrupt:
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;\nStopped by user.&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;finally&lt;/span&gt;:
    stop_car()
    pwm_A.stop()
    pwm_B.stop()
    GPIO.cleanup()
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;GPIO cleaned up.&quot;&lt;/span&gt;)
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;How the distance formula works:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;distance = (time_elapsed × 34300) / 2
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The HC-SR04 fires a sound pulse and measures how long it takes to bounce back. Sound travels at ~34,300 cm/s. We divide by 2 because the sound makes a round trip — out to the obstacle and back. If the echo takes 0.002 seconds to return, the obstacle is &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;(0.002 × 34300) / 2 = 34.3 cm&lt;/code&gt; away.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dzczI3xpTl65r56IOd32t8wyflnls6bPhjxZl0jO1-dFq4DWORnsosLOIYQOWLS-uui-BO0r5vACHYwS5URUw&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;version-2-runs-for-exactly-20-seconds&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part14.md#version-2-runs-for-exactly-20-seconds&quot; id=&quot;5&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Version 2: Runs for Exactly 20 Seconds&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Sometimes you want the robot to run a timed test rather than loop forever. Add a &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;start_run_time&lt;/code&gt; check at the top of the loop:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; RPi.GPIO &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;as&lt;/span&gt; GPIO
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; time
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; random

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(&lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;False&lt;/span&gt;)

ENA = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;18&lt;/span&gt;; IN1 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;27&lt;/span&gt;; IN2 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;22&lt;/span&gt;
IN3 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;23&lt;/span&gt;; IN4 = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;24&lt;/span&gt;; ENB = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;13&lt;/span&gt;
TRIG = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;17&lt;/span&gt;; ECHO = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;25&lt;/span&gt;

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; pin &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; [ENA, ENB, IN1, IN2, IN3, IN4, TRIG]:
    GPIO.setup(pin, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)

pwm_A = GPIO.PWM(ENA, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;)
pwm_B = GPIO.PWM(ENB, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;)
pwm_A.start(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)
pwm_B.start(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;get_distance&lt;/span&gt;():
    GPIO.output(TRIG, &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;)
    time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.00001&lt;/span&gt;)
    GPIO.output(TRIG, &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;False&lt;/span&gt;)
    start_time = stop_time = time.time()
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; GPIO.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;input&lt;/span&gt;(ECHO) == &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;:
        start_time = time.time()
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; GPIO.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;input&lt;/span&gt;(ECHO) == &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;:
        stop_time = time.time()
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;return&lt;/span&gt; (stop_time - start_time) * &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;34300&lt;/span&gt; / &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;set_motor&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;in1, in2, pwm, speed&lt;/span&gt;):
    GPIO.output(in1, GPIO.HIGH &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; speed &amp;gt;= &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt; GPIO.LOW)
    GPIO.output(in2, GPIO.LOW &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; speed &amp;gt;= &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt; GPIO.HIGH)
    pwm.ChangeDutyCycle(&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;abs&lt;/span&gt;(speed))

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;forward&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;s&lt;/span&gt;): set_motor(IN1, IN2, pwm_A, s); set_motor(IN3, IN4, pwm_B, s)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;backward&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;s&lt;/span&gt;): set_motor(IN1, IN2, pwm_A, -s); set_motor(IN3, IN4, pwm_B, -s)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;turn_left&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;s&lt;/span&gt;): set_motor(IN1, IN2, pwm_A, -s); set_motor(IN3, IN4, pwm_B, s)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;turn_right&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;s&lt;/span&gt;): set_motor(IN1, IN2, pwm_A, s); set_motor(IN3, IN4, pwm_B, -s)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;stop_car&lt;/span&gt;(): set_motor(IN1, IN2, pwm_A, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;); set_motor(IN3, IN4, pwm_B, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;try&lt;/span&gt;:
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Running for 20 seconds. Ctrl+C to stop early.&quot;&lt;/span&gt;)
    speed = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;70&lt;/span&gt;
    start_run_time = time.time()
    run_duration = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;20&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Change this to 30, 60, whatever you like&lt;/span&gt;

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; time.time() - start_run_time &amp;gt;= run_duration:
            &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Time&#39;s up. Stopping.&quot;&lt;/span&gt;)
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

        dist = get_distance()
        &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;Distance: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{dist:&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;.2&lt;/span&gt;f}&lt;/span&gt; cm&quot;&lt;/span&gt;)

        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; dist &amp;lt; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;:
            &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Obstacle! Reversing...&quot;&lt;/span&gt;)
            stop_car()
            backward(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;)
            time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;)
            stop_car()
            direction = random.choice([&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;left&#39;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;right&#39;&lt;/span&gt;])
            turn_left(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;75&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; direction == &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;left&#39;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt; turn_right(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;75&lt;/span&gt;)
            &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;Steering &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{direction}&lt;/span&gt;...&quot;&lt;/span&gt;)
            time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.8&lt;/span&gt;)
            stop_car()
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt;:
            forward(speed)
            time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.1&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;except&lt;/span&gt; KeyboardInterrupt:
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;\nInterrupted.&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;finally&lt;/span&gt;:
    stop_car()
    pwm_A.stop()
    pwm_B.stop()
    GPIO.cleanup()
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;Done.&quot;&lt;/span&gt;)
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Change &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;run_duration = 20&lt;/code&gt; to any number of seconds you like.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dyhq52tGXsnci1w5lFxSr_6m0Putlvnm9o5rMixmnNp6PdG36104BbNN7DqjvnEn0M6TueHqGR8U1q1FwvmwQ&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;what-we-just-built&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part14.md#what-we-just-built&quot; id=&quot;6&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We Just Built&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot now completes two steps of the autonomous loop:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;✅ &lt;b&gt;Learn to Move&amp;nbsp;&lt;/b&gt;— moves on command (Part 13)&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;✅ &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Perception&lt;/strong&gt; — senses obstacles and reacts (Part 14)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;One $4 sensor. About 20 extra lines of Python. And the car goes from &quot;drives until it hits something&quot; to &quot;drives, detects, avoids, continues.&quot; That’s a meaningful jump.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The avoidance logic is simple — random left or right, no analysis of which direction is actually clearer. That’s intentional. Keeping it simple here makes the next upgrade more satisfying: in Part 15, the camera will look left and right and &lt;em style=&quot;box-sizing: border-box;&quot;&gt;choose&lt;/em&gt; the better direction rather than guessing.&lt;/span&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/06/obstacle-avoidance-robot-with-hc-sr04.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhD8NHqEWSLIYulztcN1uv7OB1FMCc8mwvXGZNTejlQ7Seipti1e1Amy0AbF_-q6za91ktoHbPVenIduTARgnSAXXOf8oxRC0uqw7kVWZHnMHY48bQNpJvhujO9bFtTub6N71Q-oFVoFoQ-Z8jpt8BkAD7dG0ghJPM9RitiPzJabBPPvrXyxS85j7-nyY0=s72-w640-h426-c" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-4941912764448546298</guid><pubDate>Thu, 04 Jun 2026 01:45:30 +0000</pubDate><atom:updated>2026-06-03T20:18:38.387-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Okay I’m Hooked</category><title>Raspberry Pi 4WD Robot Car with Python and L298N — Part 13: Four Wheels, One Brain</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;New here?&lt;/strong&gt; This part covers wiring the C101 4WD kit to a Raspberry Pi 3B via L298N and writing Python directly on the Pi to drive the car — no laptop, no USB cable, no Arduino middleman. &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If some of the hardware setup feels unfamiliar, a quick read through Part 12 (Raspberry Pi setup and SSH) will fill in the gaps. Otherwise, let&#39;s go.&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Before a Robot Can Think, It Has to Walk&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Part 12, we moved the robot&#39;s brain off the laptop and into the Pi itself. Smart. But a brain with no body isn&#39;t much use.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Every autonomous robot — from a Roomba to a Mars rover — runs on the same four-step loop:&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Perception → Localization → Planning → Control&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot senses its environment, figures out where it is, decides where to go, and moves. Repeat forever.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;But here&#39;s the thing: before any of that can happen, the robot needs to know &lt;em&gt;how&lt;/em&gt; to move in the first place. You can&#39;t plan a route if the wheels don&#39;t respond to commands. So the real learning order looks like this:&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-[hsl(var(--border-300)/0.1)] pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Learn to move (Control) first → then add Perception → Localization → Planning → Control&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Think of a toddler. First they learn to walk — wobbly, directionless, occasionally into a wall. Nobody expects them to navigate to the kitchen and back on day one. Walking comes first. Everything else comes later.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That&#39;s exactly what we&#39;re doing today. Teaching the robot to walk.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And once it can walk — if the battery holds and nothing gets in the way — it could theoretically keep going in a straight line forever. &quot;So what?&quot; you might say. &quot;Leave a Toyota running in an empty parking lot and it&#39;ll roll until it hits something.&quot; True. But can you program that Toyota to take two steps forward and one step back, on repeat, for the entire journey? Or to sway left and right while moving forward? Our robot can do both — in about five lines of Python. Try that with a regular car.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;What You Need&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Component&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Notes&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Est. Cost&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Laptop&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;For setup via VNC only&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already owned&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Raspberry Pi 3B&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already have (Part 12)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;MicroSD 32/64GB&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already have (Part 12)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;L298N Motor Driver&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already have (Phase 1)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;C101 4WD Kit&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$20&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Portable USB Power Bank (5V)&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Powers the Pi&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already have&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Li-ion Battery Pack 7.4V&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Powers the motors&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$12&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;A few notes before wiring:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;✅ &lt;strong&gt;Power Bank for Pi&lt;/strong&gt;:&lt;/span&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt; Use a slim or mini power bank — small, light, easy to mount. The Pi 3B uses a Micro-USB port, so if your power bank only has USB-A output, you&#39;ll need a USB-A to Micro-USB cable.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;✅ &lt;strong&gt;Treedix 5V UPS for Pi&lt;/strong&gt; &lt;/span&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;(alternative): Mounts directly onto the Pi which is convenient, but uses 18650 batteries that need to be physically removed for charging. More hassle than it&#39;s worth for most setups — not recommended.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4Up-grSa8I-_xO0oUI3m2CyeyrcguvXas62Aap-QCYRtZsMTKsGpYv11fZAP_ycyqqVs1LDWsmx5eq__OfmUkVaKWl0gQbw6fkGE2YdDQG-NkHHSQ18hh5wvFrcp_PFujKLZaq5XWUfwAMbgEAKB8PW0yACTp7KVQ3wrNdgVsNWTX9W_3H6PNRQFPfho/s544/TreeDix_.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;429&quot; data-original-width=&quot;544&quot; height=&quot;504&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4Up-grSa8I-_xO0oUI3m2CyeyrcguvXas62Aap-QCYRtZsMTKsGpYv11fZAP_ycyqqVs1LDWsmx5eq__OfmUkVaKWl0gQbw6fkGE2YdDQG-NkHHSQ18hh5wvFrcp_PFujKLZaq5XWUfwAMbgEAKB8PW0yACTp7KVQ3wrNdgVsNWTX9W_3H6PNRQFPfho/w640-h504/TreeDix_.jpg&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;✅ &lt;strong&gt;C101 metal chassis&lt;/strong&gt;: &lt;/span&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The frame is metal. Never let the underside of any circuit board (where the solder joints are) touch the metal chassis directly — instant short circuit, instant damage. Insulate the bottom of every board before mounting. A strip of electrical tape, a piece of acrylic, or a chassis kit made from non-conductive material all work fine.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;✅ &lt;strong&gt;Li-ion Battery Pack 7.4V&lt;/strong&gt;:&lt;/span&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt; Get one that comes with pre-attached positive (+) and negative (−) leads. Without them, getting power out of the pack becomes a project in itself.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiAywy2ARw3NQuvmJGcqnNe8j8SeFvl6TLa9OHx8ps6xtDeXvyGxaYEiIMlmUTiGZTHFj28UhZC1FHA9Fpgvei7s7RMHNH8j7EhWmScbbsu8p0DXjHHEdhc_QWFNJkkNwu4pAufHSeC5bQQAE4dGGfv_ZSyCmiFiwNVPnXVLw4JW7BiuxAyUHQ4R0gaumo&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiAywy2ARw3NQuvmJGcqnNe8j8SeFvl6TLa9OHx8ps6xtDeXvyGxaYEiIMlmUTiGZTHFj28UhZC1FHA9Fpgvei7s7RMHNH8j7EhWmScbbsu8p0DXjHHEdhc_QWFNJkkNwu4pAufHSeC5bQQAE4dGGfv_ZSyCmiFiwNVPnXVLw4JW7BiuxAyUHQ4R0gaumo=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;✅ &lt;strong&gt;Raspberry Pi GPIO&lt;/strong&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;: The Pi&#39;s pins are completely different from the Arduino Nano. The diagram below shows the BCM numbering we&#39;ll use in code — the inner numbers are the GPIO numbers, the outer labels are the physical pin names. When in doubt, cross-reference with the official Raspberry Pi pinout at raspberrypi.com.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgrKItihEQM23Jp3Wfoslkmm91Mwh2VER669A1schVYioL6GS1JU1MN7JkUv9o-meDh8cmEArpFVX-Wb-BfyrX9C4AXQ_0FbrqwYBkd2zjrkW_MNlx94hJGS46yqoxxEqrTwiLj9yayELtCZFvqVKdOLkRGzvh5ggclMcRaBTK0WLs2YZgn3lerAFeWSJs&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;1187&quot; data-original-width=&quot;1601&quot; height=&quot;474&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgrKItihEQM23Jp3Wfoslkmm91Mwh2VER669A1schVYioL6GS1JU1MN7JkUv9o-meDh8cmEArpFVX-Wb-BfyrX9C4AXQ_0FbrqwYBkd2zjrkW_MNlx94hJGS46yqoxxEqrTwiLj9yayELtCZFvqVKdOLkRGzvh5ggclMcRaBTK0WLs2YZgn3lerAFeWSJs=w640-h474&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;✅ &lt;strong&gt;Motor wire connections&lt;/strong&gt;:&lt;/span&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt; The motor terminals accept bare wire — strip the end, insert, tighten the screw. Soldering the wire tips first makes for a more reliable connection, but twisted bare wire works too.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 1 — Assemble the C101 Kit First&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before any wiring, assemble the wheels and motors onto the C101 chassis. Follow the official assembly guide:
🔗 &lt;a class=&quot;underline underline underline-offset-2 decoration-1 decoration-current/40 hover:decoration-current focus:decoration-current&quot; href=&quot;https://m.media-amazon.com/images/I/B1reNOGPGgL.pdf&quot;&gt;https://m.media-amazon.com/images/I/B1reNOGPGgL.pdf&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Once assembled, decide which end is the &lt;em&gt;front&lt;/em&gt; of the car and mark it. This matters when testing motor directions later.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 2 — Wire Everything Up&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Power connections:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;From&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;To&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Battery Pack (+)&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;L298N 12V terminal&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Battery Pack (−)&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;L298N GND terminal&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Power Bank (5V)&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Pi micro-USB port&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO signal connections (Pi → L298N):&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;L298N Pin&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Raspberry Pi GPIO (BCM)&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-[hsl(var(--border-300)/0.6)] py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Function&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ENA&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 18&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Left motor speed (PWM)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;IN1&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 27&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Left motor direction&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;IN2&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 22&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Left motor direction&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;IN3&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 23&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Right motor direction&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;IN4&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 24&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Right motor direction&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ENB&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GPIO 13&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Right motor speed (PWM)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;GND&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Pin 14 (GND)&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-[hsl(var(--border-300)/0.3)] py-2 pr-4 align-top&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Common ground — mandatory&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;⚠️ &lt;strong&gt;The GND connection is not optional.&lt;/strong&gt; Without a shared ground between the Pi and L298N, no control signal gets through — the motors won&#39;t respond to anything. Use physical pin 14 on the Pi (which is a GND pin) — not GPIO 14, which is something else entirely.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Don&#39;t connect the motors yet.&lt;/strong&gt; Wire everything else first, then test each motor individually in Step 4.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 3 — The Python Code&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Connect to the Pi via VNC Viewer, open Thonny Python IDE (Menu → Programming → Thonny), and paste this in:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; RPi&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;GPIO &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;as&lt;/span&gt; GPIO
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; time

GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;setmode&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;BCM&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;setwarnings&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# GPIO pin assignments&lt;/span&gt;
ENA &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;18&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Left speed&lt;/span&gt;
IN1 &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;27&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Left direction&lt;/span&gt;
IN2 &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;22&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Left direction&lt;/span&gt;
IN3 &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;23&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Right direction&lt;/span&gt;
IN4 &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;24&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Right direction&lt;/span&gt;
ENB &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;13&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Right speed&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Configure all pins as outputs&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;for&lt;/span&gt; pin &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;[&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;setup&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;pin&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;OUT&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Set up PWM at 50Hz&lt;/span&gt;
pwm_A &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;PWM&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
pwm_B &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;PWM&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
pwm_A&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;start&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
pwm_B&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;start&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;set_motor&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;in1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; in2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; speed &lt;span class=&quot;token token&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;output&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;in1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
        GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;output&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;in2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;output&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;in1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
        GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;output&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;in2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    pwm&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;ChangeDutyCycle&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;forward&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_A&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_B&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;backward&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_A&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot;&gt;-&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_B&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot;&gt;-&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;turn_left&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_A&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot;&gt;-&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_B&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;turn_right&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_A&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_B&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot;&gt;-&lt;/span&gt;speed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;stop_car&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_A&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    set_motor&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; pwm_B&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Moving forward for 2 seconds...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    forward&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;75&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Turning right for 1 second...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    turn_right&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;75&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Turning left for 1 second...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    turn_left&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;75&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Moving backward for 2 seconds...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    backward&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Stopping.&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    stop_car&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;except&lt;/span&gt; KeyboardInterrupt&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Interrupted.&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    stop_car&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    pwm_A&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;stop&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    pwm_B&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;stop&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    GPIO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;cleanup&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;One thing worth explaining:&lt;/strong&gt; The C101 has four DC motors but no front steering servo — unlike the RC car we modified earlier, which had a separate servo for turning. Instead, the C101 steers by spinning one side faster than the other. Left side faster → turns right. Right side faster → turns left. This is called &lt;strong&gt;differential steering&lt;/strong&gt; (or skid steering) — the same method used by tanks, bulldozers, and most 4WD robot kits. It&#39;s not elegant, but it works.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 4 — Test Each Motor Before Assembling&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;With four motors, a wiring mistake is easy to make and painful to debug. If one motor spins the wrong way, the car might spin in circles or refuse to move at all — and figuring out &lt;em&gt;which&lt;/em&gt; motor is wrong when they&#39;re all mounted and wired is genuinely frustrating.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The fix: &lt;strong&gt;test each motor individually before final assembly.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Flip the car upside down. Connect one motor at a time to OUT3/OUT4, hit Run, and watch the &quot;Moving forward&quot; message appear. If the wheel spins &lt;strong&gt;counter-clockwise&lt;/strong&gt; (viewed from outside the car, arrow pointing backward) — correct. If it spins clockwise — swap the two wires between OUT3 and OUT4.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj0J7ABqLpk1DjnTCjazuLpyx3v6-WLYEdEtm5GtX6B61yauxHkaRLRo34iPHi-2QWCNrTfgyWJZ8QC5-5q_sGhp-GeU6pOM4wWEZGkizR8yL0BkYxBpwtLZCVw5_UxgT2M2gGLmIBAGWScZtNXWhicYarzWnY2mel1mK5FtxD8HwYUe2KerIBPV_I0gK4&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj0J7ABqLpk1DjnTCjazuLpyx3v6-WLYEdEtm5GtX6B61yauxHkaRLRo34iPHi-2QWCNrTfgyWJZ8QC5-5q_sGhp-GeU6pOM4wWEZGkizR8yL0BkYxBpwtLZCVw5_UxgT2M2gGLmIBAGWScZtNXWhicYarzWnY2mel1mK5FtxD8HwYUe2KerIBPV_I0gK4=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Write down your results:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Motor 1 (front-left):  Yellow → OUT1, Blue → OUT2  ✅
Motor 2 (rear-left):   ...
Motor 3 (front-right): ...
Motor 4 (rear-right):  ...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi_lA6cWv0WJfNhWvjBC9d7k5kDxYTEwVEGii7O4PJeNKTXPNQ0z3VQl3mh9TuaM79eVn8zdAheatLmE4MVhwl-jQzM7MW_rT8XrY5BhffnZ3BFYWjL2vyRBSJig5T4XKh1d0Y0q-l1A_ztXSTsllLmNu4PraFYbLwbwYkEy80vD14pxyxVA6H2b62H8H4&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;569&quot; data-original-width=&quot;1339&quot; height=&quot;272&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi_lA6cWv0WJfNhWvjBC9d7k5kDxYTEwVEGii7O4PJeNKTXPNQ0z3VQl3mh9TuaM79eVn8zdAheatLmE4MVhwl-jQzM7MW_rT8XrY5BhffnZ3BFYWjL2vyRBSJig5T4XKh1d0Y0q-l1A_ztXSTsllLmNu4PraFYbLwbwYkEy80vD14pxyxVA6H2b62H8H4=w640-h272&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Once all four are confirmed, connect left-side motors to OUT1/OUT2 and right-side motors to OUT3/OUT4 according to your notes.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 5 — Mount Everything and Run&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now comes the fun part: fitting the Pi, L298N, power bank, and battery pack onto the C101 chassis without it looking like a yard sale on wheels. Space is tight — leave room at the front for the HC-SR04 ultrasonic sensor that&#39;s coming in the next part.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A simple trick: cut an ice cream stick to about 4 inches and attach it to the front of the car as a sensor mount. Cheap, light, effective.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgU5gerSnKwjNX-7EFraiTek3jhu9i58Kz7CVrRNNyCn6vqgJqg_yYj9St_vdDjNhadhweWJxzfPJimdOuuKG9ne2Wg5kjVnIlfFGYq1bwQ-ZbKRcsWoKP7aqF13AgQBunbkKk0k1woTobRvReV7G3fE9dUYjBgE7ZDsTNHQUQ8gXakLjmLCgVeMYNWzMc&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;1200&quot; data-original-width=&quot;1200&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgU5gerSnKwjNX-7EFraiTek3jhu9i58Kz7CVrRNNyCn6vqgJqg_yYj9St_vdDjNhadhweWJxzfPJimdOuuKG9ne2Wg5kjVnIlfFGYq1bwQ-ZbKRcsWoKP7aqF13AgQBunbkKk0k1woTobRvReV7G3fE9dUYjBgE7ZDsTNHQUQ8gXakLjmLCgVeMYNWzMc=w640-h640&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi9PZQWO-Sz1YKgh0Jz081IizW6nqv8GvtDPbGhp28twr3x77Jo9_1mrFxnmSt6tyCViJdFqxWJ2ftDcrrnMqEnYJ9-d5mZW0W5lxtvgds3FBYA9lhn9C6w5jwglBAV-RP_jPUpxqL3i3NoJB0rANyRgAQJz8--zP8iPB5Djtt91vkqTbsK2-jh5yoT9rw&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;1338&quot; data-original-width=&quot;2129&quot; height=&quot;402&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi9PZQWO-Sz1YKgh0Jz081IizW6nqv8GvtDPbGhp28twr3x77Jo9_1mrFxnmSt6tyCViJdFqxWJ2ftDcrrnMqEnYJ9-d5mZW0W5lxtvgds3FBYA9lhn9C6w5jwglBAV-RP_jPUpxqL3i3NoJB0rANyRgAQJz8--zP8iPB5Djtt91vkqTbsK2-jh5yoT9rw=w640-h402&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Set the car on an open floor. Open Thonny, press &lt;strong&gt;Run&lt;/strong&gt;, and watch.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dzZM1jO7Ny-6c57LCIAxnbnYeSqxNlD-IdBFKTt8lgwd6ev5_C97EsbX-yM5DQoXWIfCQKoXca3wcd1o-QllQ&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs7IZTDAfdlqxAKu-aQfcNiEimLjpdjOjj1Zo4TUeU_tibRyvYhlkd74fvmmANTtrVm3p2OH37-_0b6r_OfdezHIhprAB14FyWkYfzeQeMXaKppMiN47dEzDvCwY7KTzP0KNfgF5wIBN0EB_KWKOW_2zEv7Ntstxk_gzHn2mW4HLFfy3JOhN2ukNNIoxc/s4512/DSC_1180.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;3000&quot; data-original-width=&quot;4512&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs7IZTDAfdlqxAKu-aQfcNiEimLjpdjOjj1Zo4TUeU_tibRyvYhlkd74fvmmANTtrVm3p2OH37-_0b6r_OfdezHIhprAB14FyWkYfzeQeMXaKppMiN47dEzDvCwY7KTzP0KNfgF5wIBN0EB_KWKOW_2zEv7Ntstxk_gzHn2mW4HLFfy3JOhN2ukNNIoxc/w640-h426/DSC_1180.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What Just Happened&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This is not the same as the RC car from Phase 1. That car still needed a human pressing keyboard keys. This one runs a Python program stored on the Pi itself — no laptop attached, no USB cable, no Bluetooth link. The Pi wakes up, reads the code, and drives.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Watching it move for the first time — four wheels spinning, the car rolling forward on its own — is one of those moments that&#39;s genuinely hard to describe. It feels a bit like watching a toddler take their first steps: wobbly, uncertain, but completely self-powered. And entirely earned.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That moment is worth at least one Starbucks Caffè Latte.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What&#39;s Next&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot can move. Now it needs to &lt;em&gt;sense&lt;/em&gt;. In Part 14, we add the HC-SR04 ultrasonic sensor to the Pi — and the car will stop automatically when something gets in its way.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Step one of the four-step loop is done. Perception is next.&lt;/span&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/06/raspberry-pi-4wd-robot-car-with-python.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4Up-grSa8I-_xO0oUI3m2CyeyrcguvXas62Aap-QCYRtZsMTKsGpYv11fZAP_ycyqqVs1LDWsmx5eq__OfmUkVaKWl0gQbw6fkGE2YdDQG-NkHHSQ18hh5wvFrcp_PFujKLZaq5XWUfwAMbgEAKB8PW0yACTp7KVQ3wrNdgVsNWTX9W_3H6PNRQFPfho/s72-w640-h504-c/TreeDix_.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-5758850632172072707</guid><pubDate>Tue, 26 May 2026 21:46:10 +0000</pubDate><atom:updated>2026-06-07T16:20:25.306-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Okay I’m Hooked</category><title>Raspberry Pi 3B Setup for Robotics — Part 12: The Robot Gets Its Own Brain</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Let&#39;s address the obvious problem.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A robot that needs a laptop sitting next to it isn&#39;t really a robot. It&#39;s a very expensive remote control. Even the thinnest laptop on the market — say, an Asus Zenbook A14 — weighs over 2.5 lbs and measures 13×9 inches. That&#39;s not riding inside a robot. That&#39;s the robot riding inside a carry-on bag.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;What we need is a way to squeeze all of that computing power into something that weighs 0.09 lbs and measures 3.4×2.3 inches.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Meet the Raspberry Pi 3B.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;A Very Brief History (Bear With Us — It Actually Goes Somewhere)&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Every computer you&#39;ve ever used — HP desktop, Dell tower, iMac, MacBook, Lenovo ThinkPad — shares one thing in common: it runs an operating system.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here&#39;s why that matters.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Early computers were built to do one thing. Like a calculator: give it numbers, get a result. But human needs kept growing. Eventually people wanted one machine that could handle &lt;em&gt;everything&lt;/em&gt; at once — play music, run a word processor, open a spreadsheet, all simultaneously. That created a new problem: something needed to manage all of that traffic inside the machine. Something needed to be in charge.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That something is the &lt;strong&gt;operating system&lt;/strong&gt; — the software layer that sits between the hardware and everything running on top of it. Without it, a computer is just an expensive paperweight.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Today there are four main families:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Unix&lt;/strong&gt; — servers and academic/engineering workstations&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;macOS&lt;/strong&gt; — Apple&#39;s universe&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Windows&lt;/strong&gt; — Microsoft&#39;s universe&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Linux&lt;/strong&gt; — open-source, runs on everything from supercomputers to smart fridges&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Which brings us back to our tiny robot brain problem. A Raspberry Pi is too small for Windows or macOS. So it runs its own flavor of Linux called &lt;strong&gt;Raspberry Pi OS&lt;/strong&gt;. Same idea, built for a credit-card-sized computer.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;So What Exactly Is a Raspberry Pi?&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In our CEO → Manager → Team Leader → Workers diagram, the Raspberry Pi takes over the CEO role entirely. Everything that used to live on the laptop — the Python programs, the decision-making logic, the commands to motors and sensors — now lives on a board the size of a deck of cards.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Pi combines a processor, memory, and programmable input/output pins into one compact package. It can talk directly to motors, sensors, and cameras without a laptop anywhere in the loop.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Phase 1, we used the laptop as CEO and Arduino Nano as Manager. From here on:&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;CEO + Manager (Python on Raspberry Pi) → Team Leader (Driver module) → Workers (Motors/Sensors)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The laptop&#39;s only job now is to &lt;em&gt;set up&lt;/em&gt; the Pi. Once that&#39;s done, we can unplug and walk away. The robot thinks for itself.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiSMxRLyG8KWaW3gMhuclcev0L3wAwPyS0TyPJMgtZuporDzJzWY069JIGimhZRDF6DMmhgJDB45Lk2Xgx6tbgLKr_MR8GmV8j33renO1NhBpSBNhQKFPWwR7jED-Rm0xIOYIy4fP-10MG4EXFs-5QPqyg7ZCsqJSPFNIrRxdfFWxIJThzhrP5QLHi8u44&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiSMxRLyG8KWaW3gMhuclcev0L3wAwPyS0TyPJMgtZuporDzJzWY069JIGimhZRDF6DMmhgJDB45Lk2Xgx6tbgLKr_MR8GmV8j33renO1NhBpSBNhQKFPWwR7jED-Rm0xIOYIy4fP-10MG4EXFs-5QPqyg7ZCsqJSPFNIrRxdfFWxIJThzhrP5QLHi8u44=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What You Need&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Component&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Notes&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Est. Cost&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Laptop&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;For setup only&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already owned&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Raspberry Pi 3B&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$50&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;MicroSD card (32GB or 64GB)&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Pi&#39;s &quot;hard drive&quot;&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$18&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Portable USB Power Bank (5V)&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Powers the Pi&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$15&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 1 — Flash the Operating System&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The MicroSD card is where Raspberry Pi OS lives. We write it from the laptop using a free tool called &lt;a href=&quot;https://www.raspberrypi.com/software/&quot;&gt;&lt;strong&gt;Raspberry Pi Imager&lt;/strong&gt;.&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Download and install &lt;strong&gt;Raspberry Pi Imager&lt;/strong&gt; on your laptop.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Insert the MicroSD card into your laptop.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Open Raspberry Pi Imager:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Choose OS&lt;/strong&gt; → select the Recommended option&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Choose Storage&lt;/strong&gt; → select your MicroSD card&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Before writing, click the &lt;strong&gt;settings gear icon&lt;/strong&gt; and configure:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Hostname&lt;/strong&gt;: anything you&#39;ll remember — e.g. &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;pi3&lt;/code&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Enable SSH&lt;/strong&gt; → Use password authentication&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Username and password&lt;/strong&gt;: e.g. username &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;pi3&lt;/code&gt;, password &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;raspberry&lt;/code&gt; — write these down, you&#39;ll use them constantly&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Configure wireless LAN&lt;/strong&gt;: enter your home WiFi name and password so the Pi connects automatically on first boot&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Click &lt;strong&gt;Write&lt;/strong&gt; and wait. Done.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiMYK_U70uq79aReJKEBSjptEWMkQww3jPfaUNkPwd9rxavfVOJEj2PD8Ttj5c64qKgQXfW8BYzNU7m1JFiYJ8gD8vmlJLkM8Tlu3gQMd_OvCkRABVKGRpifGMKGLRknGFXxO1E6ovlmnyRz87VxxgEb6CR7YGe3udkkI4EKqZ6AN5MynqdYhjRVWz3E38&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;594&quot; data-original-width=&quot;792&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiMYK_U70uq79aReJKEBSjptEWMkQww3jPfaUNkPwd9rxavfVOJEj2PD8Ttj5c64qKgQXfW8BYzNU7m1JFiYJ8gD8vmlJLkM8Tlu3gQMd_OvCkRABVKGRpifGMKGLRknGFXxO1E6ovlmnyRz87VxxgEb6CR7YGe3udkkI4EKqZ6AN5MynqdYhjRVWz3E38=w640-h480&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 2 — Boot the Pi and Find Its IP Address&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Insert the MicroSD card into the Raspberry Pi 3B. Connect power via the micro-USB port.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Wait 1–2 minutes for the Pi to boot and connect to your WiFi.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Now we need to find the Pi&#39;s IP address. The easiest way: download &lt;strong&gt;&lt;a href=&quot;https://www.advanced-ip-scanner.com&quot;&gt;Advanced IP Scanner&lt;/a&gt;&lt;/strong&gt; (free, no installation required — just run it).&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open Advanced IP Scanner, accept the terms, click &lt;strong&gt;Scan&lt;/strong&gt;. After a moment, it lists every device on your network. Look for the hostname you just set — &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;pi3&lt;/code&gt; — and note its IP address. Something like &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;192.168.1.42&lt;/code&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Before moving on, download and install &lt;a href=&quot;https://putty.org/index.html&quot;&gt;&lt;strong&gt;PuTTY&lt;/strong&gt; &lt;/a&gt;on your laptop (Windows users). Mac and Linux users already have everything they need.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 3 — Connect via SSH&lt;/span&gt;&lt;/h2&gt;
&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;SSH lets you type commands on your laptop that actually run on the Pi. No physical keyboard or monitor attached to the Pi needed.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;On Windows (PuTTY):&lt;/strong&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;Open PuTTY → enter the Pi’s IP address in Host Name → connection type SSH → port 22 → click Open.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;On macOS / Linux (Terminal):&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs &quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ssh pi3@192.168.1.42
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;(Replace with your actual username and IP.)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;When prompted for a password, type it and press Enter. The cursor won’t move while you type — that’s normal, it’s a security feature. Hit Enter and you’re in.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You should see something like:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs &quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pi3@raspberrypi:~ $
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That blinking cursor is your Pi, ready for instructions.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;step-3b--enable-vnc-required-for-remote-desktop&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: 1.5rem; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part12-updated-steps.md#step-3b--enable-vnc-required-for-remote-desktop&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;Step 3B — Enable VNC (Required for Remote Desktop)&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;SSH gives you a command line. If you want a full desktop view of the Pi on your laptop screen — mouse, icons, Thonny IDE — you need VNC enabled first.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Still in your SSH session, run:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;sudo&lt;/span&gt; raspi-config
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;→ &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Interface Options&lt;/strong&gt; → &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;VNC&lt;/strong&gt; → &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Yes&lt;/strong&gt; → &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Finish&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then restart the VNC service:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;sudo&lt;/span&gt; systemctl &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;enable&lt;/span&gt; vncserver-x11-serviced
&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;sudo&lt;/span&gt; systemctl start vncserver-x11-serviced
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Download and install &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;VNC Viewer&lt;/strong&gt; on your laptop (RealVNC, free).&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open VNC Viewer → enter the Pi’s IP address → log in with your username and password. You’ll see the Raspberry Pi desktop streamed directly to your laptop screen.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Important:&lt;/strong&gt; If VNC Viewer shows &lt;em style=&quot;box-sizing: border-box;&quot;&gt;“Timed out waiting for a response”&lt;/em&gt; — go back to SSH and run the two &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;systemctl&lt;/code&gt; commands above. That fixes it.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 4 — Set Up Python the Right Way&lt;/span&gt;&lt;/h2&gt;
&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This step matters more than it looks. How you set up the Python environment determines whether installing libraries later is smooth or painful.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;First, update the system:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;sudo&lt;/span&gt; apt update &amp;amp;&amp;amp; &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;sudo&lt;/span&gt; apt upgrade -y
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Install pip and venv tools:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;sudo&lt;/span&gt; apt install -y python3-pip python3-venv
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create the virtual environment — with one important flag:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;python3 -m venv my_project_env --system-site-packages
&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;source&lt;/span&gt; my_project_env/bin/activate
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;--system-site-packages&lt;/code&gt; flag is critical. It lets your virtual environment access system-level libraries — like &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;picamera2&lt;/code&gt;, &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;libcamera&lt;/code&gt;, and &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;RPi.GPIO&lt;/code&gt; — that can only be installed via &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;apt&lt;/code&gt;, not &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;pip&lt;/code&gt;. Without this flag, you’ll hit &lt;em style=&quot;box-sizing: border-box;&quot;&gt;“No module named picamera2”&lt;/em&gt; or &lt;em style=&quot;box-sizing: border-box;&quot;&gt;“No module named libcamera”&lt;/em&gt; errors later, even after installing everything correctly.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;When you see &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;(my_project_env)&lt;/code&gt; at the start of the command line, the environment is active.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;how-to-install-libraries--the-right-way-for-pi&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: 1.5rem; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part12-updated-steps.md#how-to-install-libraries--the-right-way-for-pi&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;How to Install Libraries — The Right Way for Pi&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Rule 1: Always use SSH for installing libraries&lt;/strong&gt;, not the Thonny terminal. SSH is stable and always uses the correct environment. Thonny’s terminal can behave unexpectedly with virtual environments.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Rule 2: Always activate the venv first:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;source&lt;/span&gt; my_project_env/bin/activate
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Rule 3: System libraries go through &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;apt&lt;/code&gt;, Python libraries go through &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;pip&lt;/code&gt;:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# System-level libraries (hardware, camera, GPIO)&lt;/span&gt;
&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;sudo&lt;/span&gt; apt install -y python3-picamera2 python3-opencv libopenblas-dev

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Python libraries&lt;/span&gt;
pip install numpy opencv-python-headless pyserial&lt;/span&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Rule 4: Verify after installing:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;bash&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;python3 -c &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;from picamera2 import Picamera2; import cv2; import RPi.GPIO as GPIO; print(&#39;All OK&#39;)&quot;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;A note on heavy libraries like PyTorch / Ultralytics:&lt;/span&gt;&lt;/strong&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Pi 3B runs a 32-bit ARM processor with only 1GB RAM. PyTorch has no official 32-bit ARM build — attempts to install it via pip will fail or hang midway through a 400MB+ download. For computer vision on Pi 3B, use&lt;/span&gt; &lt;strong style=&quot;box-sizing: border-box; font-size: large;&quot;&gt;OpenCV + picamera2&lt;/strong&gt; &lt;span style=&quot;font-size: medium;&quot;&gt;instead. Lightweight, fast, and works out of the box. We’ll cover this in Part 15.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 5 — Optional: VNC for a Visual Interface&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If command-line feels uncomfortable, VNC gives you a full desktop view of the Pi — mouse, icons, the works — streamed directly to your laptop screen.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Download and install &lt;strong&gt;&lt;a href=&quot;https://www.realvnc.com/en/connect/download/viewer-2/&quot;&gt;VNC Viewer&lt;/a&gt;&lt;/strong&gt; on your laptop (RealVNC, free).&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Open VNC Viewer → enter the Pi&#39;s IP address → log in with your username and password.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You&#39;ll see the Raspberry Pi desktop as if you were sitting in front of a monitor connected to it.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgPpp6CYXC9Nv1lk54ivFeyOeUFwxGgcMbMi2OD2D0Dx6nps9vPEnbI8HAvrbbMgy4MzeBx9S33O3nti9vNqSdl-sP2YHUHflSYvK3DFy087fdKRpHlIBsb8Q-73oR7-hSaSWrtSAlh4n_wwW9dWDD2-XvlI1o5QHoTAUBkY24Ly6-6u5m2Jq4jFYLZWPA&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;395&quot; data-original-width=&quot;729&quot; height=&quot;346&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgPpp6CYXC9Nv1lk54ivFeyOeUFwxGgcMbMi2OD2D0Dx6nps9vPEnbI8HAvrbbMgy4MzeBx9S33O3nti9vNqSdl-sP2YHUHflSYvK3DFy087fdKRpHlIBsb8Q-73oR7-hSaSWrtSAlh4n_wwW9dWDD2-XvlI1o5QHoTAUBkY24Ly6-6u5m2Jq4jFYLZWPA=w640-h346&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Once libraries are installed via SSH, open VNC Viewer → connect to the Pi → find Thonny at:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Menu (raspberry icon, top-left) → Programming → Thonny Python IDE&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before running any code in Thonny, make sure it’s using the right Python interpreter:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Tools → Options → Interpreter → Select:&lt;/strong&gt; &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;my_project_env/bin/python3&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This ensures Thonny uses your virtual environment — with all the libraries you installed — rather than the system Python.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Write code, press &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;F5&lt;/strong&gt; to run. Everything else works exactly like PyCharm did on your laptop.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What Just Happened&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;No code was written in this part. No motors turned, no sensors blinked.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;But something important happened: the robot&#39;s brain moved.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Everything that used to live on the laptop — the Python environment, the decision-making, the ability to control hardware — now lives inside a board smaller than a credit card, powered by a USB power bank, sitting on the robot itself.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The laptop&#39;s job is done. It set up the Pi and can now walk away.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In the next part, we connect the C101 4WD kit to the Pi via L298N and write Python &lt;em&gt;directly on the Pi&lt;/em&gt; to drive the car. No laptop in the loop. No USB cable. No Arduino middleman.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot is about to move on its own.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up: Part 13 — Four wheels, one brain. The C101 meets the Raspberry Pi.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-12-robot-gets-its-own-brain.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEiSMxRLyG8KWaW3gMhuclcev0L3wAwPyS0TyPJMgtZuporDzJzWY069JIGimhZRDF6DMmhgJDB45Lk2Xgx6tbgLKr_MR8GmV8j33renO1NhBpSBNhQKFPWwR7jED-Rm0xIOYIy4fP-10MG4EXFs-5QPqyg7ZCsqJSPFNIrRxdfFWxIJThzhrP5QLHi8u44=s72-w480-h640-c" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-7349837160043885</guid><pubDate>Tue, 26 May 2026 21:27:44 +0000</pubDate><atom:updated>2026-05-30T05:03:56.515-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Okay I’m Hooked</category><title>HC-SR04 Ultrasonic Sensor with Arduino and Python — Part 11: Meet the Real Sensor</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span style=&quot;background-color: white; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt;Phase 1 was a scenic tour through the world of robotics — high mileage, low spending, maximum borrowing from things we already owned. Laptop, old phone, RC car from the garage, a few skipped Starbucks runs. Ten parts, under $40, and a surprisingly complete picture of how robots actually think.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;But a tour is just a tour. At some point you have to move in.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Welcome to Phase 2.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;one-truth-we-keep-coming-back-to&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#one-truth-we-keep-coming-back-to&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;One Truth We Keep Coming Back To&lt;/span&gt;&lt;/h2&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Robots need senses and a brain. The senses are sensors. The brain is a program — specifically, our Python program, which for now lives on a laptop. We say &quot;for now&quot; because a robot that needs a laptop sitting next to it isn’t really autonomous. Eventually, that brain needs to move &lt;em style=&quot;box-sizing: border-box;&quot;&gt;into&lt;/em&gt; the robot itself. But we’ll get there.&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Based on everything the sensors collect — sight, sound, touch — the Python brain decides how to respond.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Back when we were just getting started in Phase 1:&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Python gives orders → Motors execute&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Simple enough. But motors need to spin both directions, speed up, slow down, stop instantly. That requires a middleman — a driver module — to handle the actual electrical work. So the real flow became:&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Python gives orders → Driver module → Motors execute&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And then we realized that Python and hardware don’t always speak the same language. Different components from different manufacturers don’t always play nicely together. We needed one more layer — a microcontroller — to translate and distribute commands to the right place:&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;CEO (Python) → Manager (Microcontroller) → Team Leader (Driver module) → Workers (Motors)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now here’s an interesting twist: what if the Workers aren’t motors, but sensors? Sensors don’t &lt;em style=&quot;box-sizing: border-box;&quot;&gt;execute&lt;/em&gt; commands — they &lt;em style=&quot;box-sizing: border-box;&quot;&gt;report&lt;/em&gt; information back up the chain. Same structure, reversed direction, one less middleman needed:&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Workers (Sensors) report → Manager (Microcontroller) → CEO (Python)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s exactly the setup we’re building today.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;phase-2-shopping-list&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#phase-2-shopping-list&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Phase 2 Shopping List&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before we dive in, here’s the full component list for everything ahead. Buy it all at once or piece by piece — either way works:&lt;/span&gt;&lt;/p&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; color: #2b2b2f; display: block; letter-spacing: 0.2px; margin: 1rem 0px; max-width: 100%; overflow-x: auto; width: max-content;&quot;&gt;&lt;thead style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Component&lt;/span&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Notes&lt;/span&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Est. Cost&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;C101 4WD kit&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$20&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Raspberry Pi 3B&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$50&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Pi Camera Module v2&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$13&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;L298N Motor Driver&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already have from Phase 1&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;—&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino Nano&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already have from Phase 1&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;—&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-SR04 Ultrasonic Sensor&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$4&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Portable USB Power Bank (5V)&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Power source for Pi&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$15&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Li-ion battery pack 7.4V&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Power source for motors&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$12&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;For this part, the only new purchase is the HC-SR04 — about $4 each, or $6 for two on Amazon. Everything else we already own.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg_2JR9u8tOqCqEIK3jtBMf7TPGAPoc8DSL4fd_LrWIh-RFnteXQNq0NaWjiOTKTOhUMTmrtpV1KezlF-JdcUgtqW1P3hbz7QI8DwS2NW8C-vXcnZ0SaBZlnBASsZYWv8dECm88Z9ALBcoEGZpdsXUJKyThsr65jhg74mbRQQUaQ9Kpe91ATqTtxLSu59A&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg_2JR9u8tOqCqEIK3jtBMf7TPGAPoc8DSL4fd_LrWIh-RFnteXQNq0NaWjiOTKTOhUMTmrtpV1KezlF-JdcUgtqW1P3hbz7QI8DwS2NW8C-vXcnZ0SaBZlnBASsZYWv8dECm88Z9ALBcoEGZpdsXUJKyThsr65jhg74mbRQQUaQ9Kpe91ATqTtxLSu59A=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Alright. Let’s build something.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;wiring-it-up&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#wiring-it-up&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Wiring It Up&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 1&lt;/strong&gt; — Seat the Arduino Nano on the breadboard. Make sure the two rows of pins straddle the center divider — one row on each side. If both rows land on the same side, the pins are electrically connected to each other, which is not what we want.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiTlFH_iadeHsrWdWF_YjqihplGiUL2bjTV7Zs18B6wqYDSt6Ng53Rh0NP7Gac_b6Wem1MdANVMp-8indq1QipIUcwE6mcCJ5QTREHI9CsumD2PCKXWrWpsrjVGXhWyRMtG1mU3q8xt5Gk8zpGRn-vkqyLvYMAeem1vkxhl3DDpSSmo1kfSnk4F4Z32Ulk&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiTlFH_iadeHsrWdWF_YjqihplGiUL2bjTV7Zs18B6wqYDSt6Ng53Rh0NP7Gac_b6Wem1MdANVMp-8indq1QipIUcwE6mcCJ5QTREHI9CsumD2PCKXWrWpsrjVGXhWyRMtG1mU3q8xt5Gk8zpGRn-vkqyLvYMAeem1vkxhl3DDpSSmo1kfSnk4F4Z32Ulk=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 2&lt;/strong&gt; — Connect the HC-SR04 to the Arduino Nano using four Male-to-Male jumper wires:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-SR04 VCC  → Arduino 5V
HC-SR04 TRIG → Arduino D5
HC-SR04 ECHO → Arduino D4
HC-SR04 GND  → Arduino GND
&lt;/span&gt;&lt;/code&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 3&lt;/strong&gt; — Connect the Arduino Nano to your laptop via USB-Mini-B cable. The power LED on the Nano should light up.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiDxbHsIUdsqh7LmT3-zlUYZHjOfUAnq8Qv9-UiJxeW4LkhZqlOwZpZ2u1TyJi0gAGdHw1LHhzUr_AdQwxAmwZ6Z8hdtM68s5GNtn2hd04IdIYrKGUjIo42N37ebgSK_xzgGyMrs_jp-S5w6HITf967vBaejhmcW-DnS8AttzP7rmW6lEKsh-Gdq3M2ETE&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiDxbHsIUdsqh7LmT3-zlUYZHjOfUAnq8Qv9-UiJxeW4LkhZqlOwZpZ2u1TyJi0gAGdHw1LHhzUr_AdQwxAmwZ6Z8hdtM68s5GNtn2hd04IdIYrKGUjIo42N37ebgSK_xzgGyMrs_jp-S5w6HITf967vBaejhmcW-DnS8AttzP7rmW6lEKsh-Gdq3M2ETE=w480-h640&quot; width=&quot;480&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s the hardware done. Four wires and a USB cable.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;upload-the-arduino-code&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#upload-the-arduino-code&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Upload the Arduino Code&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you’ve been through Phase 1, this process is familiar. Quick recap for completeness:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;1. Software and Driver&lt;/strong&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;Download and install the latest Arduino IDE from the official Arduino website. Most Arduino Nanos sold today use a CH340 USB chip — if your computer doesn’t recognize the board, search for &quot;CH340 driver&quot; and install it.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;2. Configure the Board&lt;/strong&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;Connect the Nano via USB, then in Arduino IDE:&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 0px; padding: 0px 0px 0px 28px;&quot;&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Tools → Board → Arduino AVR Boards → &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Arduino Nano&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Tools → Processor → &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;ATmega328P (Old Bootloader)&lt;/strong&gt; if your board is older; &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;ATmega328P&lt;/strong&gt; if newer&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Tools → Port → select the COM port that appeared when you plugged in the USB&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;3. Upload&lt;/strong&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;Paste the code below, click &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Verify&lt;/strong&gt; (✔), then &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Upload&lt;/strong&gt; (→). Wait for&amp;nbsp;&quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Done uploading.&quot;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;cpp&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;int&lt;/span&gt; trigPin = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;5&lt;/span&gt;;
&lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;int&lt;/span&gt; echoPin = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;4&lt;/span&gt;;

&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
  Serial.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;begin&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;9600&lt;/span&gt;);
  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;pinMode&lt;/span&gt;(trigPin, OUTPUT);
  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;pinMode&lt;/span&gt;(echoPin, INPUT);
}

&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;// Send ultrasonic pulse&lt;/span&gt;
  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;digitalWrite&lt;/span&gt;(trigPin, LOW);
  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;delayMicroseconds&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;);
  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;digitalWrite&lt;/span&gt;(trigPin, HIGH);
  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;delayMicroseconds&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;10&lt;/span&gt;);
  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;digitalWrite&lt;/span&gt;(trigPin, LOW);

  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;// Measure how long the echo takes to return&lt;/span&gt;
  &lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;long&lt;/span&gt; duration = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;pulseIn&lt;/span&gt;(echoPin, HIGH);

  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;// Convert time to distance in cm&lt;/span&gt;
  &lt;span class=&quot;hljs-type&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;int&lt;/span&gt; distance = duration * &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.034&lt;/span&gt; / &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;;

  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;// Send the reading to Python via Serial&lt;/span&gt;
  Serial.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;println&lt;/span&gt;(distance);

  &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;delay&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;100&lt;/span&gt;); &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;// Wait 100ms before next reading&lt;/span&gt;
}
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This code fires an ultrasonic pulse, listens for the echo, converts the round-trip time into centimeters, and sends that number to Python over Serial — 10 times per second.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-python-side&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#the-python-side&quot; id=&quot;5&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Python Side&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Install the serial library if you haven’t already:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install pyserial
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new file called &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;Ultrasonic.py&lt;/code&gt;:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; serial
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; time

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Change &#39;COM3&#39; to your actual port (check Arduino IDE → Tools → Port)&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# On Mac/Linux it looks like &#39;/dev/ttyUSB0&#39; or &#39;/dev/cu.usbserial-...&#39;&lt;/span&gt;
arduino_port = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;COM3&#39;&lt;/span&gt;
baud_rate = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;9600&lt;/span&gt;

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;try&lt;/span&gt;:
    ser = serial.Serial(arduino_port, baud_rate, timeout=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;)
    time.sleep(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Wait for Arduino to reboot after connection&lt;/span&gt;
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;Connected to &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{arduino_port}&lt;/span&gt;&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;except&lt;/span&gt; Exception &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;as&lt;/span&gt; e:
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;Connection error: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{e}&lt;/span&gt;&quot;&lt;/span&gt;)
    exit()

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;try&lt;/span&gt;:
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; ser.in_waiting &amp;gt; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;:
            line = ser.readline().decode(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;utf-8&#39;&lt;/span&gt;).rstrip()
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; line:
                &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;Distance: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{line}&lt;/span&gt; cm&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;except&lt;/span&gt; KeyboardInterrupt:
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;\nStopped.&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;finally&lt;/span&gt;:
    ser.close()
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Connection closed.&quot;&lt;/span&gt;)
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Run&lt;/strong&gt;. You’ll see&amp;nbsp;&quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Connected to COM3&quot;&lt;/em&gt;&amp;nbsp;followed by a continuous stream of distance readings. Wave your hand in front of the HC-SR04 and watch the numbers change in real time.&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Distance: 42 cm
Distance: 38 cm
Distance: 21 cm
Distance: 9 cm
Distance: 12 cm
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Manager (Arduino) is measuring, and reporting back to the CEO (Python). Exactly as planned.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;how-it-works&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#how-it-works&quot; id=&quot;6&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;How It Works&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhyzYof2MzFDF3SPyYLO31Da5P0LXIFUobyDOgvy3CsWISLKaCxQGpxUVlU_0rylngqPyhrqM6lkFGG-Lx_ZYKoQW3xfBgFZP9zq2nKnFKpZJ3F7IJZ-9l3QaZXmXnCKnSdvRZMG8FiuLZA0De8ViYfsWy1dq7pVcr98d4pWGdRLUhf3Ud994HIJCIjPxw&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;1023&quot; data-original-width=&quot;1846&quot; height=&quot;354&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhyzYof2MzFDF3SPyYLO31Da5P0LXIFUobyDOgvy3CsWISLKaCxQGpxUVlU_0rylngqPyhrqM6lkFGG-Lx_ZYKoQW3xfBgFZP9zq2nKnFKpZJ3F7IJZ-9l3QaZXmXnCKnSdvRZMG8FiuLZA0De8ViYfsWy1dq7pVcr98d4pWGdRLUhf3Ud994HIJCIjPxw=w640-h354&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The HC-SR04 fires a burst of ultrasonic sound — too high-pitched for human ears — and listens for the echo. The math is straightforward:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;distance = (travel time × speed of sound) ÷ 2
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Divide by 2 because the sound makes a round trip: out to the object, back to the sensor. That’s it. No AI, no training data, no GPU required. Just physics.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;ultrasonic-vs-camera-the-quick-version&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#ultrasonic-vs-camera-the-quick-version&quot; id=&quot;7&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Ultrasonic vs. Camera: The Quick Version&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We spent a lot of Phase 1 with camera-based detection. Now we have a $4 hardware sensor. Which one wins?&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Neither. They solve different problems.&lt;/span&gt;&lt;/p&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; color: #2b2b2f; display: block; letter-spacing: 0.2px; margin: 1rem 0px; max-width: 100%; overflow-x: auto; width: max-content;&quot;&gt;&lt;thead style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Camera&lt;/span&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-SR04&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Works in the dark?&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;No&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Yes&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Knows &lt;em style=&quot;box-sizing: border-box;&quot;&gt;what&lt;/em&gt; the object is?&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Yes&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;No&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Precise distance in cm?&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Estimates&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Yes&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;CPU cost&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;High&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Near zero&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Price&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already owned&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$4&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The camera sees the world in rich detail but needs light and processing power. The ultrasonic sensor is blind to everything except &quot;something is X centimeters away&quot; — but it works in pitch darkness, costs almost nothing, and barely uses any CPU. In a real robot, you’d use both. Different tools, different jobs.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;whats-next&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part11.md#whats-next&quot; id=&quot;8&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What’s Next&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We have a sensor that measures distance and a Python program that reads it. What’s missing? A brain that lives &lt;em style=&quot;box-sizing: border-box;&quot;&gt;inside&lt;/em&gt; the robot — not on a laptop sitting nearby.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s Part 12. The Raspberry Pi 3B comes out of the box.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up: Part 12 — The robot stops borrowing our laptop and gets a brain of its own.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-11-meet-real-sensor-hc-sr04.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEg_2JR9u8tOqCqEIK3jtBMf7TPGAPoc8DSL4fd_LrWIh-RFnteXQNq0NaWjiOTKTOhUMTmrtpV1KezlF-JdcUgtqW1P3hbz7QI8DwS2NW8C-vXcnZ0SaBZlnBASsZYWv8dECm88Z9ALBcoEGZpdsXUJKyThsr65jhg74mbRQQUaQ9Kpe91ATqTtxLSu59A=s72-w480-h640-c" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-2186107827775810465</guid><pubDate>Mon, 25 May 2026 13:08:16 +0000</pubDate><atom:updated>2026-05-30T05:03:34.985-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Beginner Robotics with Python: Phase 1 Recap — Part 10: What We Built, What We Learned</title><description>&lt;p&gt;&lt;span face=&quot;-apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif&quot; style=&quot;background-color: white; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Nine parts. Less than $40 total. A few skipped Starbucks runs, a few sacrificed Taco Bell Crunchy Tacos — all in the name of science, and the deeply held belief that somewhere down this road, we build something better than Bumblebee. Or at least Bumblebee’s budget cousin.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before we move on, let’s take stock of what actually happened here.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-one-idea-we-kept-coming-back-to&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part10.md#the-one-idea-we-kept-coming-back-to&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The One Idea We Kept Coming Back To&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Every single part of Phase 1 orbited around the same idea:&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Robots need senses. Based on what they see, hear, and feel through their sensors, the Python brain decides how to respond.&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We said it in Part 1. We said it again in Part 4. We’ll probably say it again in Phase 2 because some things are worth repeating until they’re automatic. This is one of them.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;what-we-actually-built&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part10.md#what-we-actually-built&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We Actually Built&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;We started with a keyboard.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A laptop, an Arduino Nano, an L298N Motor Driver, and two DC motors. Press an arrow key → motor spins. Simple? Yes. Boring? Maybe. Important? Absolutely.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here’s the thing that’s easy to miss: keyboard control and remote control look identical from the outside. Both make the wheels turn. But they’re completely different on the inside.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A remote is a one-trick pony. It sends fixed signals to fixed hardware. It cannot learn, adapt, or make decisions. Our Python brain can. Once the &quot;infrastructure&quot; is in place — once the robot has senses and a way to process them — you can teach it to stop automatically when something blocks its path, turn left when it reads a street sign that says &quot;ABC Street,&quot; or ignore the intersection entirely if it’s running late. An RC car cannot do any of that. Ever.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We also settled on a mental model that made everything easier to think about:&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;CEO (Python) → Manager (Microcontroller) → Team Leader (Motor Driver) → Workers (Motors)&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Every layer has one job. Every layer talks only to the layer next to it. Clean, simple, and it actually maps to how real robotics systems are structured — just with more expensive components.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;We cut the cord.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Bluetooth module HC-06, about $9 on Amazon. Suddenly the robot wasn’t tethered to a laptop anymore. It could move. It looked like a robot. Neil Armstrong once said &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;one small step for man, one giant leap for mankind&quot;&lt;/em&gt;&amp;nbsp;— ours was one less USB cable, one giant leap toward something that actually resembles Bumblebee.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This step mattered more than it sounds. A robot that can only move as far as its cable reaches isn’t a robot. It’s a very complicated puppet.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;We gave it eyes.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Object detection with YOLOv8. Distance estimation. Obstacle avoidance logic. Face Detection with Haar Cascade. Face Recognition with LBPH — complete with a working attendance system. Line following via color detection.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A lot of the &quot;actions&quot; at this stage were still our beloved &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;print(&quot;Turn left!&quot;)&lt;/code&gt; and &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;print(&quot;Stop!&quot;)&lt;/code&gt; — legendary in their simplicity, perfect for isolating the logic before wiring it to actual motors. But the logic was real. The decisions were real. Swapping &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;print()&lt;/code&gt; for motor commands is the easy part. Getting the decisions right is the hard part. We did the hard part.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;We gave it ears.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Voice commands processed in Python, no cloud service required, no API key, no monthly subscription. Say &quot;move forward&quot; → the robot understands. Not quite Siri. Not quite Alexa. But our version runs offline, costs nothing to operate, and listens without secretly sending your conversations anywhere.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-honest-summary&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part10.md#the-honest-summary&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Honest Summary&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We built all of this with:&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 0px; padding: 0px 0px 0px 28px;&quot;&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A laptop we already owned&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;An old RC car from the garage&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A phone in our pocket&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A handful of components that added up to less than a Costco run&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And the result isn’t a finished product. It was never supposed to be. It’s a foundation — a working understanding of how perception, decision-making, and action connect in a real system.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Every concept we touched in Phase 1 exists in production robotics. YOLOv8 runs in warehouse automation systems. LBPH-style face recognition powers access control. Line following is the backbone of AGV systems in factories. Voice interfaces run in hospitals and hotels. We didn’t just study these ideas — we ran them, broke them, debugged them, and made them work.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s not nothing. That’s actually quite a lot.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;whats-next&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part10.md#whats-next&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What’s Next&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Phase 1 was &quot;Cheat Mode&quot; — maximum output, minimum spending, borrow everything you can.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Phase 2 is where we start buying real things.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The C101 4WD kit and a Raspberry Pi 3B are already waiting. Real sensors. Real onboard computing. A robot that doesn’t need a laptop nearby to think. The &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;print(&quot;Turn left!&quot;)&lt;/code&gt; commands finally become actual motor commands — and the logic we spent nine parts building gets a body to move around in.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; letter-spacing: 0.2px;&quot;&gt;&lt;i&gt;Next up: Part 11 — Meet the HC-SR04 Ultrasonic Sensor. Real hardware, real distance, real robot.&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-10-phase-1-recap-what-we-built.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-3580913254315914700</guid><pubDate>Mon, 25 May 2026 12:59:31 +0000</pubDate><atom:updated>2026-05-30T05:03:10.774-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Line Following Robot Simulation with Webcam and OpenCV — Part 9: The Robot Learns to Stay in Its Lane</title><description>&lt;p&gt;&lt;span face=&quot;-apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif&quot; style=&quot;background-color: white; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Of all the senses a robot can have, vision gets the most attention. Always has. Probably always will.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And honestly? Fair enough. There’s something deeply satisfying about watching a machine &lt;em style=&quot;box-sizing: border-box;&quot;&gt;see&lt;/em&gt; something and respond to it — no buttons pressed, no keyboard involved, just the robot making a decision on its own based on what’s in front of it.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We’re not talking about fully autonomous vehicles today. But line following with a webcam — where a robot locks onto a colored line and tracks it automatically — might be the single easiest way to see that idea come to life. Draw a line on paper, run some code, watch Python chase it around the desk like a very focused, very confused puppy.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Let’s do it.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;how-it-actually-works-a-scenic-ride-through-the-theory&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#how-it-actually-works-a-scenic-ride-through-the-theory&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;How It Actually Works (A Scenic Ride Through the Theory)&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Some of this will feel abstract. That’s fine — we’re not going deep today, just getting the lay of the land. Think of it as a quick sightseeing tour: you don’t need to know the history of every building to enjoy the view.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The system runs on a closed loop: &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;detect → calculate → decide&lt;/strong&gt;. Here’s what that looks like in practice:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Capture&lt;/strong&gt;: The webcam continuously grabs frames from whatever it’s pointing at.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Image Processing&lt;/strong&gt;: Raw color video gets converted from BGR to HSV — a color space that makes it much easier to isolate specific colors regardless of lighting. Then the system applies a color mask: everything that matches the target color stays white, everything else goes black. Clean signal, no noise.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Find the line&lt;/strong&gt;: OpenCV’s contour detection scans the masked image and finds the edges of the colored region. We grab the largest contour — that’s our line — and calculate its center point using image moments.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Decide&lt;/strong&gt;: Compare the center of the line to the center of the frame. Is the line on the left? Turn left. On the right? Turn right. Dead center? Go straight. That’s the entire decision tree. Three outcomes. Surprisingly effective.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Act&lt;/strong&gt;: In a real robot, this decision gets sent to the motor controller. Today, we’re printing it on screen instead. Same logic, no wheels.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;real-world-applications-why-this-actually-matters&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#real-world-applications-why-this-actually-matters&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Real-World Applications (Why This Actually Matters)&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This isn’t just a fun webcam trick. Line following with computer vision is the foundation of some surprisingly serious technology:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;AGV/AMR systems in factories&lt;/strong&gt;: Smart warehouses use camera-equipped robots that follow floor markings to transport materials between workstations — no physical rails, no human drivers.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Prototype autonomous vehicles&lt;/strong&gt;: Entry-level self-driving research often starts here — detect the lane, stay in it, handle exceptions. The fancy stuff comes later.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Hospital and care facility robots&lt;/strong&gt;: Some medical robots navigate by following marked corridors to deliver medication or lab samples.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;STEM education&lt;/strong&gt;: Line following is practically a rite of passage in robotics courses worldwide — it teaches perception, decision-making, and closed-loop control all in one project.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;one-honest-warning-before-we-get-excited&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#one-honest-warning-before-we-get-excited&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;One Honest Warning Before We Get Excited&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Camera-based line following has real advantages: cheap, flexible, easy to experiment with, and genuinely &quot;impressive&quot;-looking results. But let’s be honest about the limitations too.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Imagine a power outage. Everything goes dark. No lights, no visibility. Our &quot;impressive&quot; robot would just… sit there. Completely blind. Utterly useless. Meanwhile, a robot with an infrared sensor would keep rolling along without missing a beat — because infrared doesn’t need visible light.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Also, processing a continuous video stream is computationally hungry. On a lightweight board, a robot that looks great on a laptop webcam might start struggling when you try to move the same code onto embedded hardware. We’ll cross that bridge when we get there.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;For now: webcam on a laptop, colored line on paper, Python doing the thinking. Controlled conditions, clear results, zero excuses.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;what-you-need&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#what-you-need&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What You Need&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;One sheet of white A4 paper and a red Sharpie. That’s it. Draw a thick, bold line — curves, angles, whatever you like. The bolder the line, the easier it is for the color mask to pick it up cleanly. Red works great against white. Other bright colors work too — we’ll cover how to switch in the code.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-code&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#the-code&quot; id=&quot;5&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Code&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new Python file called &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;LineFollow.py&lt;/code&gt;:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; cv2
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; numpy &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;as&lt;/span&gt; np

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Open webcam (change 0 if you have multiple cameras)&lt;/span&gt;
cap = cv2.VideoCapture(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Define HSV color range for the line we&#39;re tracking (red, range 1)&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Note: red in HSV spans two ranges — this covers the lower one&lt;/span&gt;
lower_color = np.array([&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;120&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;70&lt;/span&gt;])
upper_color = np.array([&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;])

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
    ret, frame = cap.read()
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;not&lt;/span&gt; ret:
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Flip the frame horizontally (mirror mode — easier to work with)&lt;/span&gt;
    frame = cv2.flip(frame, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Convert from BGR to HSV color space&lt;/span&gt;
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Create a mask — keep only pixels that fall within our color range&lt;/span&gt;
    mask = cv2.inRange(hsv, lower_color, upper_color)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Clean up the mask — remove small noise specks&lt;/span&gt;
    mask = cv2.erode(mask, &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;None&lt;/span&gt;, iterations=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
    mask = cv2.dilate(mask, &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;None&lt;/span&gt;, iterations=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Find contours of the colored region&lt;/span&gt;
    contours, _ = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;len&lt;/span&gt;(contours) &amp;gt; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;:
        &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Take the largest contour — that&#39;s our line&lt;/span&gt;
        c = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;max&lt;/span&gt;(contours, key=cv2.contourArea)

        &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Calculate the center point of the contour&lt;/span&gt;
        M = cv2.moments(c)
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m00&quot;&lt;/span&gt;] &amp;gt; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;:
            cX = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;int&lt;/span&gt;(M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m10&quot;&lt;/span&gt;] / M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m00&quot;&lt;/span&gt;])
            cY = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;int&lt;/span&gt;(M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m01&quot;&lt;/span&gt;] / M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m00&quot;&lt;/span&gt;])

            &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Draw a dot at the detected center point&lt;/span&gt;
            cv2.circle(frame, (cX, cY), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;7&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;), -&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;)

            &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Decide direction based on where the center falls&lt;/span&gt;
            h, w, _ = frame.shape
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; cX &amp;lt; w // &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt; - &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;:
                cv2.putText(frame, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Turn LEFT&quot;&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;20&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;),
                            cv2.FONT_HERSHEY_SIMPLEX, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; cX &amp;gt; w // &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt; + &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;:
                cv2.putText(frame, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Turn RIGHT&quot;&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;20&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;),
                            cv2.FONT_HERSHEY_SIMPLEX, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt;:
                cv2.putText(frame, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Go STRAIGHT&quot;&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;20&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;),
                            cv2.FONT_HERSHEY_SIMPLEX, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Show both windows — the live feed and the color mask&lt;/span&gt;
    cv2.imshow(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Line Follow Simulation&quot;&lt;/span&gt;, frame)
    cv2.imshow(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Color Mask&quot;&lt;/span&gt;, mask)

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; cv2.waitKey(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;) &amp;amp; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0xFF&lt;/span&gt; == &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;ord&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;q&#39;&lt;/span&gt;):
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

cap.release()
cv2.destroyAllWindows()&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); font-family: verdana; font-size: medium; height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Run&lt;/strong&gt;. Two windows will appear: the live camera feed and a black-and-white mask showing exactly what the algorithm &quot;sees.&quot; Hold your paper with the red line in front of the camera and move it slowly left and right. You’ll see the text on screen switch between &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Turn LEFT&quot;&lt;/em&gt;, &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Turn RIGHT&quot;&lt;/em&gt;, and &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Go STRAIGHT&quot;&lt;/em&gt;&amp;nbsp;as the line shifts across the frame.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;code-walkthrough--the-three-parts-that-matter&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#code-walkthrough--the-three-parts-that-matter&quot; id=&quot;6&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Code Walkthrough — The Three Parts That Matter&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;1. Finding the line (Contours)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;contours, _ = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
c = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;max&lt;/span&gt;(contours, key=cv2.contourArea)&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); font-family: verdana; font-size: medium; height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;findContours&lt;/code&gt; scans the black-and-white mask and traces the edges of every white region it finds. &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;max(..., key=cv2.contourArea)&lt;/code&gt; picks the largest one — we’re assuming that’s our line, not a stray red pixel on your shirt.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;2. Calculating the center (Image Moments)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;M = cv2.moments(c)
cX = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;int&lt;/span&gt;(M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m10&quot;&lt;/span&gt;] / M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m00&quot;&lt;/span&gt;])
cY = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;int&lt;/span&gt;(M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m01&quot;&lt;/span&gt;] / M[&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;m00&quot;&lt;/span&gt;])
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;cv2.moments&lt;/code&gt; computes geometric properties of the contour — think of it as finding the &quot;center of gravity&quot; of the colored region. &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;cX&lt;/code&gt; and &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;cY&lt;/code&gt; are the coordinates of that center point. That red dot you see on screen? That’s it.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;3. Simulating navigation&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; cX &amp;lt; w // &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt; - &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;:    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Line is left of center&lt;/span&gt;
    → Turn LEFT
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; cX &amp;gt; w // &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt; + &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;50&lt;/span&gt;:  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Line is right of center&lt;/span&gt;
    → Turn RIGHT
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt;:                    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Line is roughly centered&lt;/span&gt;
    → Go STRAIGHT
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The frame gets divided into three zones based on horizontal position. The 50-pixel buffer on each side creates a &quot;tolerance zone&quot; in the middle — without it, the robot would jitter left-right constantly trying to hit an exact pixel. In a real robot, these three text outputs would be replaced by motor commands. The logic stays identical.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;want-a-different-color&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#want-a-different-color&quot; id=&quot;7&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Want a Different Color?&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Red was convenient for this demo, but any bright color on a white background works. Here are the HSV ranges for common choices:&lt;/span&gt;&lt;/p&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; color: #2b2b2f; display: block; letter-spacing: 0.2px; margin: 1rem 0px; max-width: 100%; overflow-x: auto; width: max-content;&quot;&gt;&lt;thead style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Color&lt;/span&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Lower&lt;/span&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Upper&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Red (range 1)&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[0, 120, 70]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[10, 255, 255]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Red (range 2)&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[170, 120, 70]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[180, 255, 255]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Blue&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[100, 150, 50]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[140, 255, 255]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Green&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[40, 70, 70]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[80, 255, 255]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Yellow&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[20, 100, 100]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;[30, 255, 255]&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Swap the &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;lower_color&lt;/code&gt; and &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;upper_color&lt;/code&gt; values in the code and you’re good to go.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;what-we-just-built&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part9.md#what-we-just-built&quot; id=&quot;8&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We Just Built&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A Python program that watches a live video feed, isolates a specific color, finds its center of mass, and makes a directional decision — all in real time, on a laptop, with a webcam and a piece of paper.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s the full perception-decision loop. The same loop that lives inside every line-following robot, every lane-keeping system, and every autonomous warehouse vehicle — just at a different scale and with better hardware.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;When we’re ready to put this on a real robot, the change is minimal: swap the &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;putText&lt;/code&gt; commands for motor control signals. The vision logic doesn’t change at all.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Next up: Part 10 — Phase 1 Recap. Everything we’ve built, everything we’ve learned, and a proper send-off before we start buying actual hardware.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-9-robot-learns-to-stay-in-its-lane.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-673319676452423627</guid><pubDate>Sun, 24 May 2026 23:52:56 +0000</pubDate><atom:updated>2026-05-30T05:02:53.393-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Face Recognition Attendance System with Python and OpenCV — Part 8B: The Robot Knows Who You Are</title><description>&lt;p&gt;&lt;span face=&quot;-apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif&quot; style=&quot;background-color: white; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Quick recap before we dive in.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Part 8A, we built &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Face Detection&lt;/strong&gt;: the robot learned to find faces in a live video stream and draw a green box around them. It could answer &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Is there a face here, and where is it?&quot;&lt;/em&gt;&amp;nbsp;— nothing more.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now we go one level deeper. Face Detection was the prerequisite. This is the actual goal: &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Face Recognition&lt;/strong&gt; — teaching the robot to answer &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Whose face is this?&quot;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And just to make it concrete — here’s what &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;haarcascade_frontalface_default.xml&lt;/code&gt; actually is under the hood:&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 0px; padding: 0px 0px 0px 28px;&quot;&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;It contains thousands of &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Haar-like features&lt;/strong&gt; (light/dark pattern detectors) stored as decision trees inside a &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&amp;lt;stages&amp;gt;&lt;/code&gt; structure.&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;It operates on a standard &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;24×24 pixel window&lt;/strong&gt;, sliding that window across every part of the frame looking for face-shaped patterns.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That file does the &lt;em style=&quot;box-sizing: border-box;&quot;&gt;finding&lt;/em&gt;. What we’re building today does the &lt;em style=&quot;box-sizing: border-box;&quot;&gt;recognizing&lt;/em&gt;.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-plan&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8b.md#the-plan&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Plan&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Three Python files. Three jobs. One attendance system.&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Dataset.py   →   Training.py   →   Recognition.py
(collect)         (learn)            (identify)
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Install what you need first:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;pip install opencv-python opencv-contrib-python numpy&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); font-family: verdana; font-size: medium; height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;step-1--collect-face-data-datasetpy&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8b.md#step-1--collect-face-data-datasetpy&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 1 — Collect Face Data (Dataset.py)&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before the robot can recognize anyone, it needs to study them. We’re going to photograph each person 30 times — different angles, different expressions — and store those images in a folder called &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;dataset&lt;/code&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new Python file called &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;Dataset.py&lt;/code&gt; and paste this in:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; cv2
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; os

face_detector = cv2.CascadeClassifier(
    cv2.data.haarcascades + &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;haarcascade_frontalface_default.xml&quot;&lt;/span&gt;
)

os.makedirs(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;dataset&quot;&lt;/span&gt;, exist_ok=&lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
    face_id = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;input&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;\n Enter user ID (e.g. 1, 2, 3...) and press Enter: &quot;&lt;/span&gt;)
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;\n [INFO] Starting camera. Look straight ahead and stay still...&quot;&lt;/span&gt;)

    cam = cv2.VideoCapture(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)
    cam.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;640&lt;/span&gt;)
    cam.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;480&lt;/span&gt;)

    count = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
        ret, img = cam.read()
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        faces = face_detector.detectMultiScale(gray, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1.3&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;5&lt;/span&gt;)

        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; x, y, w, h &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; faces:
            cv2.rectangle(img, (x, y), (x + w, y + h), (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
            count += &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;
            cv2.imwrite(
                &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;dataset/User.&lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{face_id}&lt;/span&gt;.&lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{count}&lt;/span&gt;.jpg&quot;&lt;/span&gt;,
                gray[y : y + h, x : x + w],
            )

        cv2.putText(img, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;ID: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{face_id}&lt;/span&gt; | Photo: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{count}&lt;/span&gt;/30&quot;&lt;/span&gt;,
                    (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;), cv2.FONT_HERSHEY_SIMPLEX, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.8&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
        cv2.imshow(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;image&quot;&lt;/span&gt;, img)

        k = cv2.waitKey(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;100&lt;/span&gt;) &amp;amp; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0xFF&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; k == &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;27&lt;/span&gt;:
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; count &amp;gt;= &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;:
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

    cam.release()
    cv2.destroyAllWindows()

    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;\n [INFO] Done. 30 photos collected for ID: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{face_id}&lt;/span&gt;&quot;&lt;/span&gt;)
    next_person = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;input&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;\n Continue with another person? (Y/N): &quot;&lt;/span&gt;).strip().upper()
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; next_person != &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Y&quot;&lt;/span&gt;:
        &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;\n [INFO] Exiting.&quot;&lt;/span&gt;)
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); font-family: verdana; font-size: medium; height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Run&lt;/strong&gt;. The terminal will ask: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Enter user ID&quot;&lt;/em&gt;&amp;nbsp;— type &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;1&lt;/code&gt; and press Enter. The camera opens, and you’ll see a live feed with a counter in the top-left corner showing how many photos have been taken. Stand still, look at the camera, let it work.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;After 30 photos, the program asks: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Continue with another person? (Y/N)&quot;&lt;/em&gt;&amp;nbsp;— type &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;Y&lt;/code&gt; to register the next person (enter ID &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;2&lt;/code&gt;), or &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;N&lt;/code&gt; to stop.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;What you’ll find in the &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;dataset&lt;/code&gt; folder afterward:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;dataset/
├── User.1.1.jpg
├── User.1.2.jpg
├── User.1.3.jpg
...
├── User.2.1.jpg
├── User.2.2.jpg
...
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The naming format is &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;User.[ID].[photo number].jpg&lt;/code&gt;. Person 1’s photos are &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;User.1.1&lt;/code&gt; through &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;User.1.30&lt;/code&gt;. Person 2’s are &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;User.2.1&lt;/code&gt; through &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;User.2.30&lt;/code&gt;. The numbers after the ID are just the shot counter — not a sub-ID.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Each image is a cropped grayscale face at 255×255 pixels. Thirty of them per person. This is the raw material the training step needs.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;step-2--train-the-model-trainingpy&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8b.md#step-2--train-the-model-trainingpy&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 2 — Train the Model (Training.py)&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Install one more library:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install Pillow
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now for the interesting part. We’re going to feed all those face photos into an algorithm called &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;LBPH&lt;/strong&gt; (Local Binary Pattern Histogram) — the engine inside &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;opencv-contrib-python&lt;/code&gt;. It will study the patterns, crunch the numbers, and save everything it learned into a single file: &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;trainer.yml&lt;/code&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Think of &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;trainer.yml&lt;/code&gt; as the robot’s memory. Once it exists, the robot no longer needs to look at the photos. It carries everything it knows about each face in that one compact file.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;Training.py&lt;/code&gt;:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; cv2
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; numpy &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;as&lt;/span&gt; np
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;from&lt;/span&gt; PIL &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; Image
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; os

path = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;dataset&quot;&lt;/span&gt;
recognizer = cv2.face.LBPHFaceRecognizer_create()
detector = cv2.CascadeClassifier(
    cv2.data.haarcascades + &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;haarcascade_frontalface_default.xml&quot;&lt;/span&gt;
)
os.makedirs(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;trainer&quot;&lt;/span&gt;, exist_ok=&lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;)


&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;getImagesAndLabels&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;path&lt;/span&gt;):
    imagePaths = [os.path.join(path, f) &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; f &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; os.listdir(path)]
    faceSamples = []
    ids = []

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; imagePath &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; imagePaths:
        PIL_img = Image.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;open&lt;/span&gt;(imagePath).convert(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;L&quot;&lt;/span&gt;)  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Convert to grayscale&lt;/span&gt;
        img_numpy = np.array(PIL_img, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;uint8&quot;&lt;/span&gt;)

        &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;id&lt;/span&gt; = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;int&lt;/span&gt;(os.path.split(imagePath)[&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;].split(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;.&quot;&lt;/span&gt;)[&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;])
        faces = detector.detectMultiScale(img_numpy)

        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; x, y, w, h &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; faces:
            faceSamples.append(img_numpy[y : y + h, x : x + w])
            ids.append(&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;id&lt;/span&gt;)

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;return&lt;/span&gt; faceSamples, ids


&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;\n [INFO] Training face data. Please wait...&quot;&lt;/span&gt;)
faces, ids = getImagesAndLabels(path)
recognizer.train(faces, np.array(ids))

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Save the trained model as a .yml file&lt;/span&gt;
recognizer.write(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;trainer/trainer.yml&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(
    &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;\n [INFO] &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;len&lt;/span&gt;(np.unique(ids))}&lt;/span&gt; face(s) trained. Saved to trainer/trainer.yml&quot;&lt;/span&gt;
)
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Run it. You’ll see &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Training face data. Please wait…&quot;&lt;/em&gt;&amp;nbsp;— give it a moment — then &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;X face(s) trained. Saved to trainer/trainer.yml&quot;&lt;/em&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s it. Training complete. The robot now has memories.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;step-3--recognize-and-take-attendance-recognitionpy&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8b.md#step-3--recognize-and-take-attendance-recognitionpy&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 3 — Recognize and Take Attendance (Recognition.py)&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Last file. This is where it all comes together.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot opens the camera, scans for faces, and checks each detected face against &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;trainer.yml&lt;/code&gt;. If the match confidence is above 70%, it marks that person as present — and won’t count them again. Once everyone is checked in, the system keeps running until you press ESC.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;Recognition.py&lt;/code&gt;:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; cv2

recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;trainer/trainer.yml&quot;&lt;/span&gt;)

cascadePath = cv2.data.haarcascades + &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;haarcascade_frontalface_default.xml&quot;&lt;/span&gt;
faceCascade = cv2.CascadeClassifier(cascadePath)

font = cv2.FONT_HERSHEY_SIMPLEX
names = [&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;None&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;User.1&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;User.2&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;User.3&quot;&lt;/span&gt;]  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Match your registered IDs&lt;/span&gt;

cam = cv2.VideoCapture(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)
cam.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;640&lt;/span&gt;)
cam.&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;480&lt;/span&gt;)

minW = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.1&lt;/span&gt; * cam.get(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;3&lt;/span&gt;)
minH = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.1&lt;/span&gt; * cam.get(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;4&lt;/span&gt;)

CONFIDENCE_THRESHOLD = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;70&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Minimum confidence to accept a match (%)&lt;/span&gt;
attended = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;set&lt;/span&gt;()            &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Tracks who has already been marked present&lt;/span&gt;
message = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;&quot;&lt;/span&gt;                &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# On-screen notification text&lt;/span&gt;
message_timer = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;           &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# How many frames to show the notification&lt;/span&gt;

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
    ret, img = cam.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1.2&lt;/span&gt;,
        minNeighbors=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;5&lt;/span&gt;,
        minSize=(&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;int&lt;/span&gt;(minW), &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;int&lt;/span&gt;(minH)),
    )

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; x, y, w, h &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
        &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;id&lt;/span&gt;, confidence = recognizer.predict(gray[y : y + h, x : x + w])
        accuracy = &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;round&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;100&lt;/span&gt; - confidence)

        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; accuracy &amp;gt;= CONFIDENCE_THRESHOLD:
            name = names[&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;id&lt;/span&gt;] &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;id&lt;/span&gt; &amp;lt; &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;len&lt;/span&gt;(names) &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Unknown&quot;&lt;/span&gt;

            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; attended:
                &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# First time this person is recognized — mark attendance&lt;/span&gt;
                attended.add(&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;id&lt;/span&gt;)
                message = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;&lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{name}&lt;/span&gt; checked in! Next person...&quot;&lt;/span&gt;
                message_timer = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;60&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Show for ~2 seconds (60 frames)&lt;/span&gt;
                &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;\n [INFO] &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{name}&lt;/span&gt; marked present. Confidence: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{accuracy}&lt;/span&gt;%&quot;&lt;/span&gt;)

            label = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;&lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{name}&lt;/span&gt; (&lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{accuracy}&lt;/span&gt;%) - Present&quot;&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt;:
            name = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Unknown&quot;&lt;/span&gt;
            label = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;&lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{name}&lt;/span&gt; (&lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{accuracy}&lt;/span&gt;%)&quot;&lt;/span&gt;

        cv2.putText(img, label, (x + &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;5&lt;/span&gt;, y - &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;5&lt;/span&gt;), font, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.8&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Show attendance notification at the top of the screen&lt;/span&gt;
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; message_timer &amp;gt; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;:
        cv2.putText(img, message, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;40&lt;/span&gt;), font, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.8&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
        message_timer -= &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Show attendance summary at the bottom&lt;/span&gt;
    attended_names = [names[i] &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; i &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; attended &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; i &amp;lt; &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;len&lt;/span&gt;(names)]
    summary = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Present: &quot;&lt;/span&gt; + (&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;, &quot;&lt;/span&gt;.join(attended_names) &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; attended_names &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;None yet&quot;&lt;/span&gt;)
    cv2.putText(img, summary, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;10&lt;/span&gt;, img.shape[&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;] - &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;15&lt;/span&gt;), font, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.6&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;200&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;)

    cv2.imshow(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Camera - Attendance&quot;&lt;/span&gt;, img)

    k = cv2.waitKey(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;10&lt;/span&gt;) &amp;amp; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0xFF&lt;/span&gt;
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; k == &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;27&lt;/span&gt;:  &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# ESC to quit&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;\n [INFO] Attendance session ended.&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot; [INFO] Summary: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;len&lt;/span&gt;(attended)}&lt;/span&gt; person(s) present: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;, &#39;&lt;/span&gt;.join(attended_names)}&lt;/span&gt;&quot;&lt;/span&gt;)
cam.release()
cv2.destroyAllWindows()
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Run it. Walk in front of the camera. If your face is in the training data and the confidence clears 70%, the screen will show &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;User.1 checked in! Next person…&quot;&lt;/em&gt;&amp;nbsp;— then that notification fades after about 2 seconds. The bottom of the screen keeps a running list of everyone who’s been marked present. When you press ESC, the terminal prints the final summary.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Each person is only counted once. No double-dipping.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;what-we-just-built&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8b.md#what-we-just-built&quot; id=&quot;5&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We Just Built&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Three files. Roughly 100 lines of Python total. And the result is a working face recognition attendance system — the same concept used in real classrooms, offices, and access control systems.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The pipeline is:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Dataset.py&lt;/strong&gt; collects raw face images → &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Training.py&lt;/strong&gt; compresses those images into a compact model file → &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Recognition.py&lt;/strong&gt; loads that model and runs live identification.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot no longer just sees that someone is there. It knows &lt;em style=&quot;box-sizing: border-box;&quot;&gt;who&lt;/em&gt; is there.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s Part 8B done.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Next up: Part 9 — Line Following with a Webcam.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-8b-robot-learns-names-building.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-868788699013332624</guid><pubDate>Sat, 23 May 2026 20:40:46 +0000</pubDate><atom:updated>2026-05-30T05:02:21.712-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Real-Time Face Detection with OpenCV Haar Cascade — Part 8A: The Robot Knows You&#39;re There</title><description>&lt;p&gt;&lt;span&gt;&lt;span style=&quot;background-color: white; color: #2b2b2f; font-family: verdana; font-size: medium; letter-spacing: 0.2px;&quot;&gt;Let’s do our usual &quot;big picture&quot; check-in before diving in.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Robots need senses. Based on what they see, hear, and feel through their sensors, the Python brain decides how to respond.&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here’s how far we’ve come:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;✅ We started by controlling the robot with a keyboard — the most basic form of human-robot interaction.&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;✅ We cut the cable and gave it wireless freedom. As Neil Armstrong once said: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;One small step for man, one giant leap for mankind.&quot;&lt;/em&gt;&amp;nbsp;Our version: one less USB cable, one giant leap for our robot.&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;✅ We gave it &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;eyes&lt;/strong&gt; — object detection, distance estimation, obstacle avoidance.&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;✅ We gave it &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;ears&lt;/strong&gt; — voice commands that the robot understands, just like Siri or Alexa.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now we take vision one step further. Until now, our robot could see &lt;em style=&quot;box-sizing: border-box;&quot;&gt;that&lt;/em&gt; there’s a person in the frame. In this part, we teach it to see &lt;em style=&quot;box-sizing: border-box;&quot;&gt;where&lt;/em&gt; the face is. And in Part 8B, we’ll teach it to know &lt;em style=&quot;box-sizing: border-box;&quot;&gt;who&lt;/em&gt; that person is.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;face-detection-vs-face-recognition--not-the-same-thing&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8a.md#face-detection-vs-face-recognition--not-the-same-thing&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Face Detection vs. Face Recognition — Not the Same Thing&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Grab two photos of the same person — let’s call her Jennifer. Different days, different angles, slightly different lighting. You’d look at both for a few seconds and say: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Same person.&quot;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;For a computer, that’s two completely separate problems:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Face Detection&lt;/strong&gt; answers: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Is there a face here, and where is it?&quot;&lt;/em&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;It finds faces in an image. That’s all. It doesn’t know who they belong to.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Face Recognition&lt;/strong&gt; answers: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Whose face is this?&quot;&lt;/em&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;It compares a detected face against a database of known faces and returns a name.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You cannot do Face Recognition without Face Detection first. It’s like asking someone to recognize the handwriting in a letter before they’ve even found the letter. Face Detection is the prerequisite — the foundation everything else is built on.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;why-face-detection-matters&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8a.md#why-face-detection-matters&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Why Face Detection Matters&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We’ve already taught our robot to recognize &quot;person&quot; as a category using YOLOv8. But that’s not enough for identity-level tasks. The robot needs to specifically isolate the face region — that cropped face image becomes the raw material for everything that follows.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Think of it like division in math class. &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Why do we need to learn this?&quot;&lt;/em&gt;&amp;nbsp;Because without it, you can’t calculate that a 500-mile drive at 70 mph takes about 7–8 hours from San Francisco to San Diego. Every advanced skill is built on a simpler one. Face Detection is the division. Face Recognition is the road trip planning.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In practice, Face Detection already powers things you use every day: security cameras, automatic attendance systems, phone biometric unlock. For robots specifically, it enables: reception and guide robots, security patrol robots, delivery and service robots, search and rescue systems — and much more.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;All of it starts here.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;how-haar-cascade-works&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8a.md#how-haar-cascade-works&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;How Haar Cascade Works&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We’re using &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Haar Cascade&lt;/strong&gt; — a lightweight machine learning algorithm built directly into OpenCV. No heavy AI model, no GPU required, no internet connection. It runs on anything.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The algorithm works in three steps:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;1. Image scanning&lt;/strong&gt;: The algorithm slides a rectangular window across every part of the image, looking for patterns of light and dark — eyes are darker than forehead, nose bridge is lighter than eye sockets, and so on.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;2. Locating candidates&lt;/strong&gt;: Areas that match the expected pattern of a face are flagged, and a bounding box is drawn around them.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;3. Output&lt;/strong&gt;: The result is a cropped face region — the &quot;raw ingredient&quot; that gets passed to Face Recognition in Part 8B.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The model we’ll use is &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;haarcascade_frontalface_default.xml&lt;/code&gt; — a pre-trained file that ships with OpenCV. No training required on our end.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;setup&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8a.md#setup&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Setup&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you completed Part 1, OpenCV is already installed. If not:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;blockquote&gt;pip install opencv-python&lt;/blockquote&gt;&lt;/i&gt;
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;One important note about the model file&lt;/strong&gt;: while &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;haarcascade_frontalface_default.xml&lt;/code&gt; comes with OpenCV, the easiest approach is to load it using OpenCV’s built-in path so you don’t have to download or copy anything manually:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;haarcascade_frontalface_default.xml&#39;&lt;/span&gt;)
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This line tells Python: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Find the haarcascades folder that came with OpenCV and load this file from there.&quot;&lt;/em&gt;&amp;nbsp;No manual downloading needed.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-code&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8a.md#the-code&quot; id=&quot;5&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Code&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new Python file called &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;FaceDetect.py&lt;/code&gt; and paste this in:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; cv2

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Load Haar Cascade from OpenCV&#39;s built-in model folder&lt;/span&gt;
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;haarcascade_frontalface_default.xml&#39;&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Open webcam (0 = default laptop camera)&lt;/span&gt;
cap = cv2.VideoCapture(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Robot is running. Press &#39;q&#39; to quit.&quot;&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
    ret, frame = cap.read()
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;not&lt;/span&gt; ret:
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Convert color frame to grayscale — Haar Cascade only works on grayscale images&lt;/span&gt;
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Detect faces in the grayscale frame&lt;/span&gt;
    faces = face_cascade.detectMultiScale(gray, scaleFactor=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1.1&lt;/span&gt;, minNeighbors=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;5&lt;/span&gt;, minSize=(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;))

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Draw a bounding box around each detected face&lt;/span&gt;
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; (x, y, w, h) &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)
        cv2.putText(frame, &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Face detected!&quot;&lt;/span&gt;, (x, y-&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;10&lt;/span&gt;), cv2.FONT_HERSHEY_SIMPLEX, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0.9&lt;/span&gt;, (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)

    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Display the result in a popup window on your desktop&lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Note: this opens a separate window — not inside PyCharm&lt;/span&gt;
    cv2.imshow(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;Robot Cam - Face Detection&#39;&lt;/span&gt;, frame)

    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; cv2.waitKey(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;) &amp;amp; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0xFF&lt;/span&gt; == &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;ord&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;q&#39;&lt;/span&gt;):
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

cap.release()
cv2.destroyAllWindows()
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Run&lt;/strong&gt;. A new window will pop up on your desktop — separate from PyCharm — showing your webcam feed. Look into the camera and you’ll see a green rectangle appear around your face with the label &quot;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Face detected!&quot;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Press &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;q&lt;/code&gt;&lt;/strong&gt; to quit.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;code-walkthrough&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8a.md#code-walkthrough&quot; id=&quot;6&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Code Walkthrough&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Converting to grayscale&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;blockquote&gt;gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)&lt;/blockquote&gt;&lt;/i&gt;
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Haar Cascade only works on grayscale images — color information isn’t needed for detecting light/dark patterns. We keep the original color &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;frame&lt;/code&gt; for display, but pass &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;gray&lt;/code&gt; to the detector.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Running the detector&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;faces = face_cascade.detectMultiScale(gray, scaleFactor=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1.1&lt;/span&gt;, minNeighbors=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;5&lt;/span&gt;, minSize=(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;30&lt;/span&gt;))
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Three key parameters:&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 0px; padding: 0px 0px 0px 28px;&quot;&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;scaleFactor=1.1&lt;/code&gt; — how much the image is scaled down each pass. Smaller = more thorough but slower.&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;minNeighbors=5&lt;/code&gt; — how many neighboring detections must agree before a face is confirmed. Higher = fewer false positives.&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;minSize=(30, 30)&lt;/code&gt; — minimum face size in pixels. Filters out noise.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Drawing the box&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;for&lt;/span&gt; (x, y, w, h) &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; faces:
    cv2.rectangle(frame, (x, y), (x+w, y+h), (&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;255&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;2&lt;/span&gt;)&lt;/blockquote&gt;&lt;/i&gt;
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Each detected face returns four values: x and y position of the top-left corner, plus width and height of the bounding box. We draw a green rectangle using those coordinates.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The display window&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;blockquote&gt;cv2.imshow(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;Robot Cam - Face Detection&#39;&lt;/span&gt;, frame)&lt;/blockquote&gt;&lt;/i&gt;
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This opens a &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;separate popup window&lt;/strong&gt; on your desktop — not inside PyCharm. The string &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;&#39;Robot Cam - Face Detection&#39;&lt;/code&gt; is just the title of that window. You won’t see this text in the PyCharm terminal; you’ll see it in the title bar of the popup.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;what-we-just-built&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part8a.md#what-we-just-built&quot; id=&quot;7&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We Just Built&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The robot can now find faces in a live video stream — in real time, with no internet, no heavy AI model, and no expensive hardware. It works in a cluttered scene: background, furniture, plants, other people — and it still finds the face.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This is Part 8A complete. The face has been found. In Part 8B, we find out &lt;em style=&quot;box-sizing: border-box;&quot;&gt;who&lt;/em&gt; it belongs to.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up: Part 8B — The robot learns names.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-8a-robot-learns-to-see-faces.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-1715296585343141937</guid><pubDate>Sat, 23 May 2026 01:34:29 +0000</pubDate><atom:updated>2026-05-30T05:02:02.048-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Voice Control Robot with Python SpeechRecognition — Part 7: Hey Robot, Move!</title><description>&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 25px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;By this point, the picture is getting clearer. We’re not just &quot;vaguely understanding&quot; how robots work anymore — we actually understand it:&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote style=&quot;background-color: white; border-left: 4px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 22px 0px; padding: 1px 18px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Robots need &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;senses&lt;/strong&gt;. Based on what they see, hear, and feel through their sensors, the Python brain decides how to respond.&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We’ve been steadily making our robot smarter:&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 0px; padding: 0px 0px 0px 28px;&quot;&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;First, we controlled it with a keyboard&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then we cut the cord and gave it wireless freedom&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then we gave it eyes — object detection, distance awareness, obstacle avoidance&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Among all a robot’s senses, we’ve spent most of our time on &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;vision&lt;/strong&gt;. The robot can now recognize people, furniture, vehicles, and pets. It can estimate distance. It can decide when to stop.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Time to work on the &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;ears&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Fair warning: this part cost us nearly &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;5 hours of debugging&lt;/strong&gt;. We’re sharing every painful step so you don’t have to repeat it.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;how-voice-control-works&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#how-voice-control-works&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;How Voice Control Works&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The core principle is simple: convert sound waves into text, then map that text to code commands.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 1 — Audio capture&lt;/strong&gt;: The laptop microphone picks up sound (analog signal) and converts it to digital data.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 2 — Audio processing&lt;/strong&gt;: The &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;SpeechRecognition&lt;/code&gt; library filters out background noise and identifies the boundaries of each spoken phrase.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 3 — Speech-to-Text (STT)&lt;/strong&gt;: The audio is sent to a recognition engine — either a cloud API (Google Speech, Wit.ai, IBM) or a local AI model (Whisper, Vosk). The engine matches the audio to words and returns a text string.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 4 — Execute the command&lt;/strong&gt;: The Python code checks the text with &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;if/else&lt;/code&gt; statements. If it matches a keyword, the corresponding action runs.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Two libraries make this happen:&lt;/span&gt;&lt;/p&gt;&lt;ul style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin: 0px; padding: 0px 0px 0px 28px;&quot;&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;SpeechRecognition&lt;/strong&gt; — handles the speech-to-text pipeline&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;box-sizing: border-box; list-style: inherit; margin-bottom: 0.4em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;PyAudio&lt;/strong&gt; — gives Python direct access to the laptop’s microphone hardware&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-code&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#the-code&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Code&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new Python file called &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;VoiceCommand.py&lt;/code&gt; and paste this in:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; speech_recognition &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;as&lt;/span&gt; sr

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;box-sizing: border-box; color: #4078f2;&quot;&gt;listen_for_commands&lt;/span&gt;():
    recognizer = sr.Recognizer()
    
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;with&lt;/span&gt; sr.Microphone() &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;as&lt;/span&gt; source:
        &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Adjusting for ambient noise... please wait.&quot;&lt;/span&gt;)
        recognizer.adjust_for_ambient_noise(source, duration=&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;)
        &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Robot is listening for commands (e.g., &#39;forward&#39;, &#39;stop&#39;)...&quot;&lt;/span&gt;)
        
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot; style=&quot;box-sizing: border-box; color: #0184bc;&quot;&gt;True&lt;/span&gt;:
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;try&lt;/span&gt;:
                audio = recognizer.listen(source)
                command = recognizer.recognize_google(audio).lower()
                &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;f&quot;You said: &lt;span class=&quot;hljs-subst&quot; style=&quot;box-sizing: border-box; color: #e45649;&quot;&gt;{command}&lt;/span&gt;&quot;&lt;/span&gt;)

                &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;forward&quot;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; command:
                    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Moving Robot Forward&quot;&lt;/span&gt;)
                    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Placeholder: replace with motor forward command later&lt;/span&gt;
                &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;backward&quot;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; command:
                    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Moving Robot Backward&quot;&lt;/span&gt;)
                    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Placeholder: replace with motor backward command later&lt;/span&gt;
                &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;stop&quot;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; command:
                    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Stopping Robot&quot;&lt;/span&gt;)
                    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Placeholder: replace with motor stop command later&lt;/span&gt;
                &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;left&quot;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; command:
                    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Turning Left&quot;&lt;/span&gt;)
                    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Placeholder: replace with motor turn-left command later&lt;/span&gt;
                &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;right&quot;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; command:
                    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Action: Turning Right&quot;&lt;/span&gt;)
                    &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Placeholder: replace with motor turn-right command later&lt;/span&gt;
                &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;exit&quot;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;in&lt;/span&gt; command:
                    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Shutting down. Goodbye.&quot;&lt;/span&gt;)
                    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;
                    
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;except&lt;/span&gt; sr.UnknownValueError:
                &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Could not understand audio&quot;&lt;/span&gt;)
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;except&lt;/span&gt; sr.RequestError:
                &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Could not request results; check your internet connection&quot;&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; __name__ == &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;__main__&quot;&lt;/span&gt;:
    listen_for_commands()&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); font-family: verdana; font-size: medium; height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If everything works, hitting &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Run&lt;/strong&gt; will show:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Robot is listening for commands (e.g., &#39;forward&#39;, &#39;stop&#39;)...
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Say &quot;forward&quot; — you’ll see: &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;Action: Moving Robot Forward&lt;/code&gt;&lt;br style=&quot;box-sizing: border-box;&quot; /&gt;Say &quot;stop&quot; — you’ll see: &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;Action: Stopping Robot&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Starting to feel like Siri or Alexa? That’s because the underlying principle is exactly the same.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And when we’re ready to connect real motors, we replace those &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;print()&lt;/code&gt; placeholder lines with actual motor control commands. The entire voice recognition logic stays untouched. Zero rewriting.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-installation-nightmare-and-how-to-survive-it&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#the-installation-nightmare-and-how-to-survive-it&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Installation Nightmare (And How to Survive It)&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here’s where the 5-hour adventure begins.&lt;/span&gt;&lt;/p&gt;&lt;h3 id=&quot;attempt-1-the-normal-way&quot; style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 0px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#attempt-1-the-normal-way&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Attempt 1: The Normal Way&lt;/span&gt;&lt;/h3&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install SpeechRecognition pyaudio
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;SpeechRecognition&lt;/code&gt; installs perfectly. &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;PyAudio&lt;/code&gt; explodes:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Failed building wheel for pyaudio
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;PyAudio needs a C++ compiler to build from source. Most Windows machines don’t have one.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h3 id=&quot;attempt-2-pipwin&quot; style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 0px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#attempt-2-pipwin&quot; id=&quot;5&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Attempt 2: pipwin&lt;/span&gt;&lt;/h3&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install pipwin
pipwin install pyaudio
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;pipwin&lt;/code&gt; is supposed to find a pre-built &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;.whl&lt;/code&gt; file for Windows automatically. Instead:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;RuntimeError: your python version made changes to the bytecode
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;pipwin&lt;/code&gt; relies on some internal Python components that were removed in Python 3.12 and later. Since PyCharm auto-installs the latest Python (currently 3.14), &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;pipwin&lt;/code&gt; simply doesn’t work anymore.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h3 id=&quot;attempt-3-manual-whl-install&quot; style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 0px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#attempt-3-manual-whl-install&quot; id=&quot;6&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Attempt 3: Manual .whl Install&lt;/span&gt;&lt;/h3&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The logic: find the exact pre-built &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;.whl&lt;/code&gt; file for our Python version and Windows architecture, download it, install it manually.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;First, check your Python version:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;python --version
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And your Windows architecture: 64-bit (almost certainly) or 32-bit.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;For &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Python 3.14, 64-bit Windows&lt;/strong&gt;, the file name would be:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;PyAudio-0.2.14-cp314-cp314-win_amd64.whl
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Download it, then run:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install C:\path\to\PyAudio-0.2.14-cp314-cp314-win_amd64.whl
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Promising. But:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;could not import pyaudio C module &#39;_portaudio&#39;
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;.whl&lt;/code&gt; installs but the underlying C library it depends on (&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;portaudio&lt;/code&gt;) isn’t present on the system. Still broken.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h3 id=&quot;the-actual-solution-downgrade-python-to-311&quot; style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 0px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#the-actual-solution-downgrade-python-to-311&quot; id=&quot;7&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Actual Solution: Downgrade Python to 3.11&lt;/span&gt;&lt;/h3&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;PyAudio has reliable pre-built support for &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Python 3.11&lt;/strong&gt;. Everything above that version is a compatibility minefield.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here’s the cleanest way to fix it — yes, it involves reinstalling things, but it’s a one-time fix:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 1&lt;/strong&gt;: Uninstall PyCharm completely.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 2&lt;/strong&gt;: Uninstall Python 3.14 completely. (Don’t just install 3.11 alongside it — PATH conflicts will make your life miserable.)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 3&lt;/strong&gt;: Download and install &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Python 3.11&lt;/strong&gt; from python.org. During installation, check &quot;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Add Python to PATH&quot;&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 4&lt;/strong&gt;: Reinstall PyCharm. It will detect Python 3.11 automatically.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 5&lt;/strong&gt;: Open PyCharm Terminal and run:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install SpeechRecognition pyaudio
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Both install cleanly. No errors. No compiler needed. No &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;.whl&lt;/code&gt; hunting.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Step 6&lt;/strong&gt;: Run &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;VoiceCommand.py&lt;/code&gt;. Say “forward.” Watch it work.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Smooth as silk.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;why-this-matters&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part7.md#why-this-matters&quot; id=&quot;8&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Why This Matters&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The voice control system we just built follows the exact same &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;perception → decision → action&lt;/strong&gt; loop as everything else in this blog:&lt;/span&gt;&lt;/p&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; color: #2b2b2f; display: block; letter-spacing: 0.2px; margin: 1rem 0px; max-width: 100%; overflow-x: auto; width: max-content;&quot;&gt;&lt;thead style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Layer&lt;/span&gt;&lt;/th&gt;&lt;th style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; cursor: auto; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Component&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Sensor&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Laptop microphone&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Perception&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;SpeechRecognition + Google STT&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Decision&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;if/else&lt;/code&gt; keyword matching&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-top: 1px solid rgb(208, 215, 222); box-sizing: border-box;&quot;&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Action&lt;/span&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgb(208, 215, 222); border-image: none 100% / 1 / 0 stretch; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 0.6em 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;print()&lt;/code&gt; for now — motor commands later&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;One more sense added to our robot’s toolkit. Next, we give it a sharper pair of eyes — face detection, no AI model required.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up: Part 8 — The robot learns to recognize faces. Simpler than you’d expect.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-7-hey-robot-move-teaching-our.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-1215125680205786334</guid><pubDate>Fri, 22 May 2026 03:10:30 +0000</pubDate><atom:updated>2026-05-30T05:01:39.729-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Camera-Based Obstacle Avoidance with Python and OpenCV — Part 6: No Sensor? No Problem</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before we get into the robot vision stuff, let&#39;s talk about one of the most legendary tools in all of programming.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Print Statement: Debugging&#39;s Best Friend&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Every language has one:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Python: &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;print()&lt;/code&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;C: &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;printf()&lt;/code&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;PHP: &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;echo&lt;/code&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Java: &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;System.out.println()&lt;/code&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Why &quot;legendary&quot;? Two reasons.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;First, it&#39;s the best debugging tool ever invented.&lt;/strong&gt; Imagine a truck leaving Los Angeles headed for New York. It departs on time, but never arrives. Where did it go wrong? You&#39;d check the cameras along the route — Utah, Colorado, Nebraska, Iowa, Illinois... If the truck shows up in Nebraska but disappears by Iowa, you know something happened somewhere between those two states.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Code works the same way. Scatter a few &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;print()&lt;/code&gt; statements through hundreds of lines of code. Wherever the output stops appearing on screen — that&#39;s where your bug is hiding.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Second, it&#39;s a placeholder.&lt;/strong&gt; Imagine you&#39;re writing code for our robot and you know it should eventually stop the motors when it sees an obstacle — but you haven&#39;t written that part yet. No problem:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;text-text-500 font-small p-3.5 pb-0&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Obstacle detected — stopping!&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Placeholder: replace with motor stop command later&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The print statement holds the spot. Like booking a hotel room before you decide what you&#39;re doing that day. The logic is there; the implementation comes later.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;ll use this trick a lot in this part.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We&#39;re Actually Building&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In this project, we use the laptop webcam to build a real-time obstacle avoidance system — using YOLOv8 to detect objects and OpenCV to process the video stream.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;One honest clarification: our robot won&#39;t &lt;em&gt;actually&lt;/em&gt; avoid anything yet. It will &lt;em&gt;announce&lt;/em&gt; that it should. The motors aren&#39;t connected to this code. But the logic — the perception → decision loop — is real. And that loop is the foundation of every autonomous system on the planet.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;How It Works&lt;/span&gt;&lt;/h2&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;1. Detection&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;YOLOv8 grabs each frame from the webcam and identifies what&#39;s in it — person, chair, bottle, whatever.&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;2. Distance Estimation (The Clever Workaround)&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Regular cameras can&#39;t directly measure distance. But there&#39;s a neat trick based on a simple principle:&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The closer an object gets to the camera, the larger it appears in the frame.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The formal version involves similar triangles and looks like this:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;D = (W × f) / P&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Where:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;D&lt;/strong&gt; = distance from camera to object&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;W&lt;/strong&gt; = real-world width of the object (e.g. 0.5 meters)&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;f&lt;/strong&gt; = focal length of the camera (in pixels)&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;P&lt;/strong&gt; = width of the object as it appears in the frame (in pixels)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;re not going to use that formula. It requires calibrating the camera, knowing the real size of every possible object, and other headaches we don&#39;t need right now.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Instead, we use the shortcut: &lt;strong&gt;if the bounding box width (in pixels) exceeds a threshold, the object is too close.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;3. Decision&lt;/span&gt;&lt;/h3&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Object too close (box width &amp;gt; 200px) → &lt;strong&gt;WARNING: STOP&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Object at safe distance → &lt;strong&gt;SAFE TO MOVE&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That&#39;s the full loop. Simple, but real.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Code&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Install libraries if you haven&#39;t already (open PyCharm Terminal):&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;i&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install opencv-python ultralytics&lt;/span&gt;&lt;/blockquote&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new Python file — call it &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;avoidance.py&lt;/code&gt; — and paste this in:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;text-text-500 font-small p-3.5 pb-0&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; cv2
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;from&lt;/span&gt; ultralytics &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; YOLO

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# 1. Load YOLOv8 nano model&lt;/span&gt;
model &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; YOLO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;yolov8n.pt&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# 2. Connect to webcam (0 = default laptop webcam)&lt;/span&gt;
cap &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;VideoCapture&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;while&lt;/span&gt; cap&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;isOpened&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    success&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; frame &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; cap&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;read&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;not&lt;/span&gt; success&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;break&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# 3. Run YOLOv8 on the current frame&lt;/span&gt;
    results &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; model&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;frame&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; stream&lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;for&lt;/span&gt; r &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;in&lt;/span&gt; results&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        boxes &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; r&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;boxes
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;for&lt;/span&gt; box &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;in&lt;/span&gt; boxes&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Get bounding box coordinates&lt;/span&gt;
            x1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; y1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; x2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; y2 &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; box&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;xyxy&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;tolist&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
            
            &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Calculate width of the bounding box in pixels&lt;/span&gt;
            w &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; x2 &lt;span class=&quot;token token&quot;&gt;-&lt;/span&gt; x1
            
            &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# If the object appears large enough, it&#39;s too close&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; w &lt;span class=&quot;token token&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
                cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;putText&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;frame&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;WARNING: STOP!&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;
                            cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;FONT_HERSHEY_SIMPLEX&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Placeholder: replace with actual motor stop command later&lt;/span&gt;
                &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# print(&quot;Obstacle detected — stopping!&quot;)&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
                cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;putText&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;frame&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;SAFE TO MOVE&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;
                            cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;FONT_HERSHEY_SIMPLEX&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Display the video feed&lt;/span&gt;
    cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;imshow&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Obstacle Avoidance&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; frame&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;waitKey&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0xFF&lt;/span&gt; &lt;span class=&quot;token token&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;ord&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;q&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;break&lt;/span&gt;

cap&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;release&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;destroyAllWindows&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;strong&gt;Run&lt;/strong&gt;. Walk toward the webcam. Watch &quot;SAFE TO MOVE&quot; flip to &quot;WARNING: STOP!&quot; as you get close.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Press &lt;strong&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;q&lt;/code&gt;&lt;/strong&gt; to quit.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Code Walkthrough&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Initializing the camera&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;blockquote&gt;model &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; YOLO&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;yolov8n.pt&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
cap &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;VideoCapture&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;YOLO(&#39;yolov8n.pt&#39;)&lt;/code&gt; loads the nano model — smallest, fastest. &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;VideoCapture(0)&lt;/code&gt; opens the default webcam. Change &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;0&lt;/code&gt; to &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;1&lt;/code&gt; if your laptop has multiple cameras.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;The main loop&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;while&lt;/span&gt; cap&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;isOpened&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    success&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; frame &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; cap&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;read&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Reads the video stream one frame at a time. &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;cap.read()&lt;/code&gt; returns two things: whether the read succeeded, and the actual image data.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Detection&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;blockquote&gt;results &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; model&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;frame&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; stream&lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Passes the frame into YOLOv8. &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;stream=True&lt;/code&gt; returns a generator instead of a list — more memory-efficient when processing video.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Reading the bounding boxes&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;blockquote&gt;x1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; y1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; x2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; y2 &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; box&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;xyxy&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #b34a00;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;tolist&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
w &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; x2 &lt;span class=&quot;token token&quot;&gt;-&lt;/span&gt; x1&lt;/blockquote&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Each detected object comes with a bounding box: &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;x1, y1&lt;/code&gt; is the top-left corner, &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;x2, y2&lt;/code&gt; is the bottom-right. &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;w&lt;/code&gt; is the width of that box in pixels.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;The decision logic&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; w &lt;span class=&quot;token token&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Too close — warn&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Safe distance — continue&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This is the core of the whole system. 200 pixels is a starting threshold — adjust it based on your webcam and how sensitive you want the system to be. The closer the object, the bigger &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;w&lt;/code&gt; gets. Simple, no calibration required.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Cleanup&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;blockquote&gt;cap&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;release&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;destroyAllWindows&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Always release the camera and close the windows when done — otherwise the webcam stays &quot;occupied&quot; and you&#39;ll have to restart PyCharm to use it again.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Bonus: Using Your Phone Camera Instead of the Webcam&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you want to use IP Webcam (from Part 5) instead of the built-in webcam, just change one line:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Replace this:&lt;/span&gt;
cap &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;VideoCapture&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# With this (use your actual IP and port):&lt;/span&gt;
cap &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; cv2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;VideoCapture&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;http://192.168.1.XXX:8080/video&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Everything else stays exactly the same. Now your phone becomes the robot&#39;s eyes — which makes a lot more sense than mounting a laptop on a car chassis.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What Did We Actually Build?&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Technically: a program that watches a video feed and prints warnings on screen.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In reality: the &lt;strong&gt;perception → decision loop&lt;/strong&gt; — the most fundamental cycle in all of autonomous robotics. Every self-driving car, every warehouse robot, every drone doing collision avoidance runs on a version of this exact loop. Ours just prints text instead of turning a steering wheel.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The placeholder comments in the code are where the real robot commands will go — in a future part, we&#39;ll replace those &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;print()&lt;/code&gt; statements with actual motor control signals. The logic is already there. The hardware connection is next.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up: we skip the keyboard entirely. In Part 7, we talk to our robot.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-6-somethings-in-way-obstacle.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-4093036993755588163</guid><pubDate>Thu, 21 May 2026 20:22:09 +0000</pubDate><atom:updated>2026-05-30T05:01:07.603-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Smartphone IP Camera with YOLOv8 and Python — Part 5: Your Phone Is Now a Security Camera</title><description>&lt;p&gt;&lt;span face=&quot;-apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Oxygen, Ubuntu, Cantarell, &amp;quot;Fira Sans&amp;quot;, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, sans-serif&quot; style=&quot;background-color: white; color: #2b2b2f; letter-spacing: 0.2px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Let’s set the RC car aside for a moment and revisit something from Part 1.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Back then, we used the laptop’s built-in webcam to detect objects — people, chairs, dogs, cars. The concept worked. &lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The execution had one small problem: to point the camera at something, you had to physically carry the laptop there. And to see the results, you had to crane your neck around to look at the screen while simultaneously aiming the webcam in the opposite direction.&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Imagine trying to check whether there’s a cat behind your house. You’d walk out, hold the laptop up, tilt it toward the garden, then awkwardly twist your head around to see the screen — which now shows the cat, the garden, &lt;em style=&quot;box-sizing: border-box;&quot;&gt;and&lt;/em&gt; your own confused face staring back at you.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Not ideal.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;What we actually need is to &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;separate the camera from the screen&lt;/strong&gt;. Nothing fancy — just the ability to sit inside the house and know there’s a mailman at the front door.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We don’t need to buy a camera. We already have one in our pocket.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;the-setup-phone-as-mobile-camera&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part5.md#the-setup-phone-as-mobile-camera&quot; id=&quot;1&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Setup: Phone as Mobile Camera&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Using a phone as a mobile surveillance camera — combined with IP Webcam and YOLOv8 — is the most flexible, zero-cost solution for wireless object detection. The phone streams video over Wi-Fi; the laptop receives it, runs the AI, and shows the results.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Think of the app as a &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;real estate agent&lt;/strong&gt;: it stands in the middle, takes information from the camera, and reports back to the laptop — &quot;there’s a person&quot;, &quot;there’s a car&quot;, &quot;there’s a cat doing something suspicious.&quot;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We don’t need to write that middleman app ourselves. It already exists: &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;IP Webcam&lt;/strong&gt;, available free on the Google Play Store.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;step-1-set-up-the-phone-camera&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part5.md#step-1-set-up-the-phone-camera&quot; id=&quot;2&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 1: Set Up the Phone Camera&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Install IP Webcam&lt;/strong&gt; from the Google Play Store (Android).&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Make sure your phone and laptop are on the &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;same Wi-Fi network&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open the app → scroll to the bottom → tap &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;“Start server”&lt;/strong&gt;. You’ll see a WiFi IP and Port displayed on screen — something like:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;192.168.1.105:8080
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJth8mLCE6P43Jo3JhuXvbDAIrnvEvWxACfsJbQUhk5uDlFDMckMzNK8ojdZXNYPp7rRD6p8mi4fM62kXs5YCwUQd04rfBpbUPXjsz4SFl2SGgH1aVq5jiVdOfLk72vtOiWXOwpo6Ox-tSs5ZsKHstHc0D_Gw-Izh5iicXORIUO5X4cluEWfiGdDi0e1E/s684/IP%20Webcam.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;684&quot; data-original-width=&quot;677&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJth8mLCE6P43Jo3JhuXvbDAIrnvEvWxACfsJbQUhk5uDlFDMckMzNK8ojdZXNYPp7rRD6p8mi4fM62kXs5YCwUQd04rfBpbUPXjsz4SFl2SGgH1aVq5jiVdOfLk72vtOiWXOwpo6Ox-tSs5ZsKHstHc0D_Gw-Izh5iicXORIUO5X4cluEWfiGdDi0e1E/w634-h640/IP%20Webcam.png&quot; width=&quot;634&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Test it in your browser&lt;/strong&gt;: open Chrome or Edge on your laptop and go to:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;http://192.168.1.105:8080/video
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You should see a live video feed from your phone camera. If you do, you’re ready for Step 2.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;step-2-set-up-the-ai-on-your-laptop&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part5.md#step-2-set-up-the-ai-on-your-laptop&quot; id=&quot;3&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;Step 2: Set Up the AI on Your Laptop&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you completed Part 1, you already have everything installed. If not, open PyCharm’s Terminal and run:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;pip install opencv-python ultralytics
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new Python file — call it &lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;detect2.py&lt;/code&gt; — and paste this code in. As you’ll notice, it’s nearly identical to what we wrote in Part 1. The only real difference: instead of reading from a webcam, we’re reading from a phone over Wi-Fi.&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;hljs-pre mdr-code-block&quot; style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 247, 250); border-radius: 6px; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.6; overflow: auto; position: relative;&quot;&gt;&lt;code class=&quot;hljs&quot; lang=&quot;python&quot; style=&quot;background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-radius: 6px; box-sizing: border-box; color: #2f3237; display: block; margin: 0px; min-height: 2.2em; overflow-x: auto; padding: 0.67rem 1rem; word-break: normal;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; cv2
&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;from&lt;/span&gt; ultralytics &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;import&lt;/span&gt; YOLO

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Load YOLOv8 nano model - smallest and fastest&lt;/span&gt;
model = YOLO(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;yolov8n.pt&#39;&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Replace with your actual IP Webcam address&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Format: http://&amp;lt;WiFi_IP&amp;gt;:&amp;lt;Port&amp;gt;/video&lt;/span&gt;
droidcam_url = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&#39;http://192.168.1.105:8080/video&#39;&lt;/span&gt;

cap = cv2.VideoCapture(droidcam_url)

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;not&lt;/span&gt; cap.isOpened():
    &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Cannot connect to camera.&quot;&lt;/span&gt;)
    exit()

&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;while&lt;/span&gt; cap.isOpened():
    success, frame = cap.read()
    
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; success:
        &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Run YOLOv8 on the frame&lt;/span&gt;
        results = model(frame)
        
        &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Draw detection results on the frame&lt;/span&gt;
        annotated_frame = results[&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0&lt;/span&gt;].plot()
        
        &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Display on screen&lt;/span&gt;
        cv2.imshow(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;Mobile Surveillance with YOLOv8&quot;&lt;/span&gt;, annotated_frame)
        
        &lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #85888e; font-style: italic;&quot;&gt;# Press &#39;q&#39; to quit&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;if&lt;/span&gt; cv2.waitKey(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;1&lt;/span&gt;) &amp;amp; &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #b76b01;&quot;&gt;0xFF&lt;/span&gt; == &lt;span class=&quot;hljs-built_in&quot; style=&quot;box-sizing: border-box; color: #cb7701;&quot;&gt;ord&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #50a14f;&quot;&gt;&quot;q&quot;&lt;/span&gt;):
            &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;else&lt;/span&gt;:
        &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; color: #a626a4;&quot;&gt;break&lt;/span&gt;

cap.release()
cv2.destroyAllWindows()
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;mdr-button mdr-block__copy-btn&quot; style=&quot;--un-backdrop-blur: blur(3px); backdrop-filter: blur(3px); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(238, 238, 238, 0.7); border-radius: 10px; border-style: none; color: rgba(88, 96, 105, 0.5); cursor: pointer; height: 30px; margin: initial; opacity: 0; outline-offset: 2px; outline: transparent solid 2px; padding: 7px; position: absolute; right: 10px; top: 6px; transition: opacity 0.2s, background 0.1s, color 0.1s; width: 30px; z-index: 1;&quot; title=&quot;Copy&quot;&gt;&lt;span class=&quot;btn-icon icon-copy&quot; style=&quot;box-sizing: border-box; display: inline-block; fill: currentcolor; filter: drop-shadow(rgba(0, 0, 0, 0.12) 0.5px 0.5px 1px); height: 16px; pointer-events: none; transform-origin: center center; transition: transform 0.1s, color; width: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;svg viewbox=&quot;0 0 225 225&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M9,189.78V98.22A26.22,26.22,0,0,1,35.22,72h91.56A26.22,26.22,0,0,1,153,98.22v91.56A26.22,26.22,0,0,1,126.78,216H35.22A26.22,26.22,0,0,1,9,189.78Zm18-85.65v79.74A14.13,14.13,0,0,0,41.13,198h79.74A14.13,14.13,0,0,0,135,183.87V104.13A14.13,14.13,0,0,0,120.87,90H41.13A14.13,14.13,0,0,0,27,104.13Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M54,117h54a9,9,0,0,1,9,9h0a9,9,0,0,1-9,9H54a9,9,0,0,1-9-9h0A9,9,0,0,1,54,117Z&quot;&gt;&lt;/path&gt;&lt;rect height=&quot;18&quot; rx=&quot;9&quot; width=&quot;72&quot; x=&quot;45&quot; y=&quot;153&quot;&gt;&lt;/rect&gt;&lt;path d=&quot;M72,54V36.43A27.43,27.43,0,0,1,99.43,9h90.09A26.47,26.47,0,0,1,216,35.48v90.09A27.43,27.43,0,0,1,188.57,153H171a9,9,0,0,1-9-9h0a9,9,0,0,1,9-9h13.32A13.67,13.67,0,0,0,198,121.32V40.68A13.67,13.67,0,0,0,184.32,27H103.68A13.67,13.67,0,0,0,90,40.68V54a9,9,0,0,1-9,9h0A9,9,0,0,1,72,54Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;Run&lt;/strong&gt;. Point your phone at anything. Watch your laptop label it in real time.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Press &lt;strong style=&quot;box-sizing: border-box;&quot;&gt;&lt;code style=&quot;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 246, 255); border-radius: 6px; box-sizing: border-box; color: #607cd2; overflow-x: auto; padding: 0.065em 0.4em; word-break: break-word;&quot;&gt;q&lt;/code&gt;&lt;/strong&gt; to stop, or click the red STOP button in PyCharm.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;what-just-happened&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part5.md#what-just-happened&quot; id=&quot;4&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What Just Happened&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The phone captures video. IP Webcam streams it over Wi-Fi. Python receives each frame, feeds it into YOLOv8, and draws labeled boxes around everything it recognizes — all in real time, on your laptop screen, while the phone sits wherever you put it.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;At minimum, this gives you what we’d call &lt;em style=&quot;box-sizing: border-box;&quot;&gt;peace of mind in concept form&lt;/em&gt;: you can imagine placing that phone on top of our RC car robot and having it report back what it sees — without anyone needing to carry a laptop around like a confused tourist.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;h2 id=&quot;a-note-on-droidcam&quot; style=&quot;background-color: white; border-bottom: 1px solid rgb(208, 215, 222); box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; line-height: 1.5; margin-bottom: 10px; margin-top: 35px; padding-bottom: 8px;&quot;&gt;&lt;a aria-hidden=&quot;true&quot; class=&quot;mdr-anchor&quot; href=&quot;file:///C:/Users/Luong%20Tran/Downloads/robotics-blog-part5.md#a-note-on-droidcam&quot; id=&quot;5&quot; style=&quot;border-color: currentcolor; border-image: initial; border-style: none; border-width: medium; box-sizing: border-box; color: #607cd2; cursor: pointer; margin-bottom: initial; margin-left: -0.85em; margin-right: initial; margin-top: initial; opacity: 0; padding-right: 8px; position: absolute; scroll-margin-top: calc(-0.76em + 32px); text-decoration: none; transition: opacity 0.3s;&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;A Note on DroidCam&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You might try DroidCam and get: &quot;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;Cannot connect to camera.&quot;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That’s expected. DroidCam Free doesn’t allow video streaming via URL — that’s a Pro feature, locked behind a ~$5 paywall. We are not paying $5 just to satisfy curiosity when IP Webcam does the same thing for free.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Use IP Webcam. Free, reliable, works with OpenCV out of the box. The right tool for the job.&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;background-color: white; border-color: rgb(208, 215, 222) currentcolor currentcolor; border-image: initial; border-style: solid none none; border-width: 1px medium medium; box-sizing: border-box; letter-spacing: 0.2px; margin-bottom: 2.7rem; margin-top: 2.7rem;&quot; /&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #2b2b2f; letter-spacing: 0.2px; margin-bottom: 16px; margin-top: 16px;&quot;&gt;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up: we teach the robot to see obstacles — no physical sensor required. Just a webcam, some Python, and the concept that will eventually become the foundation of every self-driving system on the planet.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-5-your-phone-is-now-security.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJth8mLCE6P43Jo3JhuXvbDAIrnvEvWxACfsJbQUhk5uDlFDMckMzNK8ojdZXNYPp7rRD6p8mi4fM62kXs5YCwUQd04rfBpbUPXjsz4SFl2SGgH1aVq5jiVdOfLk72vtOiWXOwpo6Ox-tSs5ZsKHstHc0D_Gw-Izh5iicXORIUO5X4cluEWfiGdDi0e1E/s72-w634-h640-c/IP%20Webcam.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-8710253180636593151</guid><pubDate>Wed, 20 May 2026 22:01:25 +0000</pubDate><atom:updated>2026-05-30T05:00:34.927-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>How a Robot Really Works: Python, Arduino, and Motors — Part 4: The Big Picture</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before we move on to the next project, let&#39;s take a breath and look back at what we&#39;ve actually built.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We started with a dusty old RC car and a laptop. We ended up with a wireless robot controlled by a Python program and a keyboard. Not bad. But more importantly — do we understand &lt;em&gt;why&lt;/em&gt; it works? Let&#39;s walk through it.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Command Chain (One More Time)&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Everything comes back to this:&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 &lt;strong&gt;CEO (Python) → uses Cellphone (HC-06) → Manager (Arduino Nano) → Team Leader (L298N) → Workers (Motors)&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The CEO doesn&#39;t talk to the workers directly. Orders flow down the chain, each layer doing exactly its job and nothing more. Simple, clean, and scalable — which is exactly why real robots work the same way.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Part 1: The Arduino Code — Teaching the Manager&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Arduino Nano needs to understand what the CEO is saying. That&#39;s what the uploaded C code does — it&#39;s essentially an employee handbook for the Manager.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;1. Hardware Setup&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The code creates a virtual Bluetooth port on pins 10 (RX) and 11 (TX) — this lets the Arduino talk to the HC-06 module without interfering with the USB upload port. Communication speed: 9600 baud (the standard handshake rate).&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Six pins are defined for the L298N motor driver:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Direction pins&lt;/strong&gt;: IN1, IN2 (left motor) and IN3, IN4 (right motor)&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Speed pins&lt;/strong&gt;: ENA (left motor) and ENB (right motor)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;2. Startup (void setup)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;On power-up, the Arduino activates Bluetooth and all six motor control pins. Both motors are set to speed &lt;strong&gt;200 out of 255&lt;/strong&gt; — fast enough to move, controlled enough not to immediately crash into something.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;3. The Movement Functions&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;These are the core commands. Each one sets the IN1–IN4 pins HIGH or LOW to control which direction each motor spins:&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Function&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;What it does&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;moveForward()&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Both motors spin forward&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;moveBackward()&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Both motors spin backward&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;turnLeft()&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Left motor backward, right motor forward — spins in place&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;turnRight()&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Left motor forward, right motor backward — spins in place&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;stopCar()&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;All pins LOW — everything stops&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;4. The Main Loop (void loop)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Arduino sits in a permanent loop, constantly checking: &lt;i&gt;&quot;Has the CEO sent anything?&quot;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If data arrives over Bluetooth, it reads the character and acts:&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Key received&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Action&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;w&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Move forward&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;s&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Move backward&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;a&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Turn left&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;d&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Turn right&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;x&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Stop&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;No character? Do nothing. Wait for the next one.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Part 2: The Python Code — The CEO&#39;s Voice&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Python script is what you actually interact with. It watches the keyboard, translates keypresses into single-character commands, and fires them over Bluetooth to the Arduino.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;1. Setup&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Three tools are imported:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;serial&lt;/code&gt; — opens the Bluetooth COM port and sends data&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;keyboard&lt;/code&gt; — detects which key is being pressed&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;time&lt;/code&gt; — handles delays&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ser &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; serial&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;Serial&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;COM6&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;9600&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; timeout&lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This opens &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;COM6&lt;/code&gt; at 9600 baud — matching the Arduino exactly. &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;time.sleep(2)&lt;/code&gt; gives the connection two seconds to stabilize before anything is sent.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;2. The Control Loop&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The program runs in an infinite &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;while True&lt;/code&gt; loop, constantly checking the keyboard:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;W, A, S, or D pressed&lt;/strong&gt; → send the corresponding letter to the Arduino, print the current direction on screen&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;No key pressed&lt;/strong&gt; → automatically send &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;x&lt;/code&gt; (stop) — so the robot doesn&#39;t keep rolling when you lift your finger&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;3. Exiting&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Press &lt;strong&gt;ESC&lt;/strong&gt;: the program sends &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;x&lt;/code&gt; to stop the motors, waits 0.2 seconds, then exits the loop cleanly.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;4. Error Handling&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If anything goes wrong mid-run (lost connection, port error), the &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;except&lt;/code&gt; block catches it, prints the error message, and exits gracefully instead of crashing silently. On the way out, &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;ser.close()&lt;/code&gt; releases the COM port so it&#39;s free for next time.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Full Roster&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Role&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Who&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;CEO&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Python script on your laptop&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Cellphone&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-06 Bluetooth module&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Manager&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino Nano&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Team Leader&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;L298N H-Bridge Motor Driver&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Workers&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;2 DC motors&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Every component has one job. Every job connects to the next. Pull any one piece out and the whole chain breaks — which is also exactly how you debug it when something goes wrong.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That&#39;s the overview. Next up: we give our robot eyes it can take on the road — turning a phone into a mobile camera stream.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-4-how-it-all-works-big-picture.html</link><author>noreply@blogger.com (Unknown)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-4278672466512483667</guid><pubDate>Wed, 20 May 2026 20:47:42 +0000</pubDate><atom:updated>2026-05-30T05:00:12.820-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Convert an RC Car into a Robot with Arduino — Part 3C: The Surgery</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;After the long journey from Part 1 through Part 3B, we&#39;re finally close enough to touch our wireless robot dream. All that&#39;s left is to put everything together and press a button.&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Simple, right?&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Ha.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 1: Gutting the RC Car&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Four screws under the chassis. That&#39;s all it takes to separate the top body shell from the bottom frame. Sounds easy. And it is — until you realize the two halves aren&#39;t actually separate. Hidden wires connect the circuit board on the frame to the top shell: lights, antenna, the works.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you&#39;ve made peace with the fact that this RC car is being sacrificed for science, then the first move is simple: &lt;strong&gt;cut those wires&lt;/strong&gt;. Pull the top shell off, set it aside, and don&#39;t look back.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8gD_OyLVB3aSu_KSMVBO0k6cz5Vg6U7PsSgJlaRcqVLjQElDf8WWazy10SrCdMJ8Yezu93kQNBWPeCkgCuMVAmXooGnNiHqC4A5kCqXMJ06DMzp9lLugu8myziS2prDyXKlxag60g1SA5FDs1fMPbciDkf2lInA_EoTH1kXvqG9st0zyc8ZgMmMdIiJA/s4000/20260519_140511.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8gD_OyLVB3aSu_KSMVBO0k6cz5Vg6U7PsSgJlaRcqVLjQElDf8WWazy10SrCdMJ8Yezu93kQNBWPeCkgCuMVAmXooGnNiHqC4A5kCqXMJ06DMzp9lLugu8myziS2prDyXKlxag60g1SA5FDs1fMPbciDkf2lInA_EoTH1kXvqG9st0zyc8ZgMmMdIiJA/w480-h640/20260519_140511.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 2: Identify Your Motors&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Cheap RC cars typically have two motors: one for &lt;strong&gt;drive&lt;/strong&gt; (forward/backward) and one for &lt;strong&gt;steering&lt;/strong&gt; (left/right). These can be either DC motors or Servo motors — and this matters, because everything we&#39;ve built so far only works with DC motors. Think of it like this: the team leader from Marketing doesn&#39;t manage the Sales team&#39;s employees.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Quick reference:&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;DC Motor&lt;/strong&gt;: Simple. Just a rotor and stator. &lt;strong&gt;2 wires&lt;/strong&gt; — that&#39;s the telltale sign.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Servo Motor&lt;/strong&gt;: Complex. Has a DC motor, gearbox, control circuit, and encoder all in one. &lt;strong&gt;3 to 5 wires&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The drive motor at the rear is easy to identify — two wires, clearly visible.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwuA2ofNHy9CfR02aLj8Cz5HiV7RhNdSp2LHSbp8yZ4tdMolUS_t5lx6dI7HoZV7VXbMSMvn2miabf7yB2vPXZDkRz8rk_l1lCROa9ARVFFW5GKDWig5svIXJUlRNM1HllBAiQpr72GU14EQXDVzt2k9AvCUZjUDBYuetTydLoJgDz8ER9_w4tcwtIEeo/s4000/20260520_050437.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwuA2ofNHy9CfR02aLj8Cz5HiV7RhNdSp2LHSbp8yZ4tdMolUS_t5lx6dI7HoZV7VXbMSMvn2miabf7yB2vPXZDkRz8rk_l1lCROa9ARVFFW5GKDWig5svIXJUlRNM1HllBAiQpr72GU14EQXDVzt2k9AvCUZjUDBYuetTydLoJgDz8ER9_w4tcwtIEeo/w480-h640/20260520_050437.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The steering motor up front is a different story. A plastic cover hides most of it, and you might be tempted to take it off for a look. &lt;strong&gt;Don&#39;t.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here&#39;s the thing: the steering motor connects to a gear system that converts rotational movement into left-right movement. On a cheap RC car, all of that is held together just barely well enough to work. Once you open that cover, reassembling it is a genuine nightmare — a calorie-burning, hour-consuming ordeal that ends in frustration.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Learn from our painful experience: &lt;strong&gt;leave the cover alone&lt;/strong&gt;. Just wire it up and test it. If it moves, it&#39;s a DC motor. If it moves, you&#39;re good. Move on.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf9nI0T1AdMkt1A1uH0XFNqQ3c9JhYdpmPQZ0HpbFjVX2IidfQs1-P3iL8C8WDsexzhyLUn3UdKnz5Mx78BnGe06qSao1dqw6CHjXawu-SZupOm83JrwssjNbkoylOTI-F8xVh_d3FiewY7pk3mevLYK1IIwLsicHe9RMOPpDl-Va8Pu9ZP0oaDyazKsM/s4000/20260520_050325.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf9nI0T1AdMkt1A1uH0XFNqQ3c9JhYdpmPQZ0HpbFjVX2IidfQs1-P3iL8C8WDsexzhyLUn3UdKnz5Mx78BnGe06qSao1dqw6CHjXawu-SZupOm83JrwssjNbkoylOTI-F8xVh_d3FiewY7pk3mevLYK1IIwLsicHe9RMOPpDl-Va8Pu9ZP0oaDyazKsM/w480-h640/20260520_050325.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 3: Sort Out the Power&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Flip the chassis over. You&#39;ll find a 4×AA battery holder already built in — bonus. The negative (−) terminal already has a black wire soldered to it.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The positive (+) terminal is the metal contact on the on/off switch. The simplest approach: &lt;strong&gt;solder a wire directly to that metal contact&lt;/strong&gt;, or find a creative way to attach one without soldering. Either way, that wire becomes your positive (+) power lead.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiprjsJ1qEmIQ11zlIhbR47MLBVT-sNiWi_r3Rg8SIEMpSyziSTCNSJt6cH24j9iaQKvWANM7BvFDoADj0DREpJtTpjUyWxgffWEk8eCdMvv9bwVsMEf5Ukr_7pHoaIGiXyITF5MArtCSNYTuJUK_ZtOCqbTkIYHqJLNodR8RDlEt-unlwvyuYTVcGCwJM/s4000/20260519_181442.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiprjsJ1qEmIQ11zlIhbR47MLBVT-sNiWi_r3Rg8SIEMpSyziSTCNSJt6cH24j9iaQKvWANM7BvFDoADj0DREpJtTpjUyWxgffWEk8eCdMvv9bwVsMEf5Ukr_7pHoaIGiXyITF5MArtCSNYTuJUK_ZtOCqbTkIYHqJLNodR8RDlEt-unlwvyuYTVcGCwJM/w480-h640/20260519_181442.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFiRcyQuKmjglG1OepMP2xzIM3IhthQKquETssBInDRxm1_S-VdAOzUiiCAUymtnumfUNyZgL7VX7L2aas-1kegMrEXH-mfdXwemeqnbx0tjxpnkQjsCVDl1LrKB3HnON7pYZ_8zJZtekwrZS4HL20WjaLGFvZFRRLyra4PqBgF_CUz9vyXCkvE4_xV60/s4000/20260519_192450.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFiRcyQuKmjglG1OepMP2xzIM3IhthQKquETssBInDRxm1_S-VdAOzUiiCAUymtnumfUNyZgL7VX7L2aas-1kegMrEXH-mfdXwemeqnbx0tjxpnkQjsCVDl1LrKB3HnON7pYZ_8zJZtekwrZS4HL20WjaLGFvZFRRLyra4PqBgF_CUz9vyXCkvE4_xV60/w480-h640/20260519_192450.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 4: Remove the Old Circuit Board&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Cut every connection to the original RC board and set it free. You don&#39;t need to physically remove it — just isolate it completely. It can sit there and watch our new setup do its job. (It still serves one purpose: that metal switch contact remains the positive terminal for the battery pack.)&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;While you&#39;re at it: the motor wires are a bit short. &lt;strong&gt;Extend each one by about 3–4 inches&lt;/strong&gt; using spare wire. This gives you enough slack to route everything cleanly.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Step 5: Mount Everything and Wire It Up&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Connect the four motor wires to the L298N outputs:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Drive motor (rear)    →  OUT1, OUT2
Steering motor (front)  →  OUT3, OUT4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Don&#39;t worry about which wire is positive or negative — DC motors don&#39;t care. If a motor spins the wrong direction, just swap its two wires. Test first, fix if needed.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then mount the Arduino Nano, breadboard, L298N, HC-06, and battery wires onto the chassis. Use cardboard, double-sided tape, zip ties, hot glue — whatever works. Aesthetics are not the goal here.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXdRGg-v90y9VLf-RfoksKSgRDS09CEg3xJ7LGYBy9O6vaXdiJEcnMzCLISyX4myYPAJv6zCcNScSPH3NlB2tWeK3b5RPm1Xp3fBsjMBpFA0plU_xBmDhwtYEXsUS4UCEn_SxN4LsSC-0i9600l0jVgVwdHrnBSpQexjig7KeP_eooNvOkkI0VPY_U5SI/s4000/20260520_104555.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXdRGg-v90y9VLf-RfoksKSgRDS09CEg3xJ7LGYBy9O6vaXdiJEcnMzCLISyX4myYPAJv6zCcNScSPH3NlB2tWeK3b5RPm1Xp3fBsjMBpFA0plU_xBmDhwtYEXsUS4UCEn_SxN4LsSC-0i9600l0jVgVwdHrnBSpQexjig7KeP_eooNvOkkI0VPY_U5SI/w480-h640/20260520_104555.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Finished Robot&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here it is.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSIJXqNALQ0HJaBtfs7FWBWiHVKY9x44uiweM8TKxLN1ZZ8fDgsrd54RVtqNcjoXOVyO-CNwSveKQA-paWqE0jVFCwJ85Z_Mnv49_ByCI8OFRdSGaUgFR_IUTJfyG3Dy_rXkT_InCcM-s8BErI8bu1z8LgHObTWLKAVRTR_14ZUjdm7XxVvqbwIHZB850/s4000/20260520_104528.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSIJXqNALQ0HJaBtfs7FWBWiHVKY9x44uiweM8TKxLN1ZZ8fDgsrd54RVtqNcjoXOVyO-CNwSveKQA-paWqE0jVFCwJ85Z_Mnv49_ByCI8OFRdSGaUgFR_IUTJfyG3Dy_rXkT_InCcM-s8BErI8bu1z8LgHObTWLKAVRTR_14ZUjdm7XxVvqbwIHZB850/w480-h640/20260520_104528.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;re not going to pretend it looks good. The breadboard and L298N alone take up a significant amount of space. Add the Arduino Nano and a tangle of jumper wires, and closing the top shell becomes — as we discovered — a &lt;strong&gt;mission impossible&lt;/strong&gt;. So the shell stays off.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A few honest notes from the build:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The steering motor cover was reassembled as carefully as possible, but it never quite returned to 100%. Lesson: don&#39;t open it in the first place.&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The on/off switch was bypassed entirely. To &quot;turn off&quot; the robot, just unplug the negative (−) wire from the breadboard. Inelegant, but effective.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Test Drive&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dxbBBhmNJeR8OasiEswBQirdmp28_hLmv9nWb2xEN0F57LCIICVW4GRsNNU3xe3EUvPJhXhIFUI7_Q0OeGsdQ&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Everything works. Forward, backward, left, right — all responding to keyboard commands over Bluetooth, wirelessly, from across the room.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Does it look strange? Absolutely. Wires everywhere, no body shell, a breadboard duct-taped to a Spider-Man car chassis. But here&#39;s the thing: &lt;strong&gt;it behaves exactly like a robot&lt;/strong&gt;. Upgrade the Python code, add sensors, and this same chassis can stop itself before hitting a wall, navigate a route, or react to its environment in real time. A stock RC car can&#39;t do any of that.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Maybe it&#39;s the next generation of Bumblebee. Maybe it&#39;s Optimus Prime&#39;s budget cousin. Either way — it moves, it listens, and it does what it&#39;s told.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;What&#39;s Still Ahead&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The hardware is rough around the edges, and that&#39;s fine — for now. As our skills grow, things will get cleaner:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Custom PCB designs to replace the breadboard tangle&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Better soldering to make connections permanent and compact&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A proper enclosure that actually closes&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The big projects are still ahead. And we&#39;ve got the foundation to build them.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Parts 1 through 3C: from a webcam that recognizes objects, to a phone that senses movement, to a wireless robot driving across the floor. Not bad for stuff we already had lying around.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-3c-surgery-transplanting-brain.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8gD_OyLVB3aSu_KSMVBO0k6cz5Vg6U7PsSgJlaRcqVLjQElDf8WWazy10SrCdMJ8Yezu93kQNBWPeCkgCuMVAmXooGnNiHqC4A5kCqXMJ06DMzp9lLugu8myziS2prDyXKlxag60g1SA5FDs1fMPbciDkf2lInA_EoTH1kXvqG9st0zyc8ZgMmMdIiJA/s72-w480-h640-c/20260519_140511.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-4073337302381049513</guid><pubDate>Wed, 20 May 2026 00:49:45 +0000</pubDate><atom:updated>2026-05-30T04:59:50.880-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Wireless Robot Control with HC-06 Bluetooth — Part 3B: Cutting the Cord</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;After Parts 1, 2, and 3A, we&#39;re starting to get a feel for how a robot actually works:&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 Robots need &lt;strong&gt;senses&lt;/strong&gt; — sensors that let them see, hear, and feel the world around them. Based on what those sensors pick up, the Python &quot;brain&quot; decides what to do next.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before we get to full autonomy, we need to get comfortable controlling our robot manually — with a keyboard. And just to be clear: controlling a car with a laptop keyboard is &lt;em&gt;fundamentally different&lt;/em&gt; from using a remote control. When Python is in charge, that same &quot;brain&quot; can be upgraded to make decisions on its own. A remote control can&#39;t learn. Python can.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;But before we continue — let&#39;s agree on something important.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Our Unofficial Motto&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We do the boring stuff first. The simplest, most &quot;pointless-looking&quot; projects first. Then we upgrade, step by step, until we&#39;re building things that actually matter in real life.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you want to jump straight to a &quot;Traffic Light Controller&quot; or &quot;Smart Alarm System&quot; — tutorials for those are everywhere online. You can follow one and have a polished result in an afternoon. No shame in that.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;But that&#39;s not what we&#39;re doing here. We&#39;re here because we want to know &lt;em&gt;why&lt;/em&gt; each component exists, &lt;em&gt;why&lt;/em&gt; each line of code is there. Like the difference between taking your car to a mechanic versus crawling under it yourself, covered in grease, and figuring out what went wrong. One gets the job done. The other gives you a satisfaction that&#39;s hard to describe.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Alright. Let&#39;s get back under the car.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Problem with Part 3A&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Part 3A, we gave our robot a brain and taught it to move. Impressive in concept. Terrible in practice.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Picture this: a warehouse full of our &quot;brilliant&quot; robots from Part 3A, each one tethered to a laptop by a cable, hauling boxes around. Within sixty seconds, the entire floor would be a catastrophic tangle of wires, toppled shelves, and regret. That&#39;s not automation. That&#39;s a disaster.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;So in Part 3B, we cut the cord. We&#39;ll mount our motors onto an old RC car body and go wireless.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Same Chain of Command, New Communication Method&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The structure is exactly the same as Part 3A:&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 &lt;strong&gt;CEO (Python) → Manager (Microcontroller) → Team Leader (Driver Module) → Workers (Motors)&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The only difference is &lt;em&gt;how&lt;/em&gt; the CEO talks to the Manager.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Part 3A, the company was too broke for phones — so the CEO had to physically walk over and shout instructions. Now business is good. The CEO stays in the office and just sends a message. The Manager could be anywhere — even outside — and still gets the order instantly.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That &quot;phone&quot; can work two ways:&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;✅ &lt;strong&gt;WiFi&lt;/strong&gt; — using an ESP8266 or ESP32 module. Laptop and robot on the same network. Longer range, more stable.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;✅ &lt;strong&gt;Bluetooth&lt;/strong&gt; — using an HC-05 or HC-06 module. Pairs like a wireless headset. Simpler to set up, shorter range (~10 meters).&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;re going with &lt;strong&gt;Bluetooth&lt;/strong&gt; — it&#39;s the budget phone option. Does the job, costs less, gets us moving faster.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What You Need&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;#&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Component&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Estimated Cost&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;1&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Laptop&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Already have one&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;2&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Old RC car&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Destined for science — we&#39;ll gut it but leave it alone until Part 3C&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;3&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino Nano&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$12 for 2 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;4&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;L298N H-Bridge Motor Driver&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$7 for 2 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;5&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-06 Bluetooth Module&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$9 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;6&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Small Breadboard&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$4 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;7&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Jumper Wires&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;All 3 types: M-F, M-M, F-F&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;8&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;4×AA Battery Holder&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$5 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;9&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Small cardboard boxes, glue, screws&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Whatever&#39;s lying around&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you finished Part 3A, the only new purchase here is the HC-06 module (~$9) — and one RC car pulled out of a closet or garage. You&#39;ll also need some cardboard, glue, and screws to mount everything onto the car and give your robot the ability to stand on its own four wheels in all its glorious, jury-rigged beauty.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXw69iJ0y94Aj45g7hsAU7HbuPknFF4pvk0YrLxIDVTR1ulUntZ5bBegF5nRxU1q10TpW9bye8BnFZbv_ZHrwbvc72N4puqb_JoJRsT8Dcp-pUMsDd_Fdc2nmvuZ3K0S1Qs4PypGww0wSS68nDXdb5vFk_YvRpTGEY_9rgMOWKJZZ_b9AR9CMfp_JAuds/s4000/20260519_171623.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXw69iJ0y94Aj45g7hsAU7HbuPknFF4pvk0YrLxIDVTR1ulUntZ5bBegF5nRxU1q10TpW9bye8BnFZbv_ZHrwbvc72N4puqb_JoJRsT8Dcp-pUMsDd_Fdc2nmvuZ3K0S1Qs4PypGww0wSS68nDXdb5vFk_YvRpTGEY_9rgMOWKJZZ_b9AR9CMfp_JAuds/w480-h640/20260519_171623.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJji9FC5vWy6rqRYZA4ynbxPXPUMTnBFrhbZfSV3L-ZI_VKcZFo0o3x6dHl3fdQFXUk8FxswN_jtmcmTOVP5HcASKwSnmJlKDQ5u_-uR1IFTsdQl5OJYxarMqacYUG90t9o7LqsPiLZQHnh65-LQ0bI7CrjCf0LVVYNv6jkC-F6GdVHas17SaK0Xh029w/s4000/20260519_171640.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJji9FC5vWy6rqRYZA4ynbxPXPUMTnBFrhbZfSV3L-ZI_VKcZFo0o3x6dHl3fdQFXUk8FxswN_jtmcmTOVP5HcASKwSnmJlKDQ5u_-uR1IFTsdQl5OJYxarMqacYUG90t9o7LqsPiLZQHnh65-LQ0bI7CrjCf0LVVYNv6jkC-F6GdVHas17SaK0Xh029w/w480-h640/20260519_171640.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfBH5Aln685VL7WXCRxkAaal7sgJJ5vDkO2jMx9GgFV2CPPelmz1OkYIE6eCFuCi56RuxuMWbp4UtnlrXpIRgtWfkcURfn01DoJyV8Ns1zZ6Zpq08OAMtVtrQxILsIRAErt9rKbUw9jeBYU6RQlRc3fUiRrQNZI_mKjcweEyN6ajlNx4OMlPS-BIgyw3I/s4000/20260519_171644.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfBH5Aln685VL7WXCRxkAaal7sgJJ5vDkO2jMx9GgFV2CPPelmz1OkYIE6eCFuCi56RuxuMWbp4UtnlrXpIRgtWfkcURfn01DoJyV8Ns1zZ6Zpq08OAMtVtrQxILsIRAErt9rKbUw9jeBYU6RQlRc3fUiRrQNZI_mKjcweEyN6ajlNx4OMlPS-BIgyw3I/w480-h640/20260519_171644.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Upload the Code to Arduino Nano&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Same process as before — quick recap:&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;1. Software and Driver&lt;/strong&gt;
Download Arduino IDE (free) from the official Arduino website. If your computer doesn&#39;t recognize the board, install the CH340 driver (search &quot;CH340 driver&quot;).&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;2. Connect and Configure&lt;/strong&gt;
Plug the Arduino Nano into your laptop via USB Mini-B cable. In Arduino IDE:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Tools → Board → Arduino AVR Boards → &lt;strong&gt;Arduino Nano&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Tools → Processor → &lt;strong&gt;ATmega328P&lt;/strong&gt; (or &lt;strong&gt;ATmega328P Old Bootloader&lt;/strong&gt; for older boards)&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Tools → Port → select the correct COM port (unplug and replug to identify it)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;3. Upload&lt;/strong&gt;
Paste the code below, click &lt;strong&gt;Verify&lt;/strong&gt; (✔), then &lt;strong&gt;Upload&lt;/strong&gt; (➔). Wait for &quot;Done uploading.&quot;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;⚠️ &lt;strong&gt;Important&lt;/strong&gt;: Disconnect HC-06 from D0/D1 before uploading — if it&#39;s plugged into those pins, the upload will fail with a &quot;not in sync&quot; error.&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;cpp code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;text-text-500 font-small p-3.5 pb-0&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-cpp&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token macro directive-hash&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; style=&quot;color: #8100c2;&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: green;&quot;&gt;&amp;lt;SoftwareSerial.h&amp;gt;&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;// Bluetooth on pins 10, 11 (avoids conflicts)&lt;/span&gt;
SoftwareSerial &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;Bluetooth&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;// RX=10, TX=11&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;// Motor pins&lt;/span&gt;
&lt;span class=&quot;token token macro directive-hash&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; style=&quot;color: #b80a18;&quot;&gt;IN1&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;token token macro directive-hash&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; style=&quot;color: #b80a18;&quot;&gt;IN2&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;token token macro directive-hash&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; style=&quot;color: #b80a18;&quot;&gt;IN3&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;token token macro directive-hash&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; style=&quot;color: #b80a18;&quot;&gt;IN4&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;
&lt;span class=&quot;token token macro directive-hash&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; style=&quot;color: #b80a18;&quot;&gt;ENA&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; style=&quot;color: teal;&quot;&gt;9&lt;/span&gt;
&lt;span class=&quot;token token macro directive-hash&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; style=&quot;color: #b80a18;&quot;&gt;ENB&lt;/span&gt;&lt;span class=&quot;token token macro&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; style=&quot;color: teal;&quot;&gt;6&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
  Bluetooth&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;9600&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; OUTPUT&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; OUTPUT&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; OUTPUT&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; OUTPUT&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; OUTPUT&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; OUTPUT&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;moveForward&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;moveBackward&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;turnLeft&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;turnRight&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENA&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;analogWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;ENB&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; HIGH&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;stopCar&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN1&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN2&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN3&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;IN4&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; LOW&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;Bluetooth&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;available&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;char&lt;/span&gt; cmd &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; Bluetooth&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;      &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;cmd &lt;span class=&quot;token token&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;moveForward&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;cmd &lt;span class=&quot;token token&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;s&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;moveBackward&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;cmd &lt;span class=&quot;token token&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;turnLeft&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;cmd &lt;span class=&quot;token token&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;d&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;turnRight&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;cmd &lt;span class=&quot;token token&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: #0051c2;&quot;&gt;stopCar&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Python Code&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Same as before, just updated for Bluetooth. Save this as &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;rccar.py&lt;/code&gt;. &lt;strong&gt;Replace &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&#39;COM6&#39;&lt;/code&gt; with your actual Bluetooth COM port&lt;/strong&gt; (instructions below).&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;import&lt;/span&gt; serial
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; keyboard
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; time

ser &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; serial&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;Serial&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;COM6&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;9600&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; timeout&lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;W=forward, S=backward, A=left, D=right, X=stop. ESC=quit&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
            ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Moving forward...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;elif&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;s&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
            ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;s&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Moving backward...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;elif&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
            ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Turning left...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;elif&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;d&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
            ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;d&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Turning right...&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
            ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;esc&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
            ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
            time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;break&lt;/span&gt;

        time&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;sleep&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;except&lt;/span&gt; Exception &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;as&lt;/span&gt; e&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token string-interpolation&quot; style=&quot;color: green;&quot;&gt;f&quot;Error: &lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;token token string-interpolation interpolation&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token token string-interpolation&quot; style=&quot;color: green;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;break&lt;/span&gt;

ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;close&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Wiring It All Together&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Steps 1–6 are identical to Part 3A — we&#39;re just repeating them here for completeness.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;1. Mount Arduino Nano on Breadboard&lt;/strong&gt;
Make sure the two rows of pins straddle the center gap.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik0O9-MoN-7ZBg5gy746XOugurOGClOhbB3CKLCqwhjq5XRi4M8toD1uZ_EJubp3_tYFT98o360XnseNLqxt2DrYC4wpKmjpx41U0dDanIbsn_pXK8Y6eT2ayiDVVDk2R4pLRLxFfmeUxyONFx3oitK6t8WnSsILxrF6HEXkm3g_WuNPjXjsSheIO2GqQ/s592/Breadboard-TNC_bb_1.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEik0O9-MoN-7ZBg5gy746XOugurOGClOhbB3CKLCqwhjq5XRi4M8toD1uZ_EJubp3_tYFT98o360XnseNLqxt2DrYC4wpKmjpx41U0dDanIbsn_pXK8Y6eT2ayiDVVDk2R4pLRLxFfmeUxyONFx3oitK6t8WnSsILxrF6HEXkm3g_WuNPjXjsSheIO2GqQ/w640-h502/Breadboard-TNC_bb_1.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;2. Connect D2–D5 to L298N&lt;/strong&gt;
4× Male-to-Female jumper wires from Arduino to L298N:&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino D2  →  L298N IN1  (Motor 1 forward)
Arduino D3  →  L298N IN2  (Motor 1 backward)
Arduino D4  →  L298N IN3  (Motor 2 left)
Arduino D5  →  L298N IN4  (Motor 2 right)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLhxTc9S3ZXglDgRP4R1Qcsu614soc5Gu9309E6uFF4AXo0BsXvDRuQxBBt-kdRCEsj4sSqXQVBe1ObDil_z17W67NKZT-3crl7WCj-ir3xYAguTCuWijsp9lkDagp8P4edzIpM-zgx3a0oJH2_bNhb_-Yg8Xo-n14pfYwJfw4tq-CDUvKlHYDxyoSMeA/s592/Breadboard-TNC_bb_2.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLhxTc9S3ZXglDgRP4R1Qcsu614soc5Gu9309E6uFF4AXo0BsXvDRuQxBBt-kdRCEsj4sSqXQVBe1ObDil_z17W67NKZT-3crl7WCj-ir3xYAguTCuWijsp9lkDagp8P4edzIpM-zgx3a0oJH2_bNhb_-Yg8Xo-n14pfYwJfw4tq-CDUvKlHYDxyoSMeA/w640-h502/Breadboard-TNC_bb_2.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHlsSVqT8JdNDN3iOnp2aUem1ns1LYTwV6U_r6nBIPDUWdCbgoQSESiWze9NndeBwVF01uxkV7E13JZJaxt6VyzGlbub7ANLydYFUD1yhRwR3EMoCx2b030KbToZkMUsChxfO7FHVOcJaklQLCg-7tWr99qMGqglkBG4ZCzT5ItNd8oPPGAbndhLTAvXY/s1404/Breadboard-TNC_bb_3.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;776&quot; data-original-width=&quot;1404&quot; height=&quot;354&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHlsSVqT8JdNDN3iOnp2aUem1ns1LYTwV6U_r6nBIPDUWdCbgoQSESiWze9NndeBwVF01uxkV7E13JZJaxt6VyzGlbub7ANLydYFUD1yhRwR3EMoCx2b030KbToZkMUsChxfO7FHVOcJaklQLCg-7tWr99qMGqglkBG4ZCzT5ItNd8oPPGAbndhLTAvXY/w640-h354/Breadboard-TNC_bb_3.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;3. Connect GND&lt;/strong&gt;
1× Male-to-Male wire: Arduino GND → L298N GND.&lt;/span&gt;&lt;/p&gt;
&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQL_gLeiWU9Q36RJGkuj3h_zJPZgoJdMj2ePYu_3dEj3xwku7ujOczZDs1YaUo9XvLUeKnUrBaafCpcWv_scvbhk5Ize3f3GoXhC2GhHAAbxMx6uTainYs4jZe0cOf1_Jqz7ySS-JkBhG1GcI6QwbFoiTGno0IuGtDLOel3ubPVEkeaAQegZmKeR8T-wk/s592/Breadboard-TNC_bb_4.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQL_gLeiWU9Q36RJGkuj3h_zJPZgoJdMj2ePYu_3dEj3xwku7ujOczZDs1YaUo9XvLUeKnUrBaafCpcWv_scvbhk5Ize3f3GoXhC2GhHAAbxMx6uTainYs4jZe0cOf1_Jqz7ySS-JkBhG1GcI6QwbFoiTGno0IuGtDLOel3ubPVEkeaAQegZmKeR8T-wk/w640-h502/Breadboard-TNC_bb_4.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtvEQVCaK1RUGBXIIaxa6UnedDozNA__XE983F2k7XZJ06LHVdYIxXobIEeV_dqU0_FDsgcCW9xxugupZ4knr3_1pXiG6-lLSTRNMoKQmNywiRBxlv9W_7t4gjw-fusu8YX2CbDxBB2cJsTr4lhmGjY4n33JwId9mPsgLarkEN47JRZW1dv1hET_U1Kz4/s1404/Breadboard-TNC_bb_5.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;776&quot; data-original-width=&quot;1404&quot; height=&quot;354&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtvEQVCaK1RUGBXIIaxa6UnedDozNA__XE983F2k7XZJ06LHVdYIxXobIEeV_dqU0_FDsgcCW9xxugupZ4knr3_1pXiG6-lLSTRNMoKQmNywiRBxlv9W_7t4gjw-fusu8YX2CbDxBB2cJsTr4lhmGjY4n33JwId9mPsgLarkEN47JRZW1dv1hET_U1Kz4/w640-h354/Breadboard-TNC_bb_5.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;4. Connect the Motors&lt;/strong&gt;
Motor 1 → OUT1, OUT2. Motor 2 → OUT3, OUT4.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhiIO3xtZkBzaWCixYOcgID6WAlN5P9J_odivKMvEoeMaY5V5G7azluHGuWH4owTB6dtt3oS4JsZFScexuauyQaw8W96swXWMCrNdNRzUiPTmBPCciGXzfyu4xx4xX8px3vjb_9Bc3lQDru98tbnz6F-op2J_eb61V0PuTBYSpzTctGwsvT28IpoaOpDhg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;1013&quot; data-original-width=&quot;1158&quot; height=&quot;561&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhiIO3xtZkBzaWCixYOcgID6WAlN5P9J_odivKMvEoeMaY5V5G7azluHGuWH4owTB6dtt3oS4JsZFScexuauyQaw8W96swXWMCrNdNRzUiPTmBPCciGXzfyu4xx4xX8px3vjb_9Bc3lQDru98tbnz6F-op2J_eb61V0PuTBYSpzTctGwsvT28IpoaOpDhg=w640-h561&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;5. Connect Battery Pack&lt;/strong&gt;
Red (+) → L298N &lt;strong&gt;12V&lt;/strong&gt; terminal. Black (−) → L298N GND.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBSHWjf2f3XOBULjrpZ8lxeNqM6vu3TBvYa-dZHuf7xSkqijJW5BcHVMZIu_z38uPcX14paxQeTnzwKodOXa8KGxtcZpYRVH-cXlmb2VlK8MoNLDZiv2imVqmtAI8addSzA0X7oEH_wKw4dmpC3izf-4DiuPFf9g2tys2uDVl_wBlSi0n_2Mt1JnFI2-8/s592/Breadboard-TNC_bb_7.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBSHWjf2f3XOBULjrpZ8lxeNqM6vu3TBvYa-dZHuf7xSkqijJW5BcHVMZIu_z38uPcX14paxQeTnzwKodOXa8KGxtcZpYRVH-cXlmb2VlK8MoNLDZiv2imVqmtAI8addSzA0X7oEH_wKw4dmpC3izf-4DiuPFf9g2tys2uDVl_wBlSi0n_2Mt1JnFI2-8/w640-h502/Breadboard-TNC_bb_7.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;6. Steps 1–5 are a repeat of Part 3A. Now for the new guest: the HC-06.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2DocFE1Z7_sIAYsfIaEJ-cR6bt27k4_Ff5OcaHtEY0cCD4-GKQKLvGRU-g0Sm5jxOtqIjckv3OuJRd2-93OeOFSdSRyv_apuOh7bq5xvuQSxhOkcaWovybp2Flf0O7LL_Hdhyphenhyphenk7CXDtl8eu6Ex0Y6PRlZqs2UUrw3Ay31Lh6QhxiNsMghmA9gI0YiWZE/s4000/20260519_173544.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2DocFE1Z7_sIAYsfIaEJ-cR6bt27k4_Ff5OcaHtEY0cCD4-GKQKLvGRU-g0Sm5jxOtqIjckv3OuJRd2-93OeOFSdSRyv_apuOh7bq5xvuQSxhOkcaWovybp2Flf0O7LL_Hdhyphenhyphenk7CXDtl8eu6Ex0Y6PRlZqs2UUrw3Ay31Lh6QhxiNsMghmA9gI0YiWZE/w480-h640/20260519_173544.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-UCYBL3CFPvwEGVFkz1Q71HEPU43TBoKzGmmsBmX7HdCCd6PNNvB-EYTunzLvMuYH9L-b3VjLsBrQEk1mYWzQ94hlVI3FOfEhyphenhyphenLSN901EH94klWl_GfM9Y3NOKTXjesUF9st24kdTgXQ-ZbuZsPAv669GP_JNdymVzV1Jk8saiwIhnGvhaeD-xwIaJrs/s4000/20260519_173550.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-UCYBL3CFPvwEGVFkz1Q71HEPU43TBoKzGmmsBmX7HdCCd6PNNvB-EYTunzLvMuYH9L-b3VjLsBrQEk1mYWzQ94hlVI3FOfEhyphenhyphenLSN901EH94klWl_GfM9Y3NOKTXjesUF9st24kdTgXQ-ZbuZsPAv669GP_JNdymVzV1Jk8saiwIhnGvhaeD-xwIaJrs/w480-h640/20260519_173550.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;7. Mount HC-06 on the Breadboard — horizontally&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This matters more than it sounds. Here&#39;s why: on a breadboard, holes in the same &lt;em&gt;column&lt;/em&gt; (vertical) are connected. Holes in the same &lt;em&gt;row&lt;/em&gt; (horizontal) are not.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;So if you plug the HC-06 in vertically, you&#39;re accidentally shorting all its pins together. Plug it in &lt;em&gt;horizontally&lt;/em&gt;, and each pin gets its own isolated column. Also leave at least one column of gap between HC-06 and the Arduino Nano — same reason.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6ZBowZFMnTqE8gFiXxCsaDKVTaulLJGp_kjrD7nIdSu8oI19SbDEco-EBn74Ygg1kDWFQNRs6vXH1btEfwj5wqZrbOMAPYfM6VvkGhpu2DrVXp4Oi2qCYdIR4XGjdntCvO-0-Ps4Qi60_WmDQxofXe0aIpZ9cNgoAxfkoSXzeFDIL1KVCjUrUq0nBu00/s678/Breadboard-TNC_bb_9.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;464&quot; data-original-width=&quot;678&quot; height=&quot;438&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6ZBowZFMnTqE8gFiXxCsaDKVTaulLJGp_kjrD7nIdSu8oI19SbDEco-EBn74Ygg1kDWFQNRs6vXH1btEfwj5wqZrbOMAPYfM6VvkGhpu2DrVXp4Oi2qCYdIR4XGjdntCvO-0-Ps4Qi60_WmDQxofXe0aIpZ9cNgoAxfkoSXzeFDIL1KVCjUrUq0nBu00/w640-h438/Breadboard-TNC_bb_9.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicwL99WMghyiI-JMC1GABCnc6OPcIYMMDEng978cX820DhX2c_VWbiYSKDfFbA1pKDxcFyVdPnxjtyvNiqFLgV3fYYyntXVbldAB39u0sKAMxaoQSGRwL28yWwWTRFryhM8PnYsv_rXED2q7jbLhRtL3mJ9oPmM2XqxQMtGOCie563EQvM0nsTw0foCt8/s863/BreadboardingLEDCircuit_Step2_ByJonFroehlich.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;384&quot; data-original-width=&quot;863&quot; height=&quot;284&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicwL99WMghyiI-JMC1GABCnc6OPcIYMMDEng978cX820DhX2c_VWbiYSKDfFbA1pKDxcFyVdPnxjtyvNiqFLgV3fYYyntXVbldAB39u0sKAMxaoQSGRwL28yWwWTRFryhM8PnYsv_rXED2q7jbLhRtL3mJ9oPmM2XqxQMtGOCie563EQvM0nsTw0foCt8/w640-h284/BreadboardingLEDCircuit_Step2_ByJonFroehlich.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;8. Connect HC-06&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-06 GND  →  Arduino GND
HC-06 VCC  →  Arduino 5V
HC-06 RXD  →  Arduino D11
HC-06 TXD  →  Arduino D10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;9. ENA and ENB — remove the jumper caps&lt;/strong&gt;
In Part 3A, we used jumper caps to keep ENA and ENB permanently HIGH. Now we want Python to control motor speed, so we wire them directly:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;L298N ENA  →  Arduino D9
L298N ENB  →  Arduino D6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;10. Power the Arduino from the L298N&lt;/strong&gt;
Connect Arduino &lt;strong&gt;VIN&lt;/strong&gt; → L298N &lt;strong&gt;12V&lt;/strong&gt; terminal. Both the Arduino and L298N should light up. The HC-06 LED will blink, waiting for a connection.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Full Wiring Diagram&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBx00iJ24GMHtBBDSZy-aLC3MzAcC5Z_ttSooE3QF3mA8_98Vb6ShJzU18Hl0DmWAvKEFueIXCYzZCF1t3xW1FxERpUiM3MZrp9Dp-2l5tGfq6iHf-4yJHEsi5o7z3OdHGT98FZ7WLuGQszm1ttQ_Dz62lyfTYlvlwZfctPOgiCAYr9aPt6RhYN_wwsww/s2221/SoDo2.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1104&quot; data-original-width=&quot;2221&quot; height=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBx00iJ24GMHtBBDSZy-aLC3MzAcC5Z_ttSooE3QF3mA8_98Vb6ShJzU18Hl0DmWAvKEFueIXCYzZCF1t3xW1FxERpUiM3MZrp9Dp-2l5tGfq6iHf-4yJHEsi5o7z3OdHGT98FZ7WLuGQszm1ttQ_Dz62lyfTYlvlwZfctPOgiCAYr9aPt6RhYN_wwsww/w640-h318/SoDo2.png&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Connecting HC-06 to Your Laptop&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Pair the module:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Power up the circuit — HC-06 LED will blink rapidly&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;On Windows: Settings → Bluetooth &amp;amp; devices → Add device → Bluetooth&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Select &lt;strong&gt;HC-06&lt;/strong&gt; (may also appear as &quot;Linvar&quot; or &quot;JY-MCU&quot;)&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Enter PIN: &lt;strong&gt;1234&lt;/strong&gt; (or &lt;strong&gt;0000&lt;/strong&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Find the COM port:&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Settings → Bluetooth &amp;amp; devices → More Bluetooth settings&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Go to the &lt;strong&gt;COM Ports&lt;/strong&gt; tab&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Find HC-06 with Direction = &lt;strong&gt;Outgoing&lt;/strong&gt; — that&#39;s your port&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Update &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;rccar.py&lt;/code&gt; with that port number&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Run It&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open PyCharm, run &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;rccar.py&lt;/code&gt;, and press &lt;strong&gt;W, A, S, D&lt;/strong&gt; to control the motors.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Freedom. No cables. No chaos. Just a robot that actually listens from across the room.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Troubleshooting: Lessons Learned the Hard Way&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Problem&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Cause&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Fix&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Pin conflict — motor and Bluetooth fighting over same pin&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ENB and HC-06 TX both assigned to D10&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Move ENB to D6; keep Bluetooth on D10/D11&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Upload fails with &quot;not in sync&quot; error&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;HC-06 plugged into D0/D1 during upload&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Unplug HC-06 before uploading, replug after&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Motors make a clicking sound but don&#39;t spin&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Old or weak batteries&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Replace with fresh AA batteries — seriously, check this first&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;That last one is a classic. We spent a while convinced the code was wrong. It was the batteries.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Next up — Part 3C: we finally operate on the RC car. The motors are waiting. The servo steering is a mystery. Let&#39;s find out what&#39;s inside.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-3b-cutting-cord-wireless-control.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXw69iJ0y94Aj45g7hsAU7HbuPknFF4pvk0YrLxIDVTR1ulUntZ5bBegF5nRxU1q10TpW9bye8BnFZbv_ZHrwbvc72N4puqb_JoJRsT8Dcp-pUMsDd_Fdc2nmvuZ3K0S1Qs4PypGww0wSS68nDXdb5vFk_YvRpTGEY_9rgMOWKJZZ_b9AR9CMfp_JAuds/s72-w480-h640-c/20260519_171623.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-3660953102029934941</guid><pubDate>Sat, 16 May 2026 00:07:05 +0000</pubDate><atom:updated>2026-05-30T04:59:26.767-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>DC Motor Control with Arduino Nano and Python — Part 3A: Two Motors, One Keyboard</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In the previous two parts, we built the &quot;infrastructure&quot; for our robot:&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;It can &lt;strong&gt;see&lt;/strong&gt; — recognizing people, cars, furniture, and more&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;It can &lt;strong&gt;feel&lt;/strong&gt; — knowing when it&#39;s tilting, spinning, or moving through space&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;But if we&#39;re talking about a self-driving car, what comes next?&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;re splitting this into two parts:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Part 3A&lt;/strong&gt;: Program two DC motors to move forward, backward, left, and right. That&#39;s it.&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Part 3B&lt;/strong&gt;: Upgrade by mounting everything onto a real RC car, controlled wirelessly via Wi-Fi or Bluetooth from a laptop keyboard.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now, we know what you&#39;re thinking: &lt;em&gt;&quot;This doesn&#39;t sound like a robot at all. Even Part 3B just sounds like... a remote-controlled car.&quot;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Fair point. Let&#39;s address that.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Is a Remote-Controlled Toy Car a Robot?&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Absolutely not.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;At first glance, controlling a car with a laptop keyboard looks no different from using a remote to drive an RC car around. But here&#39;s the thing — remember the &quot;infrastructure&quot; we built?&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Our robot already has &lt;strong&gt;eyes&lt;/strong&gt; and &lt;strong&gt;awareness&lt;/strong&gt;. Sitting inside the house, while the robot roams outside, we can know when it needs to stop for an obstacle, when it should turn left, when it should turn right to reach a destination. A regular RC car? Completely helpless in that situation.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;And it gets better. With those senses already in place, we can upgrade our Python program so the robot &lt;strong&gt;automatically&lt;/strong&gt; stops when it detects something in its path — or automatically turns left when it sees &quot;ABC Street&quot; and right when it sees &quot;DEF Road.&quot;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A toy RC car can&#39;t dream of doing any of that.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Adding a Brain: How the Command Chain Works&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before we build, let&#39;s picture how the &quot;brain&quot; of our robot works.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The brain is the laptop — more precisely, the Python program running on it. It listens to the keyboard, decides where to go, and sends commands to the motors.&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 &lt;strong&gt;Python gives the order → Motors execute&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Simple enough. But in reality, motors need to spin both directions, speed up, slow down, and stop instantly. We need something in the middle to manage all of that — a &lt;strong&gt;driver module&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 &lt;strong&gt;Python gives the order → Driver module → Motors execute&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Still straightforward. But here&#39;s where real life gets complicated.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Just like in the office — not everyone &quot;gets along&quot; with everyone else. Different electronics have different standards; some components work perfectly together; others simply refuse to cooperate. Think of it like a corporate chain of command: the CEO (Python code) doesn&#39;t talk directly to every employee (motors). Orders go through Managers, then Team Leaders (the driver module), and finally reach the workers (motors).&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;So, we need a manager. That Manager is a &lt;strong&gt;microcontroller&lt;/strong&gt; — a tiny single-chip computer whose job is to receive commands and translate them into physical actions: spin motor, stop motor, go left, go right.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here&#39;s our official command chain:&lt;/span&gt;&lt;/p&gt;
&lt;blockquote class=&quot;ml-2 border-l-4 border-border-300/10 pl-4 text-text-300&quot;&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;👉 &lt;strong&gt;Python gives the order → Microcontroller → Driver module → Motors execute&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Sounds complicated? Don&#39;t worry. Everything here is small, cheap, and beginner friendly. True to our &quot;use what you have&quot; philosophy, we only need to buy a few inexpensive parts. The final result won&#39;t be pretty — it&#39;ll look like a tangled mess of wires. But looks are deceiving. This &quot;mess&quot; behaves exactly like a real robot: upgrade the code, add sensors, and those motors will respond intelligently — fast, slow, forward, reverse, stop — reacting to real-world input.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What You Need (Components List)&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;#&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Component&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Estimated Cost&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;1&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Laptop&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You already have one&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;2&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;USB to Mini-B cable&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$5 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;3&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino Nano&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$12 for 2 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;4&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;L298N H-Bridge Motor Driver Module&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$7 for 2 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;5&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;DC Motors&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$6 for 2 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;6&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Small Breadboard&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$4 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;7&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Jumper Wires&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Get all 3 types: M-F, M-M, F-F&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;8&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;4×AA Battery Holder&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;~$5 on Amazon&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You can also find starter kits on Amazon that bundle several of these together — that&#39;ll bring the total cost down nicely.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Everything here is reusable for future projects. If you&#39;ve made it through Parts 1 and 2 and you&#39;re still excited — skipping a few Starbucks runs to fund this is probably worth it.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFCvdEEsFq8mH-f6JkEH3xTJ667PwS4GH0y9knITDnWdUA5T4fVpZayCD1LSDMp_Bk1BYj6FOxuyEoH_Ylks24QnfUlaCAs9IbJcz4lydLeLbCwijT2qgR1IpW71rmhjtDQBM-C4JR4erZb-vNtbpto1wKFc4NkSx3cPLI6WhklQkSLy0dYqLsJlgqGcI/s4000/20260515_102200.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFCvdEEsFq8mH-f6JkEH3xTJ667PwS4GH0y9knITDnWdUA5T4fVpZayCD1LSDMp_Bk1BYj6FOxuyEoH_Ylks24QnfUlaCAs9IbJcz4lydLeLbCwijT2qgR1IpW71rmhjtDQBM-C4JR4erZb-vNtbpto1wKFc4NkSx3cPLI6WhklQkSLy0dYqLsJlgqGcI/w480-h640/20260515_102200.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEDqHbzIySoX_MrhmT0R-SApYagcm7qtQH2nB3xspk9fjXo16fiVSoAVsSEs8GLg4CePNqWr5FqfkYCDjz2hqtAxAUe1QNwB2aVY6nFD3-dklr6jTPQxgCc9C_ZI3b5T67LJOeWzvAEV9QILt0ddCTHOnCZXt3qJl7DocOmRI-GCK_D6-mjOaok7lz0Mg/s4000/20260515_102054.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEDqHbzIySoX_MrhmT0R-SApYagcm7qtQH2nB3xspk9fjXo16fiVSoAVsSEs8GLg4CePNqWr5FqfkYCDjz2hqtAxAUe1QNwB2aVY6nFD3-dklr6jTPQxgCc9C_ZI3b5T67LJOeWzvAEV9QILt0ddCTHOnCZXt3qJl7DocOmRI-GCK_D6-mjOaok7lz0Mg/w480-h640/20260515_102054.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Meet the Arduino Nano&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The Arduino Nano is our microcontroller — the Manager in our command chain. Because it&#39;s essentially a tiny computer, it needs to be treated like one. Just like your laptop asks for a driver when you plug in something new, the Arduino Nano needs a &quot;driver&quot; too — in this case, that means uploading code to it before we can use it.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh348leX2fktSMtjaLYwvTONMVszZjIW6AGQHcla291zaIKf7AsmsObqkOZyNbdHmV3E_y3oZbROqA4UaXYVunxp4fnYVGN5PC5WBLBQTup9Fwudli4qvTKFCQMky0m21-Hn6qa2AqV7U7gXdQzWwVuT1_1OwohwXLeY84nY1wW2_fcKnXtk5350OWSaa4/s4000/20260515_102117.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;4000&quot; data-original-width=&quot;3000&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh348leX2fktSMtjaLYwvTONMVszZjIW6AGQHcla291zaIKf7AsmsObqkOZyNbdHmV3E_y3oZbROqA4UaXYVunxp4fnYVGN5PC5WBLBQTup9Fwudli4qvTKFCQMky0m21-Hn6qa2AqV7U7gXdQzWwVuT1_1OwohwXLeY84nY1wW2_fcKnXtk5350OWSaa4/w480-h640/20260515_102117.jpg&quot; width=&quot;480&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Step 1: Prepare the Software and Driver&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Download Arduino IDE&lt;/strong&gt; (free) from the &lt;a href=&quot;https://www.arduino.cc/en/software/&quot;&gt;official Arduino website&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Install the CH340 Driver&lt;/strong&gt; &lt;em&gt;(important, but sometimes your computer handles this automatically)&lt;/em&gt;: Most Arduino Nanos sold today use the CH340 chip for USB communication. If your computer doesn&#39;t recognize the board after plugging it in, search for &quot;CH340 driver&quot; and install it from the manufacturer&#39;s site.&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Step 2: Connect and Configure the Board&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Connect the Arduino Nano to your laptop using the USB to Mini-B cable — USB end into the laptop, Mini-B end into the Arduino Nano.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open Arduino IDE, then:&lt;/span&gt;&lt;/p&gt;
&lt;ul class=&quot;[li_&amp;amp;]:mb-0 [li_&amp;amp;]:mt-1 [li_&amp;amp;]:gap-1 [&amp;amp;:not(:last-child)_ul]:pb-1 [&amp;amp;:not(:last-child)_ol]:pb-1 list-disc flex flex-col gap-1 pl-8 mb-3&quot;&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Select Board&lt;/strong&gt;: Tools → Board → Arduino AVR Boards → &lt;strong&gt;Arduino Nano&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Select Processor&lt;/strong&gt;: Tools → Processor → If it&#39;s an older board, choose &lt;strong&gt;ATmega328P (Old Bootloader)&lt;/strong&gt;; newer boards use &lt;strong&gt;ATmega328P&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;font-claude-response-body whitespace-normal break-words pl-2&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;strong&gt;Select Port&lt;/strong&gt;: Tools → Port → Choose the correct COM port (e.g. COM3, COM4). Not sure which one? Unplug the cable, plug it back in, and see which port just appeared.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Step 3: Upload the Code&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Paste the code below into the Arduino IDE editor. Click &lt;strong&gt;Verify&lt;/strong&gt; (✔) to check for errors, then click &lt;strong&gt;Upload&lt;/strong&gt; (➔) to flash it to the board. Wait for &lt;strong&gt;&quot;Done uploading&quot;&lt;/strong&gt; at the bottom.&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;cpp code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;code class=&quot;language-cpp&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #6e7687;&quot;&gt;// &lt;/span&gt;&lt;span style=&quot;color: #6e7687;&quot;&gt;Commands from Python via Serial to Control the L298N&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token token macro directive-hash&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;IN1&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token token macro directive-hash&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;IN2&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token token macro directive-hash&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;IN3&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token token macro directive-hash&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token token macro directive&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro macro-name&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt;IN4&lt;/span&gt;&lt;span class=&quot;token token macro&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #b80a18;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token macro expression&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
  Serial&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: teal;&quot;&gt;9600&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN1&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; OUTPUT&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN2&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; OUTPUT&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN3&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; OUTPUT&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN4&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; OUTPUT&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;void&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;available&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;char&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; cmd &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;=&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; Serial&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #6e7687;&quot;&gt;// Reset tất cả&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN1&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; LOW&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN2&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; LOW&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN3&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; LOW&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN4&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; LOW&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;

    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;cmd &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;==&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: green;&quot;&gt;&#39;F&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #6e7687;&quot;&gt;// Forward &lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN1&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN3&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;cmd &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;==&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: green;&quot;&gt;&#39;B&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #6e7687;&quot;&gt;// Backward &lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN2&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN4&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;cmd &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;==&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: green;&quot;&gt;&#39;L&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #6e7687;&quot;&gt;// Left &lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN1&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN4&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;cmd &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;==&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: green;&quot;&gt;&#39;R&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;{&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #6e7687;&quot;&gt;// Right &lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN2&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #0051c2;&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;IN3&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt; HIGH&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;;&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #6e7687;&quot;&gt;// cmd == &#39;S&#39; → Stop, all pins LOW&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token token&quot; face=&quot;var(--font-mono)&quot; style=&quot;color: #2b303b;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Once uploaded, the Arduino Nano is set. You won&#39;t need to touch it again.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;The Python Code (Our CEO)&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you&#39;ve been with us since Parts 1 and 2, this part is almost too easy. Create a new file in PyCharm called &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;motor.py&lt;/code&gt; and paste this in. &lt;strong&gt;Remember to change &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&#39;COM3&#39;&lt;/code&gt; to match your actual Arduino port.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;div aria-label=&quot;python code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code class=&quot;language-python&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; serial
&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;import&lt;/span&gt; keyboard

&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Replace &#39;COM3&#39; with your Arduino&#39;s actual port&lt;/span&gt;
&lt;span class=&quot;token token&quot; style=&quot;color: #6e7687;&quot;&gt;# Windows: COM3, COM4... / Mac/Linux: /dev/ttyUSB0&lt;/span&gt;
ser &lt;span class=&quot;token token&quot;&gt;=&lt;/span&gt; serial&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;Serial&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;COM3&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;9600&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&quot;Arrow keys to control. Press ESC to quit.&quot;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token token&quot; style=&quot;color: teal;&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;up&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;F&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;elif&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;down&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;B&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;elif&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;left&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;L&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;elif&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;right&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;R&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;b&#39;S&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;if&lt;/span&gt; keyboard&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;is_pressed&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: green;&quot;&gt;&#39;esc&#39;&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token token&quot; style=&quot;color: #8100c2;&quot;&gt;break&lt;/span&gt;

ser&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;.&lt;/span&gt;close&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token token&quot; style=&quot;color: #2b303b;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Wiring Everything Together&lt;/span&gt;&lt;/h2&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;1. Mount the Arduino Nano on the Breadboard&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Make sure the two rows of pins sit on opposite sides of the center gap.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjSUy_08P11B_KV_m3i5W26y-YQMNnlZu4zHkDu__NO6b5WmzO_n2e2hhskdXjKcHfN_s41_tz9w9TswVcjP1_hLFUSWzuW_fdywUdJft1baRzXvX4ipMkmkv-PMmQXMztDkHRPMHq79sBXFYYUvP1NantT2iJc2rrPQ2hA_I4oeCKOcrIi7LYQ9AC-SCU&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjSUy_08P11B_KV_m3i5W26y-YQMNnlZu4zHkDu__NO6b5WmzO_n2e2hhskdXjKcHfN_s41_tz9w9TswVcjP1_hLFUSWzuW_fdywUdJft1baRzXvX4ipMkmkv-PMmQXMztDkHRPMHq79sBXFYYUvP1NantT2iJc2rrPQ2hA_I4oeCKOcrIi7LYQ9AC-SCU=w640-h502&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;2. Connect D2–D5 to the L298N&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Take 4 &lt;strong&gt;Male-to-Female&lt;/strong&gt; jumper wires. Plug the Male ends into pins D2, D3, D4, D5 on the Arduino Nano.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgK-vNUdLRr80cO-VNmSxahOiFTK4nXY8TYPBkKvgonv9bL35Gl1RVcLOmOqaLxqRjffIMSLSMG91DlbO0bqIyMo1Og5S-1m2kYrj1tZxwOP_vY3Klry-WicXjSGr6Cd8QxUP6jyC7Z-uFW336kyKt8THf2GRFTzvQ_v86vbO0cmobVF8j2ge4YeO3BA10&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgK-vNUdLRr80cO-VNmSxahOiFTK4nXY8TYPBkKvgonv9bL35Gl1RVcLOmOqaLxqRjffIMSLSMG91DlbO0bqIyMo1Og5S-1m2kYrj1tZxwOP_vY3Klry-WicXjSGr6Cd8QxUP6jyC7Z-uFW336kyKt8THf2GRFTzvQ_v86vbO0cmobVF8j2ge4YeO3BA10=w640-h502&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Plug the Female ends into IN1, IN2, IN3, IN4 on the L298N, following this mapping:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span face=&quot;var(--font-mono)&quot; style=&quot;color: #14181f; font-family: verdana; font-size: medium; white-space: pre-wrap;&quot;&gt;Arduino D2  →  L298N IN1  (Motor 1 forward)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino D3  →  L298N IN2  (Motor 1 backward)&lt;/span&gt;&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino D4  →  L298N IN3  (Motor 2 left)&lt;/span&gt;&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino D5  →  L298N IN4  (Motor 2 right)&lt;/span&gt;&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div aria-label=&quot;Code&quot; class=&quot;relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100&quot; role=&quot;group&quot; tabindex=&quot;0&quot;&gt;&lt;div class=&quot;overflow-x-auto&quot;&gt;&lt;pre class=&quot;code-block__code !my-0 !rounded-lg !text-sm !leading-relaxed p-3.5&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #14181f;&quot;&gt;&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgUiUekWs3jEVbo49Qk4XQNRlLVJ0Jwos68bCoJELkRQDdHtMvXL2khGUTllfV0SyBmUeAhSOfpV_z1LL1UdEAPXP8H1vpEzD0AX-glZl-xzhOLfu6lXHspAQvSmGk6xLM2acomyLTDsnTmp2UtsvLYH-u_xRq3lO8HUTz3D0xhoIWPRjIToXFbOHbpSt0&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;776&quot; data-original-width=&quot;1404&quot; height=&quot;354&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgUiUekWs3jEVbo49Qk4XQNRlLVJ0Jwos68bCoJELkRQDdHtMvXL2khGUTllfV0SyBmUeAhSOfpV_z1LL1UdEAPXP8H1vpEzD0AX-glZl-xzhOLfu6lXHspAQvSmGk6xLM2acomyLTDsnTmp2UtsvLYH-u_xRq3lO8HUTz3D0xhoIWPRjIToXFbOHbpSt0=w640-h354&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;3. Connect GND&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Take 1 &lt;strong&gt;Male-to-Male&lt;/strong&gt; jumper wire. One end into the GND pin on the Arduino Nano, other end into the GND on the L298N.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEitGGl20uowiNaro8HS9X6sSxK_qpqp8dZym_N9sFoxOTInPjfgPQl0w2MPdBoAQX1BOxhZoj_hbqHMMez-pJs-EOsrEQyQKw0i8xT2Z-RLeImcQ46LtDDDdqennk33Zg7OUJZNn0sl1AhcAHJn1sEGdT7klsGTfAwj8Fw3MColK9dF8VfD3lhfh8415YM&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEitGGl20uowiNaro8HS9X6sSxK_qpqp8dZym_N9sFoxOTInPjfgPQl0w2MPdBoAQX1BOxhZoj_hbqHMMez-pJs-EOsrEQyQKw0i8xT2Z-RLeImcQ46LtDDDdqennk33Zg7OUJZNn0sl1AhcAHJn1sEGdT7klsGTfAwj8Fw3MColK9dF8VfD3lhfh8415YM=w640-h502&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhgbqMXG0aCmiUv228jnjKCeFzAObq6CpaGBsmEg1Y6lhELLx5X9pZcj6ewMdCb84INCn398OFvKZbNMXaQzzcxGuUas1SPlo_LlltKzoC8eihYFBxZa6tUjurJuNpUQJfCz6bHFM_BckcuzAjkGnBjqeridiTMR65Q0F2ZpL8Gd3pcKdiM8OjNG7a_Sho&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;776&quot; data-original-width=&quot;1404&quot; height=&quot;354&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhgbqMXG0aCmiUv228jnjKCeFzAObq6CpaGBsmEg1Y6lhELLx5X9pZcj6ewMdCb84INCn398OFvKZbNMXaQzzcxGuUas1SPlo_LlltKzoC8eihYFBxZa6tUjurJuNpUQJfCz6bHFM_BckcuzAjkGnBjqeridiTMR65Q0F2ZpL8Gd3pcKdiM8OjNG7a_Sho=w640-h354&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;4. Connect the Motors&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-pre-wrap leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Motor 1 wires → OUT1 and OUT2 on the L298N.
Motor 2 wires → OUT3 and OUT4 on the L298N.&lt;/span&gt;&lt;/p&gt;
&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjia38e90hmRxCZX75hoMCbrRwMe-TOwP4KN4IpjBkCVQb3GAHjuWX2gh6lT7Se5xhZ8KuySKF1z3KljQVr4H0I01J1mcxgR8ZWtgHSueckkacsgj4_ZdA4bVCp4UxkPjsee3knTtytSduzyuTegMN648e0Vpaw58N6Ex7DHwOXAmqRQw-41lVBHasR99M&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;1013&quot; data-original-width=&quot;1158&quot; height=&quot;561&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjia38e90hmRxCZX75hoMCbrRwMe-TOwP4KN4IpjBkCVQb3GAHjuWX2gh6lT7Se5xhZ8KuySKF1z3KljQVr4H0I01J1mcxgR8ZWtgHSueckkacsgj4_ZdA4bVCp4UxkPjsee3knTtytSduzyuTegMN648e0Vpaw58N6Ex7DHwOXAmqRQw-41lVBHasR99M=w640-h561&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;5. Connect the Battery Pack&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Red wire (+) from the battery holder → &lt;strong&gt;12V terminal&lt;/strong&gt; on the L298N.
Black wire (−) → GND on the Arduino Nano.&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi_DZvWVghk2nD2sQV_7MM13p1vNPhc7eiwFSrpD9BMJmcBRHjZQ1GAVuTH5wLlwSC00vXJr94Tj6_WbvKA_i-lC5ZZCSAN0JY1z7vPylaPEU_NZUfy72Qt7kbjxCjHrkk39WD39iSRh_hKLgu7ki9tsmx423uR7pu1pn8sGjc7296sfd0hRVY1pv_lTX4&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;464&quot; data-original-width=&quot;592&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi_DZvWVghk2nD2sQV_7MM13p1vNPhc7eiwFSrpD9BMJmcBRHjZQ1GAVuTH5wLlwSC00vXJr94Tj6_WbvKA_i-lC5ZZCSAN0JY1z7vPylaPEU_NZUfy72Qt7kbjxCjHrkk39WD39iSRh_hKLgu7ki9tsmx423uR7pu1pn8sGjc7296sfd0hRVY1pv_lTX4=w640-h502&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiRAM1DlftjLwJbKN4W0TPFZxG-8OP8dxKXcRvycurSkU-L2LltM4FroOggTMPV9Z93fggKow5segl0qOftXlKIG29VNQF47Fex6evjTmfC0BopkbuVWtiYVpSugF90GN6DAESS6tb60frx6z_rciwS_3K0K-8z0T6VjjqpxSS4w6gi4o5PYFu93l582Mo&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;776&quot; data-original-width=&quot;1404&quot; height=&quot;354&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiRAM1DlftjLwJbKN4W0TPFZxG-8OP8dxKXcRvycurSkU-L2LltM4FroOggTMPV9Z93fggKow5segl0qOftXlKIG29VNQF47Fex6evjTmfC0BopkbuVWtiYVpSugF90GN6DAESS6tb60frx6z_rciwS_3K0K-8z0T6VjjqpxSS4w6gi4o5PYFu93l582Mo=w640-h354&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 class=&quot;text-text-100 mt-2 -mb-1 text-base font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;6. Connect the USB Cable&lt;/span&gt;&lt;/h3&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Plug the USB end into your laptop, Mini-B end into the Arduino Nano. Both the Arduino Nano and the L298N should light up.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Full Wiring Diagram&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgisRskVSrM35LaK_bJUyQVcPE-UPHIc96ivRC9nKmd2caa3i5wlu2kzukHf9KKmJ349DbGgLDI_d4jtXf6_UNkESHnA3IKg-GZzeQtpPrF8UZvp6hP3OAX7hZxSXV4mwwjTPR0G2hqX9RKK_lf8NwJXQrv_ZiDT9Ao_f4BJpdEQqDShXmlwFpy5fUd308&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;1104&quot; data-original-width=&quot;2221&quot; height=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgisRskVSrM35LaK_bJUyQVcPE-UPHIc96ivRC9nKmd2caa3i5wlu2kzukHf9KKmJ349DbGgLDI_d4jtXf6_UNkESHnA3IKg-GZzeQtpPrF8UZvp6hP3OAX7hZxSXV4mwwjTPR0G2hqX9RKK_lf8NwJXQrv_ZiDT9Ao_f4BJpdEQqDShXmlwFpy5fUd308=w640-h318&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Run It&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open PyCharm and run &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;motor.py&lt;/code&gt;. Press the arrow keys — and watch your motors move.&lt;/span&gt;&lt;/p&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Congratulations. You just took another solid step toward building your own Bumblebee. Or Optimus Prime. We don&#39;t judge.&lt;/span&gt;&lt;/p&gt;
&lt;hr class=&quot;border-border-200 border-t-0.5 my-3 mx-1.5&quot; /&gt;
&lt;h2 class=&quot;text-text-100 mt-3 -mb-1 text-[1.125rem] font-bold&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Troubleshooting: Things That Will Go Wrong (And How to Fix Them)&lt;/span&gt;&lt;/h2&gt;
&lt;p class=&quot;font-claude-response-body break-words whitespace-normal leading-[1.7]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Real talk — here&#39;s every problem we ran into during this build, so you don&#39;t have to suffer through them alone:&lt;/span&gt;&lt;/p&gt;
&lt;div class=&quot;overflow-x-auto w-full px-2 mb-6&quot;&gt;&lt;table class=&quot;min-w-full border-collapse text-sm leading-[1.7] whitespace-normal&quot;&gt;&lt;thead class=&quot;text-left&quot;&gt;&lt;tr&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Problem&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Cause&lt;/span&gt;&lt;/th&gt;&lt;th class=&quot;text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold&quot; scope=&quot;col&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Fix&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;No response when pressing arrow keys&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Wrong COM port in Python code&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Check Arduino IDE → Tools → Port and update &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;motor.py&lt;/code&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&quot;Access is denied&quot;&lt;/code&gt; error&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Arduino IDE is holding the COM port&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Close Arduino IDE completely before running Python&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;keyboard&lt;/code&gt; library not working&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Needs admin privileges&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Right-click PyCharm → Run as Administrator&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&quot;No module named serial&quot;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Wrong Python environment&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Use PyCharm&#39;s built-in Terminal → &lt;code class=&quot;bg-text-200/5 border border-0.5 border-border-300 text-danger-000 whitespace-pre-wrap rounded-[0.4rem] px-1 py-px text-[0.9rem]&quot;&gt;pip install pyserial&lt;/code&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Motors don&#39;t move, no errors&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;ENA/ENB jumpers missing&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Plug jumper caps onto ENA and ENB pins on the L298N&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Motors still don&#39;t move&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Battery connected to 5V instead of 12V&lt;/span&gt;&lt;/td&gt;&lt;td class=&quot;border-b-0.5 border-border-300/30 py-2 pr-4 align-top&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Move the red wire to the &lt;strong&gt;12V&lt;/strong&gt; terminal on the L298N&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-3a-giving-our-robot-brain-and.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFCvdEEsFq8mH-f6JkEH3xTJ667PwS4GH0y9knITDnWdUA5T4fVpZayCD1LSDMp_Bk1BYj6FOxuyEoH_Ylks24QnfUlaCAs9IbJcz4lydLeLbCwijT2qgR1IpW71rmhjtDQBM-C4JR4erZb-vNtbpto1wKFc4NkSx3cPLI6WhklQkSLy0dYqLsJlgqGcI/s72-w480-h640-c/20260515_102200.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-409795682583769141</guid><pubDate>Fri, 15 May 2026 03:23:56 +0000</pubDate><atom:updated>2026-05-30T04:58:37.350-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Smartphone as IMU Sensor for Robotics — Part 2: Your Pocket Knows Which Way Is Up</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In Part 1, we &quot;programmed&quot; our robot&#39;s sensor to recognize what&#39;s a person, what&#39;s a chair, what&#39;s a phone...&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now let&#39;s go one step further. What if we want our robot to know how it&#39;s moving? Is it tilting left, or right? Standing still or spinning? This is where the concept of an IMU sensor (Inertial Measurement Unit) comes in.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Before you go out and buy an actual IMU sensor — guess what&#39;s already sitting in your pocket?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Your Android phone.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A modern Android phone works like a professional IMU sensor right out of the box. It already has built-in hardware: an &lt;b&gt;accelerometer&lt;/b&gt;, a &lt;b&gt;gyroscope&lt;/b&gt;, and a &lt;b&gt;magnetometer&lt;/b&gt;. Data from these sensors can be streamed directly to your computer or laptop (and later, to microcontrollers like Raspberry Pi when we start building things that actually do something useful in the real world).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now, technically, you could write your own Android app to do this. But someone already did the hard work for us. There are dedicated apps that read phone sensors and broadcast the data over Wi-Fi or Bluetooth. We&#39;ll use one called HyperIMU.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;&quot;Grand&quot; Project #2: Using an Android Phone as an IMU Sensor&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Think of HyperIMU as a secret agent — a &lt;b&gt;007 on your phone&lt;/b&gt;, reporting every movement back to HQ (your computer or laptop) in real time.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;Download &amp;amp; Install HyperIMU&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Get &lt;b&gt;HyperIMU&lt;/b&gt; from the Google Play Store.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg5VT8yk_78lRdY-5n5rMCig50u7Vie9Y9TaetHtqiMetBneecyAl1qtq3X1VLZR6fZupkAaST4Lz1z0ri-UCcp88V6KBr0H9kNFist28Ad-EYog3yDZljblUoW_9Wd9G9pc_P83lGg4O5AqLMUHe8r9vIyZmNlzZM1gJYAZZZQIhst-zjrsLzzYCC3c0A&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;939&quot; data-original-width=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg5VT8yk_78lRdY-5n5rMCig50u7Vie9Y9TaetHtqiMetBneecyAl1qtq3X1VLZR6fZupkAaST4Lz1z0ri-UCcp88V6KBr0H9kNFist28Ad-EYog3yDZljblUoW_9Wd9G9pc_P83lGg4O5AqLMUHe8r9vIyZmNlzZM1gJYAZZZQIhst-zjrsLzzYCC3c0A=s16000&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Step 1: Connect Both Devices to the Same Wi-Fi — Then Find Your PC&#39;s IP Address&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Make sure your phone and your computer are on the &lt;b&gt;same Wi-Fi network&lt;/b&gt;. Then grab your PC&#39;s IP address:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Windows&lt;/b&gt;: Open Command Prompt → type &lt;span style=&quot;color: red;&quot;&gt;ipconfig &lt;/span&gt;→ press Enter → look for &lt;b&gt;IPv4 Address&lt;/b&gt; (e.g. &lt;span style=&quot;color: red;&quot;&gt;192.168.1.10&lt;/span&gt;)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Mac/Linux&lt;/b&gt;: Open Terminal → type &lt;span style=&quot;color: red;&quot;&gt;ifconfig &lt;/span&gt;→ press Enter → same idea&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Write that IP address down. You&#39;ll need it in the next step.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhHbKMS6mH6RoqKWZEqRgA8ON870MCJo-dKpj1QFKCRzAKA14G1lW7nsL3oLnrd9yhQuRO49Jd6QxeUtdWW_oy-OwqedFz3lOYDy6WHZ5YWw1ZlEojXh_T3CkvFjliB5yRyN4JkojbDpMpFenFG07xv4Ugajp6_VuMs-ZtUmE0_XKUKsX0mZE6HETCDJEM&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;586&quot; data-original-width=&quot;700&quot; height=&quot;335&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhHbKMS6mH6RoqKWZEqRgA8ON870MCJo-dKpj1QFKCRzAKA14G1lW7nsL3oLnrd9yhQuRO49Jd6QxeUtdWW_oy-OwqedFz3lOYDy6WHZ5YWw1ZlEojXh_T3CkvFjliB5yRyN4JkojbDpMpFenFG07xv4Ugajp6_VuMs-ZtUmE0_XKUKsX0mZE6HETCDJEM=w400-h335&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Step 2: Set Up HyperIMU on Your Phone&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Open the HyperIMU app. Go to &lt;b&gt;Settings &lt;/b&gt;and configure the following:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Protocol&lt;/b&gt;: Choose &lt;b&gt;UDP &lt;/b&gt;— it&#39;s recommended for real-time sensor streaming&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Server IP&lt;/b&gt; &lt;b&gt;/ Target IP&lt;/b&gt;: Enter your PC&#39;s IP address from Step 1&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Port&lt;/b&gt;: Set the same port on both devices (e.g. &lt;span style=&quot;color: red;&quot;&gt;5000 &lt;/span&gt;or &lt;span style=&quot;color: red;&quot;&gt;5555&lt;/span&gt;)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Sensors&lt;/b&gt;: Select &lt;b&gt;Accelerometer&lt;/b&gt; and &lt;b&gt;Gyroscope&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi22esXU5oFdfgwFwKwXeT3jtEz2JPD_kvMm0MSyJu1Ht8V-rjfCo2wSqd_S4TMNFezbYGTE4ZnBsxk_MHjl7Go5nJM6GJ66Oer12ME7R4LKUsxvoogCaAC6qfcaHIz-vMc_rC6ddTdfjMP9d1s3okS0DGMpopG2k-w5FJzUfocJDwXm7AkNEGiVbZr-tU&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img data-original-height=&quot;925&quot; data-original-width=&quot;478&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi22esXU5oFdfgwFwKwXeT3jtEz2JPD_kvMm0MSyJu1Ht8V-rjfCo2wSqd_S4TMNFezbYGTE4ZnBsxk_MHjl7Go5nJM6GJ66Oer12ME7R4LKUsxvoogCaAC6qfcaHIz-vMc_rC6ddTdfjMP9d1s3okS0DGMpopG2k-w5FJzUfocJDwXm7AkNEGiVbZr-tU=s16000&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Step 3: Write the Receiver Code on Your PC&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Depending on what you want to do with the data, there are a couple of approaches:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Python&lt;/b&gt;: Use the &lt;span style=&quot;color: red;&quot;&gt;socket &lt;/span&gt;library to write a simple receiver — basically a &quot;phone answering machine&quot; that picks up the call from your Android phone and processes the incoming data in real time.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Processing software&lt;/b&gt;: For visualization (like simulating your phone as a 3D airplane spinning in space), you can download Processing, install the UDP library, and run a sample sketch.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;ll skip the Processing option for now (even though it&#39;s genuinely cool) and focus on building a &lt;b&gt;Python receiver&lt;/b&gt; on your computer — something that listens for the &quot;turning, tilting, spinning&quot; signals coming from your Android phone.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In plain terms: once this is set up, if you hold your phone like an airplane and pretend to fly it around — left, right, up, down — the receiver on your computer will print out exactly what&#39;s happening. That&#39;s it for now. No processing, no action. Just listening.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new project and a new Python file (same as how you made &lt;span style=&quot;color: red;&quot;&gt;Hello &lt;/span&gt;or &lt;span style=&quot;color: red;&quot;&gt;detect &lt;/span&gt;in Part 1). Name it something like &lt;span style=&quot;color: red;&quot;&gt;receiver.py&lt;/span&gt;. Paste the code below — and remember to update the IP and Port to match your setup.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;import &lt;/span&gt;socket&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;# Configure IP and Port (must match HyperIMU app)&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;UDP_IP = &quot;&lt;span style=&quot;color: #38761d;&quot;&gt;0.0.0.0&lt;/span&gt;&quot; # Listen on all interfaces&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;UDP_PORT = &lt;span style=&quot;color: #38761d;&quot;&gt;5000&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;sock.bind((UDP_IP, UDP_PORT))&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span style=&quot;color: #38761d;&quot;&gt;Listening for HyperIMU data..&lt;/span&gt;.&quot;)&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;while &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;True&lt;/span&gt;:&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; data, addr = sock.recvfrom(&lt;span style=&quot;color: #38761d;&quot;&gt;1024&lt;/span&gt;) # Buffer size 1024&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff00fe;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;color: #38761d;&quot;&gt;f&quot;Received&lt;/span&gt;: {data.decode(&#39;&lt;span style=&quot;color: #38761d;&quot;&gt;utf-8&lt;/span&gt;&#39;)}&quot;)&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;b&gt;Run&lt;/b&gt;. You should see something like the screenshot below. To stop, click the red &lt;b&gt;STOP &lt;/b&gt;button in PyCharm.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE7_-HrjerfohFa0TQ1XNHj-Q3YXLFVX-H3uZz7xDBmbSGYRLH0I7f91fSyGxBgwMk_i8Nevlrt1wZHr9ls5b_eAOzX32By1XdXNaa02HulFza5XsXuIVI1R1PLUi2uHIEWhIgX14FaJBxKMh8ZoWDqAviuYqk1d-rTW586zb8lyNCRlw7mJq9svEeB3o/s1600/H2.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;900&quot; data-original-width=&quot;1600&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE7_-HrjerfohFa0TQ1XNHj-Q3YXLFVX-H3uZz7xDBmbSGYRLH0I7f91fSyGxBgwMk_i8Nevlrt1wZHr9ls5b_eAOzX32By1XdXNaa02HulFza5XsXuIVI1R1PLUi2uHIEWhIgX14FaJBxKMh8ZoWDqAviuYqk1d-rTW586zb8lyNCRlw7mJq9svEeB3o/w400-h225/H2.png&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;So... does this project do anything impressive? Honestly? Not really. It just prints numbers on a screen.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;But here&#39;s what actually matters: now you understand something real.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you use an IMU sensor correctly, your robot will know when it&#39;s tilting, when it&#39;s spinning, when it&#39;s level. That&#39;s the foundation of drones and self-driving cars. The fancy stuff isn&#39;t magic — it&#39;s just this, done properly.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;What We Have So Far&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Congratulations&lt;/b&gt; — you&#39;ve just completed Robot Project #2, still using nothing but stuff you already owned.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Let&#39;s take stock of what our &quot;homegrown&quot; setup can now do:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Part 1:&lt;/b&gt; The robot sees the world — it knows if there&#39;s a person, a phone, or a chair in front of it.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Part 2: &lt;/b&gt;The robot feels its own movement — it knows if it&#39;s tilting left, spinning right, or flying through the air (in your imagination, at least).&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;With the right sensors and the right code, a robot can know where it is, what&#39;s in front of it, and how it&#39;s moving.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The world of Robotics is looking for a lot less mysterious now, isn&#39;t it?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;re getting somewhere.&lt;/span&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-2-your-phone-is-already-robot.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEg5VT8yk_78lRdY-5n5rMCig50u7Vie9Y9TaetHtqiMetBneecyAl1qtq3X1VLZR6fZupkAaST4Lz1z0ri-UCcp88V6KBr0H9kNFist28Ad-EYog3yDZljblUoW_9Wd9G9pc_P83lGg4O5AqLMUHe8r9vIyZmNlzZM1gJYAZZZQIhst-zjrsLzzYCC3c0A=s72-c" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8566775542304208489.post-4552792534830641096</guid><pubDate>Wed, 13 May 2026 23:50:30 +0000</pubDate><atom:updated>2026-05-30T04:57:59.832-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Simple Mode</category><title>Object Detection with YOLOv8 and Webcam — Part 1: Teaching a Sensor to See</title><description>&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;This is Part 1 — the one that decides whether your future in the hottest fields on the planet (AI and Robotics) is going to be fun or miserable. So we&#39;re going to do a quick scenic ride first: no pressure, no deep dives, just a bird&#39;s-eye view.&lt;/span&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now, if you were perfectly happy imagining robots as human-shaped things that walk around, say a few lines, and do stuff &quot;easily&quot; — welcome to the club. Then you Googled &quot;What is a Robot?&quot; and suddenly felt like you were reading a legal document written in alien.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Here&#39;s what Wikipedia says (academic edition):&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&quot;A robot must have some (not necessarily all) of the following characteristics:&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Not naturally occurring — it is created by humans.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Capable of sensing its environment.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Capable of interacting with objects in its environment.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Has some intelligence — can make decisions based on its environment and is controlled automatically according to pre-programmed sequences.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Can be controlled by commands to change its behavior based on user requirements.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Can move rotationally or translationally in one or more axes.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;Has dexterity in movement.&quot;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Just reading that is exhausting. No wonder people quit before they even start.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;So let&#39;s define it ourselves — short, sweet, and something a human being can actually accept:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;&lt;b&gt;If something is programmed to do work automatically — that thing is a robot.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Done. Moving on.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Throughout this blog, we&#39;ll explore the world of Robotics together — a world that feels far away but is actually closer than you think and feels close but somehow keeps surprising you. We&#39;ll go from the simplest projects (&quot;anyone can do this&quot;) all the way to the kind of stuff that sounds like science fiction — but is very, very real.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;&lt;b&gt;The First &quot;Grand&quot; Project&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;As we defined it: robots must be &lt;b&gt;programmed&lt;/b&gt;. But we don&#39;t want to scare you off in the first five minutes, so here&#39;s the deal:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Easy stuff first. No programming required. Just roll up your sleeves and build.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then, slowly, we&#39;ll start writing actual code together. Before you know it, you&#39;ll be the person at the party who casually mentions they build robots.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A typical robot has: a &lt;b&gt;motor&lt;/b&gt;, a &lt;b&gt;power supply&lt;/b&gt;, a &lt;b&gt;microcontroller &lt;/b&gt;(the &quot;brain&quot; — a compact chip with a processor, memory, and I/O peripherals all in one), and &lt;b&gt;sensors&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In this first part, we&#39;re going to play with sensors. And the good news? You don&#39;t need to buy anything. &lt;b&gt;The webcam on your laptop counts as a sensor.&lt;/b&gt; We&#39;ll use it to build a simple object detection system.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Python: The Language of Choice&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;To program robots, people use programming languages. And among all the options out there, Python is the fan favorite. We&#39;ll be using Python for most of what we do here.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;What We&#39;re Actually Building&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;By the end of this project, when you stand in front of your webcam — it will know there&#39;s a human there. Hold up your phone — it&#39;ll know it&#39;s a phone.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Not bad for a first project, right?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Quick Concepts (Optional but Recommended)&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We want you to actually understand what we&#39;re doing — because that&#39;s what makes this fun, not just copy-paste.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Programming = teaching and giving orders to a computer.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;The problem? Computers are machines. They don&#39;t understand English, French, or Vietnamese. They only understand machine language — basically an endless stream of 1s and 0s. Writing millions of 1s and 0s by hand would be insane, so humans invented programming languages.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Like spoken languages, each programming language has its own grammar and syntax. We write instructions in a language, then a tool translates it into machine code that the computer actually understands.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Think of it like traveling abroad. When you visit Japan, you need a Japanese interpreter. When you go to China, you need a Chinese one. When you code in Python, you need a &quot;Python interpreter.&quot; When you code in C, you need a &quot;C interpreter.&quot;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now, when you&#39;re writing code, it helps to have something that:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Suggests syntax and commands&lt;/b&gt; (like your phone&#39;s autocomplete — you type &quot;To&quot; and it suggests &quot;Tomorrow&quot;, &quot;Tonight&quot;, &quot;Today&quot;...)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Catches mistakes&lt;/b&gt; (like someone telling you &quot;Hey, it&#39;s Good morning, not Bad morning&quot;)&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Combine the interpreter + syntax hints + error checking and you get an &lt;b&gt;IDE &lt;/b&gt;(Integrated Development Environment).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Popular Python IDEs include PyCharm, Jupyter Notebook, Atom, IDLE, Visual Studio Code... You&#39;ll find plenty of articles debating which one is &quot;the best.&quot; Don&#39;t stress about it. You&#39;ll figure out what works for you.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;We&#39;ll use PyCharm. It has two versions (PyCharm is now one unified product!&lt;/span&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;) — we&#39;ll use the free one: &lt;/span&gt;&lt;b style=&quot;font-family: verdana; font-size: large;&quot;&gt;PyCharm Community Edition&lt;/b&gt;&lt;span style=&quot;font-family: verdana; font-size: large;&quot;&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: x-large;&quot;&gt;&lt;b&gt;Setting Up PyCharm&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/217d5ea0-623d-40b1-9b31-027b904a5f15/dccudp7-3a29ffd5-4e85-4123-88cc-4e948bedd7c1.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiIvZi8yMTdkNWVhMC02MjNkLTQwYjEtOWIzMS0wMjdiOTA0YTVmMTUvZGNjdWRwNy0zYTI5ZmZkNS00ZTg1LTQxMjMtODhjYy00ZTk0OGJlZGQ3YzEucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.EERGgMetPMUibnLaBkC2HpyCUz6DkiCqAmAthwGOMU0&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;512&quot; data-original-width=&quot;512&quot; height=&quot;512&quot; src=&quot;https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/217d5ea0-623d-40b1-9b31-027b904a5f15/dccudp7-3a29ffd5-4e85-4123-88cc-4e948bedd7c1.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiIvZi8yMTdkNWVhMC02MjNkLTQwYjEtOWIzMS0wMjdiOTA0YTVmMTUvZGNjdWRwNy0zYTI5ZmZkNS00ZTg1LTQxMjMtODhjYy00ZTk0OGJlZGQ3YzEucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.EERGgMetPMUibnLaBkC2HpyCUz6DkiCqAmAthwGOMU0&quot; width=&quot;512&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Download PyCharm from the link below:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;a href=&quot;https://www.jetbrains.com/pycharm/download/?section=windows&quot;&gt;PyCharm&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Once downloaded, click the .&lt;span style=&quot;color: red;&quot;&gt;exe&lt;/span&gt; file to install.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiut1tjYPGPg82urKjFBSvT3CD5cEaRESH7rqo9rGjQfgnbIbXRr0x-knKJc7yE1cefpqHaOCd8QMlBfBDgJ76ABoCtaYVqmF46sxx07q52oJpLpdL_p8mcYRMR6574SAffAujWOm_JEmm57hr2xdS0S-n0Yo30TyjWIrmUghzZOQcPaMYQsbVIxKHThnS8/s400/LTC265.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;309&quot; data-original-width=&quot;400&quot; height=&quot;309&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiut1tjYPGPg82urKjFBSvT3CD5cEaRESH7rqo9rGjQfgnbIbXRr0x-knKJc7yE1cefpqHaOCd8QMlBfBDgJ76ABoCtaYVqmF46sxx07q52oJpLpdL_p8mcYRMR6574SAffAujWOm_JEmm57hr2xdS0S-n0Yo30TyjWIrmUghzZOQcPaMYQsbVIxKHThnS8/w400-h309/LTC265.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Click &lt;b&gt;Next &lt;/b&gt;to continue.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOFQGXMExJnWUM3X8dDNo4K0XGK4a-zZREnS_UfOxfiICLEXix_BunR2jU_7hfIy7my5d-9Ia1EwXiylSzYWG1BapJtkO_QMtAtiMXFmed7LpCPTKHK1I0bN_4X0iLW_ggfxmBfZyBOfLgCJ4Jcq_9WE02FZPU5BF9ZaMDsMenqIhAs1_QhaxyWdPCOjXR/s400/LTC266.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;313&quot; data-original-width=&quot;400&quot; height=&quot;313&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOFQGXMExJnWUM3X8dDNo4K0XGK4a-zZREnS_UfOxfiICLEXix_BunR2jU_7hfIy7my5d-9Ia1EwXiylSzYWG1BapJtkO_QMtAtiMXFmed7LpCPTKHK1I0bN_4X0iLW_ggfxmBfZyBOfLgCJ4Jcq_9WE02FZPU5BF9ZaMDsMenqIhAs1_QhaxyWdPCOjXR/w400-h313/LTC266.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Choose an install folder or keep the default, then click &lt;b&gt;Next&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0ZjOHTyXCYPEC76ek0FpNYhdgBw_WOAJyusbYrXhUDV81vdgWmYp-FFSvpYo5Vm-FrNrt5A4IbDvpZMmq0-zRv9DRTTCD61Qqi0yQbOSB74tay2gCL1MGKL87nZzsOp_godLyjg-Kd0VVOS638ZbrxsIhPq9WX_HRWosO5ZDah7FsCYhiRKvzY5yyLSmw/s400/LTC267.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;312&quot; data-original-width=&quot;400&quot; height=&quot;313&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0ZjOHTyXCYPEC76ek0FpNYhdgBw_WOAJyusbYrXhUDV81vdgWmYp-FFSvpYo5Vm-FrNrt5A4IbDvpZMmq0-zRv9DRTTCD61Qqi0yQbOSB74tay2gCL1MGKL87nZzsOp_godLyjg-Kd0VVOS638ZbrxsIhPq9WX_HRWosO5ZDah7FsCYhiRKvzY5yyLSmw/w400-h313/LTC267.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Select &lt;b&gt;JetBrains &lt;/b&gt;and click &lt;b&gt;Install&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitZ6roc7ruTWr3k-DuT1JI89di4dPy7R2yl90MZajuXO3f025jDcfTYR93SdCyVhCiFak4yTbQGvM8VjBMvzgX6wbKx-Q0xKE9zdghv368TH-z9P4amAKZFQI9HOO1oMVOpCjxNFuLDkFSOckasePqE_pxtHFU6FrkOvh2S2pF0PGbYaa8clkN6zA4Mi2i/s400/LTC268.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;318&quot; data-original-width=&quot;400&quot; height=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitZ6roc7ruTWr3k-DuT1JI89di4dPy7R2yl90MZajuXO3f025jDcfTYR93SdCyVhCiFak4yTbQGvM8VjBMvzgX6wbKx-Q0xKE9zdghv368TH-z9P4amAKZFQI9HOO1oMVOpCjxNFuLDkFSOckasePqE_pxtHFU6FrkOvh2S2pF0PGbYaa8clkN6zA4Mi2i/w400-h318/LTC268.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Click Finish to complete the installation and launch PyCharm.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYEoAwjmaQngmCsnt2hBM6El-uZupmx1lbgi43YdAzl0kpJX82YOMz2NV0mzYnFyBitDrNFTVyfRjq6PBoiav5sWlyQqRr6PHz6RnKw4pFPoFMEKnrIH6M5KJuvn26zX0WPpJZQ_7OuxstAFWVoCr8HnL040gmXUULNBTyHG5ukBzNqZFXRvgM6ZL1Wtnn/s400/LTC269.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;256&quot; data-original-width=&quot;400&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYEoAwjmaQngmCsnt2hBM6El-uZupmx1lbgi43YdAzl0kpJX82YOMz2NV0mzYnFyBitDrNFTVyfRjq6PBoiav5sWlyQqRr6PHz6RnKw4pFPoFMEKnrIH6M5KJuvn26zX0WPpJZQ_7OuxstAFWVoCr8HnL040gmXUULNBTyHG5ukBzNqZFXRvgM6ZL1Wtnn/w400-h256/LTC269.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Click &quot;&lt;b&gt;I confirm...&lt;/b&gt;&quot; then hit &lt;b&gt;Continue&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnugzSGHd6460vMhLShsl8rOSxbxmNjaW7GyaipDpUa_UOxfHpYzadtaeXbm95AARTNGD08PlPzLMWZAdGeuaSecpvHcbawARrYEcQebVfyaq_QBR3wa63D-6jy6d6FLdJICgDxy93ukE94dw3fgvJgR7PGEbI7fT0LhUbCi2orf2F2wen8-PkvAgP2BkQ/s400/LTC270.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;305&quot; data-original-width=&quot;400&quot; height=&quot;305&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnugzSGHd6460vMhLShsl8rOSxbxmNjaW7GyaipDpUa_UOxfHpYzadtaeXbm95AARTNGD08PlPzLMWZAdGeuaSecpvHcbawARrYEcQebVfyaq_QBR3wa63D-6jy6d6FLdJICgDxy93ukE94dw3fgvJgR7PGEbI7fT0LhUbCi2orf2F2wen8-PkvAgP2BkQ/w400-h305/LTC270.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Select &lt;b&gt;Don&#39;t send&lt;/b&gt;. You&#39;re ready to use PyCharm.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1U_BXpb8kY6gs8U3PhQrpPJckX5EIAyAlPnKJFflPt5m-AqjpNU87ppVqWJyEP7ijeCdtlowZsfrsV-r0SfpYBGF70T76EgWUz3HYwIgKH0ku4aKmBSmYUnKAO-RPmg1O_ipXIdp01k803UUMh3ZdoUgSlLyhiRYrlpuW4ahTSHg3BJEV571cjoCVmmT7/s400/LTC271.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;326&quot; data-original-width=&quot;400&quot; height=&quot;326&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1U_BXpb8kY6gs8U3PhQrpPJckX5EIAyAlPnKJFflPt5m-AqjpNU87ppVqWJyEP7ijeCdtlowZsfrsV-r0SfpYBGF70T76EgWUz3HYwIgKH0ku4aKmBSmYUnKAO-RPmg1O_ipXIdp01k803UUMh3ZdoUgSlLyhiRYrlpuW4ahTSHg3BJEV571cjoCVmmT7/w400-h326/LTC271.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;When creating a new project, you&#39;ll need to specify a Python &lt;b&gt;Interpreter &lt;/b&gt;— this is what actually runs your Python code. You need at least one Python installation on your machine.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Click &lt;b&gt;New Project&lt;/b&gt;, choose a folder (or keep the default), then click &lt;b&gt;Create&lt;/b&gt;. If Python isn&#39;t installed yet, PyCharm will automatically install the latest version for you.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtMMxVlIWX9goeFaIjX3LsisasYBx5dmidUWyxqjS7wiAu9Kl6cKpTzdGVpKBYvv6VMN9czQ-xvas0XwEBHHxCQkH8QvBUzO9Vd767-G917ZJoAV9s_yEFyk6V06DaDVBYJhNwLLCa1Cc2zPlkr4AU363lM2ggLwOb2NzUQxVQSKEKrcO88ILWuXyoCCaf/s400/LTC273.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;241&quot; data-original-width=&quot;400&quot; height=&quot;241&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtMMxVlIWX9goeFaIjX3LsisasYBx5dmidUWyxqjS7wiAu9Kl6cKpTzdGVpKBYvv6VMN9czQ-xvas0XwEBHHxCQkH8QvBUzO9Vd767-G917ZJoAV9s_yEFyk6V06DaDVBYJhNwLLCa1Cc2zPlkr4AU363lM2ggLwOb2NzUQxVQSKEKrcO88ILWuXyoCCaf/w400-h241/LTC273.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;PyCharm creates an isolated virtual environment for each new project. The default is called &lt;b&gt;Project venv&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju8la1j7zrQsEfJt1YHEu7qh-KFNFuDsmkbNPI0Bwx7SaLjNEiYf4TX3gageWaLFn4IFQAIWG5lWpyhQ-0eRU3RmT1gSJ_nETCKIyXzjm4RgYGfzOPt1YGGeS9SMgwtqut0AqwvMCuPGGhBZfVXxuD38cCl_s76PsV6sbd0m2N1Ll4jlhOOVv2kgQwNAAq/s399/LTC283.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;326&quot; data-original-width=&quot;399&quot; height=&quot;326&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju8la1j7zrQsEfJt1YHEu7qh-KFNFuDsmkbNPI0Bwx7SaLjNEiYf4TX3gageWaLFn4IFQAIWG5lWpyhQ-0eRU3RmT1gSJ_nETCKIyXzjm4RgYGfzOPt1YGGeS9SMgwtqut0AqwvMCuPGGhBZfVXxuD38cCl_s76PsV6sbd0m2N1Ll4jlhOOVv2kgQwNAAq/w400-h326/LTC283.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Right-click on the &lt;b&gt;Project root&lt;/b&gt; on the left panel. Select &lt;b&gt;New → Python File&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy9epC7wKRjAoWQVYn6_JVfj0RPb_5S5M11tmOeeqjZAZ6-g-eMsLf_iquxCVAhDQuLSsyMWwy5DTCVsI5GfayC5JkqJCamSLYITvdFGP_UXtDS9sRIVM7hPoTF9UzbFgirDzJwI1ngErbNVVoTPwPPDfT-rjrHaDy52I2eTZVfAX_akvZvVSXE0FTUJ6H/s400/LTC274.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;310&quot; data-original-width=&quot;400&quot; height=&quot;310&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy9epC7wKRjAoWQVYn6_JVfj0RPb_5S5M11tmOeeqjZAZ6-g-eMsLf_iquxCVAhDQuLSsyMWwy5DTCVsI5GfayC5JkqJCamSLYITvdFGP_UXtDS9sRIVM7hPoTF9UzbFgirDzJwI1ngErbNVVoTPwPPDfT-rjrHaDy52I2eTZVfAX_akvZvVSXE0FTUJ6H/w400-h310/LTC274.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Name the file — let&#39;s call it Hello.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRbgIaZWY4Iju2ku_o2cOBclXoGXT7RUQXAwl1knfExllkZQYghwzLhUIo6dxvjto3keYWGPvQP6Zmq20aO2uCofJ77m7jdEWSBfOfv43jvHcvWwyCNAD8hEC4Ixuwe15lu55dTgl_7G6l2uWN5bDpNnt1JV_FuNrXDHKwzX-IOByArkD5SCfdNlDjHUBQ/s399/LTC275.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;297&quot; data-original-width=&quot;399&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRbgIaZWY4Iju2ku_o2cOBclXoGXT7RUQXAwl1knfExllkZQYghwzLhUIo6dxvjto3keYWGPvQP6Zmq20aO2uCofJ77m7jdEWSBfOfv43jvHcvWwyCNAD8hEC4Ixuwe15lu55dTgl_7G6l2uWN5bDpNnt1JV_FuNrXDHKwzX-IOByArkD5SCfdNlDjHUBQ/w400-h297/LTC275.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;A blank editor window will appear. Now we&#39;re ready to write our first line of Python code.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Enter this &quot;extremely complex&quot; line:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;print&lt;/span&gt;(&#39;&lt;span style=&quot;color: #38761d;&quot;&gt;Hello World&lt;/span&gt;&lt;span style=&quot;color: #04ff00;&quot;&gt;&#39;&lt;/span&gt;)&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGcRMvtzlFjaSbrhBHUbmKLkRvlzCDF1R-8HBeLzTj4nd3LV8ULn4QoYAHlhsv4FRqecSXwgA6OI3Z6XPhc0olKkUFHJ_z-JnW6vGojSZo-ogjt86zUN_Th46Z9zcMRf6ho9WwISotA9s8tCFWQLapCpfqA_WhVj8UgPAewT1XH8FyjrDFtFcX5qxarQgO/s400/LTC277.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;253&quot; data-original-width=&quot;400&quot; height=&quot;253&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGcRMvtzlFjaSbrhBHUbmKLkRvlzCDF1R-8HBeLzTj4nd3LV8ULn4QoYAHlhsv4FRqecSXwgA6OI3Z6XPhc0olKkUFHJ_z-JnW6vGojSZo-ogjt86zUN_Th46Z9zcMRf6ho9WwISotA9s8tCFWQLapCpfqA_WhVj8UgPAewT1XH8FyjrDFtFcX5qxarQgO/w400-h253/LTC277.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/i&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;If you don&#39;t see the main menu, click the four horizontal lines (☰) in the top-left corner to bring it up.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Then go to &lt;b&gt;Run → Run &#39;Hello.py&#39;&lt;/b&gt; to run the program.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL6GPI0Y8FjVzzFbHMj1sJsYFHaLIJfcVBI4Y7Vvv9auwkJEAQYfIJQ8npQmNk1oP2SJwp8wpS5sDSZ1CUCfxNnJBzTHLYjVde2v7luJrLmgLlL5BqKPcNRY7mXCIpGBm3A8QYsyk870QEypYOt3zxO67es_PjubIIGutUe9AaJMNuJ5U3N5e4LEIeTRcC/s400/LTC279.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;278&quot; data-original-width=&quot;400&quot; height=&quot;278&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL6GPI0Y8FjVzzFbHMj1sJsYFHaLIJfcVBI4Y7Vvv9auwkJEAQYfIJQ8npQmNk1oP2SJwp8wpS5sDSZ1CUCfxNnJBzTHLYjVde2v7luJrLmgLlL5BqKPcNRY7mXCIpGBm3A8QYsyk870QEypYOt3zxO67es_PjubIIGutUe9AaJMNuJ5U3N5e4LEIeTRcC/w400-h278/LTC279.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Congratulations — you&#39;ve just written your first Python program! Fair warning: this program is completely useless. It literally just prints &quot;Hello World.&quot; But that&#39;s the point — we just wanted a quick win before the real stuff.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQpJaLTXvCcKOmevbS1SKklCAwyqxBt_8yp_vnJeLFJlK2AW8BciZlwwTms0sv63kHgcNabaH83cB6ZgjnD9VAq52MOMMnosic68LjC-WCbS_WBFzRM5XVKaAWijhxohjVmv8-3I0_tEHy6hfJnWIc45_o2L9WGA8megG20eHoRFNi98cbM6TxAr8bsnNV/s400/LTC280.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;292&quot; data-original-width=&quot;400&quot; height=&quot;293&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQpJaLTXvCcKOmevbS1SKklCAwyqxBt_8yp_vnJeLFJlK2AW8BciZlwwTms0sv63kHgcNabaH83cB6ZgjnD9VAq52MOMMnosic68LjC-WCbS_WBFzRM5XVKaAWijhxohjVmv8-3I0_tEHy6hfJnWIc45_o2L9WGA8megG20eHoRFNi98cbM6TxAr8bsnNV/w400-h293/LTC280.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;The Main Event: Object Detection with Your Webcam&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Now we have almost all the ingredients. Let&#39;s cook.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;For simple object detection using a laptop webcam and Python, the fastest and most effective method right now is using &lt;b&gt;YOLOv8&lt;/b&gt; (via the &lt;span style=&quot;color: red;&quot;&gt;ultralytics&lt;/span&gt; library — an open-source AI model famous for object detection) combined with &lt;b&gt;OpenCV&lt;/b&gt; (a leading open-source library for image processing, video handling, and computer vision tasks).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;In plain English: you&#39;re using a pre-built AI that already knows how to spot objects, and a Python image-processing library to hook it up to your webcam.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Step 1: Install the Libraries&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Think of libraries like a toolbox — you only grab what you need for the job. Open the &lt;b&gt;Terminal &lt;/b&gt;in PyCharm and type:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;pip install opencv-python ultralytics&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Press &lt;b&gt;Enter &lt;/b&gt;and wait for PyCharm to finish installing.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Step 2: Write the Code&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Create a new project and a new Python file (same as how you made Hello earlier). Name it something like &lt;b&gt;detect.py&lt;/b&gt;. Copy the code below and paste it into detect.py:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;import &lt;/span&gt;cv2&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;from &lt;/span&gt;ultralytics &lt;span style=&quot;color: #ff00fe;&quot;&gt;import &lt;/span&gt;YOLO&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;# 1. Load the YOLOv8n (nano) model — small and fast, suitable for laptops&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;model = YOLO(&#39;&lt;span style=&quot;color: #38761d;&quot;&gt;yolov8n.pt&lt;/span&gt;&#39;)&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;# 2. Open the webcam (usually index 0)&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;cap = cv2.VideoCapture(0)&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;if not&lt;/span&gt; cap.isOpened():&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff00fe;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span style=&quot;color: #38761d;&quot;&gt;Unable to open webcam&lt;/span&gt;&quot;)&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; exit()&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;print&lt;/span&gt;(&quot;&lt;span style=&quot;color: #38761d;&quot;&gt;Running object detection... Press &#39;q&#39; to exit&lt;/span&gt;&quot;)&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: #ff00fe;&quot;&gt;while &lt;/span&gt;True:&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; # Read a single frame from the webcam&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; ret, frame = cap.read()&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff00fe;&quot;&gt;if not&lt;/span&gt; ret:&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff00fe;&quot;&gt;break&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; # 3. Run the YOLO model on the frame&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; results = model(frame)&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; # 4. Display the results on the frame&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; annotated_frame = results[0].plot()&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; # Display the video&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; cv2.imshow(&#39;&lt;span style=&quot;color: #38761d;&quot;&gt;YOLOv8 Real-time Detection&lt;/span&gt;&#39;, annotated_frame)&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; # Press &#39;q&#39; to exit&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff00fe;&quot;&gt;if&lt;/span&gt; cv2.waitKey(1) &amp;amp; 0xFF == ord(&#39;q&#39;):&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff00fe;&quot;&gt;break&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;# Release the webcam and close the window&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;cap.release()&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;cv2.destroyAllWindows()&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Step 3: Run It&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Hit &lt;b&gt;Run&lt;/b&gt;. Watch your webcam come alive.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;To stop, press &#39;q&#39; on your keyboard — or click the red STOP button in PyCharm.&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-SeJKb4gESLIETdq4fQYkix7mNMpxqTvTywpr65Iv_2OtpO2uNEgBtzv-diBt_0x1fFOJHD6wwSUoavCsOjEchRmveJHP_al-XMxx3w2vVWFc5qoYqOE9RyjYzUsfj0b0ROyzxiRYxOtAEp0lS9sB2iAwR4iJF1_dhN-v8ld0vIaligU5Dq7DvGLr4Hk/s1600/H1.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;900&quot; data-original-width=&quot;1600&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-SeJKb4gESLIETdq4fQYkix7mNMpxqTvTywpr65Iv_2OtpO2uNEgBtzv-diBt_0x1fFOJHD6wwSUoavCsOjEchRmveJHP_al-XMxx3w2vVWFc5qoYqOE9RyjYzUsfj0b0ROyzxiRYxOtAEp0lS9sB2iAwR4iJF1_dhN-v8ld0vIaligU5Dq7DvGLr4Hk/w400-h225/H1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;🎉 &lt;/span&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;Congratulations!&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;You just completed &lt;b&gt;your first Robot project&lt;/b&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;No Raspberry Pi. No Arduino. No expensive hardware. Just a laptop, some code, and a webcam that now knows you exist.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;Not bad for Day 1.&lt;/span&gt;&lt;/p&gt;</description><link>https://vn4000.blogspot.com/2026/05/part-1-lets-ride-past-and-see-what-this.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiut1tjYPGPg82urKjFBSvT3CD5cEaRESH7rqo9rGjQfgnbIbXRr0x-knKJc7yE1cefpqHaOCd8QMlBfBDgJ76ABoCtaYVqmF46sxx07q52oJpLpdL_p8mcYRMR6574SAffAujWOm_JEmm57hr2xdS0S-n0Yo30TyjWIrmUghzZOQcPaMYQsbVIxKHThnS8/s72-w400-h309-c/LTC265.png" height="72" width="72"/></item></channel></rss>