<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged task</title>
<link>https://coderlegion.com/tag/task</link>
<description>Powered by Question2Answer</description>
<item>
<title>Zapier for Small Business: Pricing, Limits, and Best Fit</title>
<link>https://coderlegion.com/25685/zapier-for-small-business-pricing-limits-and-best-fit</link>
<description>
&lt;p&gt;
        Zapier is a strong first automation platform for a small business that needs a simple workflow live quickly. The Free plan is useful for testing one-trigger, one-action workflows, Professional unlocks multi-step automation, and Team adds shared connections and controls. The trade-off is task billing: every successful counted action uses capacity, so cost can rise as workflows become longer or run more often.
      &lt;/p&gt;
      &lt;p&gt;
        Prices and task rules can change. The plan details below were verified against Zapier's official pricing and task documentation on August 1, 2026.
      &lt;/p&gt;

      &lt;h2 id=&quot;quick-decision-is-zapier-the-right-fit&quot;&gt;Quick decision: is Zapier the right fit?&lt;/h2&gt;
      &lt;div class=&quot;article-table-wrap&quot;&gt;
        &lt;table class=&quot;article-table&quot;&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Situation&lt;/th&gt;
              &lt;th&gt;Best starting point&lt;/th&gt;
              &lt;th&gt;Why&lt;/th&gt;
              &lt;th&gt;Watch for&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;One simple app-to-app workflow&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Zapier Free&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Fast setup, 100 tasks per month, and two-step workflows.&lt;/td&gt;
              &lt;td&gt;The free plan allows one trigger and one action per workflow.&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Several multi-step workflows&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Zapier Professional&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Multi-step workflows, premium apps, webhooks, and built-in logic.&lt;/td&gt;
              &lt;td&gt;Successful actions and some AI steps consume tasks.&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;A team sharing automations&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Zapier Team&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Shared workflows, folders, app connections, roles, and SAML SSO.&lt;/td&gt;
              &lt;td&gt;Confirm the current user and task limits before buying.&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;High-volume or complex branching&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Compare Make and n8n&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Another billing model or self-hosting may reduce cost and add control.&lt;/td&gt;
              &lt;td&gt;More control also creates more setup and maintenance work.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;

      &lt;h2 id=&quot;what-zapier-actually-is&quot;&gt;What Zapier actually is&lt;/h2&gt;
      &lt;p&gt;
        Zapier is a workflow automation tool, in the same family as Make and n8n. You build a &lt;strong&gt;Zap&lt;/strong&gt;: a &lt;strong&gt;trigger&lt;/strong&gt; that starts it, then one or more &lt;strong&gt;actions&lt;/strong&gt; that do the work. New lead in a form, then create a CRM record, send an email, post a Slack alert. That chain is your Zap. It is the same trigger-steps-workflow model I walked through in &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/what-is-n8n-small-business&quot;&gt;what is n8n&lt;/a&gt;, just with Zapier's names on it.
      &lt;/p&gt;

      &lt;h2 id=&quot;what-zapier-is-genuinely-best-at&quot;&gt;What Zapier is genuinely best at&lt;/h2&gt;
      &lt;p&gt;
        Zapier is not the cheapest tool, and I will get to that. But it is the best at several things that matter to a small business:
      &lt;/p&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;strong&gt;The most integrations, by a wide margin.&lt;/strong&gt; Zapier connects 9,000+ apps. If you use a tool, even a niche one, the odds that Zapier already supports it are higher than with any competitor. That alone solves a lot of &quot;but does it work with ___&quot; questions.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;The easiest start.&lt;/strong&gt; The setup is the friendliest in the category. Pick a trigger, pick an action, map a few fields, turn it on. Most people get their first Zap running without reading a manual.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;It is reliable and well-documented.&lt;/strong&gt; Zapier has been doing this the longest, so between templates, help docs, and the guides online, you are rarely the first person to try what you are trying.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;A practical free plan for testing.&lt;/strong&gt; It includes 100 tasks per month, unlimited workflow assets, and two-step workflows with one trigger and one action.&lt;/li&gt;
      &lt;/ul&gt;

      &lt;h2 id=&quot;zapier-includes-more-than-workflows&quot;&gt;Zapier includes more than workflows&lt;/h2&gt;
      &lt;p&gt;
        Zapier now bundles more of its core platform into the Free, Professional, and Team plans. That matters because a small business can keep a lightweight form, data table, and automation in the same account:
      &lt;/p&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;strong&gt;Forms and Interfaces&lt;/strong&gt; collect data through simple pages without requiring a separate form product for a basic intake flow.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Tables&lt;/strong&gt; stores leads, projects, inventory, or workflow state. Zapier's current task-rate page lists Tables and Forms among the built-in tools that do not use tasks.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Zapier MCP&lt;/strong&gt; lets supported AI assistants call Zapier actions. The current rate is two tasks per MCP tool call, so usage still needs a budget.&lt;/li&gt;
      &lt;/ul&gt;
      &lt;p&gt;
        The platform is more unified than it was, but &quot;included&quot; does not mean unlimited. Plans still have task, record, page, user, and feature limits. Check the live plan comparison before building a core process around any one allowance.
      &lt;/p&gt;

      &lt;h2 id=&quot;what-zapier-costs&quot;&gt;What Zapier costs&lt;/h2&gt;
      &lt;p&gt;
        Zapier bills most automation work with &lt;strong&gt;tasks&lt;/strong&gt;. A standard successful action normally uses one task. Polling triggers do not use tasks, and Zapier currently lists built-in tools such as Filters, Paths, Formatter, Delay, Tables, and Forms at zero tasks.
      &lt;/p&gt;
      &lt;div class=&quot;article-table-wrap&quot;&gt;
        &lt;table class=&quot;article-table&quot;&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Plan&lt;/th&gt;
              &lt;th&gt;Published starting price&lt;/th&gt;
              &lt;th&gt;Useful limit or feature&lt;/th&gt;
              &lt;th&gt;Best fit&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Free&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;$0&lt;/td&gt;
              &lt;td&gt;100 tasks per month and two-step workflows.&lt;/td&gt;
              &lt;td&gt;Testing one small automation.&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Professional&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;$19.99/month, billed annually&lt;/td&gt;
              &lt;td&gt;Starts at 750 tasks with multi-step workflows and premium apps.&lt;/td&gt;
              &lt;td&gt;An individual or small team with real production workflows.&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Team&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;$69/month, billed annually&lt;/td&gt;
              &lt;td&gt;Shared workflows and app connections, roles, and up to 25 users.&lt;/td&gt;
              &lt;td&gt;A team that needs collaboration and account controls.&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Enterprise&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Custom&lt;/td&gt;
              &lt;td&gt;Governance, observability, deployment controls, and enterprise support.&lt;/td&gt;
              &lt;td&gt;Large or regulated organizations.&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;
      &lt;p&gt;
        These are starting prices published by Zapier and may change with billing interval, currency, tax, task tier, or product updates. I put the billing models side by side with Make and n8n in &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/zapier-vs-make-vs-n8n-pricing&quot;&gt;Zapier vs Make vs n8n pricing&lt;/a&gt;.
      &lt;/p&gt;

      &lt;h2 id=&quot;where-zapier-can-get-expensive&quot;&gt;Where Zapier can get expensive&lt;/h2&gt;
      &lt;p&gt;
        The same task-based pricing that keeps simple Zaps cheap is what bites at scale. Picture a four-step Zap that runs 500 times a month. That is roughly 2,000 tasks, and a fifth step adds another 500. The cost grows with both how many steps you have and how often they run. For a light, simple automation this is a non-issue. For a heavy multi-step workflow running thousands of times a month, the invoice is where Zapier tends to lose to &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/make-for-small-business&quot;&gt;Make&lt;/a&gt; and n8n.
      &lt;/p&gt;
      &lt;p&gt;
        AI steps need a separate check. Since June 15, 2026, AI by Zapier uses model tiers: Standard uses one task per step, Advanced uses three, and Premium uses five. Tool calls add tasks at the same tier. A workflow that looks like one AI step in the editor can therefore consume more than one task per run.
      &lt;/p&gt;
      &lt;p&gt;
        It is not a flaw, it is a trade-off. You are paying for the easiest, most-connected tool on the market. The question is just whether that premium is worth it for your specific workflow.
      &lt;/p&gt;

      &lt;h2 id=&quot;what-you-can-automate-with-zapier&quot;&gt;What you can automate with Zapier&lt;/h2&gt;
      &lt;p&gt;
        Theory is dull, so here is what Zapier actually does for a small team. Each of these is a real Zap you can build today:
      &lt;/p&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;strong&gt;Catch and follow up on new leads&lt;/strong&gt; before they go cold, pulling them from forms, email, and chat into your CRM and inbox. See &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/small-business-automation-philippines&quot;&gt;small business automation in the Philippines&lt;/a&gt;.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Automate the right thing first.&lt;/strong&gt; Most small businesses pick the wrong starting point. Here is how to choose a first Zap that actually pays off: &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/simple-zapier-automations-small-business&quot;&gt;most businesses automate the wrong thing first&lt;/a&gt;.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Turn a free Google Form into an intake pipeline&lt;/strong&gt;, so every submission is logged, tagged, and acted on without you touching it. See how to &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/free-business-automation-google-forms-no-zapier&quot;&gt;connect Google Forms to Sheets and Gmail without Zapier&lt;/a&gt;.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Replace manual copy-paste&lt;/strong&gt; between the apps you already pay for, so nobody moves data by hand all day.&lt;/li&gt;
      &lt;/ul&gt;
      &lt;p&gt;
        None of these need a developer on staff. They need a clear process and a tool that can run it. Before you commit a core process to it, it is worth knowing what the same workflow costs on each platform, which I broke down in &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/cost-to-automate-lead-follow-up-philippines&quot;&gt;how much it costs to automate lead follow-up&lt;/a&gt;.
      &lt;/p&gt;

      &lt;h2 id=&quot;is-zapier-right-for-your-business&quot;&gt;Is Zapier right for your business?&lt;/h2&gt;
      &lt;p&gt;
        Often, yes, especially at the start. Zapier is the right choice when you value simplicity and breadth over price, when you need an integration with a less common app, or when you just want your first few automations live this afternoon without a learning curve. For a small team automating a handful of simple things, it is hard to beat.
      &lt;/p&gt;
      &lt;p&gt;
        It becomes a weaker fit when a workflow has many counted actions, runs at high volume, or must be self-hosted. At that point compare &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/what-is-n8n-small-business&quot;&gt;n8n&lt;/a&gt;, which prices Cloud by full workflow executions and offers a self-hosted option, or Make's credit model. If the source and destination already have a dependable native integration, use that first. The &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/zapier-vs-make-vs-n8n-pricing&quot;&gt;pricing comparison&lt;/a&gt; shows the same workflow under all three billing models.
      &lt;/p&gt;

      &lt;h2 id=&quot;where-to-learn-zapier&quot;&gt;Where to learn Zapier&lt;/h2&gt;
      &lt;p&gt;
        Zapier has its own free &lt;a href=&quot;https://learn.zapier.com/&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;learning hub&lt;/a&gt;. It is lighter than Make's academy and you can get through it quickly, but it gives you the core ideas fast, which is exactly what Zapier is about. For most people that plus the in-product templates is enough to get going.
      &lt;/p&gt;
      &lt;p&gt;
        Personally, the resource I would point a beginner to is this free &lt;a href=&quot;https://youtu.be/-leIp449qXA&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;4-hour Zapier course&lt;/a&gt; from &lt;a href=&quot;https://www.youtube.com/@freecodecamp&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;freeCodeCamp&lt;/a&gt;. Four hours sounds like a lot, but the delivery is so easy it flies by. One rule: do not just watch it. Build every example alongside the video in your own account, that is the difference between having seen it and being able to do it. freeCodeCamp is a great channel in general, with a huge amount of free material worth digging into.
      &lt;/p&gt;

      &lt;h2 id=&quot;where-to-start&quot;&gt;Where to start&lt;/h2&gt;
      &lt;p&gt;
        Pick the most annoying repetitive task in your week and describe it in one sentence: when X happens, do Y, then tell me. Build that one Zap on the free plan and let it run for a week. Keep it small; a Zap that quietly saves ten minutes a day teaches you more than an ambitious one that breaks on its first edge case. Once it is running, the next few tasks become obvious. If you would rather have the first few built properly, with error handling so they do not fail silently, that is what I do.
      &lt;/p&gt;

      &lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;https://zapier.com/pricing&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Zapier plans and pricing&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://zapier.com/pricing/rates&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Zapier task usage rates&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://help.zapier.com/hc/en-us/articles/8496196837261-How-is-task-usage-measured-in-Zapier&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;How Zapier measures task usage&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://help.zapier.com/hc/en-us/articles/32337438839565-What-s-included-in-Zapier-s-Free-plan&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;What is included in Zapier's Free plan&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://help.zapier.com/hc/en-us/articles/39645433045773-Zapier-plan-updates-Tables-Interfaces-and-MCP-now-included&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Zapier plan updates for Tables, Interfaces, and MCP&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://help.zapier.com/hc/en-us/articles/46597632373389-AI-by-Zapier-new-model-based-pricing-starting-June-15-2026&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;AI by Zapier model-based task pricing&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;

            &lt;nav class=&quot;article-related&quot; aria-label=&quot;Related reading&quot;&gt;
        &lt;p class=&quot;article-related-h mono&quot;&gt;Keep reading&lt;/p&gt;
        &lt;ul&gt;
        &lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/make-for-small-business&quot;&gt;Make for Small Business&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/what-is-n8n-small-business&quot;&gt;What Is n8n? A Guide for Small Business&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/simple-zapier-automations-small-business&quot;&gt;3 Simple Zapier Automations&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/nav&gt;

      &lt;div class=&quot;article-cta&quot; style=&quot;margin-top: 24px;&quot;&gt;
        &lt;p class=&quot;cta-h&quot;&gt;Not sure which tool fits?&lt;/p&gt;
        &lt;p&gt;
          Tell me the most repetitive task in your week. I can map a simple workflow for it and tell you honestly whether to build it on Zapier, Make, or n8n, and what it will cost to run.
        &lt;/p&gt;
        &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/#contact&quot; class=&quot;btn btn-primary article-cta-button&quot;&gt;Get the map&lt;/a&gt;
      &lt;/div&gt;
&lt;p&gt;&lt;em&gt;Originally published on &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/zapier-for-small-business&quot;&gt;FloxoLab&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/25685/zapier-for-small-business-pricing-limits-and-best-fit</guid>
<pubDate>Sat, 24 Oct 2026 15:50:00 +0000</pubDate>
</item>
<item>
<title>Why Claude + MCP Is the Most Powerful Tool I Have Ever Put to Work</title>
<link>https://coderlegion.com/22847/why-claude-mcp-is-the-most-powerful-tool-i-have-ever-put-to-work</link>
<description>
&lt;h1&gt;Why Claude + MCP Is the Most Powerful Tool I've Ever Put to Work&lt;/h1&gt;
&lt;p class=&quot;post-byline&quot;&gt;
    &lt;span&gt; AI &amp;amp; MCP&lt;/span&gt; &amp;middot;     Updated July 2026     &amp;middot; 9 min read    &amp;middot; by Jacob Campbell
&lt;/p&gt;

&lt;p class=&quot;article-intro&quot;&gt;&lt;/p&gt;&lt;p&gt;I build websites for a living, so I'm hard to impress with 'AI tools.' Most of them talk. Claude, connected through MCP servers, is the first one I've watched actually do the work &amp;mdash; reach into my real tools, make the change, and check it &amp;mdash; all inside one conversation. This isn't a chatbot review; it's what happened when I pointed it at this very website, and why I now think the combination of Claude and MCP is the most capable tool I've ever put to work.&lt;/p&gt;

&lt;h2&gt;Key facts&lt;/h2&gt;
&lt;ul class=&quot;post-facts&quot;&gt;
        &lt;li&gt;&lt;strong&gt;1 ask&lt;/strong&gt; &amp;mdash; One request, many tools working together&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;88&lt;/strong&gt; &amp;mdash; Files translated and updated in a single task&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;11&lt;/strong&gt; &amp;mdash; Languages kept in sync automatically&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;MCP&lt;/strong&gt; &amp;mdash; The open standard that connects Claude to your tools&lt;/li&gt;
    &lt;/ul&gt;

&lt;h2&gt;From answering questions to doing the work&lt;/h2&gt;
&lt;p&gt;The old model of AI was a smart parrot: you asked, it answered, and you did the work. MCP flips that. The Model Context Protocol lets Claude connect to your actual applications &amp;mdash; your files, your CMS, your automations &amp;mdash; and act in them directly. Instead of 'here's how you'd fix that,' it's 'I fixed it, here's the diff, and I verified it.' That single shift is the difference between advice and a colleague.&lt;/p&gt;&lt;h2&gt;What MCP actually is, in plain English&lt;/h2&gt;
&lt;p&gt;MCP (Model Context Protocol) is an open standard &amp;mdash; think of it as a universal adapter between Claude and software. Each 'server' exposes a set of tools (read a file, publish a post, query a database) that Claude can call safely, only after you connect it. You're not wiring up brittle scripts; you connect a tool once and Claude can use it in any conversation. Because it's an open standard, the same Claude can drive thousands of different apps.&lt;/p&gt;&lt;h2&gt;What that looked like on this very site&lt;/h2&gt;
&lt;p&gt;This isn't theoretical &amp;mdash; here's a sample of what Claude did on this site in one session. It fixed the mobile language picker and phone placement across every page. It added a fresh, topic-specific section to eight of my blog guides and translated it into all eleven languages &amp;mdash; &lt;strong&gt;88 files updated in a single pass&lt;/strong&gt;, each validated. Through a Zapier MCP server it read my newest posts from Webflow and published a roundup to an RSS feed &amp;mdash; two separate apps cooperating in one request. Then it built an entire new multilingual article and wired it into routing, the sitemap and the feed. See one of those posts: &lt;a href=&quot;/blog/seo-aeo-geo-serp&quot;&gt;SEO, AEO, GEO &amp;amp; SERP explained&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;The real unlock: set Claude up to succeed&lt;/h2&gt;
&lt;p&gt;The magic isn't luck; it's setup. Give Claude the right context &amp;mdash; access to the folder, the connected tools, and a clear task &amp;mdash; and it plans, executes, and checks its own work. The pattern that makes every task land is simple: connect the tools it needs, state the outcome you want, and let it verify before it calls something done. Set it up to succeed and it succeeds; leave it guessing and it guesses. Most 'AI didn't work' stories are really setup stories.&lt;/p&gt;&lt;h2&gt;Learn faster by watching Claude work&lt;/h2&gt;
&lt;p&gt;Here's the part I didn't expect: I learn more by watching Claude do a task than by reading a tutorial about it. It narrates each step, shows the code it changed, and explains why &amp;mdash; so a job like 'wire a translated article into the sitemap' becomes a walkthrough I can actually follow. After a few tasks you absorb the how, not just the result. It's teaching by doing, on your own project, at your pace &amp;mdash; the fastest way to learn something new that I've found.&lt;/p&gt;&lt;h2&gt;Why this is a step-change &amp;mdash; and how to start&lt;/h2&gt;
&lt;p&gt;Tools that only advise leave all the doing (and all the learning curve) on you. A tool that connects to your stack, acts, verifies, and explains as it goes compounds: every task ships and teaches at the same time. You don't need to be technical to start &amp;mdash; connect one or two tools you already use, hand Claude a real task, and watch. The first time you see one ask move work across two apps, the paradigm clicks.&lt;/p&gt;&lt;h2&gt;Sources &amp;amp; further reading&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://www.anthropic.com/news/model-context-protocol&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Anthropic &amp;mdash; Introducing the Model Context Protocol&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://modelcontextprotocol.io&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;modelcontextprotocol.io &amp;mdash; the open MCP standard&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://docs.claude.com&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Claude documentation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Related services&lt;/h2&gt;
&lt;ul class=&quot;post-related-list&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/seo-aeo-geo-serp&quot;&gt;SEO, AEO, GEO &amp;amp; SERP explained&lt;/a&gt; &amp;mdash; How AI is reshaping search &amp;mdash; a post Claude helped build.&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/core-web-vitals&quot;&gt;Core Web Vitals explained&lt;/a&gt; &amp;mdash; The kind of technical work Claude can act on directly.&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/why-isnt-my-website-ranking-on-google&quot;&gt;Why your site isn't ranking&lt;/a&gt; &amp;mdash; Fixable issues an AI-plus-tools workflow can catch fast.&lt;/li&gt;
    &lt;/ul&gt;

&lt;h2&gt;Frequently asked questions&lt;/h2&gt;
&lt;h3&gt;What is MCP?&lt;/h3&gt;
&lt;p&gt;MCP (Model Context Protocol) is an open standard that connects Claude to your real software &amp;mdash; files, a CMS, automations, databases &amp;mdash; so it can act in those tools directly instead of only giving advice.&lt;/p&gt;
&lt;h3&gt;What can Claude do with MCP that it couldn't before?&lt;/h3&gt;
&lt;p&gt;It can read and change things in the apps you connect: edit files, publish content, run automations across services, and verify the result &amp;mdash; all within one conversation, rather than handing you steps to do yourself.&lt;/p&gt;
&lt;h3&gt;Does Claude act on my tools without permission?&lt;/h3&gt;
&lt;p&gt;You choose which tools to connect, and connections are approved by you. Claude works within the tools you've granted, and for sensitive actions the right pattern is to review what it proposes before it runs.&lt;/p&gt;
&lt;h3&gt;How do I get started with Claude and MCP?&lt;/h3&gt;
&lt;p&gt;Connect one or two tools you already use, then give Claude a small, real task that spans them. Seeing a single request pull from one app and act in another is the fastest way to understand the value.&lt;/p&gt;
&lt;h3&gt;How does this help me learn faster?&lt;/h3&gt;
&lt;p&gt;Because Claude narrates and shows its work as it goes, you learn by watching a real task on your own project &amp;mdash; the code it changes, the tools it calls, and why. It's teaching by doing, which sticks better than a generic tutorial.&lt;/p&gt;

&lt;div class=&quot;post-cta&quot;&gt;
    &lt;h2&gt;Want a site &amp;mdash; and a workflow &amp;mdash; built to move this fast?&lt;/h2&gt;
    &lt;p&gt;I build custom sites and set up the tools and automations around them so the whole thing runs like you saw here. One flat fee.&lt;/p&gt;
    &lt;a class=&quot;btn&quot; href=&quot;/free-quote/&quot;&gt;Get my free quote&lt;/a&gt;
&lt;/div&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/22847/why-claude-mcp-is-the-most-powerful-tool-i-have-ever-put-to-work</guid>
<pubDate>Thu, 16 Jul 2026 23:21:39 +0000</pubDate>
</item>
<item>
<title>How Do Smart Devices Perform Multiple Tasks?</title>
<link>https://coderlegion.com/16118/how-do-smart-devices-perform-multiple-tasks</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;Ever wonder how your Alexa, robot vacuum cleaner, and smartwatch seamlessly perform multiple tasks without getting stuck in the middle? How exactly are these devices programmed to handle it all?&lt;/p&gt;

&lt;p&gt;You came to the right place to understand how it happens under the hood.&lt;/p&gt;

&lt;p&gt;In this article, we will understand how these tasks are performed and how they work.&lt;/p&gt;

&lt;p&gt;As all these devices use a microcontroller. I will be explaining using the simple microcontroller &lt;code&gt;ESP8266&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How will the task be performed?
&lt;/h2&gt;

&lt;p&gt;Every smart device consists of a microcontroller. These microcontrollers are programmed to perform specific tasks.&lt;/p&gt;

&lt;p&gt;These tasks are performed using a single loop function.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// Perform Task&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loop function will run continuously.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pfzvp6pl2vc3456w6s7.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pfzvp6pl2vc3456w6s7.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;210&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this loop, we can do multiple things.&lt;/p&gt;

&lt;p&gt;Let's take the example of a weather monitoring device.&lt;br&gt;
These operations are done using a single loop function. As there is nothing else to do.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start Device&lt;/li&gt;
&lt;li&gt;Start Loop&lt;/li&gt;
&lt;li&gt;Read sensor data&lt;/li&gt;
&lt;li&gt;Display data / Store data&lt;/li&gt;
&lt;li&gt;Repeat the process
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;But this comes with a problem. &lt;/p&gt;

&lt;p&gt;This loop will be running with a microsecond delay.&lt;br&gt;
If we run this loop function, it will run continuously. Means there will be no delay between the operations.&lt;/p&gt;
&lt;h2&gt;
  
  
  How will a normal loop cause a problem?
&lt;/h2&gt;

&lt;p&gt;Let's assume the above operation takes 1 ms (which is not true in real-world use, as it depends on which microcontroller you use).&lt;/p&gt;

&lt;p&gt;The DHT11 sensor should have a 1-second delay between readings.&lt;/p&gt;

&lt;p&gt;That means the above loop will run 1000 times in 1 second to just see if the sensor data has changed.&lt;/p&gt;

&lt;p&gt;Can you see the problem?&lt;/p&gt;

&lt;p&gt;1000 times operation means 1000 times power consumption.&lt;/p&gt;

&lt;p&gt;1000 times the power consumption means the battery will drain fast, or the embedded system will heat up.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtjhcsxp65gge0pu0ipw.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtjhcsxp65gge0pu0ipw.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;419&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To avoid this, we can use a delay function.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Wait for 1 second&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding a delay, we are making sure that the loop function is not running continuously.&lt;/p&gt;

&lt;p&gt;This is a good implementation if we have only one task to perform.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4590vh7dezcbp8ee5s9c.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4590vh7dezcbp8ee5s9c.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;400&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But if we want to do multiple operations to be performed in specific intervals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Other Operations in a loop
&lt;/h2&gt;

&lt;p&gt;Like this, if we want to read the DHT11 sensor every 1 second and read the MQ2 sensor every 5 seconds. We can't use the delay function.&lt;/p&gt;

&lt;p&gt;It will be like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;analogRead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MQ2_PIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Wait for 5 seconds&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will cause a 5-second no-data reading from the DHT11 sensor.&lt;/p&gt;

&lt;p&gt;Hence, there will be data loss for 5 seconds.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foz2eu4u5zcgthgqn8494.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foz2eu4u5zcgthgqn8494.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;392&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is where the task scheduler comes into the picture.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Task Scheduler?
&lt;/h2&gt;

&lt;p&gt;A task scheduler is a lightweight system that allows a processor to juggle multiple activities seemingly at the same time, a concept known as multitasking.&lt;/p&gt;

&lt;p&gt;A Task Scheduler solves this problem using a &quot;to-do list&quot; approach. &lt;/p&gt;

&lt;p&gt;Instead of freezing, the program loops continuously at top speed. &lt;/p&gt;

&lt;p&gt;Every time it loops, the scheduler checks the clock and looks at its list of tasks to see if any are due to run right now. &lt;/p&gt;

&lt;p&gt;If a task's time is up, the scheduler runs it and then immediately goes back to checking the clock.&lt;/p&gt;

&lt;p&gt;To understand the internal clock, imagine the microcontroller holding a stopwatch that starts counting milliseconds the moment it powers on. &lt;/p&gt;

&lt;p&gt;In the Arduino framework, this stopwatch is read using a function called &lt;code&gt;millis()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead of pausing the whole system to wait, the scheduler constantly checks this stopwatch against a simple formula for each task:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Current Time - Last Time Executed &amp;gt;= Interval&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here is a simple example of how the task scheduler works in ESP8266.&lt;/p&gt;

&lt;p&gt;Ex:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousDHTTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Remembers the last time DHT ran&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousMQ2Time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Remembers the last time MQ2 ran&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dhtInterval&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 1000 milliseconds = 1 second&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mq2Interval&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 5000 milliseconds = 5 seconds&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// Initialization code goes here&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// 1. Read the internal stopwatch&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; 

 &lt;span class=&quot;c1&quot;&gt;// 2. Check the DHT Task&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousDHTTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dhtInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;previousDHTTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Reset this task's timer&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// 3. Check the MQ2 Task&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousMQ2Time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mq2Interval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;previousMQ2Time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Reset this task's timer&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;analogRead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MQ2_PIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqvsh8kgn96wljcpdkeg.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqvsh8kgn96wljcpdkeg.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;535&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way, we can perform multiple operations in specific intervals without blocking the loop function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Logic of Task Scheduler
&lt;/h2&gt;

&lt;p&gt;I want to perform two operations in ESP8266.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Blink the LED every 2.5 seconds 1 time.&lt;/li&gt;
&lt;li&gt;Blink the LED every 5 seconds 2 times.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's see how to do this without using the built-in task scheduler.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set up serial communication and the LED pin.&lt;/li&gt;
&lt;li&gt;Start Loop.&lt;/li&gt;
&lt;li&gt;Check if 2.5 seconds have passed since the last task activation.&lt;/li&gt;
&lt;li&gt;If yes, perform the blink.&lt;/li&gt;
&lt;li&gt;Check if 5 seconds have passed since the last task activation.&lt;/li&gt;
&lt;li&gt;If yes, perform the blink
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;Arduino.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
 * Performs a single blink on the built-in LED (Active Low).
 * @param message Debug message to output to Serial.
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;performBlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// LED ON&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// LED OFF&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;115200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OUTPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Start with LED OFF&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// Task 1: Every 2.5s (triggers at 2.5s, 5.0s, 7.5s...)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;performBlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[2.5s] &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;c1&quot;&gt;// Task 2: Every 5.0s (triggers at 5.0s, 10.0s...)&lt;/span&gt;
 &lt;span class=&quot;c1&quot;&gt;// At 5s, both tasks trigger, resulting in a double blink.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;performBlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[5.0s] &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;5.0s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;5.0s] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See, as we defined, to use a 2.5 sec interval for the first task and a 5 sec interval for the second task. &lt;/p&gt;

&lt;p&gt;This also means the 2nd time, a 2.5 sec blink will happen after 5 sec from the 1st blink. &lt;/p&gt;

&lt;p&gt;This will create a 2-second blink in 5 sec. &lt;/p&gt;

&amp;lt;h2
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/16118/how-do-smart-devices-perform-multiple-tasks</guid>
<pubDate>Mon, 04 May 2026 10:58:23 +0000</pubDate>
</item>
<item>
<title>How to use Task Scheduler in ESP8266?</title>
<link>https://coderlegion.com/14076/how-to-use-task-scheduler-in-esp8266</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In this article, We will be exploring inbult task function in ESP8266.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Logic of Task Scheduler
&lt;/h2&gt;

&lt;p&gt;I want to perform two operations in ESP8266.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Blink LED every 2.5 seconds 1 time.&lt;/li&gt;
&lt;li&gt;Blink LED every 5 seconds 2 times.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's see how to do this without using inbuilt task scheduler.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setup Serial communication and LED pin.&lt;/li&gt;
&lt;li&gt;Start Loop.&lt;/li&gt;
&lt;li&gt;Check if 2.5 seconds have passed since the last task activation.&lt;/li&gt;
&lt;li&gt;If yes, perform the blink.&lt;/li&gt;
&lt;li&gt;Check if 5 seconds have passed since the last task activation.&lt;/li&gt;
&lt;li&gt;If yes, perform the blink
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;Arduino.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
 * Performs a single blink on the built-in LED (Active Low).
 * @param message Debug message to output to Serial.
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;performBlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// LED ON&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// LED OFF&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;115200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OUTPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Start with LED OFF&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Task 1: Every 2.5s (triggers at 2.5s, 5.0s, 7.5s...)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;performBlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[2.5s] &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Task 2: Every 5.0s (triggers at 5.0s, 10.0s...)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// At 5s, both tasks trigger, resulting in a double blink.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;performBlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[5.0s] &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;5.0s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;5.0s] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See as we defined to use 2.5 sec interval for first task and 5 sec interval for second task. &lt;/p&gt;

&lt;p&gt;This also mean 2nd time 2.5 sec blink will happen after 5 sec from 1st blink. &lt;/p&gt;

&lt;p&gt;This will create 2 times blink in 5 sec. &lt;/p&gt;

&lt;h2&gt;
  
  
  Using Task Scheduler
&lt;/h2&gt;

&lt;p&gt;We are going to use task scheduler library to perform multiple operations in specific intervals.&lt;/p&gt;

&lt;p&gt;Let's see how to do this using task scheduler library.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Include task scheduler library.&lt;/li&gt;
&lt;li&gt;Create a scheduler object.&lt;/li&gt;
&lt;li&gt;Define tasks.&lt;/li&gt;
&lt;li&gt;Add tasks to the scheduler.&lt;/li&gt;
&lt;li&gt;Enable tasks.&lt;/li&gt;
&lt;li&gt;Run the scheduler.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;Arduino.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;TaskScheduler.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Scheduler&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;runner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
 * Performs a single blink pulse.
 * Note: NodeMCU V2 built-in LED is active LOW.
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pulse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ON&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// OFF&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;pulse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Task Definitions&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;t25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TASK_FOREVER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[2.5s] &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;t50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TASK_FOREVER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[5.0s] &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;115200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;pinMode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OUTPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;digitalWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LED_BUILTIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Start OFF&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;runner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Add tasks to the scheduler&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;runner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;addTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;runner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;addTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Enable tasks&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;t25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;t50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;runner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By this way we can perform multiple operations in specific intervals without blocking the loop function.&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;5.0s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;5.0s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2.5s] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also see 5.0s blink is happening first and sometimes 2.5s blink is happening first.&lt;/p&gt;

&lt;p&gt;This is because of the task scheduler.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By this we understood how task scheduler works in ESP8266.&lt;/p&gt;

&lt;p&gt;And we actualy used task scheduler to perform multiple operations in specific intervals without blocking the loop function.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/14076/how-to-use-task-scheduler-in-esp8266</guid>
<pubDate>Sun, 12 Apr 2026 22:21:41 +0000</pubDate>
</item>
<item>
<title>How to perform multiple operations in the ESP8266?</title>
<link>https://coderlegion.com/14077/how-to-perform-multiple-operations-in-the-esp8266</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In this article, We will be exploring how to perform multiple operations in ESP8266.&lt;/p&gt;

&lt;p&gt;As we are using ESP8266, we will be using Arduino framework.&lt;br&gt;
Let see how operations are performed in ESP8266 or any other embedded system.&lt;/p&gt;
&lt;h2&gt;
  
  
  How Operations are performed in ESP8266?
&lt;/h2&gt;

&lt;p&gt;Before going to understand how to perform multiple operations in ESP8266. Let's understand what is how regular programming works in embedded systems.&lt;/p&gt;

&lt;p&gt;Any activity in embedded system is done using loop function.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Do something&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loop function will run continuously.&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z7vutuawksya5mgg9pu.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z7vutuawksya5mgg9pu.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;210&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this loop we can do multiple things.&lt;/p&gt;

&lt;p&gt;For example we can read dht11 sensor data&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this comes with a problem. &lt;/p&gt;

&lt;p&gt;If we run this loop function, it will run continuously. Means there will be no delay between the operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Normal Loop will cause problem?
&lt;/h2&gt;

&lt;p&gt;Let's assume above operation takes 1 ms (which is not true in real world).&lt;br&gt;
And DHT11 sensor should have 1 second delay between readings.&lt;/p&gt;

&lt;p&gt;That means above loop will run 1000 times in 1 second to just see if the sensor data is changed.&lt;/p&gt;

&lt;p&gt;Can you see the problem?&lt;/p&gt;

&lt;p&gt;1000 times operation means 1000 times power consumption.&lt;/p&gt;

&lt;p&gt;1000 times power consumption means battery will drain fast or embedded system will heat up.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs01qpskpmds6chix0kqs.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs01qpskpmds6chix0kqs.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;418&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To Avoid this we can use delay function.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Wait for 1 second&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding delay we are making sure that the loop function is not running continuously.&lt;/p&gt;

&lt;p&gt;But this also has a problem. &lt;/p&gt;

&lt;p&gt;If we add delay of 1 second, it means the loop function will run only once in 1 second.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fte8v3x8mx0btwzmwa2uq.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fte8v3x8mx0btwzmwa2uq.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;400&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So if we want to do multiple operations to be performed in specific intervals. It will be blocked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Other Operation in loop
&lt;/h2&gt;

&lt;p&gt;Like this if we want to read dht11 sensor every 1 second and read mq2 sensor every 5 seconds. We can't use delay function.&lt;/p&gt;

&lt;p&gt;It will be like this&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Read data from sensor&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;analogRead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MQ2_PIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Wait for 5 seconds&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will cause 5 sec no data reading from dht11 sensor.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnllq9w0u7kaxva0j7kr.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnllq9w0u7kaxva0j7kr.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;392&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here where task scheduler comes into picture.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Task Scheduler?
&lt;/h2&gt;

&lt;p&gt;A task scheduler is a lightweight system that allows a processor to juggle multiple activities seemingly at the same time, a concept known as multitasking.&lt;/p&gt;

&lt;p&gt;A Task Scheduler solves this problem using a &quot;to-do list&quot; approach. &lt;/p&gt;

&lt;p&gt;Instead of freezing, the program loops continuously at top speed. &lt;/p&gt;

&lt;p&gt;Every time it loops, the scheduler checks the clock and looks at its list of tasks to see if any are due to run right now. &lt;/p&gt;

&lt;p&gt;If a task's time is up, the scheduler runs it, and then immediately goes back to checking the clock.&lt;/p&gt;

&lt;p&gt;To understand the internal clock, imagine the microcontroller holding a stopwatch that starts counting milliseconds the moment it powers on. &lt;/p&gt;

&lt;p&gt;In Arduino framework, this stopwatch is read using a function called &lt;code&gt;millis()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead of pausing the whole system to wait, the scheduler constantly checks this stopwatch against a simple formula for each task:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Current Time - Last Time Executed &amp;gt;= Interval&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here is simple example of how task scheduler works in ESP8266.&lt;/p&gt;

&lt;p&gt;Ex:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight cpp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousDHTTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// Remembers the last time DHT ran&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousMQ2Time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// Remembers the last time MQ2 ran&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dhtInterval&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;// 1000 milliseconds = 1 second&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mq2Interval&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;// 5000 milliseconds = 5 seconds&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Initialization code goes here&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// 1. Read the internal stopwatch&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;millis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; 

  &lt;span class=&quot;c1&quot;&gt;// 2. Check the DHT Task &amp;#9201;&amp;#65039;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousDHTTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dhtInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;previousDHTTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// Reset this task's timer&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readTemperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dht&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readHumidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;humidity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// 3. Check the MQ2 Task &amp;#9201;&amp;#65039;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previousMQ2Time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mq2Interval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;previousMQ2Time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentMillis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// Reset this task's timer&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;analogRead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MQ2_PIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Send data to cloud&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sendDataToCloud&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2xv1snl09h9dmfk7i8r.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2xv1snl09h9dmfk7i8r.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;534&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way we can perform multiple operations in specific intervals without blocking the loop function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article we have seen how to perform multiple operations in specific intervals without blocking the loop function in ESP8266.&lt;/p&gt;

&lt;p&gt;In next article we will use inbuilt task scheduler and itegrate with painlessmesh.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/14077/how-to-perform-multiple-operations-in-the-esp8266</guid>
<pubDate>Fri, 10 Apr 2026 21:18:16 +0000</pubDate>
</item>
<item>
<title>Automation periodically tasks with CRON job scheduler</title>
<link>https://coderlegion.com/794/automation-periodically-tasks-with-cron-job-scheduler</link>
<description>&lt;p&gt;What is CRON? Unix-like operating systems provide utility for run periodical tasks. For example you need to run script every day at 08:00 AM. CRON read tasks from configuration file line by line and have special syntax.&lt;/p&gt;
&lt;p&gt;Windows have their own tool named as &quot;Windows Task Scheduler&quot;.&lt;/p&gt;
&lt;p&gt;Open terminal and run &quot;crontab -e&quot; command. When you open crontab first time, you must choose editor, which is convenient for your use. Enter number of preferred editor and press &quot;Enter&quot;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user@localhost:~$ crontab -e
no crontab for user - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        &amp;lt;---- easiest
  2. /usr/bin/vim.tiny

Choose 1-2 [1]:
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When you open cron system display generated configuration file with description:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Structure of executable command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of the month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of the week (0–6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * &amp;lt;command to execute&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here cheat-sheet of some examples:&lt;/p&gt;
&lt;p&gt;Run task every minute:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;* * * * * cd /home/user &amp;amp;&amp;amp; ./my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run task every 5 minutes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;*/5 * * * * cd /home/user &amp;amp;&amp;amp; ./my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run task every 1 hour:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0 * * * * cd /home/user &amp;amp;&amp;amp; ./my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or use &quot;@hourly&quot; definition.&lt;/p&gt;
&lt;p&gt;Run task every day at 00:00:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0 0 * * * cd /home/user &amp;amp;&amp;amp; ./my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or use &quot;@daily&quot; definition.&lt;/p&gt;
&lt;p&gt;If your command not running by any reason use &quot;bash -c&quot;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;*/5 * * * * bash -c 'cd /home/user &amp;amp;&amp;amp; ./my_script.sh'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run task at system startup:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@reboot cd /home/user &amp;amp;&amp;amp; ./my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Save changes and exit from editor. Now we're need to reload CRON service. Its need for read configuration file again. Just use &quot;service cron reload&quot; command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user@localhost:~$ service cron reload
Reloading configuration files for periodic command scheduler: cron.
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Cron Jobs</category>
<guid isPermaLink="true">https://coderlegion.com/794/automation-periodically-tasks-with-cron-job-scheduler</guid>
<pubDate>Mon, 13 Jan 2025 20:57:40 +0000</pubDate>
</item>
</channel>
</rss>