<?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"><channel><title><![CDATA[DigiCirq]]></title><description><![CDATA[Electronics, explained one circuit at a time. Written companions to the DigiCirq YouTube Shorts: pull-ups, debouncing, 555 timers, flip-flops, Arduino internals]]></description><link>https://digicirq.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6af40a0e4d90c3845e28c9df/3e9417bd-a275-4939-bf59-9bcb8c14e5b0.png</url><title>DigiCirq</title><link>https://digicirq.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 09:30:01 GMT</lastBuildDate><atom:link href="https://digicirq.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[WhatsApp Ticks Explained: One Grey, Two Grey, Two Blue, and Why Blue Doesn't Always Mean Read]]></title><description><![CDATA[One tick is the server, two is the phone, blue is the eyes. How delivery and read receipts travel, why two grey ticks sit for days, how to read without…]]></description><link>https://digicirq.hashnode.dev/whatsapp-ticks-explained-one-grey-two-grey-two-blue-and-why-blue-doesn-t-always-mean-read</link><guid isPermaLink="true">https://digicirq.hashnode.dev/whatsapp-ticks-explained-one-grey-two-grey-two-blue-and-why-blue-doesn-t-always-mean-read</guid><category><![CDATA[System Design]]></category><category><![CDATA[networking]]></category><category><![CDATA[technology]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 07:05:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/d1a23e28-6b97-4ae6-903a-3d0190a8e31d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>One tick is the server, two is the phone, blue is the eyes. How delivery and read receipts travel, why two grey ticks can sit for days, and how to read without blue.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=5Z9cBKU1wBQ">https://www.youtube.com/watch?v=5Z9cBKU1wBQ</a></p>

<p>Two grey ticks. Still two grey ticks. The message has been "delivered" for a day and a half, and you're drafting theories. Before you settle on one, it helps to know exactly what each tick is actually reporting, because each one comes from a different machine.</p>
<h2>What do the WhatsApp ticks mean?</h2>
<p>Each tick is an <strong>acknowledgement</strong> that came back along the path your message took. Three different things can acknowledge it.</p>
<ul>
<li><strong>Clock icon:</strong> your phone hasn't managed to send it yet. You're offline, or the app is still connecting.</li>
<li><strong>One grey tick:</strong> WhatsApp's <strong>server</strong> has your message. It's left your phone. Nothing is known about the recipient's phone.</li>
<li><strong>Two grey ticks:</strong> the recipient's <strong>phone</strong> has received it. Not the person: the device. The app on their phone fetched the message and sent a receipt back up to the server, which passed it to you.</li>
<li><strong>Two blue ticks:</strong> the recipient's app has <strong>shown it on screen</strong> in an open chat, and sent a read receipt back the same way.</li>
</ul>
<p>That's it. Three machines reporting in: server, their phone, their chat window.</p>
<h2>Why does WhatsApp only show one tick?</h2>
<p>Because the message is sitting on the server waiting for their phone to collect it. WhatsApp can't push a message to a phone that isn't connected. One tick means: their phone has had no internet since you sent it, or it's off, or the battery's dead, or they've blocked you (a blocked sender's messages never get delivered, so they stay on one tick forever).</p>
<p>Delivery is the phone's job, not the server's. The server simply holds the message, encrypted, and hands it over the next time the phone checks in. If that never happens, after about <strong>30 days</strong> the undelivered message is deleted.</p>
<h2>Why two grey ticks but not blue?</h2>
<p>Because delivery and reading are two different events, and only the first one is automatic.</p>
<p>Two grey ticks fire as soon as the app on their phone receives the message, which happens in the background, with the screen off, while they're asleep. It doesn't mean they looked at the phone. It means their phone was online. Hence "delivered at 03:14".</p>
<p>Blue requires the chat to be <strong>opened</strong>. Not the notification, not the chat list: the actual conversation, on screen, with the message visible. Until that happens, the receipt isn't generated, and it can't be, because the phone doesn't know they've read it.</p>
<h2>Can someone read a message without the ticks turning blue?</h2>
<p>Yes, in several ways, and this is the part the theories miss.</p>
<ul>
<li><strong>Read receipts off.</strong> In settings, anyone can turn off read receipts. Their ticks stay grey forever, and in exchange they don't see yours either. (Group chats ignore this setting: in a group, the ticks go blue when <strong>every</strong> member has read it, which is why group ticks are so slow.)</li>
<li><strong>The notification.</strong> The whole message is visible in the notification shade and on the lock screen. No chat opened, no receipt sent.</li>
<li><strong>The widget / preview.</strong> Same thing: WhatsApp's home-screen widget shows messages without opening the chat.</li>
<li><strong>Airplane mode.</strong> Open the chat offline, read, close the chat, then force-quit the app before reconnecting. The read receipt never gets sent. It's a well-known trick precisely because it works.</li>
</ul>
<p>So two grey ticks means "their phone has it". It does not mean "they haven't seen it".</p>
<h2>Why can't the server just tell me when they read it?</h2>
<p>Because the server can't read anything. WhatsApp is <strong>end-to-end encrypted</strong>: the message leaves your phone as ciphertext that only the recipient's phone can decrypt. The server shuffles sealed envelopes. It knows an envelope was accepted by a phone (delivery) only because that phone sent back a tiny signed receipt. It knows it was read only because the phone sent another one. The ticks are the phone volunteering information, which is exactly why the phone can also decline to.</p>
<h2>Does WhatsApp notify screenshots or show who's online?</h2>
<p>Screenshots: no, except for "view once" photos, where a screenshot is blocked rather than reported. Online status: yes, by default, "online" and "last seen" are visible, but both can be hidden in privacy settings, and hiding them doesn't affect the ticks.</p>
<p>The ticks are honest about what they know and silent about what they don't. One tick: the server has it. Two: a phone has it. Blue: a chat window had it open. Everything beyond that is you, not the app.</p>
<blockquote>
<p><strong>Quick reference:</strong> Clock = still on your phone · 1 grey = on the server · 2 grey = on their phone · 2 blue = chat opened. Grey for days = phone offline, or blocked. Delivered but never blue = read receipts off, or read from the notification.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[What Does “Rate Limited” Mean? (Twitter, Discord, APIs and the 429 Error Explained)]]></title><description><![CDATA[Rate limited means you sent requests faster than the service allows, so it refused some. What the 429 error is, how token buckets count, and why apps do…]]></description><link>https://digicirq.hashnode.dev/what-does-rate-limited-mean-twitter-discord-apis-and-the-429-error-explained</link><guid isPermaLink="true">https://digicirq.hashnode.dev/what-does-rate-limited-mean-twitter-discord-apis-and-the-429-error-explained</guid><category><![CDATA[System Design]]></category><category><![CDATA[backend]]></category><category><![CDATA[api]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 07:02:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/058ce9b4-8bba-43d0-a260-e36beab0ca07.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Rate limited means you sent requests faster than the service allows, so it refused some. What the 429 error is, how token buckets count, and why apps do it on purpose.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=OtMpt9uBURs">https://www.youtube.com/watch?v=OtMpt9uBURs</a></p>

<p>You scroll, you refresh, you tap a bit too enthusiastically, and the app stops: "You are being rate limited." Or "Rate limit exceeded." Or nothing loads for a minute and then everything is fine again. You weren't banned. You weren't hacked. You hit a counter.</p>
<h2>What does "rate limited" mean?</h2>
<p><strong>Rate limiting</strong> means a service has a cap on how many requests it will accept from you in a given window of time, and you went over it. Every time your phone asks the server for something (a feed refresh, a message send, a search) that's one request. The server keeps a tally per user, per account, per IP address, or per app. Cross the line and the next requests are refused until the window rolls over. Usually that's seconds; sometimes it's minutes; in Twitter's July 2023 "rate limit exceeded" episode, it was a hard daily cap on how many posts you could read at all.</p>
<p>On the web, the refusal has a name: HTTP status <strong>429 Too Many Requests</strong>. Well-behaved servers send it with a <code>Retry-After</code> header saying how long to wait, and well-behaved apps read that header and wait.</p>
<h2>Why do apps rate limit on purpose?</h2>
<p>Four reasons, and they're all about the server, not about you.</p>
<p><strong>Capacity.</strong> A server can handle a finite number of requests per second. If one user, one bot or one buggy script can send ten thousand a second, everyone else's experience depends on that one client's manners. A limit converts "first come, first served" into "everyone gets a fair share".</p>
<p><strong>Cost.</strong> Each request costs CPU, bandwidth and sometimes a paid downstream call. A limit is a budget.</p>
<p><strong>Abuse.</strong> Password guessing, scraping, spam, buying up every ticket. All of them look like one account doing something normal, far too fast. A limit of five login attempts a minute makes brute-forcing a password take years instead of hours.</p>
<p><strong>Protection from mistakes.</strong> The most common thing that gets rate limited isn't an attacker; it's a developer's script stuck in a loop. A limit turns an outage into a 429.</p>
<h2>How does the server count?</h2>
<p>A few standard algorithms, from simplest to most common.</p>
<p><strong>Fixed window.</strong> Count requests per minute. At the top of each minute, reset to zero. Simple, but it has an edge problem: 100 requests at 11:59:59 and another 100 at 12:00:00 is 200 requests in two seconds, all allowed.</p>
<p><strong>Sliding window.</strong> Count requests in the last 60 seconds from <em>right now</em>. Fixes the edge problem at the cost of remembering timestamps.</p>
<p><strong>Token bucket.</strong> The one most big services use. Imagine a bucket that holds, say, 100 tokens. Tokens drip into it at a fixed rate, 10 per second. Each request takes one token; if the bucket is empty, the request is refused. The beauty is that it allows <strong>bursts</strong> (you can spend all 100 at once if you've been quiet) while still enforcing an average (10 per second over the long run). Tapping refresh twenty times in a row is fine; doing it for a solid minute is not.</p>
<p><strong>Leaky bucket.</strong> The mirror image: requests pour in, and they're let out at a steady rate. Smooths traffic instead of allowing bursts.</p>
<p>In practice the counters live in a fast in-memory store like <strong>Redis</strong>. The pattern for a fixed window is two commands: increment the key <code>user:123:minute:1699999980</code> and set it to expire in 60 seconds. One round trip, a few microseconds, and every server in the fleet shares the same count.</p>
<h2>Why does Discord rate limit me for sending messages?</h2>
<p>Because sending messages is the thing bots abuse most. Discord's limits are per channel and per action: send too many messages, reactions or edits in a few seconds and the client tells you to slow down. It's the same reason a game won't let you spam chat. The limit is tuned so that typing like a human never trips it and pasting a loop does.</p>
<h2>How do I avoid being rate limited?</h2>
<p>If you're a user: stop tapping, wait the time it tells you, and if you're on a shared network (an office, a university, a VPN) remember that everyone behind that one IP address may be sharing a bucket.</p>
<p>If you're writing code against an API:</p>
<ol>
<li>Read the limits in the docs before you write the loop.</li>
<li>Check for 429 and honour <code>Retry-After</code>.</li>
<li>Back off exponentially: wait 1 s, then 2, then 4, then 8, with a little random jitter so a thousand clients don't all retry at the same instant.</li>
<li>Cache. The fastest request is the one you don't make.</li>
</ol>
<p>Rate limiting isn't the service being difficult. It's the service staying up, for you and for everyone sharing it, by making the one rule that scales: nobody gets to go faster than their share.</p>
<blockquote>
<p><strong>Quick reference:</strong> 429 = too many requests, try later · 403 = you're not allowed at all · 503 = the server itself is overloaded. Only the first one is about your rate.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[How Does an Arduino Actually Work? From Your Sketch to One Pin Going HIGH]]></title><description><![CDATA[What happens between digitalWrite(13, HIGH) and 5 V on a pin: the compiler, the upload, the bootloader, the ATmega328P, and the one bit in one register…]]></description><link>https://digicirq.hashnode.dev/how-does-an-arduino-actually-work-from-your-sketch-to-one-pin-going-high</link><guid isPermaLink="true">https://digicirq.hashnode.dev/how-does-an-arduino-actually-work-from-your-sketch-to-one-pin-going-high</guid><category><![CDATA[Electronics]]></category><category><![CDATA[microcontroller]]></category><category><![CDATA[arduino]]></category><category><![CDATA[embedded systems]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 06:59:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/77f9fee2-4bcb-4b10-8770-ec42f6f91de2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>What happens between digitalWrite(13, HIGH) and 5 volts on a pin: the compiler, the upload, the bootloader, the ATmega328P, and the one bit in one register that does it.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=27VT0bMY5Zw">https://www.youtube.com/watch?v=27VT0bMY5Zw</a></p>

<p>Blink is the first program everyone runs. Two lines: set pin 13 HIGH, wait, set it LOW, wait. An LED blinks and you move on. Which is a shame, because between <code>digitalWrite(13, HIGH)</code> and the LED lighting up there is an entire computer doing something you can actually follow, bit by bit, all the way down.</p>
<h2>What is a microcontroller, in an easy way?</h2>
<p>A <strong>microcontroller</strong> is a complete computer on one chip: processor, program memory, RAM and the input/output pins, all in one package, with no operating system. The Arduino Uno's chip is the <strong>ATmega328P</strong>, a 28-pin part with 32 KB of flash for your program, 2 KB of RAM, and an 8-bit CPU ticking at 16 MHz.</p>
<p>That's the whole difference between a microcontroller and a <strong>microprocessor</strong>. A Raspberry Pi's chip is a microprocessor: it needs external RAM, an SD card for storage, and Linux to boot, and it runs your program as one of hundreds. The ATmega runs <strong>one program</strong>, yours, starting the instant power arrives, with nothing in between. That's why an Arduino can toggle a pin in a few nanoseconds of certainty and a Pi can't promise anything about timing at all.</p>
<h2>Is Arduino just C++?</h2>
<p>Yes. The "Arduino language" is C++ with a library and a small amount of pre-processing. When you click Upload, the IDE takes your sketch, adds <code>#include &lt;Arduino.h&gt;</code> at the top, generates prototypes for your functions, and hands the result to <strong>avr-gcc</strong>, the standard GNU C++ compiler built for AVR chips. Your <code>setup()</code> and <code>loop()</code> are ordinary functions. The library supplies the <code>main()</code> you never see:</p>
<pre><code class="language-cpp">int main() {
  init();      // start the timers that millis() and PWM use
  setup();     // yours, once
  for (;;) {
    loop();    // yours, forever
  }
}
</code></pre>
<p><code>loop()</code> repeats because it's called inside an infinite <code>for</code>. There's no scheduler, no operating system. When <code>loop()</code> returns, <code>main()</code> calls it again. Forever.</p>
<h2>How does the code get onto the chip?</h2>
<p>The compiler produces a <code>.hex</code> file: the raw bytes of machine code. Now it has to reach the chip's flash memory, and the chip is in the middle of running whatever was there before.</p>
<p>The IDE runs <strong>avrdude</strong>, which talks over the USB cable. On an Uno, USB doesn't go to the ATmega328P directly; it goes to a second, smaller chip (an ATmega16U2) that pretends to be a serial port. avrdude first toggles the serial port's DTR line, which, through a 100 nF capacitor, yanks the 328P's reset pin low for a moment. The chip <strong>reboots</strong>.</p>
<p>The first thing it runs after reset isn't your program. It's the <strong>bootloader</strong> (Optiboot), half a kilobyte of code living at the top of flash, which listens on the serial pins for about a second. If avrdude shows up speaking the STK500 protocol, the bootloader accepts the new program page by page, writes it into flash, and jumps to it. If nobody shows up, it jumps to whatever program is already there. That one-second pause after you press reset is the bootloader waiting to be told what to do.</p>
<h2>What does digitalWrite actually do?</h2>
<p>Now the LED. Your program is running. It calls <code>digitalWrite(13, HIGH)</code>.</p>
<p>The 328P doesn't know about "pin 13". It has three <strong>ports</strong>, B, C and D, each a group of up to eight pins, and each port is controlled by a handful of memory-mapped registers. Pin 13 on the Uno board is wired to <strong>PB5</strong>: port B, bit 5. The Arduino library keeps lookup tables in flash that translate 13 into "port B, bit 5", and then does, in effect:</p>
<pre><code class="language-cpp">PORTB |= (1 &lt;&lt; 5);   // set bit 5 of the PORTB register
</code></pre>
<p><code>PORTB</code> is a byte at a fixed address in the chip's memory. Writing a 1 to its bit 5 is the entire operation. On the far side of that register, a pair of transistors connects the physical pin to 5 V (for a 1) or to ground (for a 0). Those transistors can source or sink about 40 mA at most, which is why you put a resistor in series with the LED: the pin is a switch, not a battery.</p>
<p>The lookup, the port read-modify-write and the checks inside <code>digitalWrite()</code> take around <strong>4 microseconds</strong> on an Uno. Write to the register directly and it takes one clock cycle, 62.5 nanoseconds. Same bit, same transistors; the library just takes the scenic route so that "13" means the same thing on every board.</p>
<h2>How does delay() work if there's no operating system?</h2>
<p>Because the chip has hardware <strong>timers</strong>. <code>init()</code> set up Timer 0 to overflow every 1.024 ms and fire an <strong>interrupt</strong>: a hardware event that pauses your code, runs a tiny function that adds one to a counter, and resumes. That counter is <code>millis()</code>. <code>delay(1000)</code> just spins in a loop reading <code>millis()</code> until it has grown by 1000. The CPU is doing nothing useful during that second, which is why <code>delay()</code> is the thing you outgrow first.</p>
<h2>What are the 28 pins of the ATmega328P?</h2>
<p>Twenty-three are I/O: port B (8), port C (7, of which six double as the analogue inputs A0 to A5), and port D (8, including the two serial pins). The other five are power and ground, the analogue reference, and two for the 16 MHz crystal. Every "digital pin 7" or "A3" on the board is just one of those 23, given a friendlier name by the silkscreen and a lookup table.</p>
<p>That's the whole trip. C++ to machine code, serial cable to bootloader, bootloader to flash, <code>digitalWrite</code> to <code>PORTB</code>, bit 5 to two transistors, transistors to 5 V, 5 V through a resistor to an LED. Nothing in it is magic, and all of it is yours to touch.</p>
<blockquote>
<p><strong>Try it:</strong> Replace <code>digitalWrite(13, HIGH); digitalWrite(13, LOW);</code> in a loop with <code>PORTB |= (1 &lt;&lt; 5); PORTB &amp;= ~(1 &lt;&lt; 5);</code> and watch pin 13 on a scope. The square wave goes from roughly 100 kHz to several MHz. That's the library's overhead, made visible.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[What Is a Flip-Flop Circuit? SR, D, JK and T Flip-Flops Explained]]></title><description><![CDATA[A flip-flop is one bit of memory made from two gates that feed each other. How the SR latch holds a value, what the clock adds, and what D, JK and T…]]></description><link>https://digicirq.hashnode.dev/what-is-a-flip-flop-circuit-sr-d-jk-and-t-flip-flops-explained</link><guid isPermaLink="true">https://digicirq.hashnode.dev/what-is-a-flip-flop-circuit-sr-d-jk-and-t-flip-flops-explained</guid><category><![CDATA[Electronics]]></category><category><![CDATA[Digital electronics ]]></category><category><![CDATA[Computer Science]]></category><category><![CDATA[beginnersguide]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 06:56:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/ca943eea-da16-4ad6-b8ec-5ba4cce544e1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A flip-flop is one bit of memory made from two gates that feed each other. How the SR latch holds a value, what the clock adds, and what D, JK and T flip-flops are for.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=PJZhHA_2pz8">https://www.youtube.com/watch?v=PJZhHA_2pz8</a></p>

<p>A logic gate has no memory. Change its inputs and the output changes; put the inputs back and it forgets anything happened. Yet every computer is built from logic gates, and computers remember things. The trick that makes it possible is one of the oldest ideas in digital electronics: take two gates and feed each one's output into the other.</p>
<h2>What is a flip-flop circuit?</h2>
<p>A <strong>flip-flop</strong> is a circuit that stores one bit. It has two stable states, 0 and 1, and it stays in whichever state it was last put into until something tells it to change. That's it. Registers, counters, RAM caches, the program counter in a CPU: they're all rows of flip-flops.</p>
<p>The simplest version is the <strong>SR latch</strong> (set-reset), and you can build it with two NOR gates.</p>
<h2>How does an SR latch remember?</h2>
<p>Wire two NOR gates so the output of each one goes to an input of the other. The remaining input on the first gate is <strong>S</strong> (set); the remaining input on the second is <strong>R</strong> (reset). Call the outputs Q and Q-bar.</p>
<ul>
<li>Pulse <strong>S</strong> high: Q goes to 1, Q-bar goes to 0. Release S. Q-bar is 0, which is one of the first gate's inputs, so the first gate keeps Q at 1. The gates are now holding each other in place.</li>
<li>Pulse <strong>R</strong> high: the mirror image happens. Q goes to 0 and stays there.</li>
<li>Both low: nothing changes. This is the "hold" state, and it's where the memory lives.</li>
<li>Both high at the same time: both outputs go to 0, which breaks the rule that Q and Q-bar are opposites. This is the <strong>forbidden state</strong>. Release both inputs together and the latch lands on whichever gate happens to be a picosecond faster. Unpredictable, so you design around it.</li>
</ul>
<p>The loop is the memory. Neither gate is doing anything clever; each one is just holding the other in a grip.</p>
<h2>What does the clock add?</h2>
<p>An SR latch responds the instant S or R changes. In a real system with thousands of these, you want them all to update at the same moment, not whenever their inputs happen to wobble. So you add a <strong>clock</strong> input and gate S and R through AND gates with it. Now the latch only listens while the clock is high.</p>
<p>Go one step further and make it respond only to the clock's <strong>rising edge</strong>, the instant it goes from 0 to 1, and you have a proper <strong>flip-flop</strong>. The classic way to do that is master-slave: two latches back to back, one that captures while the clock is low and one that passes the value on when the clock goes high. The result is a device that samples its input once per clock tick and ignores it the rest of the time. That's what lets a CPU run millions of operations in lockstep.</p>
<h2>What are the different types of flip-flops for?</h2>
<p>They all store one bit. They differ in how you tell them what to store.</p>
<p><strong>D flip-flop (data).</strong> One input, D. On the clock edge, Q becomes whatever D was. No forbidden state, because there's only one input. This is the workhorse: a register is just eight D flip-flops sharing a clock. The 7474 (two per chip) and the CD4013 are the standard parts.</p>
<p><strong>JK flip-flop.</strong> Two inputs like SR, but the forbidden state is given a job: J and K both high means <strong>toggle</strong>. Q flips to the opposite of whatever it was. The name is often credited to Jack Kilby, co-inventor of the integrated circuit, though the story is disputed.</p>
<p><strong>T flip-flop (toggle).</strong> One input, T. If T is high on the clock edge, Q flips; if low, it holds. It's a JK with J and K tied together. Its superpower is that a toggling output runs at exactly <strong>half</strong> the clock frequency. Chain four of them, each clocked by the previous one's output, and you've built a 4-bit binary counter that counts to 15.</p>
<h2>Why do real flip-flops have setup and hold times?</h2>
<p>Because the input has to be steady for a few nanoseconds <strong>before</strong> and <strong>after</strong> the clock edge. Change D at the exact moment the clock rises and the master latch can be caught half-way between states, a condition called <strong>metastability</strong>, where Q hovers at a voltage that's neither 0 nor 1 for an unpredictable time before falling one way or the other. It's the same ambiguity as the SR forbidden state, and it's why a noisy button fed straight into a clock input gives you chaos: the bounce lands on edges at random.</p>
<h2>Where will I meet one?</h2>
<p>Everywhere you need to remember a single thing. A push-on, push-off light switch is a T flip-flop. The "seen" flag on a notification is a D flip-flop. A frequency divider is a chain of them. And the 2 KB of SRAM in an Arduino is sixteen thousand of them, each one two gates holding each other in a grip.</p>
<blockquote>
<p><strong>Try it:</strong> Breadboard an SR latch from one 74HC02 (four NOR gates; you need two). Put an LED on Q, pull-down resistors on S and R, and two buttons to 5 V. Tap S: the LED stays on after you let go. Tap R: it stays off. Press both and release: now you've seen the forbidden state decide for itself.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[What Is a Decoupling Capacitor? (Values, Placement, and Why Your Chip Resets Without One)]]></title><description><![CDATA[A decoupling capacitor is a tiny local battery beside a chip power pin. Why 100 nF, why it must sit close to the pin, which leg goes to ground, decoupling…]]></description><link>https://digicirq.hashnode.dev/what-is-a-decoupling-capacitor-values-placement-and-why-your-chip-resets-without-one</link><guid isPermaLink="true">https://digicirq.hashnode.dev/what-is-a-decoupling-capacitor-values-placement-and-why-your-chip-resets-without-one</guid><category><![CDATA[Electronics]]></category><category><![CDATA[arduino]]></category><category><![CDATA[embedded systems]]></category><category><![CDATA[Pcb Design]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 06:54:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/51aa35c8-80af-4697-bec8-724cacaa54c0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A decoupling capacitor is a tiny local battery beside a chip's power pin. Why 100 nF, why it must sit close to the pin, which leg goes to ground, decoupling vs bypass.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=1zLRvDnvohw">https://www.youtube.com/watch?v=1zLRvDnvohw</a></p>

<p>The circuit works on the breadboard. Then you move it to a proper board, make the wires tidy, and the microcontroller starts resetting itself every few seconds. Nothing in the code changed. What changed is that the chip lost the small, unglamorous capacitor that was sitting next to it by accident.</p>
<h2>What is a decoupling capacitor?</h2>
<p>A <strong>decoupling capacitor</strong> is a small capacitor wired between a chip's power pin and ground, as close to the pin as you can get it. Its job is to be a local reservoir of charge. When the chip suddenly needs current, the capacitor supplies it from a few millimetres away, instead of the chip having to pull it through the whole length of the power trace from the regulator.</p>
<p>That's the entire idea. The reason it matters is time.</p>
<h2>Why can't the power supply just keep up?</h2>
<p>A digital chip doesn't draw a steady current. Every time its clock ticks, thousands of transistors switch at once, and for a few <strong>nanoseconds</strong> the chip wants a sharp spike of current, then almost none, then another spike. A microcontroller running at 16 MHz does this 16 million times a second.</p>
<p>The copper trace between the regulator and the chip isn't a perfect wire. Every centimetre of trace has a little inductance, and inductance resists changes in current. Ask it for a spike that rises in a nanosecond and it simply can't deliver in time. For that nanosecond the voltage at the chip's pin <strong>sags</strong>. If it sags far enough, the chip's brown-out detector decides the power has failed and resets. Or an ADC reading comes back noisy. Or a bit flips in RAM and nothing makes sense.</p>
<p>A capacitor right at the pin doesn't care about the trace. The charge is already there. The spike is served locally, the trace tops the capacitor back up at its leisure, and the pin never sees the dip.</p>
<h2>Decoupling capacitor vs bypass capacitor: is there a difference?</h2>
<p>In practice they're the same part doing the same job described from two directions. "Decoupling" describes it from the chip's side: the chip is decoupled from the supply's slowness. "Bypass" describes it from the noise's side: high-frequency noise on the supply rail is given a low-impedance path to ground, bypassing the chip. One capacitor, both effects. Don't lose sleep over the terminology.</p>
<h2>What value should a decoupling capacitor be?</h2>
<p>The near-universal answer is <strong>100 nF (0.1 µF) ceramic</strong>, one per power pin. It isn't a magic number; it's a good compromise. A ceramic capacitor in a small package has very little inductance of its own, so it can respond at the tens-of-MHz speeds where the spikes live. Larger values in bigger packages respond more slowly, which is exactly the wrong trade.</p>
<p>For chips that draw bigger gulps (motor drivers, radio modules, anything with a USB port) you add a <strong>bulk</strong> capacitor of 10 µF or more alongside, not instead. The 10 µF handles the slower, larger demands in the microsecond range; the 100 nF handles the nanosecond edges. Datasheets will tell you when the chip wants something specific. Most of the time: 100 nF ceramic, and a 10 µF nearby if the chip is hungry.</p>
<h2>Where should decoupling capacitors be placed?</h2>
<p>As close to the power pin as physically possible, with the shortest possible path to ground. This is the rule people break most, and it's the one that matters most. A 100 nF capacitor three centimetres away has three centimetres of trace inductance between it and the pin, which defeats the purpose. On a PCB that means the capacitor sits next to the pin, with a via to the ground plane right at its ground pad. On a breadboard it means the capacitor's legs go into the same row as the VCC pin and the nearest ground.</p>
<p>If a chip has several VCC pins, each one gets its own capacitor. They're not sharing one tank; each pin has its own trace inductance to defeat.</p>
<h2>Which side of the capacitor goes to ground?</h2>
<p>For the ceramic capacitors used for decoupling: <strong>it doesn't matter</strong>. They're not polarised; either leg can go to ground. The question comes from electrolytic capacitors, the cylindrical ones used for bulk decoupling. Those are polarised: the leg marked with a stripe (and usually the shorter leg) is negative and goes to ground. Fit one backwards and it will heat up, and in the worst case vent with a pop.</p>
<h2>Are decoupling capacitors necessary?</h2>
<p>Yes. The reason beginners doubt it is that circuits often work without them, for a while, on a breadboard, on a lucky day. The failures are intermittent: a reset every few minutes, a sensor reading that jitters, a crash that only happens when the motor starts. Those are the signature of a chip starved for a nanosecond at a time. Adding a 100 nF capacitor next to the VCC pin is the cheapest fix in electronics, and it's cheaper still to put it there before you need it.</p>
<blockquote>
<p><strong>Try it:</strong> Take any working Arduino project with a motor or a buzzer. Hook a scope (or a cheap USB one) to the 5 V pin and ground, then watch the trace when the motor starts. Now add a 100 nF ceramic across the same pins, as close as you can. The spikes shrink. That's the whole lesson, live.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[How a 7-Segment Display Works: Eight LEDs, One Shared Pin]]></title><description><![CDATA[A 7-segment display is eight LEDs sharing one pin. Common anode vs common cathode, which segments make each digit, resistor values, and Arduino code.]]></description><link>https://digicirq.hashnode.dev/how-a-7-segment-display-works-eight-leds-one-shared-pin</link><guid isPermaLink="true">https://digicirq.hashnode.dev/how-a-7-segment-display-works-eight-leds-one-shared-pin</guid><category><![CDATA[Electronics]]></category><category><![CDATA[arduino]]></category><category><![CDATA[embedded systems]]></category><category><![CDATA[beginnersguide]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 06:49:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/ac5cd85f-65f3-4aed-83da-800c9f637f0a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A 7-segment display is eight LEDs sharing one pin. Common anode vs common cathode, which segments make each digit, resistor values, and Arduino code.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=2x65kJwLQ5g">https://www.youtube.com/watch?v=2x65kJwLQ5g</a></p>

<p>Every microwave, alarm clock and petrol pump counts with the same part: seven bars and a dot. Open it up and there's nothing clever inside. It's eight LEDs that happen to share one leg.</p>
<h2>What is a 7-segment display made of?</h2>
<p>Eight light-emitting diodes arranged in a figure-8: segments <strong>a</strong> to <strong>g</strong> around the outside and through the middle, plus <strong>dp</strong>, the decimal point. Each LED has its own pin on one side. On the other side, all eight are tied together to a single <strong>common</strong> pin. That sharing is the whole trick: it turns 16 wires into 9, and it's why the part comes in two flavours.</p>
<h2>Common anode vs common cathode: what's the difference?</h2>
<table>
<thead>
<tr>
<th></th>
<th>Common cathode (CC)</th>
<th>Common anode (CA)</th>
</tr>
</thead>
<tbody><tr>
<td>Shared pin connects to</td>
<td>Ground</td>
<td>+V (e.g. 5 V)</td>
</tr>
<tr>
<td>To light a segment, drive its pin</td>
<td>HIGH</td>
<td>LOW</td>
</tr>
<tr>
<td>Arduino <code>digitalWrite</code> to turn on</td>
<td><code>HIGH</code></td>
<td><code>LOW</code></td>
</tr>
<tr>
<td>Easy to tell apart?</td>
<td>Only by the part number, or by testing</td>
<td>—</td>
</tr>
</tbody></table>
<p>Electrically they're identical; only the direction is flipped. Mix them up and <em>every</em> segment appears inverted: you'll get a "0" when you asked for an "8". If you don't know which you have, put a 1 kΩ resistor in series with a 5 V supply, touch the common pin to one rail and a segment pin to the other, then swap. Whichever way lights it tells you.</p>
<h2>Which segments make which digit?</h2>
<p>With segments ordered <strong>a b c d e f g</strong>:</p>
<table>
<thead>
<tr>
<th>Digit</th>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
<th>f</th>
<th>g</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>6</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>7</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>8</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>9</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
</tbody></table>
<p>"8" uses all seven; "1" uses two. That table is literally what a <strong>BCD-to-7-segment decoder</strong> chip like the 7447 (for CA) or 4511 (for CC) has burned into it: four input bits in, seven segment lines out. If you watched the <a href="https://www.youtube.com/shorts/fK1wrKEewLM">decoders Short</a>, this is the same idea.</p>
<h2>Do I need a resistor for each segment?</h2>
<p>Yes, <strong>one per segment</strong>, not one on the common pin. A single resistor on the common leg is shared by however many segments are on, so "1" (two segments) is bright and "8" (seven segments) is dim, because the same current is being split seven ways.</p>
<p>Typical values: for a red display at 5 V with a ~2 V forward drop and 10 mA per segment, R = (5 − 2) / 0.010 = <strong>300 Ω</strong>, so 330 Ω is the usual pick. Blue and white displays drop about 3 V, so 220 Ω.</p>
<h2>Driving it from an Arduino</h2>
<p>Wire a–g to pins 2–8 through 330 Ω each, common to GND (for CC). Then:</p>
<pre><code class="language-cpp">const byte SEG[7] = {2,3,4,5,6,7,8};        // a..g
const byte DIGIT[10] = {                     // bit 0 = a ... bit 6 = g
  0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110,
  0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111 };

void show(int n) {
  for (int s = 0; s &lt; 7; s++)
    digitalWrite(SEG[s], bitRead(DIGIT[n], s));   // invert for common anode
}
</code></pre>
<p>For a common-anode part write <code>!bitRead(...)</code> instead.</p>
<h2>How do multi-digit displays work with so few pins?</h2>
<p>A 4-digit clock display doesn't have 32 segment pins; it has 8 segment pins and 4 common pins. The microcontroller lights digit 1's segments, turns on <em>only</em> digit 1's common, waits a millisecond, then does digit 2, and so on, cycling faster than your eye can follow. That's <strong>multiplexing</strong>, and the 1 ms flicker is why phone cameras sometimes catch clocks with missing digits.</p>
<blockquote>
<p><strong>Try it:</strong> Count 0–9 with a one-second delay. Then remove the resistor from segment a and watch it burn brighter than the rest: that's the current-sharing problem in one LED.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[How the 555 Timer Works: Three Resistors, Two Thirds, One Capacitor]]></title><description><![CDATA[Inside the 555: three resistors set 1/3 and 2/3 thresholds, two comparators watch a capacitor, a flip-flop makes it blink. Astable and monostable with…]]></description><link>https://digicirq.hashnode.dev/how-the-555-timer-works-three-resistors-two-thirds-one-capacitor</link><guid isPermaLink="true">https://digicirq.hashnode.dev/how-the-555-timer-works-three-resistors-two-thirds-one-capacitor</guid><category><![CDATA[Electronics]]></category><category><![CDATA[arduino]]></category><category><![CDATA[embedded systems]]></category><category><![CDATA[beginnersguide]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 06:47:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/7a5aa888-7ce6-46a4-a1c4-729792d83fe1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Inside the 555: three resistors set ⅓ and ⅔ thresholds, two comparators watch a capacitor, a flip-flop makes it blink. Astable and monostable, with formulas.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=zN1rbiRQHAI">https://www.youtube.com/watch?v=zN1rbiRQHAI</a></p>

<p>The 555 is the chip in a million blinking-LED kits, and it is called 555 for a boring reason: the three 5 kΩ resistors inside it. Understand those three resistors and the whole chip stops being magic.</p>
<h2>What's inside a 555?</h2>
<p>Four things:</p>
<ol>
<li><strong>A voltage divider</strong> of three equal resistors across the supply. That creates two reference voltages: <strong>⅓ Vcc</strong> and <strong>⅔ Vcc</strong>.</li>
<li><strong>Two comparators.</strong> One watches the <em>threshold</em> pin (pin 6) against ⅔ Vcc. The other watches the <em>trigger</em> pin (pin 2) against ⅓ Vcc.</li>
<li><strong>A flip-flop</strong> (a 1-bit memory) that the comparators set and reset.</li>
<li><strong>A discharge transistor</strong> (pin 7) that the flip-flop switches on and off, plus an output driver (pin 3) that can source or sink around 200 mA.</li>
</ol>
<p>That's it. Everything the 555 does is: <em>a capacitor voltage crosses ⅓ or ⅔ of the supply, a comparator flips the memory, the memory changes the output and the discharge transistor.</em></p>
<h2>Astable mode: why it blinks</h2>
<p>Wire a capacitor C from pin 6/2 to ground, charge it through R1 + R2 from Vcc, and let the discharge pin (7) empty it through R2 alone.</p>
<ul>
<li>Capacitor charges up through R1 + R2. When it reaches <strong>⅔ Vcc</strong>, the threshold comparator resets the flip-flop: output goes LOW, discharge transistor turns on.</li>
<li>Capacitor now drains through R2 into pin 7. When it falls to <strong>⅓ Vcc</strong>, the trigger comparator sets the flip-flop: output goes HIGH, discharge turns off.</li>
<li>Repeat forever.</li>
</ul>
<p>The capacitor just bounces between one third and two thirds of the supply, and the output is a square-ish wave that follows it.</p>
<pre><code class="language-plaintext">f  = 1.44 / ((R1 + 2·R2) · C)
t_high = 0.693 · (R1 + R2) · C
t_low  = 0.693 · R2 · C
</code></pre>
<p>Example: R1 = 1 kΩ, R2 = 100 kΩ, C = 10 µF → f ≈ 0.72 Hz, a lazy blink roughly once a second, with the LED on slightly longer than off. Because the capacitor charges through R1 + R2 but discharges through R2 only, the high time is always longer than the low time; put a diode across R2 if you need a true 50 % duty cycle.</p>
<h2>Monostable mode: one press, one timed pulse</h2>
<p>Tie pin 2 high through a resistor and pull it low briefly with a button. The trigger comparator sets the flip-flop, the output goes HIGH, and the capacitor starts charging through a single resistor R. When it reaches ⅔ Vcc the output drops. One press gives one clean pulse of:</p>
<pre><code class="language-plaintext">t = 1.1 · R · C
</code></pre>
<p>R = 100 kΩ, C = 10 µF → 1.1 s. This is the "stay on for a while" circuit: stairwell lights, a hardware debounce, a timed relay. Notice the ⅓-Vcc trigger threshold means a bouncing button is ignored once the timer is running: the 555 is a debouncer by construction.</p>
<h2>Why doesn't the supply voltage change the timing?</h2>
<p>Because the thresholds are <em>fractions</em> of Vcc, not fixed volts. Run it at 5 V and the capacitor swings 1.67 → 3.33 V; run it at 12 V and it swings 4 → 8 V. The RC curve to go from ⅓ to ⅔ of <em>any</em> target takes the same time, so the frequency stays put from 4.5 V to 16 V. That's the clever part of the design.</p>
<h2>Common mistakes</h2>
<ul>
<li><strong>Pin 5 (control) left floating.</strong> Add a 10 nF capacitor to ground or the thresholds pick up noise.</li>
<li><strong>Electrolytic capacitor backwards.</strong> The stripe goes to ground.</li>
<li><strong>Expecting a perfect square wave.</strong> The standard astable can't go below ~50 % duty cycle without the diode trick.</li>
<li><strong>Using a bipolar NE555 on a 3.3 V board.</strong> Use the CMOS version (LMC555 / TLC555), which runs from 2 V and draws far less current.</li>
</ul>
<blockquote>
<p><strong>Try it:</strong> Build the astable with R1 = 1 kΩ, R2 = 100 kΩ, C = 10 µF and an LED (with a 330 Ω resistor) on pin 3. Then swap C for 1 µF. The blink gets ten times faster and nothing else changes: that's the formula in your hands.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[Button Debouncing Explained: Why One Press Counts as Three (and How to Fix It)]]></title><description><![CDATA[Mechanical switches bounce for a few milliseconds every press. What that looks like on a scope, and three ways to debounce: a delay, millis(), and an RC…]]></description><link>https://digicirq.hashnode.dev/button-debouncing-explained-why-one-press-counts-as-three-and-how-to-fix-it</link><guid isPermaLink="true">https://digicirq.hashnode.dev/button-debouncing-explained-why-one-press-counts-as-three-and-how-to-fix-it</guid><category><![CDATA[arduino]]></category><category><![CDATA[Electronics]]></category><category><![CDATA[embedded systems]]></category><category><![CDATA[beginnersguide]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 06:44:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/7fa910dd-845f-44e7-852e-84ed4f89370f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Mechanical switches bounce for a few milliseconds every press. Here's what that looks like on a scope, and three ways to debounce: a delay, millis(), and an RC filter.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=nt6GSc6CDhA">https://www.youtube.com/watch?v=nt6GSc6CDhA</a></p>

<p>Your counter sketch should add one for every press. Instead it jumps by two, sometimes three, and occasionally one. The code is right. The problem is physics: a push button is two pieces of metal slamming together, and they bounce.</p>
<h2>What is switch bounce?</h2>
<p>When the contacts meet, they don't close once and stay closed. They hit, spring apart a tiny bit, hit again, and settle, all within roughly <strong>1 to 20 milliseconds</strong> depending on the switch. On an oscilloscope the pin doesn't go cleanly from HIGH to LOW; it looks like a short burst of noise before it settles.</p>
<p>A microcontroller reads its pins millions of times a second, so to it that burst is several clean presses in a row. Your counter faithfully counts every one.</p>
<p>The release bounces too, which is why an "on release" handler can misfire as well.</p>
<h2>Fix 1: the delay (quick, blocking)</h2>
<p>The simplest fix: when you see the first edge, wait longer than the bounce could last, then read again.</p>
<pre><code class="language-cpp">if (digitalRead(BTN) == LOW) {   // pressed (pull-up wiring)
  delay(30);                     // let it settle
  if (digitalRead(BTN) == LOW) count++;
  while (digitalRead(BTN) == LOW) {}  // wait for release
}
</code></pre>
<p>It works, and it's fine for a demo. The cost is that <code>delay()</code> freezes everything else: no LED animation, no sensor reads, nothing, for 30 ms per press. In anything real that matters.</p>
<h2>Fix 2: millis() (non-blocking, the usual answer)</h2>
<p>Instead of stopping, remember <em>when</em> the pin last changed, and only accept a new state once it has been stable for a while:</p>
<pre><code class="language-cpp">const unsigned long DEBOUNCE = 30;  // ms
int stable = HIGH, lastRaw = HIGH;
unsigned long lastChange = 0;

void loop() {
  int raw = digitalRead(BTN);
  if (raw != lastRaw) { lastChange = millis(); lastRaw = raw; }
  if (millis() - lastChange &gt; DEBOUNCE &amp;&amp; raw != stable) {
    stable = raw;
    if (stable == LOW) count++;     // one clean press
  }
  // everything else keeps running
}
</code></pre>
<p>Every bounce resets the timer, so the state only updates after the contacts have been quiet for 30 ms. The loop never blocks. This is the pattern inside every "Bounce" library.</p>
<h2>Fix 3: a capacitor (hardware debounce)</h2>
<p>If you'd rather not debounce in code, or the signal feeds something with no code (a 555, a flip-flop, a clock pin), slow the edge down in hardware. With a pull-up in place, add a capacitor from the pin to ground:</p>
<ul>
<li>10 kΩ pull-up + 100 nF capacitor → time constant RC = 1 ms</li>
<li>The capacitor charges and discharges through the resistor, so the bounces get smoothed into one slow curve.</li>
</ul>
<p>The catch is that a slow curve through the input threshold can itself trigger multiple times on a plain logic input. Pair it with a <strong>Schmitt trigger</strong> input (a 74HC14, or a microcontroller pin with hysteresis) and the ramp becomes one clean edge. That's the textbook hardware debounce: RC plus Schmitt.</p>
<h2>How long should the debounce time be?</h2>
<table>
<thead>
<tr>
<th>Switch type</th>
<th>Typical bounce</th>
<th>Safe debounce</th>
</tr>
</thead>
<tbody><tr>
<td>Tactile push button</td>
<td>1–5 ms</td>
<td>10–20 ms</td>
</tr>
<tr>
<td>Toggle / rocker switch</td>
<td>5–20 ms</td>
<td>30–50 ms</td>
</tr>
<tr>
<td>Relay contacts</td>
<td>10–50 ms</td>
<td>50–100 ms</td>
</tr>
</tbody></table>
<p>Longer is safer but caps how fast a human can press: 50 ms allows 20 presses a second, which is more than anyone's thumb manages.</p>
<blockquote>
<p><strong>The two bugs beginners mix up:</strong> Random readings while nobody is pressing = a floating input (fix: pull-up resistor). Several readings from one press = bounce (fix: this guide). Different problems, both cheap to fix.</p>
</blockquote>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[What Does a Pull-Up Resistor Do? (And Why Your Button Reads Random Values Without One)]]></title><description><![CDATA[A pull-up resistor gives an input pin a definite voltage when nothing drives it. Why a floating pin reads garbage, what value to use, pull-up vs pull-down.]]></description><link>https://digicirq.hashnode.dev/what-does-a-pull-up-resistor-do-and-why-your-button-reads-random-values-without-one</link><guid isPermaLink="true">https://digicirq.hashnode.dev/what-does-a-pull-up-resistor-do-and-why-your-button-reads-random-values-without-one</guid><category><![CDATA[arduino]]></category><category><![CDATA[Electronics]]></category><category><![CDATA[embedded systems]]></category><category><![CDATA[beginnersguide]]></category><dc:creator><![CDATA[DigiCirq]]></dc:creator><pubDate>Wed, 11 Nov 2026 06:42:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6af40a0e4d90c3845e28c9df/399b6555-ebf4-47e6-8993-4f473e870107.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A pull-up resistor gives an input pin a definite voltage when nothing drives it. Why a floating pin reads garbage, what value to use, and pull-up vs pull-down.</em></p>
<p>Watch the one-minute version first, then read on for the numbers.</p>
<p><a class="embed-card" href="https://www.youtube.com/watch?v=GGGjqbI5YEM">https://www.youtube.com/watch?v=GGGjqbI5YEM</a></p>

<p>You wire a push button to an Arduino pin, write a sketch that prints the pin, and the serial monitor shows <code>1 0 0 1 1 0 1</code> while nobody is touching anything. The button isn't broken. The pin is <em>floating</em>, and a pull-up resistor is the two-cent fix.</p>
<h2>What is a floating input?</h2>
<p>A digital input pin is a very high-impedance probe. It draws almost no current, which is great for measuring, but it means the pin has no opinion of its own. If nothing is connected to it, or the only thing connected is an <em>open</em> switch, the pin's voltage is whatever stray charge, nearby wires and your finger's electric field make it. The chip still has to decide "HIGH or LOW?" every time you read it, so it rounds that noise to a 1 or a 0, and you get random values.</p>
<p>A floating pin is not "zero". It is <em>undefined</em>.</p>
<h2>What does a pull-up resistor actually do?</h2>
<p>A pull-up is a resistor from the input pin to the supply voltage (5 V on an Uno, 3.3 V on an ESP32). With the switch open, no current flows, so there is no voltage drop across the resistor and the pin sits at the supply voltage: a clean, definite HIGH.</p>
<p>Press the button and the switch connects the pin straight to ground. Now the pin reads LOW, and the resistor's only job is to limit the current flowing from the supply to ground through the closed switch. With 10 kΩ and 5 V that is 0.5 mA, which is nothing.</p>
<p>So the resistor "pulls the pin up" to HIGH by default, and the button overrides it by pulling the pin down to LOW. Pressed reads 0, released reads 1. That inverted logic surprises beginners, but it's the normal convention.</p>
<h2>What value should a pull-up resistor be?</h2>
<p>Anything from about 1 kΩ to 100 kΩ works; <strong>10 kΩ</strong> is the default for good reasons:</p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Current when pressed (5 V)</th>
<th>Trade-off</th>
</tr>
</thead>
<tbody><tr>
<td>1 kΩ</td>
<td>5 mA</td>
<td>Strong (noise-immune), but wastes power while held</td>
</tr>
<tr>
<td>10 kΩ</td>
<td>0.5 mA</td>
<td>The usual compromise</td>
</tr>
<tr>
<td>100 kΩ</td>
<td>0.05 mA</td>
<td>Low power, but slow edges on long wires and more noise pickup</td>
</tr>
</tbody></table>
<p>A <em>stronger</em> pull-up (lower resistance) holds the pin HIGH more firmly against noise and charges the wire's capacitance faster. A <em>weaker</em> one (higher resistance) saves power. For a button on a short wire, 10 kΩ is the answer.</p>
<h2>Can I use the built-in pull-up instead?</h2>
<p>Yes. Most microcontrollers have internal pull-ups you can switch on in software. On Arduino:</p>
<pre><code class="language-cpp">pinMode(2, INPUT_PULLUP);   // internal ~20–50 kΩ pull-up on pin 2
int pressed = digitalRead(2) == LOW;
</code></pre>
<p>The internal pull-up is weak (20–50 kΩ on the ATmega328P), so it is fine for a button on the board but less reliable on a long cable in a noisy environment. For I²C lines, which need a specific pull-up to meet timing, use external resistors (typically 4.7 kΩ).</p>
<h2>Pull-up or pull-down: which should I use?</h2>
<p>A pull-down is the mirror image: resistor to ground, button to the supply, pressed reads HIGH. It reads "naturally" but is less common because:</p>
<ul>
<li>Built-in pull-ups are everywhere; built-in pull-downs are rarer.</li>
<li>Open-drain devices (I²C, many sensors, reset lines) can only pull <em>down</em>, so the resting state must be pulled <em>up</em>.</li>
<li>Active-low conventions (<code>RESET</code>, <code>CS</code>) are the industry default.</li>
</ul>
<p>Use a pull-down when the logic genuinely reads better that way and you're wiring the resistor yourself. Otherwise, pull-up.</p>
<blockquote>
<p><strong>Try it:</strong> Read a pin with nothing connected and print it 20 times a second. Then touch the pin with your finger. Then add a 10 kΩ pull-up. You'll see random → wandering → steady 1.</p>
</blockquote>
<h2>Why the button still glitches when you press it</h2>
<p>Once the pin is pulled up you'll notice a second problem: one press sometimes registers as two or three. That isn't floating any more; it's the metal contacts <em>bouncing</em> for a few milliseconds. That's the next guide: button debouncing.</p>
<hr />
<p><em>DigiCirq makes short animated explainers on electronics, Arduino and the systems behind everyday apps. New guides every week:</em> <a href="https://www.youtube.com/@digicirq"><em>youtube.com/@digicirq</em></a><em>.</em></p>
]]></content:encoded></item></channel></rss>