<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shivangsh Roy on Medium]]></title>
        <description><![CDATA[Stories by Shivangsh Roy on Medium]]></description>
        <link>https://medium.com/@curiousshivi?source=rss-120236db00ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*It9nuP5hEu3wZhgp</url>
            <title>Stories by Shivangsh Roy on Medium</title>
            <link>https://medium.com/@curiousshivi?source=rss-120236db00ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 00:41:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@curiousshivi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Wi-Fi Connection to Popup Page: Demystifying Captive Portals]]></title>
            <link>https://medium.com/the-curious-circuit/from-wi-fi-connection-to-popup-page-demystifying-captive-portals-89454dae2c32?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/89454dae2c32</guid>
            <category><![CDATA[tcp]]></category>
            <category><![CDATA[captive-portal]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[wifi]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Sun, 15 Nov 2026 00:26:48 GMT</pubDate>
            <atom:updated>2026-11-15T00:27:17.755Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dOhoBRm6JJ8Guo7K4GyVsw.png" /></figure><h4><strong>Introduction:</strong></h4><p>Ever connected to Wi-Fi at an airport or hotel, only to have a webpage pop up asking you to accept the Terms and Conditions before accessing the internet?</p><p>Ever wondered how that works?</p><p>Let’s break down the technology behind captive portals and see how a simple Wi-Fi connection can trigger an entire webpage.</p><p>First let’s start with concepts that are used in Captive Portals.</p><h3><strong>Review of TCP:</strong></h3><p>As written in the <a href="https://medium.com/the-curious-circuit/networking-basics-and-a-quantum-simulation-experiment-4b22b49bb414">previous post</a>, TCP is a protocol that is used to transmit data over network.</p><p><strong>TCP (Transmission Control Protocol)</strong> establishes a connection and ensures data arrives reliably and in the correct order. If data is lost, TCP can retransmit it.</p><p>TCP prioritizes <strong>reliability</strong> rather than <strong>speed</strong>.</p><h3><strong>What is DNS:</strong></h3><p>DNS (Domain Name System) acts as a translator between domain name and its corresponding IP address. This translation process is called DNS resolution.</p><p>Example:</p><p>When you go to your browser, and you search up google.com and press Enter, this is what really happens:</p><ol><li>The browser interprets the URL. The browser classifies ‘google.com’ as a domain name. The browser needs to find the IP address associated with google.com.</li><li>DNS resolution: finding Google’s IP address. Your computer first checks whether it already knows the IP address from its DNS cache. If not, it sends a DNS query to its configured DNS resolver. The DNS resolver may be your router, your ISP’s DNS server, or a public DNS service. The DNS system translates the domain into an IP address.</li><li>HTTP request is sent</li><li>Google’s server responds</li><li>The browser renders the webpage.</li></ol><p><strong>DNS Redirection:</strong></p><p>Another DNS concept is DNS Redirection. This is when the DNS server returns a different IP address than the one corresponding to the requested domain. More about DNS Redirection in the Captive Portal Experiment below. DNS uses port 53 to respond to queries.</p><h3><strong>How TCP and HTTP work Together:</strong></h3><p>TCP is how the data is transported, whereas HTTP(Hypertext Transfer Protocol) defines what data means and what devices are asking for. HTTP uses port 80 by default. Both of them work together to enable reliable communication between a client and a web server.</p><h3><strong>What is a Web Server:</strong></h3><p>A web server is a program that serves webpages to browsers when they request them.</p><h4><strong>Web Server Experiment:</strong></h4><p>In this experiment, I configured the ESP32 to operate in Station (STA) mode, allowing it to connect to an existing Wi-Fi network using the network’s SSID and password.</p><p>Once connected, the router assigns the ESP32 an IP address using DHCP. I then start an asynchronous web server on port 80, which listens for incoming HTTP requests.</p><p>I registered a route for the root path (/) using the HTTP GET method. When a client enters the ESP32&#39;s IP address in a browser, the browser sends a GET request, triggering the corresponding callback function.</p><p>The callback accesses the shared variables containing the latest BME280 sensor readings and sends them back to the client as a plain-text HTTP response.</p><p>This allows any device connected to the same Wi-Fi network to access the ESP32’s temperature, humidity, and pressure readings through a browser.</p><p><a href="https://github.com/Quantum-Shivi/HomeSense/blob/main/webserver.ino"><strong>**Web Server Code</strong></a></p><h3><strong>What is a Captive Portal &amp; How Does it Work?</strong></h3><p>A captive portal is a webpage that automatically opens when you connect to Wi-Fi network. Usually, it asks you to complete an action before using the network.</p><p>In order for a Captive Portal to work, it must have the concepts discussed above.</p><p>For example, when you connect to public Wi-Fi at a hotel, you might be asked to accept terms and conditions or enter a password.</p><p>DNS Redirection plays a huge role in opening a captive portal.</p><p>This is how a captive portal typically opens:</p><ol><li>Client connects to a Wi-Fi access point network.</li></ol><p>2. The client will check whether it has internet access by making a network request.</p><p>3. DNS queries (such as the network request in Step 2) will be redirected so that domain names resolve to the captive portal’s IP address.</p><p>4) The client device will display the portal web page.</p><p>5) The user will complete the task shown on the web page and can now use the network.</p><h4><strong>Captive Portal Experiment:</strong></h4><p>In my Captive Portal Experiment, I started a DNS server (port 53), and a web server at port 80. I also put the ESP32 in access point mode. When the client connects to the network, the client will try to check for internet. To do this, it may try to search a domain. This will cause the client to request the corresponding IP address of the domain. When it does this, the DNS server responds with the ESP32’s IP. This interception causes the captive portal to open.</p><p><a href="https://github.com/Quantum-Shivi/HomeSense/blob/main/HomeSense/captivePortal.ino"><strong>**Captive Portal Code</strong></a></p><h3><strong>Conclusion:</strong></h3><p>A captive portal might look like just a webpage asking you to accept some terms and conditions, but there is quite a bit happening behind the scenes.</p><p>As we explored, DNS resolution helps translate the domain name to its IP address, TCP establishes reliable communication, and HTTP allows the browser and web server to exchange requests and responses. Together, these technologies make the captive portal experience possible.</p><p>Building this experiment using the ESP32 helped me understand how these networking concepts work together in a real-world application. What initially looks like a simple Wi-Fi login page is actually a combination of several networking mechanisms working behind the scenes.</p><p>In my project HomeSense (more details about it on another post), I am using Captive Portal to do something cool. When the user first connects to the HomeSense network which is in access point mode (with its own SSID), a Captive Portal is displayed that asks the user to enter the credentials for their home Wi-Fi network. This information would be stored in flash memory, so the user doesn’t always have to enter their credentials. While I am still using the Captive Portal concept, I am using it for unique application: making initial Wi-Fi configuration of an embedded device much simpler.</p><p><a href="https://github.com/Quantum-Shivi/HomeSense/tree/main/HomeSense">HomeSense Project Link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89454dae2c32" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/from-wi-fi-connection-to-popup-page-demystifying-captive-portals-89454dae2c32">From Wi-Fi Connection to Popup Page: Demystifying Captive Portals</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Networking Basics and a Quantum Simulation Experiment]]></title>
            <link>https://medium.com/the-curious-circuit/networking-basics-and-a-quantum-simulation-experiment-4b22b49bb414?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b22b49bb414</guid>
            <category><![CDATA[quantum-superposition]]></category>
            <category><![CDATA[computer-network]]></category>
            <category><![CDATA[tcp-ip]]></category>
            <category><![CDATA[netcat]]></category>
            <category><![CDATA[quantum-entanglement]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Mon, 12 Oct 2026 21:47:00 GMT</pubDate>
            <atom:updated>2026-10-12T22:47:45.355Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNc7pqjOGY6g2kWDfnWWJA.png" /></figure><p>The goal of this article is to explain networking fundamentals through a practical ESP32 server-client experiment, then apply those communication concepts to build a quantum-inspired simulation exploring measurement, probability, and the Quantum Zeno Effect.</p><h3>IP Address and Port Basics</h3><p>An IP address is a numerical label assigned to a device by the router on a network. It allows devices to identify and communicate with each other.</p><p>A router typically assigns local IP addresses using DHCP(a network managing protocol) when devices join a network. IP addresses can also be configured manually.</p><p>An IP address helps data reach the correct device.</p><p>A port is a logical endpoint that directs network data to the correct application or service on a device. While an IP address identifies the device, the port identifies where the data should go.</p><p>For example, your microcontroller can listen on port 8888, allowing a client to connect using the microcontroller’s IP address and that port number. Once connected, both devices can send and receive data.</p><h3>Servers and Clients: The Basics</h3><p>A <strong>server</strong> is a program that listens for incoming connections on a specific port that it has opened. A <strong>client</strong> is a program that connects to that server using its IP address and port number.</p><p>Once connected, they can exchange data. The server can receive requests and send responses, while the client initiates the connection.</p><p>Servers and clients don’t have to be on the same network. They can communicate over a local network or across different networks.</p><p>Think of a port as a pipe opened by the server. The client connects to it using the server’s IP address and port number. Once connected, the pipe allows two-way communication: both the server and client can send and receive data.</p><h3>TCP vs UDP</h3><p>TCP and UDP are two protocols used to send data over a network.</p><p><strong>TCP (Transmission Control Protocol)</strong> establishes a connection and ensures data arrives reliably and in the correct order. If data is lost, TCP can retransmit it.</p><p><strong>UDP (User Datagram Protocol)</strong> sends data without establishing a connection or guaranteeing delivery or order. This makes it faster and simpler, but packets can be lost.</p><p>In short, <strong>TCP prioritizes reliability, while UDP prioritizes speed.</strong></p><h3>Experiment: Two Way TCP Communication Between Server and Client</h3><p>For this experiment, my main goal was to demonstrate a two way communication between the Server(ESP32) and a Client. I used nc(netcat), which is a command line networking tool that can read and send data over TCP or UDP connections. I used nc as a TCP client to communicate with my ESP32.</p><p><strong>How my project would work:</strong></p><p>The user types a message, such as “Hello,” into nc, which sends it through port 8888 to the ESP32. The server prints the message in the Serial Monitor. The user can also type a message into the Serial Monitor, which the ESP32 sends back through the same port to be displayed in nc.</p><h3>How It Works</h3><h3>1. Connecting to Wi-Fi</h3><p>The ESP32 first connects to the Wi-Fi network using its SSID and password. Once connected, the router assigns it a local IP address, which other devices on the network can use to reach it.</p><h3>2. Starting the TCP Server</h3><p>The ESP32 creates an AsyncServer on port 8888 and starts listening for incoming TCP connections. An AsyncServer allows the server to wait for clients to connect without repeatedly polling for new connections in the main loop.</p><h3>3. Connecting the Client</h3><p>On Ubuntu, the user runs nc with the ESP32&#39;s IP address and port number. Netcat establishes a TCP connection to the server, creating a communication channel between the two endpoints.</p><h3>4. Receiving Messages on the ESP32</h3><p>When a client connects, a callback runs. The ESP32 registers an data callback for that client, which runs whenever data arrives.</p><p>The callback receives the incoming data and its length. The ESP32 prints the received bytes to the Serial Monitor.</p><h3>5. Sending Messages Back</h3><p>When the user types a message into the Serial Monitor, the ESP32 reads it and sends it through the existing TCP connection.</p><p>Netcat receives the bytes and displays the message in the terminal.</p><h3>6. Two-Way Communication</h3><p>Both endpoints use the same TCP connection to send and receive data. TCP provides reliable, ordered delivery of bytes, while AsyncTCP uses callbacks to handle incoming network data without requiring continuous polling.</p><p>This creates a simple two-way messaging system between the Ubuntu terminal and the ESP32.</p><p>Link to code : <a href="https://github.com/Quantum-Shivi/Arduino-Projects/tree/main/server-clienttrial">https://github.com/Quantum-Shivi/Arduino-Projects/tree/main/server-clienttrial</a></p><h3>BONUS: The Quantum Simulation</h3><p>My quantum simulation proves 2 main concepts:</p><p><strong>1: “A Watched Pot Never Boils” The Quantum Zeno Effect</strong></p><p>A phenomenon in quantum mechanics where repeatedly measuring(observing) a quantum system can completely prevent it from changing.</p><p><strong>2: Quantum Probability vs Classical Certainty</strong></p><p>Unlike regular coin-flip probability where things are either heads or tails, quantum probability handles things that exist in multiple possibilities at once.</p><p>My quantum simulation was a game in which there was one server and two clients. I used my ESP32 as the server, serial monitor as client 1, and nc as client 2.</p><p>The server simulated a “infiltrator” trying to creep past a security perimeter. The clients each simulated radar operators that must fire radar pings to reset the infiltrator’s progress back to 0%. Every second, the infiltrator creeped up 2%. Once the infiltrator reached 100%, it was game over.</p><p><strong>The Wave State</strong></p><p>The infiltrator isn’t a solid object. Instead, they exist as a ghost-like probability wave stretched between the start line and their current progress.</p><p>When a user types “ping radar” into the serial monitor or nc, the client alerts the ESP32 server to fire the radar at the start line.</p><p>Let’s look an example:</p><ul><li><strong>The 84% Chance (Radar Wins):</strong> If the infiltrator has crept to 16%, there is an 84% chance the radar confirms they are still at the start. In quantum physics, finding “nothing” down the hallway instantly collapses the wave, erasing the spy’s progress and snapping them back to 0%. This works just like the counter-intuitive math used in quantum physics.</li><li><strong>The 16% Chance (Infiltrator Wins):</strong> This is the probability that the infiltrator wins the digital dice roll. If they win, the quantum wave collapses <em>forward</em>. The spy solidifies at 16%, their progress is not reset, and 16% becomes your new permanent start line.</li></ul><p>Conclusion</p><p>By building this project, we proved two massive physics principles:</p><ol><li><strong>The Quantum Zeno Effect:</strong> If you constantly spam the radar, the infiltrator can never leave the 0% mark. You freeze them in place simply by looking at them.</li><li><strong>Quantum Probability:</strong> Before you check the radar, the infiltrator physically exists at both 0% and 16% at the exact same time.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ge4YoEZV3eLjAgE5JDoMVw.png" /><figcaption>Gameplay(nc is right window, serial monitor is left)</figcaption></figure><p>Link to code : <a href="https://github.com/Quantum-Shivi/Arduino-Projects/tree/main/QuantumInfiltrator">https://github.com/Quantum-Shivi/Arduino-Projects/tree/main/QuantumInfiltrator</a></p><p><strong>Code Issues</strong></p><p>The first time I tested out my code, I ran into an issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*RfiVey1osL3nW_z00ftuaQ.png" /><figcaption>ESP 32 Crash</figcaption></figure><p>Every time the Infiltrator reached 100%, the ESP32 crashed. The issue was simple: I broke the golden rule of interrupts. An Interrupt Service Routine (ISR) must be lightning-fast, but mine was slowed down trying to print to the serial monitor and transmit data over Wi-Fi. It hogged the processor, triggering a watchdog timeout crash. To fix it, I stripped the heavy lifting out of the ISR entirely. Now, the timer simply flips a true/false flag, and my main loop checks for that flag to safely handle the serial prints and network messages.</p><h3>Conclusion</h3><p>Networking allows devices to communicate and exchange data using IP addresses, ports, and protocols such as TCP and UDP. Understanding these basics makes it easier to see how clients connect to servers and how data moves across a network. Building a two-way messaging system with an ESP32 was a practical way to put these concepts into action.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b22b49bb414" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/networking-basics-and-a-quantum-simulation-experiment-4b22b49bb414">Networking Basics and a Quantum Simulation Experiment</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I2C and My First Device Driver]]></title>
            <link>https://medium.com/the-curious-circuit/i2c-and-my-first-device-driver-3755a831c15f?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/3755a831c15f</guid>
            <category><![CDATA[e-paper-display]]></category>
            <category><![CDATA[device-drivers]]></category>
            <category><![CDATA[i2c]]></category>
            <category><![CDATA[bit-banging]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Sun, 23 Aug 2026 23:16:33 GMT</pubDate>
            <atom:updated>2026-08-30T18:20:04.449Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What is I2C?</strong></h3><p><strong>I2C </strong>is a communication protocol that allows a microcontroller, such as an Arduino, to communicate with multiple electronic devices using just <strong>two signal wires</strong>.</p><p>I²C is like a <strong>conversation</strong> between an Arduino and several devices. The Arduino decides who it wants to talk to, and the devices respond when they are addressed. The master device is the device that <strong>starts and controls the communication(</strong>like a microcontroller). It decides which device to communicate with. The slave device(s) is the device that <strong>responds to the master</strong>. It has an address so the master can select it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1D1amzQxr9UalyezA4epw.png" /></figure><p>Basically,</p><p>I2C is a communication protocol that uses a master device to control the clock and start or stop communication, and it allows that master to communicate with other devices (slaves) using only two main signal lines:</p><p>SDA =&gt; Serial Data</p><p>SCL =&gt; Serial Clock</p><p>Multiple devices share the same SDA and SCL lines. The master chooses which device it wants to communicate with by sending that device’s address.</p><h3><strong>How does I2C work?</strong></h3><h4><strong>SDA/SCL</strong></h4><p><strong>SDA</strong></p><p>SDA carries the actual data.</p><p>This includes:</p><p>Device Addresses</p><p>Commands</p><p>Configuration Values</p><p>Display Data</p><p>Sensor Data</p><p>Each bit is transmitted as either 0 or 1.</p><p><strong>SCL</strong></p><p>SCL provides the timing.</p><p>The clock tells the devices when to look at the data. Each clock pulse corresponds to one bi being transferred.</p><p>The main concept is:</p><p>SDA contains the data, while SCL controls when that data is transmitted.</p><h4><strong>Clocking Data</strong></h4><p>Suppose we want to send:</p><p>10110010</p><p>The sender places each bit onto SDA when SCL is low.</p><p>Then SCL changes state, allowing the reciever to read that bit.</p><p>This process repeats for every bit.</p><p>So a byte:</p><p>10110010</p><p>requires: 8 bits =&gt; 8 clock cycles</p><p>This process is called Bit-Banging</p><p>More on Bit-Banging linked <a href="https://medium.com/the-curious-circuit/thinking-like-a-microcontroller-bits-bytes-hexadecimal-registers-bitwise-operators-a1c4a9618317">here</a> (Jump to the Experiment: Bit-Banging section)</p><h4><strong>Start and Stop Conditions</strong></h4><p>An I2C transaction needs a way to begin and end.</p><p><strong>Start</strong></p><p>A start condition occurs when SDA changes from HIGH to LOW while SCL is HIGH. This tells all devices on the bus that a I2C transaction is beginning.</p><p><strong>Stop</strong></p><p>A stop condition occurs when SDA changes from LOW to HIGH while SCL is HIGH. This tells the device that the transaction is completed.</p><h4><strong>I2C Addresses</strong></h4><p>Because multiple devices can share SDA and SCL, the master needs a way to select a specific device. Each device has an <strong>address</strong>. When the master sends the address, the device with that address learns that the transaction is intended for the device. In a standard 1 byte (8 bits) transmission frame, 7 bits are used for the unique device address, and the 8th bit specifies a read or write operation. Theoretically, each of the 7 bits could be a 0 or a 1, 2⁷ = 128 different devices. Reserved system addresses usually reduce this to a usable maximum of 112 devices.</p><h4><strong>ACK and NACK</strong></h4><p>After receiving a byte, the receiving device can respond with:</p><p>ACK =&gt; Acknowledged</p><p>NACK =&gt; Not Acknowledged</p><h3><strong>Using Wire.h</strong></h3><p>The Arduino provides the Wire.h library to interact with the I2C hardware. The mainly used functions are:</p><h4><strong>Wire.begin()</strong></h4><p>This initializes the I2C hardware, such as configuring the clock frequency.</p><h4><strong>Wire.beginTransmission(address)</strong></h4><p>This tells Wire that it wants to prepare a transmission to the device address. At this point, the data has <strong>not </strong>been sent yet. Instead, the Arduino begins building a transmit buffer.</p><h4><strong>Wire.write(data)</strong></h4><p>This adds your data to the transmission buffer.</p><p>For example:</p><p>Wire.write(0x3C);</p><p>adds a byte to the transmission buffer.</p><p>Wire.write(0x2B);</p><p>Wire.write(0x16);</p><p>adds two bytes to the transmission buffer.</p><h4><strong>Wire.endTransmission()</strong></h4><p>The Arduino performs the actual I2C transaction.</p><p>Conceptually:</p><p>START =&gt; Send Address =&gt; Send buffered bytes =&gt; Receive ACKs =&gt; STOP</p><p>This is the point where the bytes actually begin appearing on SDA and are synchronized by SCL.</p><h3><strong>My First Device Driver (Driven by I2C)</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*dmDOoaQ5eTMituY8mxG8dA.jpeg" /></figure><p>The waveshare 1.9 inch Segment e-paper module was a bit difficult to understand at first. I did not understand what the “segment codes” were and how to display different numbers. Eventually I understood that the segment codes were literally codes to display different numbers. In order to Power on and off the display, there is a whole command sequence:</p><ol><li>Power on display</li><li>Turn on High Voltage</li><li>Configure Temperature</li><li>Set Frame time</li><li>Configure Display Data</li><li>Send 15 byte buffer containing data on what to display</li><li>Start refreshing the display</li><li>Power off and High voltage off</li></ol><p><strong>The Display Connctions</strong></p><p>The display has 6 pins:</p><p>SDA (A4)</p><p>SCL (A5)</p><p>VCC (VCC)</p><p>GND (GND)</p><p>RST (D8)</p><p>BUSY (D7)</p><p><strong>What does Reset do?</strong></p><p>RST stands for Reset. The display controller can be reset by applying a reset pulse.</p><p>For example:</p><p>HIGH =&gt; LOW =&gt; HIGH</p><p>The reset ensures that the controller starts from a known state.</p><p><strong>What does BUSY do?</strong></p><p>E-paper updates are not instantaneous. After receiving a refresh command, the display may spend time applying electrical waveforms and moving particles. The BUSY pin tells the Arduino whether the controller is ready.</p><p><strong>Commands vs Display Data</strong></p><p>My module uses two I2C addressses:</p><p>Command Address =&gt; 0x3C</p><p>Data Address =&gt; 0x3D</p><p>Commands tell the Display controller what to do.</p><p>Display data tells the Display controller what segments should be black or white.</p><p><strong>Segment Codes</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*9pcvTr4RzoLhBMBqCCX0UQ.png" /><figcaption>The Segment positions. (The indices in the 15 byte buffer)</figcaption></figure><p>To display numbers I created a lookup table containing the segment codes as defined in the LCD <a href="https://www.waveshare.com/wiki/1.9inch_Segment_e-Paper_Module_Manual">datasheet</a>. Each number has an associated set of bytes:</p><p>0: 0xBF, 0x1F<br>1: 0 x 1F (position 0), 0 x 00, 0 x 1F (other positions)<br>2: 0xFD, 0x17<br>3: 0xF5, 0x1F<br>4: 0x47, 0x1F<br>5: 0xF7, 0x1D<br>6: 0xFF, 0x1D<br>7: 0x21, 0x1F<br>8: 0xFF, 0x1F<br>9: 0xF7, 0x1F</p><p>These codes go in the corresponding segments to display the number.</p><p>For e.g. to display 10 in the top row, the following sequence will be followed and the corresponding bytes will go into the I2C bus.</p><ol><li>Power on display =&gt; 0x2B</li><li>Turn on High Voltage =&gt; 0xA7, 0xE0</li><li>Configure Temperature =&gt; 0x7E, 0x81, 0xB4</li><li>Set Frame time =&gt; 0xE7, 0x0E</li><li>Configure Display Data =&gt; 0xAC, 0x2B, 0x40, 0xA9, 0xA8</li><li>Send 15 byte buffer containing data on what to display. =&gt; 0x1F, 0xBF, 0x1F, 0x00, 0x00, 0x00, 0x00 … 0x00 <strong>** </strong>(See the explanation below)</li><li>Start refreshing the display =&gt; 0xAB, 0xAA, 0xAF</li><li>Power off and High voltage off =&gt; 0xAE, 0x28, 0xAD</li></ol><p>** Data formation logic</p><p>Essentially the position number (number in red above) indicates the index of the 15 byte array, and together with the code(s) from the lookup table of the digit codes, essentially one has to put the right code in the right index of the data array. In this case, I want to display 1 in position 0 and 0 in position 1, thus the byte sequence woulod become : [0x1F, 0xBF, 0x1F … rest all 0&#39;s].</p><p>There is also some other trickeries that I did to extract the digits from the given number and mapping it to a 2D array, refer to my code <a href="https://github.com/Quantum-Shivi/HomeSense/tree/main/HomeSense">here</a>, in particular the display function <a href="https://github.com/Quantum-Shivi/HomeSense/blob/11f87e6bc582893abe0407c8ebd3b893dcdd1314/HomeSense/epaper_driver.ino#L134">here</a> for details.</p><h3>Conclusion</h3><p>This project started as an experiment to display numbers on an e-paper screen, but it became a much deeper look at how microcontrollers communicate with hardware.</p><p>Instead of using a display library that hides the details, I used Wire.h and worked directly with:</p><ul><li>I²C addresses</li><li>Commands</li><li>Display data</li><li>Segment bitmasks</li><li>RAM buffers</li><li>Reset signals</li><li>Busy signals</li><li>Refresh sequences</li></ul><p><a href="https://medium.com/the-curious-circuit">Link to my other articles on learning electronics and embedded systems</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3755a831c15f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/i2c-and-my-first-device-driver-3755a831c15f">I2C and My First Device Driver</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Interrupts in Arduino]]></title>
            <link>https://medium.com/the-curious-circuit/understanding-interrupts-in-arduino-004c92197611?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/004c92197611</guid>
            <category><![CDATA[circuit]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[electronics-engineering]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Wed, 12 Aug 2026 21:01:08 GMT</pubDate>
            <atom:updated>2026-08-12T21:15:13.173Z</atom:updated>
            <content:encoded><![CDATA[<h3>Beyond loop(): Understanding Interrupts in Arduino</h3><p>When I first started learning Arduino, I thought of the microcontroller as a machine that simply runs my code from top to bottom:</p><p>The Arduino keeps going through loop() again and again.</p><p>But what happens if something important happens <strong>right now</strong>, while the Arduino is busy doing something else?</p><p>What if a button is pressed, a sensor produces a pulse, a timer expires, or a byte arrives through serial communication?</p><p>This is where <strong>interrupts</strong> come in.</p><p>An interrupt gives the microcontroller a way to say:</p><p><em>“Stop what you’re doing for a moment. Something important just happened.”</em></p><h3>What Is an Interrupt?</h3><p>An interrupt is a mechanism that allows hardware or software to get the CPU’s attention when a particular event occurs.</p><p>Without an interrupt, we might use <strong>polling</strong>.</p><p>For example:</p><p>The Arduino repeatedly asks:</p><p><em>“Is the button pressed?”</em></p><p>This works, but the CPU has to keep checking.</p><p>With an interrupt, we can instead say:</p><p><em>“Tell me when the button is pressed.”</em></p><p>Then the hardware watches the pin for us.</p><p>When the event occurs, the CPU temporarily pauses its normal execution and runs a special function called an <strong>Interrupt Service Routine</strong>, or <strong>ISR</strong>.</p><h3>Polling vs Interrupts</h3><p>Imagine I’m working on a math problem.</p><p>With polling, I would constantly stop and ask:</p><p><em>“Did someone call me?”</em></p><p>Work<br> ↓<br>Check<br> ↓<br>Work<br> ↓<br>Check<br> ↓<br>Work<br> ↓<br>Check</p><p>With an interrupt, I can simply continue working until someone calls me.</p><p>Work<br>Work<br>Work<br>Work<br> ↓<br> INTERRUPT!<br> ↓<br> Handle event<br> ↓<br>Return to work</p><p>This is one of the most important differences between polling and interrupts.</p><h3>What Actually Happens During an Interrupt?</h3><p>Suppose the Arduino is executing:</p><p>Instruction<br>Instruction<br>Instruction<br>Instruction</p><p>Suddenly, an interrupt event occurs.</p><p>The processor:</p><ol><li>Detects the interrupt.</li><li>Finishes the current instruction.</li><li>Saves enough information to return to the interrupted program.</li><li>Jumps to the interrupt handler.</li><li>Executes the ISR.</li><li>Returns to the previous program.</li><li>Continues execution.</li></ol><p>Conceptually:</p><p>Main Program<br> │<br> ▼<br>Instruction<br> │<br> ▼<br>Instruction<br> │<br> ▼<br>INTERRUPT!<br> │<br> ▼<br>Save execution state<br> │<br> ▼<br>Run ISR<br> │<br> ▼<br>Restore execution state<br> │<br> ▼<br>Continue main program</p><p>The important thing is that the ISR doesn’t replace the main program.</p><p>It temporarily interrupts it.</p><h3>What Is an ISR?</h3><p>ISR stands for:</p><p><strong>Interrupt Service Routine</strong></p><p>It is simply the function that runs when an interrupt occurs.</p><p>For example:</p><p>void buttonISR() {<br> buttonPressed = true;<br>}</p><p>This function doesn’t normally get called from loop().</p><p>Instead, the microcontroller calls it automatically when the configured interrupt event occurs.</p><h3>Interrupt Trigger Types</h3><p>Arduino provides several trigger modes.</p><h3>RISING (edge interrupt)</h3><p>An interrupt occurs when the signal changes from LOW to HIGH:</p><p>Configured with:</p><p>attachInterrupt(<br> digitalPinToInterrupt(2),<br> buttonISR,<br> RISING<br>);</p><h3>FALLING(edge interrupt)</h3><p>An interrupt occurs when:</p><p>HIGH → LOW</p><h3>CHANGE (in state)</h3><p>An interrupt occurs whenever the signal changes.</p><p>So both:</p><p>LOW → HIGH</p><p>and:</p><p>HIGH → LOW</p><p>trigger the interrupt.</p><p>attachInterrupt(<br> digitalPinToInterrupt(2),<br> buttonISR,<br> CHANGE<br>);</p><h3>LOW</h3><p>The interrupt is triggered while the pin is LOW.</p><p>attachInterrupt(<br> digitalPinToInterrupt(2),<br> buttonISR,<br> LOW<br>);</p><p>This behaves differently from the edge-triggered modes and isn’t usually what I would choose for a simple button.</p><h3>Why Does the ISR Need to Be Short?</h3><p>This is one of the most important rules of interrupts:</p><p><strong><em>Keep your ISR as short as possible.</em></strong></p><p>For example, this is good:</p><p>void buttonISR() {<br> buttonPressed = true;<br>}</p><p>Why?</p><p>Because while the ISR is running, the CPU isn’t simply carrying on with the normal program.</p><p>Other time-sensitive events can be delayed or missed.</p><h3>So Where Does the Actual Work Go?</h3><p>This leads to one of the most useful patterns in embedded programming:</p><p><strong><em>The ISR captures the event. The main program processes the event.</em></strong></p><p>Think of an ISR like a receptionist.</p><p>The receptionist doesn’t solve a complicated problem for every person who walks in.</p><p>They simply take the message:</p><p><em>“Someone needs help.”</em></p><p>Then the appropriate person handles the actual work.</p><h3>Why volatile?</h3><p>volatile bool buttonPressed = false;</p><p>Why volatile?</p><p>Because the variable is accessed by two different parts of the program:</p><pre>buttonPressed<br>                  │<br>          ┌───────┴────────┐<br>          │                │<br>          ▼                ▼<br>        loop()            ISR</pre><p>The ISR can change the variable unexpectedly from the perspective of the main program.</p><p>volatile tells the compiler:</p><p><em>“This value can change outside the normal flow of the program. Don’t assume it stays the same.”</em></p><p>So variables shared between an ISR and normal code often need to be declared volatile.</p><h3>Interrupts Can Count Events</h3><p>An ISR doesn’t have to set a Boolean flag.</p><p>It can also count events.</p><p>For example, imagine a sensor that produces a pulse every time a wheel rotates.</p><p>volatile unsigned long pulseCount = 0;</p><p>void sensorISR() {<br> pulseCount++;<br>}</p><p>Now every pulse causes:</p><p>Pulse 1 → pulseCount = 1<br>Pulse 2 → pulseCount = 2<br>Pulse 3 → pulseCount = 3<br>Pulse 4 → pulseCount = 4</p><p>The main program can then calculate the speed.</p><p>This is useful for:</p><ul><li>Wheel encoders</li><li>Motor speed sensors</li><li>Hall-effect sensors</li><li>Flow meters</li><li>Rotational sensors</li></ul><h3>Timer Interrupts</h3><p>Not all interrupts come from external pins.</p><p>A microcontroller can also generate an interrupt using a <strong>hardware timer</strong>.</p><p>A timer is a hardware counter inside the microcontroller.</p><p>For example:</p><p>0<br>1<br>2<br>3<br>4<br>5<br>...<br>999<br>1000<br> ↓<br>INTERRUPT</p><p>The CPU can then execute a timer ISR.</p><p>This allows us to create precise periodic events:</p><p>1 ms → ISR<br>2 ms → ISR<br>3 ms → ISR<br>4 ms → ISR<br>5 ms → ISR</p><p>Timer interrupts are useful for:</p><ul><li>Periodic sensor sampling</li><li>Motor control</li><li>Generating precise timing</li><li>Scheduling tasks</li><li>Creating system clocks</li><li>Real-time applications</li></ul><p>They are fundamentally different from an external button interrupt in <strong>what causes the interrupt</strong>, but the CPU handles the interrupt using the same basic idea.</p><h3>Different Sources of Interrupts</h3><p>An interrupt is essentially a way for some hardware or software event to request the CPU’s attention.</p><p>Common interrupt sources include:</p><p>External pin<br> ↓<br>Timer<br> ↓<br>UART / Serial</p><p>and more …</p><p>Different microcontrollers provide different combinations of these.</p><h3>What Happens Inside the Microcontroller?</h3><p>Arduino makes interrupts easy with:</p><p>attachInterrupt()</p><p>But underneath, the ATmega328P has actual hardware registers controlling the interrupt system.</p><p>For example, some bits determine:</p><ul><li>What event triggers the interrupt</li><li>Whether the interrupt is enabled</li></ul><p>This connects directly to something else I’ve been learning:</p><p>Binary<br> ↓<br>Bits<br> ↓<br>Bitwise operators<br> ↓<br>Registers<br> ↓<br>Peripheral configuration<br> ↓<br>Interrupt</p><p>One of the biggest things I learned about interrupts is that loop() isn&#39;t the only thing happening inside a microcontroller.</p><p>Normally:</p><p>setup()<br> ↓<br>loop()<br> ↓<br>loop()<br> ↓<br>loop()<br> ↓<br>loop()</p><p>But with interrupts:</p><p>setup()<br> ↓<br>loop()<br> ↓<br>loop()<br> ↓<br> ┌──────── INTERRUPT<br> │<br> ▼<br> ISR<br> │<br> └──────────────┐<br> ▼<br> loop()<br> ↓<br> loop()</p><p>The ISR is like a temporary detour.</p><h3><strong>Core Concepts</strong></h3><ul><li><strong>Interrupt source:</strong> Something that needs the CPU’s attention — a pin, timer, UART, ADC, etc.</li><li><strong>Interrupt request:</strong> The hardware signals the CPU that an event occurred.</li><li><strong>Interrupt vector:</strong> Tells the CPU where the corresponding ISR is located.</li><li><strong>ISR:</strong> The function that runs when the interrupt occurs.</li><li><strong>Interrupt registers:</strong> Special hardware registers are used to <strong>configure, enable, monitor, and control</strong> interrupts.</li><li><strong>Interrupt flags:</strong> Bits in registers can indicate that an interrupt event occurred.</li><li><strong>Short ISR:</strong> The ISR should quickly capture the event and let the main program do the heavier work.</li></ul><h3><strong>Experiment</strong></h3><p>I made a simple circuit to test out interrupts. My circuit consisted of a LED and a button which were connected to Arduino pins D13 and A1, respectively. I wanted the Arduino to generate an interrupt when the button was pushed, but since the button was connected to A1, I had to use a <strong>Pin-Change Interrupt</strong>. In order to this, I had to first enable the whole PCINT group, which is essentially just a port on the Arduino. After that, I enabled the individual pin (in my case pin A1). This allowed for the pin A1 inside its Pin-Change group (in my case group 1) to be constantly monitored. Once the interrupt was triggered, I would make sure that the button was pressed by checking the state. Once I verified that, I switched on the LED.</p><p>** I verified the state of the button inside the ISR, but I did not turn on the LED inside the ISR. I just updated boolean button pressed to true. The LED was switched on in my main loop.</p><p><a href="https://github.com/Quantum-Shivi/Arduino-Projects/blob/main/interruptbuttonled/interruptbuttonled.ino">Link to my code</a></p><h3>When Should I Use an Interrupt?</h3><p>Interrupts are particularly useful when:</p><ul><li>An event can happen at an unpredictable time.</li><li>The event is short and needs a quick response.</li><li>You need accurate timing.</li><li>You need to count pulses.</li><li>You need to detect transitions.</li><li>Polling would waste CPU time.</li><li>Missing an event would be a problem.</li></ul><p>Examples include:</p><p>Button<br>Encoder<br>IR receiver<br>Motor sensor<br>Timer<br>Serial data<br>ADC completion<br>Communication peripherals</p><p>But an interrupt isn’t automatically better than polling.</p><p>For a button that you check once every second, an interrupt might be unnecessary.</p><p>Good embedded design means choosing the appropriate method for the problem.</p><h3>Final Takeaway</h3><p>Before learning interrupts, I thought of an Arduino as a processor that simply runs:</p><p>loop();<br>loop();<br>loop();<br>loop();</p><p>Now I understand that there is much more happening underneath.</p><p>The microcontroller has hardware peripherals constantly doing their jobs:</p><p>Timers<br>GPIO<br>UART<br>When one of those peripherals needs the CPU’s attention, it can generate an interrupt.</p><p>The CPU temporarily pauses its normal execution, runs an ISR, and then returns to the program.</p><p>The key idea is:</p><p><strong><em>Interrupts allow a microcontroller to react to events instead of constantly checking whether those events have happened.</em></strong></p><p>And the most important programming rule is:</p><p><strong><em>Keep the ISR short. Capture the event quickly, then let the main program do the heavy work.</em></strong></p><p>That simple idea is one of the foundations of real-time embedded programming.</p><p><a href="https://medium.com/the-curious-circuit">Link to my other articles on learning electronics and embedded systems</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=004c92197611" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/understanding-interrupts-in-arduino-004c92197611">Understanding Interrupts in Arduino</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Thinking Like a Microcontroller: Bits, Bytes, Hexadecimal, Registers, Bitwise Operators, &…]]></title>
            <link>https://medium.com/the-curious-circuit/thinking-like-a-microcontroller-bits-bytes-hexadecimal-registers-bitwise-operators-a1c4a9618317?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1c4a9618317</guid>
            <category><![CDATA[binary]]></category>
            <category><![CDATA[register]]></category>
            <category><![CDATA[bitwise-operator]]></category>
            <category><![CDATA[bit-banging]]></category>
            <category><![CDATA[hexadecimal]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Wed, 05 Aug 2026 21:26:46 GMT</pubDate>
            <atom:updated>2026-08-05T23:43:23.373Z</atom:updated>
            <content:encoded><![CDATA[<h3>Thinking Like a Microcontroller: Bits, Bytes, Hexadecimal, Registers, Bitwise Operators, &amp; Bitmasking</h3><h3>Introduction</h3><p>Every electronic device around you — your phone, keyboard, smartwatch, gaming controller, or microwave — is powered by a tiny computer called a <strong>microcontroller</strong>.</p><p>Unlike a desktop computer, a microcontroller interacts directly with the physical world. It turns LEDs on and off, reads buttons, drives motors, communicates with sensors, and responds to external events in real time.</p><p>To do that efficiently, it doesn’t think in terms of LEDs and buttons.</p><p>It thinks in <strong>bits</strong>.</p><p>Learning embedded programming means learning to think like the microcontroller itself.</p><p>In this blog post, I’ll write about:</p><ul><li>Bits and Bytes</li><li>Binary and Hexadecimal</li><li>Registers</li><li>Reading and Writing Ports</li><li>Bitwise Operators</li><li>Bitmasking</li><li>Real-world examples</li></ul><h3>Bits and Bytes</h3><p>A <strong>bit</strong> is the smallest unit of information a computer can store.</p><p>A bit has only two possible values:</p><p>0 = OFF<br>1 = ON</p><p>You can think of a bit as a light switch.</p><ul><li>OFF → 0</li><li>ON → 1</li></ul><p>Eight bits grouped together form a <strong>byte</strong>.</p><p>0 1 0 1 1 0 0 1</p><p>Almost every register inside the ATmega328P (the chip used on the Arduino Uno) is <strong>8 bits wide</strong>, meaning it stores one byte.</p><h3>The 8421 Rule</h3><p>Every group of four bits (called a <strong>nibble</strong>) represents a number.</p><p>Each position has a value.</p><p>Example:</p><p>1010</p><p>Using the 8421 rule:</p><p>8 + 2 = 10</p><p>Decimal <strong>10</strong> is represented by <strong>A</strong> in hexadecimal.</p><p>Another example:</p><p>1101</p><p>8 + 4 + 1 = 13</p><p>Decimal 13 becomes <strong>D</strong>.</p><h3>Binary and Hexadecimal</h3><p>Writing long binary numbers quickly becomes difficult.</p><p>Instead of writing</p><p>11110000</p><p>we write</p><p>0xF0</p><p>The prefix <strong>0x</strong> tells us the number is hexadecimal.</p><p>To convert binary to hexadecimal:</p><ol><li>Split the binary into groups of four bits.</li><li>Convert each group using the 8421 rule.</li></ol><p>Example:</p><p>10101101</p><p>↓</p><p>1010 1101</p><p>↓</p><p>A D</p><p>↓</p><p>0xAD</p><p>Converting back is just as easy.</p><p>0x5C</p><p>↓</p><p>5 = 0101</p><p>C = 1100</p><p>↓</p><p>01011100</p><h3>Registers</h3><p>A register is a very small storage location inside the microcontroller.</p><p>Each register in my Arduino usually stores <strong>8 bits</strong>.</p><p>Example:</p><p>PORTD</p><p>00000000</p><p>Each bit corresponds to one Arduino pin.</p><p>If</p><p>PORTD = 00001000</p><p>only <strong>D3</strong> is HIGH.</p><p>If</p><p>PORTD = 11111111</p><p>every pin is HIGH.</p><h3>PORTx</h3><p>The PORT register controls output voltage.</p><p>PORTD = 10101010</p><p>This produces:</p><ul><li>D7 HIGH</li><li>D6 LOW</li><li>D5 HIGH</li><li>D4 LOW</li><li>D3 HIGH</li><li>D2 LOW</li><li>D1 HIGH</li><li>D0 LOW</li></ul><h3>PINx</h3><p>The PIN register lets you read the current voltage on the pins.</p><p>Example:</p><p>byte value = PIND;</p><p>Suppose:</p><p>PIND = 10000101</p><p>This means:</p><ul><li>D7 HIGH</li><li>D2 HIGH</li><li>D0 HIGH</li></ul><h3>Reading and Writing Entire Ports</h3><p>Instead of reading one pin at a time:</p><p>digitalRead(2);<br>digitalRead(3);<br>digitalRead(4);</p><p>you can read all eight pins together:</p><p>byte inputs = PIND;</p><p>Likewise, instead of calling multiple digitalWrite() functions, you can write all eight output pins in one operation:</p><p>PORTD = 0xAA;</p><p>This immediately sets the pattern:</p><p>10101010</p><p>Direct register access is much faster than repeatedly calling Arduino library functions.</p><h3>Bitwise Operators</h3><p>Registers contain multiple bits, but often we only want to modify one or two without disturbing the rest.</p><p>Bitwise operators make this possible.</p><h3>OR ( | ) — Set Bits</h3><h4><strong>PORTD |= (1 &lt;&lt; 3);</strong></h4><p>Turns D3 HIGH while leaving every other pin unchanged.</p><h3>AND ( &amp; ) — Read or Clear Bits</h3><p>Reading a pin:</p><p>if (PIND &amp; (1 &lt;&lt; 5))<br> D5 is HIGH</p><p>Clearing a pin:</p><p>PORTD &amp;= ~(1 &lt;&lt; 3);</p><p>Turns D3 LOW without affecting any other output.</p><h3>NOT ( ~ )</h3><p>Flips every bit.</p><p>10100101</p><p>↓</p><p>01011010</p><p>Often used when creating masks.</p><h3>Shift Operators</h3><h4><strong>1 &lt;&lt; 5</strong></h4><p>produces</p><p>00100000</p><p>Instead of memorizing binary numbers, programmers simply shift a single 1 into the correct position.</p><h3>Bitmasking</h3><p>A <strong>bitmask</strong> is simply a pattern of bits used to select or modify certain bits in a register.</p><p>Example:</p><p>PORTD |= (1 &lt;&lt; 7) | (1 &lt;&lt; 2);</p><p>This creates the mask:</p><p>10000100</p><p>Only D7 and D2 become HIGH.</p><p>To clear them:</p><p>PORTD &amp;= ~((1 &lt;&lt; 7) | (1 &lt;&lt; 2));</p><p>Bitmasking allows us to manipulate individual pins while leaving every other pin unchanged.</p><h3>Experiment : Bit-Banging</h3><p>In this very simple circuit, I used a LED, 220 Ohm resistor, and an Arduino. In my code, I wrote a function called BitBang, which took a byte as its parameter, and split it into bits. If the bit was 1, I turned the state of the pin high, and if the bit was low, I turned it to 0. This resulted in the LED being switched on when the bit was 1, and off when the bit was 0. The graph displayed on the oscilloscope represents the value of each bit(High for 1, low for 0). The unique characteristic of my project is the perfect square waves, which are formed because the byte I am using is 0xAA, or 10101010 in binary. The bits are alternating between 0 and 1, so the signals are alternating between low and high. The square waves are equal, but 1 square wave is not because once the BitBang function completes, there is a delay before it is called again.</p><p><a href="https://github.com/Quantum-Shivi/Arduino-Projects/blob/main/BitBanging.ino">Link to the code</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P2k_XWJvvTEpKR9OiuVs0g.jpeg" /></figure><h3>Where Are These Concepts Used?</h3><p>Once you begin building more advanced electronics projects, you’ll see these techniques everywhere.</p><p>Examples include:</p><ul><li>LED matrices</li><li>Seven-segment displays</li><li>Rotary encoders</li><li>Keypad scanning</li><li>SPI communication</li><li>I²C communication</li><li>UART serial communication</li><li>Motor drivers</li><li>Robotics</li><li>IR remote receivers</li><li>Digital sensors</li><li>High-speed data acquisition</li></ul><p>Whenever speed, precision, or direct hardware control is important, programmers use registers and bitwise operations instead of high-level functions.</p><h3>Final Thoughts</h3><p>Learning Arduino begins with blinking an LED.</p><p>Learning embedded systems begins when you ask:</p><p>“What is actually happening inside the microcontroller?”</p><p>Understanding bits, bytes, hexadecimal, registers, bitwise operators, and bitmasking completely changes the way you write code.</p><p>Instead of treating the Arduino like a black box, you begin speaking the language of the hardware itself.</p><p>And once you can think in bits, you’re no longer just programming an Arduino — you are programming the microcontroller.</p><p><a href="https://medium.com/the-curious-circuit">Link to my other articles on learning electronics and embedded systems</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1c4a9618317" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/thinking-like-a-microcontroller-bits-bytes-hexadecimal-registers-bitwise-operators-a1c4a9618317">Thinking Like a Microcontroller: Bits, Bytes, Hexadecimal, Registers, Bitwise Operators, &amp;…</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the 4-Digit 7-Segment Display]]></title>
            <link>https://medium.com/the-curious-circuit/understanding-the-4-digit-7-segment-display-5e0964206b3c?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e0964206b3c</guid>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[oscilloscope]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[circuit]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Thu, 23 Jul 2026 18:44:58 GMT</pubDate>
            <atom:updated>2026-08-06T19:45:43.711Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever looked at a digital clock, microwave oven, calculator, or stopwatch, you’ve probably seen a <strong>7-segment display</strong>. These displays are one of the simplest and most efficient ways to display numbers.</p><p>In this blog, I’ll explain the <strong>5641AS 4-Digit 7-Segment Display</strong>, understand how it works, learn its pin layout, and discover the concept of multiplexing.</p><h3>What is a 7-Segment Display?</h3><p>A 7-segment display is an electronic display made up of <strong>seven individual LEDs</strong> arranged in the shape of the number <strong>8</strong>.</p><p>Each LED is called a <strong>segment</strong> and is identified by a letter.</p><pre>     ---A---<br>    |       |<br>    F       B<br>    |       |<br>     ---G---<br>    |       |<br>    E       C<br>    |       |<br>     ---D---   • DP</pre><p>The display contains:</p><ul><li>Segment A</li><li>Segment B</li><li>Segment C</li><li>Segment D</li><li>Segment E</li><li>Segment F</li><li>Segment G</li><li>Decimal Point (DP)</li></ul><p>By turning different segments on or off, we can display every number from <strong>0 to 9</strong>, as well as many letters.</p><p>For example:</p><p>0 = ABCDEF</p><p>1 = BC</p><p>2 = ABDEG</p><h3>From One Digit to Four Digits</h3><p>A single 7-segment display can only show one number.</p><p>The <strong>5641AS</strong> combines <strong>four individual 7-segment displays</strong> into one package.</p><pre>-------------------------<br>| 8 | 8 | 8 | 8 |<br> -------------------------<br> D1  D2  D3  D4</pre><p>This allows us to display:</p><ul><li>1234</li><li>2026</li><li>9999</li><li>12.34</li><li>Timers</li><li>Scores</li><li>Clocks</li><li>Counters</li></ul><h3>Common Cathode Display</h3><p>The 5641AS is a <strong>Common Cathode (CC)</strong> display.</p><p>Each digit has:</p><ul><li>Seven LEDs</li><li>One decimal point LED</li></ul><p>All the negative terminals (cathodes) of a digit are connected together.</p><p>That shared connection is called the <strong>Common Cathode</strong>.</p><p>To turn on a segment:</p><ol><li>Set the segment pin HIGH.</li><li>Connect the digit’s common cathode to GND.</li></ol><p>Electricity flows:</p><pre>Arduino Pin (HIGH)<br>        │<br>        ▼<br>     Segment LED<br>        │<br>        ▼<br>Common Cathode<br>        │<br>       GND</pre><h3>Pin Layout of the 5641AS</h3><p>Looking at the display from the front:</p><pre>      -----------------<br>     |  _   _   _   _  |<br>     | |_| |_| |_| |_| |<br>     | |_| |_| |_| |_| |<br>      -----------------</pre><pre>        12 11 10 9 8 7<br>         |           |<br>         |           |<br>         1  2  3  4 5 6</pre><p>Notice something interesting.</p><p>There are only <strong>12 pins</strong>.</p><p>How can four displays fit into only twelve pins?</p><p>Let’s understand why.</p><h3>Shared Segment Pins</h3><p>Imagine four separate displays.</p><p>Normally each display would need:</p><ul><li>8 segment pins</li><li>1 common pin</li></ul><p>That’s:</p><pre>9 pins × 4 displays = 36 pins</pre><p>Instead, all four displays <strong>share</strong> the segment pins.</p><pre>Segment A ────────────────┐<br>                          │<br>Digit1  Digit2  Digit3  Digit4</pre><p>The same is true for every segment:</p><pre>A<br>B<br>C<br>D<br>E<br>F<br>G<br>DP</pre><p>Only the common cathodes are separate.</p><p>So we have:</p><p>8 segment pins + 4 digit pins = 12 total pins</p><p>This clever design greatly reduces the number of connections required.</p><h3>What Are the Digit Pins?</h3><p>The digit pins act like switches.</p><p>Only one digit is enabled at a time.</p><p>For example:</p><pre>Enable Digit 2</pre><pre>Digit2 → LOW</pre><pre>Digit1 → HIGH</pre><pre>Digit3 → HIGH</pre><pre>Digit4 → HIGH</pre><p>Only Digit 2 now has a path to ground.</p><h3>Multiplexing</h3><p>This is the most important concept behind multi-digit displays.</p><p>Instead of lighting all four digits at once, the Arduino lights them <strong>one after another</strong>.</p><p>For example, the logic to display 1234 would be:</p><p><strong>Extract the Digits:</strong></p><p>Break the number into individual digits:</p><p>thousands 1, hundreds 2, tens 3, and ones 4.</p><p><strong>Translate to Segment Data:</strong></p><p>Map each digit to a binary value corresponding to its specific LEDs (A through G) using a lookup table.</p><p><strong>Loop &amp; Display:</strong></p><p>Activate the 1st digit pin</p><p>Send the segment data for “1” to the segment pins. Wait for 2 to 5 milliseconds. Turn off the 1st digit. Repeat the process for each of the digits.</p><p>Our eyes cannot see the switching.</p><p>Instead, we perceive:</p><p>1234</p><p>as if every digit were continuously lit.</p><p>This phenomenon is called <strong>Persistence of Vision</strong>, where the human eye briefly retains an image after the light disappears. Because the display refreshes much faster than our eyes can detect, all four digits appear to glow steadily.</p><h3>Example: Displaying “1234”</h3><p>Suppose we want to show:</p><p>1234</p><p>The Arduino performs these steps repeatedly:</p><h3>Step 1</h3><pre>B<br>C</pre><pre>Enable Digit 1</pre><h3>Step 2</h3><pre>A<br>B<br>D<br>E<br>G</pre><pre>Enable Digit 2</pre><h3>Step 3</h3><pre>A<br>B<br>C<br>D<br>G</pre><pre>Enable Digit 3</pre><h3>Step 4:</h3><pre>B<br>C<br>F<br>G</pre><pre>Enable Digit 4</pre><p>Then it immediately starts over.</p><p>This process happens so quickly that the display appears to show <strong>1234</strong> continuously.</p><h3>Why Multiplexing Is Useful</h3><p>Without multiplexing, a four-digit display would require dozens of Arduino pins.</p><p>With multiplexing:</p><ul><li>Fewer wires</li><li>Fewer microcontroller pins</li><li>Lower cost</li><li>Simpler circuit</li><li>Smaller display modules</li></ul><p>This is why nearly every digital clock, timer, counter, and calculator uses multiplexing.</p><h3>Current-Limiting Resistors</h3><p>Each LED segment must have a resistor to prevent excessive current from flowing.</p><p>Without a resistor, too much current could damage both the LED segments and the Arduino’s output pins.</p><p>Typical resistor values are:</p><ul><li>220 Ω</li><li>330 Ω</li></ul><p>When driving a bare 5641AS display directly, a resistor should be placed in series with each segment line (A–G and DP).</p><h3>Common Applications</h3><p>The 5641AS is commonly used in:</p><ul><li>Digital clocks</li><li>Countdown timers</li><li>Stopwatches</li><li>Frequency counters</li><li>Voltage meters</li><li>Temperature displays</li><li>Electronic scoreboards</li><li>Calculator displays</li><li>Arduino projects</li><li>Embedded systems</li></ul><h3>Key Takeaways</h3><ul><li>A 7-segment display is made of <strong>seven LED segments plus a decimal point</strong>.</li><li>The <strong>5641AS</strong> contains <strong>four 7-segment displays</strong> in one package.</li><li>It is a <strong>Common Cathode</strong> display.</li><li>The display has <strong>12 pins</strong>: eight shared segment pins and four digit-select pins.</li><li>All digits share the same segment connections, reducing the required number of pins.</li><li>The Arduino lights one digit at a time using <strong>multiplexing</strong>.</li><li>Because of <strong>Persistence of Vision</strong>, the four rapidly refreshed digits appear to be continuously illuminated.</li><li>Multiplexing makes four-digit displays practical, efficient, and widely used in electronic devices.</li></ul><h3>Project: Building a 4-Digit Counter with Increment and Decrement Buttons</h3><p>Now that we understand how a 4-digit 7-segment display works, it’s time to put that knowledge into practice.</p><p>One of my first projects using the <strong>5641AS</strong> was creating a <strong>4-digit up/down counter</strong> using an Arduino Uno and two push buttons. Although the project seems simple on the surface, it combines many important concepts in embedded systems.</p><h3>Project Goal</h3><p>The objective was to display a number on the 4-digit display and allow the user to:</p><ul><li>Press one button to <strong>increment</strong> the number.</li><li>Press another button to <strong>decrement</strong> the number.</li><li>Continuously refresh the display using <strong>multiplexing</strong>.</li><li>Keep the display stable without visible flickering.</li></ul><p>For example:</p><pre>0000</pre><pre>↓</pre><pre>Increment Button</pre><pre>0001</pre><pre>↓</pre><pre>Increment Button</pre><pre>0002</pre><pre>↓</pre><pre>...</pre><pre>↓</pre><pre>0099</pre><pre>↓</pre><pre>0100</pre><p>Likewise, pressing the decrement button reduces the displayed number</p><pre>↓</pre><pre>Decrement Button</pre><pre>0099</pre><pre>↓</pre><pre>0098</pre><h3>Components Used</h3><ul><li>Arduino Uno</li><li>5641AS 4-Digit Common Cathode Display</li><li>2 Push Buttons</li><li>8 × 220 Ω resistors (one for each segment line)</li><li>Breadboard</li><li>Jumper wires</li><li>USB cable</li></ul><h3>Concepts Used</h3><p>This project combines nearly everything I’ve learned so far.</p><h3>1. GPIO (General Purpose Input/Output)</h3><p>The Arduino configures:</p><ul><li>Segment pins as <strong>OUTPUT</strong></li><li>Digit pins as <strong>OUTPUT</strong></li><li>Push buttons as <strong>INPUT_PULLUP</strong></li></ul><p>This allows the Arduino to both control the display and read user input.</p><h3>2. Multiplexing</h3><p>The Arduino never turns on all four digits at once.</p><p>Instead it repeatedly performs the following cycle:</p><pre>Display Digit 1</pre><pre>↓</pre><pre>Display Digit 2</pre><pre>↓</pre><pre>Display Digit 3</pre><pre>↓</pre><pre>Display Digit 4</pre><pre>↓</pre><pre>Repeat hundreds of times every second</pre><p>Because this happens so quickly, our eyes see a steady display.</p><h3>3. Breaking a Number into Digits</h3><p>The Arduino stores a single integer, for example:</p><p>int number = 4827;</p><p>Before displaying it, the program separates it into individual digits.</p><p>4827</p><pre>↓</pre><pre>4<br>8<br>2<br>7</pre><p>Each digit is then looked up in a segment table and displayed on its corresponding position.</p><h3>4. Lookup Tables</h3><p>Rather than writing dozens of if statements, the project uses a <strong>lookup table</strong> (usually an array) that stores the segment pattern for each number from <strong>0–9</strong>.</p><p>For example:</p><p>Digit 0 → Segments A B C D E F</p><p>Digit 1 → Segments B C</p><p>Digit 2 → Segments A B D E G</p><p>...</p><p>This makes the code cleaner, easier to read, and much easier to expand.</p><h3>5. Number Limits</h3><p>To prevent invalid values, the project defines limits.</p><p>For example:</p><pre>Minimum</pre><pre>0000</pre><pre>Maximum</pre><pre>9999</pre><p>If the counter reaches <strong>9999</strong>, additional increment presses are ignored (or the value can wrap back to <strong>0000</strong>, depending on the program design).</p><p>Similarly, decrementing below <strong>0000</strong> can either stop at zero or wrap to <strong>9999</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-As5JQRJTsyPW2_8duOgZw.jpeg" /></figure><h3>What I Learned</h3><p>Although this project only displays numbers, it taught me many important embedded programming concepts:</p><ul><li>How LEDs inside a 7-segment display are wired.</li><li>How Common Cathode displays operate.</li><li>Why current-limiting resistors are essential.</li><li>How multiplexing reduces the number of required pins.</li><li>How to use arrays and lookup tables to simplify code.</li><li>How to read push buttons reliably.</li><li>How to manage timing so the display remains bright and flicker-free.</li><li>How software and hardware work together to create responsive electronic systems.</li></ul><h3>Future Improvements</h3><p>This project can be extended in many exciting ways.</p><p>Some ideas include:</p><ul><li>Add a <strong>Reset</strong> button.</li><li>Display hexadecimal values (0–F).</li><li>Build a digital stopwatch.</li><li>Create a countdown timer.</li><li>Display sensor readings such as temperature or distance.</li><li>Use hardware timers for more precise multiplexing.</li><li>Control the display through interrupts for even smoother performance.</li><li>Design a custom PCB containing the display, buttons, and Arduino-compatible microcontroller.</li></ul><h3>Final Thoughts</h3><p>At first glance, a 4-digit 7-segment display seems like a simple collection of LEDs. However, building this project showed me that it involves several fundamental concepts found throughout embedded systems, including GPIO control, multiplexing, timing, arrays, lookup tables, and user input.</p><p>What started as a simple counter became an excellent introduction to designing efficient embedded software. Every time I pressed the increment or decrement button and watched the display update instantly, I wasn’t just changing a number — I was controlling four displays, dozens of LEDs, and precise timing logic through a single microcontroller.</p><p><strong>Links:</strong></p><p><a href="https://github.com/Quantum-Shivi/Arduino-Projects/blob/main/IncrementDecrement4digit7segment/IncrementDecrement4digit7segment.ino">My Code</a></p><p><a href="https://vimeo.com/1212423607?fl=tl&amp;fe=ec">Video of the Project</a></p><p><a href="https://medium.com/the-curious-circuit">Link to my other articles on learning electronics and embedded systems</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e0964206b3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/understanding-the-4-digit-7-segment-display-5e0964206b3c">Understanding the 4-Digit 7-Segment Display</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arduino Basics]]></title>
            <link>https://medium.com/the-curious-circuit/arduino-basics-abf042f752d5?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/abf042f752d5</guid>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[arduino-uno]]></category>
            <category><![CDATA[electronics-engineering]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Sun, 19 Jul 2026 18:57:46 GMT</pubDate>
            <atom:updated>2026-08-06T19:47:17.427Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first started learning electronics, I thought the Arduino was simply a small board that could blink LEDs and read buttons. As I built more projects — from LEDs and photo resistors to LCDs, infrared receivers, and 7-segment displays — I realized something much more interesting:</p><p><strong><em>The Arduino isn’t just a board with pins — it’s a complete embedded computer designed to interact with the real world.</em></strong></p><p>Understanding how an Arduino works internally has made learning electronics much easier. Instead of memorizing functions like digitalWrite() or analogRead(), I now understand what the hardware is actually doing.</p><p>In this post, I’ll explain the Arduino Uno from the ground up, including microcontrollers, memory, ports, communication protocols, interrupts, and the overall architecture.</p><h3>What is Arduino Uno?</h3><p>The <strong>Arduino Uno</strong> is an open-source micro controller<strong> development board</strong> designed for learning embedded systems and building electronic projects.</p><p>The board contains several supporting components such as:</p><ul><li>USB interface</li><li>Power regulation</li><li>Reset circuitry</li><li>LEDs</li><li>Pin headers</li></ul><p>But the most important component is the <strong>ATmega328P microcontroller</strong>, which is the actual computer that runs your program.</p><p>Everything you write in your Arduino sketch is eventually executed by the ATmega328P.</p><h3>Microcontroller vs. Microprocessor</h3><p>One of the first concepts I learned was the difference between a <strong>microcontroller</strong> and a <strong>microprocessor</strong>.</p><p>Although the names sound similar, they are designed for completely different purposes.</p><h3>What is a Microprocessor?</h3><p>A <strong>microprocessor</strong> is primarily a CPU.</p><p>It relies on external hardware such as RAM, storage, and input/output controllers before it can function as a complete computer.</p><p>Examples include:</p><ul><li>Intel Core processors</li><li>AMD Ryzen processors</li><li>Apple M-series processors</li><li>The Broadcom processor inside a Raspberry Pi</li></ul><p>A microprocessor is designed to run operating systems such as Linux, Windows, or macOS.</p><p>Its job is to perform general-purpose computing.</p><p>Examples include:</p><ul><li>Running a web browser</li><li>Editing documents</li><li>Playing videos</li><li>Running artificial intelligence models</li><li>Executing multiple applications simultaneously</li></ul><h3>What is a Microcontroller?</h3><p>A <strong>microcontroller</strong> is a complete computer built onto a single chip.</p><p>Instead of requiring external memory and peripherals, it already contains almost everything needed to run a program.</p><p>Inside the ATmega328P are:</p><ul><li>CPU</li><li>Flash Memory</li><li>SRAM</li><li>EEPROM</li><li>Timers</li><li>Analog-to-Digital Converter (ADC)</li><li>GPIO (General Purpose Input/Output)</li><li>UART</li><li>SPI</li><li>I²C</li></ul><p>Everything needed for embedded programming is already integrated into one chip.</p><p>Microcontrollers are designed for controlling hardware.</p><p>Examples include:</p><ul><li>Reading buttons</li><li>Measuring sensors</li><li>Controlling motors</li><li>Turning LEDs on and off</li><li>Driving LCD displays</li><li>Reading infrared remote controls</li></ul><h3>Arduino vs. Raspberry Pi</h3><p>A simple comparison helped me understand the difference.</p><h3>Arduino Uno</h3><ul><li>Runs one program repeatedly</li><li>No operating system</li><li>Excellent at precise hardware control</li><li>Extremely low power consumption</li></ul><h3>Raspberry Pi</h3><ul><li>Runs Linux</li><li>Can execute many programs simultaneously</li><li>Supports networking, graphics, and multitasking</li><li>Designed more like a desktop computer</li></ul><p>The two devices are often used together in professional projects.</p><p>The Raspberry Pi makes high-level decisions while the Arduino controls hardware in real time.</p><h3>The Arduino Architecture</h3><p>The Arduino Uno is built around the <strong>ATmega328P microcontroller</strong>.</p><p>Inside the microcontroller are several important hardware components that work together to execute your program.</p><p>These include:</p><ul><li>CPU</li><li>Flash Memory</li><li>SRAM</li><li>EEPROM</li><li>GPIO Ports</li><li>Timers</li><li>Interrupt Controller</li><li>ADC</li><li>Communication Peripherals</li></ul><p>Each serves a different purpose.</p><h3>The CPU</h3><p>The CPU (Central Processing Unit) is the brain of the microcontroller.</p><p>Its job is to execute instructions one at a time.</p><p>For example, when you write:</p><p>digitalWrite(13, HIGH);</p><p>The CPU performs the operations necessary to change the electrical voltage on pin 13.</p><p>Every instruction your Arduino executes passes through the CPU.</p><h3>Flash Memory</h3><p>The Arduino Uno contains <strong>32 KB of Flash memory</strong>.</p><p>Flash memory stores your compiled program.</p><p>When you click <strong>Upload</strong>, your code is:</p><ol><li>Compiled into machine code.</li><li>Uploaded into Flash memory.</li><li>Executed by the CPU.</li></ol><p>Flash memory is <strong>non-volatile</strong>, meaning your program remains even after power is removed.</p><h3>SRAM</h3><p>SRAM (Static Random Access Memory) stores variables while your program is running.</p><p>For example:</p><p>int var = 0;</p><p>The variable ‘var’ is stored in SRAM.</p><p>Unlike Flash memory, SRAM is cleared whenever the Arduino loses power.</p><p>The Uno contains <strong>2 KB of SRAM</strong>, so memory management becomes important as projects grow.</p><h3>EEPROM</h3><p>EEPROM is another type of memory inside the ATmega328P.</p><p>Unlike SRAM, EEPROM retains its contents even after power is removed.</p><p>Typical uses include:</p><ul><li>Saving settings</li><li>Calibration values</li><li>High scores</li><li>User preferences</li></ul><p>The Uno provides <strong>1 KB of EEPROM</strong>.</p><h3>Clock Speed</h3><p>The Arduino Uno runs at <strong>16 MHz</strong>.</p><p>This means the processor’s clock ticks <strong>16 million times every second</strong>.</p><p>The clock synchronizes everything inside the microcontroller, including:</p><ul><li>CPU execution</li><li>Timers</li><li>Communication peripherals</li><li>PWM generation</li></ul><h3>Understanding the Pin Layout</h3><p>The Arduino Uno exposes many of the ATmega328P’s pins through convenient headers.</p><p>These pins are divided into two main categories.</p><h3>Digital Pins</h3><p>The Uno contains <strong>14 digital pins (D0–D13)</strong>.</p><p>Digital pins can:</p><ul><li>Read HIGH or LOW</li><li>Output HIGH or LOW</li></ul><p>Some digital pins also provide additional features.</p><h3>UART</h3><ul><li>D0 → RX</li><li>D1 → TX</li></ul><p>Used for Serial communication.</p><h3>External Interrupts</h3><ul><li>D2</li><li>D3</li></ul><p>Used for detecting events immediately.</p><h3>PWM</h3><ul><li>D3</li><li>D5</li><li>D6</li><li>D9</li><li>D10</li><li>D11</li></ul><p>Used for analog-style output using Pulse Width Modulation.</p><h3>SPI</h3><ul><li>D10</li><li>D11</li><li>D12</li><li>D13</li></ul><p>Used for high-speed communication.</p><h3>Analog Pins</h3><p>The Uno contains <strong>6 analog pins</strong>.</p><ul><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4</li><li>A5</li></ul><p>These pins measure voltages between <strong>0 V and 5 V</strong>.</p><p>The built-in Analog-to-Digital Converter converts the measured voltage into a number between <strong>0 and 1023</strong>.</p><p>For example:</p><p>analogRead(A0);</p><p>returns a number proportional to the voltage applied to pin A0.</p><h3>Understanding Ports</h3><p>One concept I found confusing initially was <strong>ports</strong>.</p><p>Arduino names pins individually:</p><ul><li>D2</li><li>D3</li><li>D4</li></ul><p>Internally, however, the ATmega328P groups these pins into <strong>ports</strong>.</p><p>A <strong>port</strong> is simply a collection of pins controlled by the same hardware register.</p><p>The Uno contains three GPIO ports.</p><h3>PORTD</h3><p>Controls:</p><ul><li>D0</li><li>D1</li><li>D2</li><li>D3</li><li>D4</li><li>D5</li><li>D6</li><li>D7</li></ul><h3>PORTB</h3><p>Controls:</p><ul><li>D8</li><li>D9</li><li>D10</li><li>D11</li><li>D12</li><li>D13</li></ul><h3>PORTC</h3><p>Controls:</p><ul><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4</li><li>A5</li></ul><p>Professional embedded programmers often manipulate entire ports simultaneously because doing so is significantly faster than calling digitalWrite() multiple times.</p><h3>Communication Interfaces</h3><p>The Arduino contains several dedicated communication peripherals.</p><h3>UART</h3><p>Pins:</p><ul><li>D0 (RX)</li><li>D1 (TX)</li></ul><p>Used for:</p><ul><li>Serial Monitor</li><li>Bluetooth</li><li>GPS modules</li><li>Communication with computers</li></ul><h3>I²C</h3><p>Pins:</p><ul><li>A4 (SDA)</li><li>A5 (SCL)</li></ul><p>Uses only two wires.</p><p>Common devices include:</p><ul><li>LCD Displays</li><li>Temperature Sensors</li><li>EEPROM chips</li><li>Real-Time Clock modules</li></ul><p>Each device has its own address, allowing many devices to share the same two wires.</p><h3>SPI</h3><p>Pins:</p><ul><li>D10</li><li>D11</li><li>D12</li><li>D13</li></ul><p>SPI is much faster than I²C and is commonly used for:</p><ul><li>SD cards</li><li>TFT displays</li><li>Flash memory</li><li>High-speed sensors</li></ul><h3>Understanding Interrupts</h3><p>Normally, the Arduino repeatedly executes the loop() function.</p><p>Suppose you are reading an IR remote.</p><p>The pulses may only last a few hundred microseconds.</p><p>If your program is busy doing something else, it could completely miss those pulses.</p><p>This is where <strong>interrupts</strong> become useful.</p><p>An interrupt tells the processor:</p><p><em>“Stop what you’re doing because something important just happened.”</em></p><p>The CPU immediately pauses its current work, executes a special function called an <strong>Interrupt Service Routine (ISR)</strong>, and then returns exactly where it left off.</p><p>This allows the Arduino to respond almost instantly to important events.</p><p>Interrupts are commonly used for:</p><ul><li>Push buttons</li><li>IR receivers</li><li>Rotary encoders</li><li>Timers</li><li>Communication peripherals</li></ul><p>Without interrupts, the CPU would have to constantly check every input, wasting valuable processing time.</p><h3>How an Arduino Program Runs</h3><p>Every Arduino sketch follows the same sequence.</p><ol><li>The board powers on.</li><li>The bootloader starts.</li><li>setup() runs once.</li><li>loop() executes repeatedly forever.</li><li>If an interrupt occurs, the CPU pauses loop(), runs the ISR, and then continues where it left off.</li></ol><p>This simple execution model makes Arduino programming both easy to understand and extremely powerful.</p><h3>Why Learning the Architecture Matters</h3><p>Before learning about the Arduino’s architecture, I mostly memorized functions.</p><p>Now I understand <strong>why</strong> they work.</p><p>I know:</p><ul><li>where my program is stored,</li><li>where variables live,</li><li>how sensors communicate,</li><li>why interrupts are needed,</li><li>how analog voltages become numbers,</li><li>and why communication protocols such as UART, SPI, and I²C exist.</li></ul><p>Understanding these concepts has helped me think more like an embedded systems engineer instead of simply following tutorials.</p><h3>My First Arduino Project: Blinking an LED</h3><p>No Arduino journey is complete without the classic <strong>Blink</strong> project.</p><p>Although blinking an LED looks incredibly simple, it introduces several fundamental concepts that you’ll use in almost every embedded project:</p><ul><li>Digital outputs</li><li>GPIO pins</li><li>Program structure (setup() and loop())</li><li>Timing</li><li>The compilation and upload process</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPDSxFvrCiveQpAWfgsWiQ.jpeg" /><figcaption>My First Arduino Circuit</figcaption></figure><h3>Components Required</h3><ul><li>Arduino Uno</li><li>Breadboard</li><li>LED</li><li>220 Ω resistor</li><li>Jumper wires</li><li>USB cable</li></ul><h3>Circuit</h3><p>The circuit is surprisingly simple.</p><p>Connect:</p><ul><li>Arduino <strong>Digital Pin 13</strong> → <strong>220 Ω resistor</strong></li><li>Resistor → <strong>Positive (long) leg of the LED</strong></li><li>Negative (short) leg of the LED → <strong>GND</strong></li></ul><h3><strong>Final Thoughts</strong></h3><p>The Arduino Uno may look like a simple board with a few pins, but inside it is a complete embedded computer capable of interacting with the physical world.</p><p>Learning its architecture has given me a much deeper appreciation for how electronics and software work together.</p><p>More importantly, these concepts are not limited to Arduino. Whether you’re programming an STM32, ESP32, Raspberry Pi Pico, or another microcontroller, you’ll encounter the same fundamental ideas:</p><ul><li>CPUs</li><li>Memory</li><li>GPIO</li><li>Timers</li><li>Interrupts</li><li>Communication protocols</li></ul><p>Arduino is simply one of the best places to begin that journey.</p><p><a href="https://medium.com/the-curious-circuit">Link to my other articles on learning electronics and embedded systems</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abf042f752d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/arduino-basics-abf042f752d5">Arduino Basics</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Basics of Electricity and Magnetism]]></title>
            <link>https://medium.com/the-curious-circuit/understanding-the-basics-of-electricity-and-magnetism-5191dae62f1f?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/5191dae62f1f</guid>
            <category><![CDATA[electromagnetism]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[electronics-engineering]]></category>
            <category><![CDATA[magnetism]]></category>
            <category><![CDATA[circuit]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Sat, 18 Jul 2026 05:44:03 GMT</pubDate>
            <atom:updated>2026-08-06T19:46:39.704Z</atom:updated>
            <content:encoded><![CDATA[<p>Before diving into circuits, sensors, and microcontrollers, I wanted to understand the fundamental concepts that make electronics work. Everything from LEDs to electric motors relies on a few core ideas. In this post, I’ll summarize the concepts I learned while beginning my journey into electronics.</p><h3>1. Electric Current</h3><p>Current is the <strong>flow of electric charge through a conductor</strong>, such as a copper wire. In metal wires, this charge is carried by <strong>electrons</strong> moving through the material.</p><p>Current is measured in <strong>amperes (A)</strong>.</p><p>One ampere means that one coulomb of charge passes through a point in the circuit every second.</p><p>You can think of current like the flow of water through a pipe — the more water flowing each second, the greater the current.</p><h3>2. Voltage</h3><p>Voltage is the <strong>electrical force that pushes electrons through a circuit</strong>.</p><p>Without voltage, electrons have no reason to move, so no current flows.</p><p>Voltage is measured in <strong>volts (V)</strong>.</p><p>A battery provides voltage by creating a difference in electrical potential between its positive and negative terminals.</p><p>An easy analogy is water pressure in a pipe. Pressure pushes the water forward, just as voltage pushes electric charge through a circuit.</p><h3>3. Resistance</h3><p>Resistance is a property that <strong>opposes the flow of electric current</strong>.</p><p>Every material resists the movement of electrons to some extent. Components called <strong>resistors</strong> are specifically designed to limit current and protect other components in a circuit.</p><p>Resistance is measured in <strong>ohms (Ω)</strong>.</p><p>The higher the resistance, the harder it is for current to flow.</p><h3>4. Electric Charge</h3><p>Charge is a fundamental property carried by particles such as electrons and protons.</p><ul><li>Electrons carry <strong>negative charge</strong>.</li><li>Protons carry <strong>positive charge</strong>.</li></ul><p>Charge is measured in <strong>coulombs ( C ).</strong></p><p>Electric current is simply the movement of this charge through a conductor.</p><h3>5. The Current Equation</h3><p>Current is defined by the equation:</p><p>I = Q/t</p><p>where:</p><ul><li><strong>I</strong> = Current (amperes)</li><li><strong>Q</strong> = Charge (coulombs)</li><li><strong>t</strong> = Time (seconds)</li></ul><p>This equation tells us <strong>how much electric charge passes through a wire every second</strong>.</p><p>For example, if 5 coulombs of charge pass through a wire in one second, the current is:</p><p>I = 5C/1sec = 5A</p><p>This equation helped me understand what current actually represents instead of simply memorizing its unit.</p><h3>6. Magnetic Fields</h3><p>A magnetic field is the <strong>region around a magnet where magnetic forces can act</strong>.</p><p>Although magnetic fields are invisible, their effects are easy to observe. They can attract magnetic materials like iron and influence other magnets nearby.</p><p>Every magnet is surrounded by its own magnetic field.</p><h3>7. Magnetic Poles</h3><p>Every magnet has two poles:</p><ul><li>North</li><li>South</li></ul><p>The rule is simple:</p><ul><li><strong>Opposite poles attract.</strong></li><li><strong>Like poles repel.</strong></li></ul><p>This simple rule explains many everyday interactions between magnets.</p><h3>8. Permanent Magnets vs. Electromagnets</h3><p>Not all magnets work the same way.</p><h3>Permanent Magnets</h3><p>Permanent magnets remain magnetic all the time.</p><p>Examples include refrigerator magnets and compass needles.</p><h3>Electromagnets</h3><p>Electromagnets only become magnetic <strong>when electric current flows through a wire</strong>.</p><p>When the current stops, the magnetic field disappears.</p><p>This makes electromagnets incredibly useful because they can be turned on and off whenever needed.</p><h3>9. Current Creates Magnetic Fields</h3><p>One of the most interesting discoveries I learned is that <strong>electric current creates a magnetic field</strong>.</p><p>The greater the current flowing through a wire, the stronger the magnetic field around it.</p><p>This relationship forms the basis of many devices we use every day, including:</p><ul><li>Electric motors</li><li>Speakers</li><li>Relays</li></ul><p>It is amazing that simply moving electrons through a wire can create an invisible magnetic field.</p><h3>10. Building My First Electromagnet</h3><p>To see this concept in action, I built a simple electromagnet.</p><h3>Materials</h3><ul><li>One iron nail</li><li>Insulated copper wire</li><li>One AA battery</li><li>Paperclips</li></ul><p>I wrapped the insulated copper wire tightly around the nail several times and connected the ends of the wire to a AA battery.</p><p>As soon as current began flowing through the wire, the nail became magnetic and was able to pick up paperclips.</p><p>When I disconnected the battery, the nail immediately lost its magnetism.</p><p>This simple experiment demonstrated that electricity and magnetism are closely connected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*uHdSUdxBmLM4clAR-tbSjA.png" /><figcaption>The Electromagnet</figcaption></figure><h3>What I Learned</h3><p>Learning electronics starts with understanding a few simple ideas:</p><ul><li>Current is the movement of electric charge.</li><li>Voltage provides the push that makes current flow.</li><li>Resistance limits that flow.</li><li>Charge is measured in coulombs and current measures how quickly charge moves.</li><li>Moving electric charge creates magnetic fields.</li><li>Electromagnets use electricity to create temporary magnets.</li></ul><p>These concepts may seem simple on their own, but together they form the foundation of nearly everything in electronics. Understanding them has made it much easier for me to understand circuits, LEDs, motors, sensors, and everything else I plan to build as I continue this journey.</p><p><a href="https://medium.com/the-curious-circuit">Link to my other articles on learning electronics and embedded systems</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5191dae62f1f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/understanding-the-basics-of-electricity-and-magnetism-5191dae62f1f">Understanding the Basics of Electricity and Magnetism</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Curious Teen’s Electronics Journal]]></title>
            <link>https://medium.com/@curiousshivi/a-curious-teens-electronics-journal-d4b34a5a6001?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4b34a5a6001</guid>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[circuit]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Sat, 18 Jul 2026 05:38:52 GMT</pubDate>
            <atom:updated>2026-08-06T19:50:40.724Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A curious teens electronics journal" src="https://cdn-images-1.medium.com/max/1024/1*LLpqB3g1ZvAQz6LpkPGVCA.jpeg" /></figure><p>One day, I looked at a simple LED glowing on a breadboard that my dad built — and wondered:</p><p><strong>“How does this tiny light know when to turn on?”</strong></p><p>That one question led to another… and another… and before I knew it, I had fallen down the rabbit hole of electronics.</p><p>I’m not an expert. I’m just a curious teenager who loves asking <em>why</em>. Instead of only building projects, I want to understand what happens inside every wire, resistor, transistor, and microchip.</p><p>This journal is where I document everything I learn, from my very first circuits to designing my own PCB’s and building real hardware. Every lesson, experiment, mistake, and breakthrough will be linked here as I continue this journey with my dad.</p><p>If you’re learning electronics too, I hope my notes make your journey a little easier.</p><p>Below you’ll find links to every lesson, experiment, and project I’ve done, documented, from the fundamentals of electricity to more advanced topics as I continue to learn.</p><p>Whether you’re following along from the beginning or jumping into a specific topic, I hope these notes and experiments help make electronics a little easier to understand.</p><p>Below, I also have linked my GitHub Repository, where I have uploaded all my project details and code.</p><p><a href="https://github.com/Quantum-Shivi/Arduino-Projects">GitHub Repository</a></p><p><a href="https://medium.com/the-curious-circuit?source=following_feed--------------------------------------------">Blog Posts</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4b34a5a6001" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Verifying Kirchhoff’s Current Law (KCL) with a Parallel Circuit]]></title>
            <link>https://medium.com/the-curious-circuit/verifying-kirchhoffs-current-law-kcl-with-a-parallel-circuit-9383c477bfc1?source=rss-120236db00ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/9383c477bfc1</guid>
            <category><![CDATA[kirchhoffs-current-law]]></category>
            <category><![CDATA[circuit]]></category>
            <category><![CDATA[parallel-circuit]]></category>
            <category><![CDATA[electronics-engineering]]></category>
            <category><![CDATA[kirchhoff]]></category>
            <dc:creator><![CDATA[Shivangsh Roy]]></dc:creator>
            <pubDate>Fri, 17 Jul 2026 01:52:32 GMT</pubDate>
            <atom:updated>2026-08-06T19:46:13.199Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most fundamental principles in electrical engineering is <strong>Kirchhoff’s Current Law (KCL)</strong>. While it is easy to memorize the equation, I wanted to verify it experimentally using a simple parallel circuit and a digital multi-meter.</p><p>Instead of simply accepting the law, I built the circuit, made predictions, and compared them with real measurements.</p><h3>The Circuit</h3><p>For this experiment, I built a parallel circuit consisting of:</p><ul><li>9V battery</li><li>Two identical branches</li><li>Each branch contains:</li><li>Two 220 Ω resistors connected in series</li><li>One red LED</li><li>Breadboard and jumper wires</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*pd0q69rshJb_JUmSBJGd-g.png" /><figcaption>Circuit Schematic</figcaption></figure><p>Each branch has the same resistance and the same LED, so I expected the current to split evenly between the two branches.</p><h3>What is Kirchhoff’s Current Law?</h3><p>Kirchhoff’s Current Law states:</p><p><strong><em>The total current entering a junction is equal to the total current leaving the junction.</em></strong></p><p>In equation form:</p><p>Total Current = Current of 1st Branch + Current of 2nd Branch + …</p><p>This law is based on a simple but powerful idea:</p><p><strong>Electric charge cannot suddenly appear or disappear at a junction.</strong></p><p>If 30 mA enters a node, then exactly 30 mA must leave that node through one or more branches.</p><h3>My Prediction</h3><p>Since both branches are identical:</p><ul><li>Same resistance</li><li>Same LED</li><li>Same supply voltage</li></ul><p>I predicted that:</p><ul><li>Each branch would carry approximately the same current.</li><li>The total current supplied by the battery would equal the sum of the currents in both branches.</li></ul><h3>Experiment</h3><p>To verify KCL, I measured:</p><ol><li>The current flowing through <strong>Branch 1</strong>.</li><li>The current flowing through <strong>Branch 2</strong>.</li><li>The <strong>total current</strong> supplied by the battery before the current split into the two branches.</li></ol><p>Using a digital multi-meter in current mode, I inserted the meter <strong>in series</strong> with the section of the circuit being measured each time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07YPralpLrNG6NDh09Ms5w.jpeg" /><figcaption>Branch Current Measure (same in Branch 1 and 2)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2OM9-_dWBJuBmP_G6xwT9w.jpeg" /><figcaption>Battery Supply Current</figcaption></figure><h3>Results</h3><p>After measuring the currents, I compared the values.</p><p>The result was exactly what Kirchhoff’s Current Law predicts:</p><p>Total Current = Current of 1st Branch + Current of 2nd Branch</p><p>Within normal measurement tolerance, the sum of the branch currents matched the total current supplied by the battery.</p><p>This experimentally confirmed Kirchhoff’s Current Law.</p><h3>Why Does This Happen?</h3><p>At the junction, the current doesn’t disappear or get used up. Instead, it <strong>splits</strong> between the available paths.</p><p>Since both branches in my circuit are identical, they have the same resistance. As a result, the current divides almost equally between them.</p><p>If one branch had a lower resistance than the other, it would carry a larger share of the current, but the total current would still satisfy:</p><p>Total Current = Current of 1st Branch + Current of 2nd Branch</p><p>No matter how the current divides, the amount entering the junction always equals the amount leaving it.</p><h3>What I Learned</h3><p>This experiment showed that Kirchhoff’s Current Law is much more than a formula in a textbook — it accurately describes what happens in a real electrical circuit.</p><p>By measuring the current in each branch and comparing it to the total current entering the junction, I was able to experimentally verify that electric charge is conserved.</p><p>Combined with my earlier experiments verifying <strong>Ohm’s Law</strong> and <strong>Kirchhoff’s Voltage Law (KVL)</strong>, this experiment completed the three fundamental principles that form the foundation of basic circuit analysis.</p><p>Sometimes the best way to understand a law isn’t by reading about it — it’s by building a circuit, making predictions, and seeing the measurements confirm the theory.</p><p><a href="https://medium.com/the-curious-circuit">Link to my other articles on learning electronics and embedded systems</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9383c477bfc1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-curious-circuit/verifying-kirchhoffs-current-law-kcl-with-a-parallel-circuit-9383c477bfc1">Verifying Kirchhoff’s Current Law (KCL) with a Parallel Circuit</a> was originally published in <a href="https://medium.com/the-curious-circuit">the-curious-circuit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>