<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Clinton Emerhana on Medium]]></title>
        <description><![CDATA[Stories by Clinton Emerhana on Medium]]></description>
        <link>https://medium.com/@simeonclinton10?source=rss-b3811760f632------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2_1JgOcH4R79k4DYUJhhRA.png</url>
            <title>Stories by Clinton Emerhana on Medium</title>
            <link>https://medium.com/@simeonclinton10?source=rss-b3811760f632------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:10:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@simeonclinton10/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Control Three LEDs with an IR Remote and Arduino: Step-by-Step Guide]]></title>
            <link>https://medium.com/@simeonclinton10/how-to-control-three-leds-with-an-ir-remote-and-arduino-step-by-step-guide-14a44f263602?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/14a44f263602</guid>
            <category><![CDATA[led]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[ir-remote]]></category>
            <category><![CDATA[arduino-projects]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Wed, 21 May 2025 04:37:13 GMT</pubDate>
            <atom:updated>2025-05-21T16:14:02.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HdtY9jsYiAiJywxZeTQQg.jpeg" /></figure><p>Have you ever wondered how your TV remote talks to your television? Or how do those small black IR sensors magically respond to button presses? In this beginner-friendly project, we’ll demystify IR communication by building a simple LED control system using an Arduino Uno and the VS1838B IR receiver module. By the end of this project, you’ll not only control three LEDs with your remote but also decode any IR signal using Arduino.</p><p><strong>Components Required</strong></p><ol><li>Arduino UNO (or compatible board)</li><li>VS1838B IR Receiver Module (or sensor)</li><li>IR Remote Control (any old DVD/TV remote will do)</li><li>Breadboard &amp; Jumper Wires</li><li>3 LEDs (Red, Green, Blue)</li><li>3 x 220Ω resistors</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhIiVjzdje3pAvaCNeH44A.jpeg" /><figcaption><strong>Components Required to Build the IR Remote LED Control Project</strong></figcaption></figure><p><strong>Project 1: Reading IR Remote Codes Using Arduino</strong></p><p><strong>Circuit Connections</strong></p><ol><li>VS1838B IR Receiver:</li></ol><p>a. GND → Arduino GND</p><p>b. VCC → Arduino 5V</p><p>c. OUT → Arduino Digital Pin 7</p><p><strong>Decode the IR signals</strong></p><p>In this part of the project, you need to decode the IR signals associated with each button.</p><p><strong>Schematics</strong></p><p>Connect the IR receiver according to the schematics below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*XdevGiX5C_SSvXEh8FkU9g.png" /></figure><p><strong>Install the IRremote Library</strong></p><p>To decode IR signals, you need the IRremote library:</p><ol><li>Go to Sketch → Include Library → Manage Libraries…</li></ol><p>2. Search for IRremote by shirriff and install it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*Y7hDi1vU_N_X1eCZOXAIBg.png" /></figure><p><strong>Arduino Code: Read IR Button Values</strong></p><pre>#include &lt;IRremote.h&gt;              // Include the IR remote library<br><br>const int RECV_PIN = 7;            // Pin connected to IR Receiver<br>IRrecv irrecv(RECV_PIN);           // Create an IR receiver object<br>decode_results results;            // Create a results object to hold decoded data<br><br>void setup() {<br>  Serial.begin(9600);              // Start Serial Monitor at 9600 baud<br>  irrecv.enableIRIn();             // Start the receiver<br>  irrecv.blink13(true);            // Blink pin 13 LED when a signal is received<br>}<br><br>void loop() {<br>  if (irrecv.decode(&amp;results)) {   // Check if signal is received<br>    Serial.println(results.value); // Print decoded IR signal<br>    irrecv.resume();               // Get ready for the next signal<br>  }<br>  delay(100);                      // Short pause to avoid reading the same signal twice<br>}</pre><p>🔍 <strong>Try This:</strong> Open the Serial Monitor (Ctrl + Shift + M), point your remote at the IR sensor, and press buttons. You should see the numeric value of each button press displayed in the Serial Monitor. This value is unique to each button and can be used to control different functions in your projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*GtWq5tNyNcRqN8hXBK5jyw.png" /></figure><p><strong>Building the final circuit to control three LEDs using an IR Remote</strong></p><p>Once you’ve captured the codes for a few buttons, it’s time to turn on/off LEDs with each one.</p><p><strong>Hardware Setup</strong></p><ol><li>Connect LEDs to Pins 8, 9, and 10</li></ol><ul><li>Red → Pin 8</li><li>Green → Pin 9</li><li>Blue → Pin 10</li></ul><p><strong>2. Use 220Ω resistors</strong> for each LED’s GND leg to prevent burning them out.</p><p><strong>Building the final circuit</strong></p><p>In this part, you will see the circuit with three LEDs that will be controlled using your remote.</p><p><strong>Schematics</strong></p><p>Assemble all the parts by following the schematics below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*Wr2IeHt3W2t6nusjY8UIfw.png" /></figure><p><strong>Code</strong></p><p>Use the command values you captured earlier for each button and insert them into the code below.</p><pre>#include &lt;IRremote.h&gt;  // Include the IRremote library to use functions for reading IR signals<br><br>// Define pin connections for the IR receiver and RGB LEDs<br>int IR_Recv = 7;       // IR receiver signal pin is connected to digital pin 7<br>int bluePin = 10;      // Blue LED is connected to digital pin 10<br>int greenPin = 9;      // Green LED is connected to digital pin 9<br>int redPin = 8;        // Red LED is connected to digital pin 8<br><br>IRrecv irrecv(IR_Recv);        // Create an IRrecv object to receive signals on pin 7<br>decode_results results;        // This will hold the decoded IR signal results<br><br>void setup() {<br>  Serial.begin(9600);          // Start serial communication to display values on Serial Monitor<br>  irrecv.enableIRIn();         // Begin the IR receiver so it can detect signals<br>  pinMode(bluePin, OUTPUT);    // Set the blue LED pin as an OUTPUT<br>  pinMode(greenPin, OUTPUT);   // Set the green LED pin as an OUTPUT<br>  pinMode(redPin, OUTPUT);     // Set the red LED pin as an OUTPUT<br>}<br><br>void loop() {<br>  // Check if the IR receiver has received any signal<br>  if (irrecv.decode(&amp;results)) {<br>    long int decCode = results.value;     // Store the received IR code into a variable<br>    Serial.println(results.value);        // Print the received IR code on the Serial Monitor<br><br>    // Take action based on the button pressed on the remote<br>    switch (results.value) {<br><br>      case 16724175: // If &#39;1&#39; button is pressed<br>        digitalWrite(bluePin, HIGH);  // Turn ON the blue LED<br>        break;<br><br>      case 16718055: // If &#39;2&#39; button is pressed<br>        digitalWrite(bluePin, LOW);   // Turn OFF the blue LED<br>        break;<br><br>      case 16743045: // If &#39;3&#39; button is pressed<br>        digitalWrite(greenPin, HIGH); // Turn ON the green LED<br>        break;<br><br>      case 16716015: // If &#39;4&#39; button is pressed<br>        digitalWrite(greenPin, LOW);  // Turn OFF the green LED<br>        break;<br><br>      case 16726215: // If &#39;5&#39; button is pressed<br>        digitalWrite(redPin, HIGH);   // Turn ON the red LED<br>        break;<br><br>      case 16734885: // If &#39;6&#39; button is pressed<br>        digitalWrite(redPin, LOW);    // Turn OFF the red LED<br>        break;<br><br>      case 16738455: // If &#39;0&#39; button is pressed<br>        digitalWrite(bluePin, LOW);   // Turn OFF all LEDs<br>        digitalWrite(greenPin, LOW);<br>        digitalWrite(redPin, LOW);<br>        break;<br><br>      case 16732845: // If &#39;9&#39; button is pressed<br>        digitalWrite(bluePin, HIGH);  // Turn ON all LEDs<br>        digitalWrite(greenPin, HIGH);<br>        digitalWrite(redPin, HIGH);<br>        break;<br>    }<br><br>    irrecv.resume();  // Prepare the IR receiver to read the next signal<br>  }<br><br>  delay(100);         // Add a small delay to avoid signal overlap or bouncing<br>}</pre><p><strong>Watch the video demonstration</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FnoEjaKaho2E%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DnoEjaKaho2E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FnoEjaKaho2E%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/830bcb8342c8d036979cee5beb90fb29/href">https://medium.com/media/830bcb8342c8d036979cee5beb90fb29/href</a></iframe><p><a href="https://youtu.be/noEjaKaho2E">https://youtu.be/noEjaKaho2E</a></p><p>This is a cool project to learn about the IR receiver while also learning essential Arduino concepts. From reading infrared signals to using switch statements and controlling RGB LEDs, this hands-on experience introduces you to real-world embedded system applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14a44f263602" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an RFID Bus/Train Ticketing System with Arduino]]></title>
            <link>https://medium.com/@simeonclinton10/building-an-rfid-bus-train-ticketing-system-with-arduino-0d48f39ce203?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d48f39ce203</guid>
            <category><![CDATA[arduino-rfid-projects]]></category>
            <category><![CDATA[iot-in-public-transport]]></category>
            <category><![CDATA[smart-ticketing-systems]]></category>
            <category><![CDATA[transportation-solutions]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 04:05:33 GMT</pubDate>
            <atom:updated>2025-01-09T04:05:33.568Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong><br>RFID (Radio Frequency Identification) technology is widely used for communication and data transfer via electromagnetic waves in the radio frequency spectrum. It has versatile applications, including inventory management, access control, and transportation ticketing systems. In this project, we explore how to build an RFID-based bus or train ticketing system using an Arduino, an RFID reader (MFRC522), an LCD, and other components. Here, an RFID tag serves as a user’s ticket. When swiped, the system deducts a predefined fare from the user’s balance. If the balance is insufficient or the card is invalid, the system provides feedback through an LCD, buzzer, and LED.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*S_ufoB503g2KJZtHi4RP7Q.jpeg" /></figure><p><strong>Understanding RFID Technology</strong><br>RFID, or Radio Frequency Identification, is a technology that relies on two essential components: the RFID reader and the RFID tag.</p><p>The RFID reader, also referred to as the Proximity Coupling Device (PCD), is equipped with an antenna that emits high-frequency electromagnetic waves. It also includes a circuit that interprets the data from RFID tags. In this particular project, the MFRC522 RFID module is used, which is a well-regarded and affordable option for implementing RFID systems.</p><p>On the other hand, the RFID tag, known as the Proximity Integrated Circuit Card (PICC), can either be passive or active. Passive tags are powered by the electromagnetic waves emitted by the reader, while active tags have an internal battery that powers them. These tags store specific data and transmit it back to the reader when prompted. RFID tags come in various forms, including cards, stickers, and key fobs.</p><p>One significant advantage of RFID over barcodes or QR codes is that RFID tags do not require a direct line of sight for scanning. This feature makes RFID highly suitable for applications that demand rapid and convenient access, such as transportation systems, inventory management, and security.</p><h3>Components Required</h3><ol><li>Arduino UNO</li><li>MFRC522 RFID Module</li><li>16x2 LCD Display (with I2C adapter for fewer pin connections)</li><li>Buzzer</li><li>LED</li><li>Push Button (for resetting the system)</li><li>Jumper Wires</li><li>Breadboard</li></ol><p><strong>Circuit Setup</strong></p><ol><li><strong>RFID Reader (MFRC522): </strong>Connect <strong>RST</strong> to pin 9, <strong>SDA (SS)</strong> to pin 10, <strong>MOSI</strong> to pin 11, <strong>MISO</strong> to pin 12, <strong>SCK</strong> to pin 13, and <strong>GND</strong> and <strong>3.3V</strong> to the Arduino.</li><li><strong>LCD Display: </strong>Connect the SDA and SCL pins of the LCD to the Arduino’s A4 and A5 pins, respectively (for I2C communication).</li><li><strong>Buzzer and LED: </strong>Connect the <strong>buzzer</strong> to pin A1 and the <strong>LED</strong> to pin A0 via 220-ohm resistors.</li><li><strong>Push Button: </strong>Connect one terminal of the button to pin 8 and the other to <strong>GND</strong>, with a pull-up resistor.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*jOo0DmZ9vfJ4GECjpNtWwA.jpeg" /><figcaption><strong>RFID Reader and the Arduino Uno Interface</strong></figcaption></figure><h3>Code Upload with Detailed Comments for Clarity</h3><ol><li>Open the Arduino IDE on your computer.</li><li>Copy the following code into the editor:</li></ol><h3>Code Explanation</h3><p>The following code performs these tasks:</p><ul><li>Initializes RFID reader, LCD, and peripherals.</li><li>Reads the RFID card’s UID.</li><li>Verifies the card against a stored UID.</li><li>Deducts fare if the card is valid and the balance is sufficient.</li></ul><pre>#include &lt;SPI.h&gt;              // Library for SPI communication<br>#include &lt;MFRC522.h&gt;          // Library for RFID reader<br>#include &lt;LiquidCrystal.h&gt;    // Library for controlling the LCD<br><br>// Pin Definitions<br>#define RST_PIN 9             // Reset pin for the RFID module<br>#define SS_PIN 10             // Slave Select pin for the RFID module<br>#define BUZZER_PIN A1         // Pin connected to the buzzer<br>#define LED_PIN A0            // Pin connected to the LED<br>#define BUTTON_PIN 8          // Pin connected to the reset button<br><br>// Initialize the LCD with the pins (RS, E, D4, D5, D6, D7)<br>LiquidCrystal lcd(7, 6, 5, 4, 3, 2);<br><br>// Initialize the RFID reader with the defined pins<br>MFRC522 mfrc522(SS_PIN, RST_PIN);<br><br>// Variables<br>String registeredCard = &quot;73FC233&quot;; // UID of a registered card<br>float balance = 900.0;             // Starting balance for the user<br>float busFare = 250.0;             // Cost of a single bus trip<br><br>void setup() {<br>  // Start serial communication for debugging<br>  Serial.begin(9600);<br><br>  // Initialize SPI communication for RFID<br>  SPI.begin();<br><br>  // Initialize the RFID reader<br>  mfrc522.PCD_Init();<br><br>  // Initialize the LCD<br>  lcd.begin(16, 2); // 16 columns, 2 rows<br><br>  // Set pin modes<br>  pinMode(BUZZER_PIN, OUTPUT); // Set buzzer pin as output<br>  pinMode(LED_PIN, OUTPUT);    // Set LED pin as output<br>  pinMode(BUTTON_PIN, INPUT_PULLUP); // Set button pin as input with pull-up resistor<br><br>  // Display the initial greeting message<br>  resetSystem();<br>}<br><br>void loop() {<br>  // Check if the reset button is pressed<br>  if (digitalRead(BUTTON_PIN) == LOW) {<br>    resetSystem(); // Call the function to reset the system<br>  }<br><br>  // Check if a new RFID card is present<br>  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {<br>    return; // Exit if no card is detected<br>  }<br><br>  // Get the UID of the detected card<br>  String cardUID = getCardUID();<br>  Serial.println(&quot;Card UID: &quot; + cardUID); // Print the card UID for debugging<br><br>  // Check if the card UID matches the registered card<br>  if (cardUID == registeredCard) {<br>    handleRegisteredCard(); // Handle a valid card<br>  } else {<br>    handleUnregisteredCard(); // Handle an invalid card<br>  }<br><br>  // Stop the RFID reader from continuously reading the same card<br>  mfrc522.PICC_HaltA();<br>}<br><br>String getCardUID() {<br>  String uid = &quot;&quot;; // Initialize an empty string for the UID<br>  // Loop through each byte of the UID and convert it to a hexadecimal string<br>  for (byte i = 0; i &lt; mfrc522.uid.size; i++) {<br>    uid += String(mfrc522.uid.uidByte[i], HEX); // Concatenate each byte<br>  }<br>  uid.toUpperCase(); // Convert the UID to uppercase for consistency<br>  return uid; // Return the UID<br>}<br><br>void handleRegisteredCard() {<br>  lcd.clear(); // Clear the LCD screen<br><br>  if (balance &gt;= busFare) {<br>    // Deduct the bus fare from the balance<br>    balance -= busFare;<br><br>    // Display a success message<br>    lcd.print(&quot;Hi User!&quot;);<br>    lcd.setCursor(0, 1); // Move to the second row<br>    lcd.print(&quot;Payment OK!&quot;);<br><br>    delay(2000); // Wait for 2 seconds<br><br>    // Display the updated balance<br>    lcd.clear();<br>    lcd.print(&quot;Balance: N&quot;);<br>    lcd.print(balance);<br><br>    // Sound the buzzer and flash the LED<br>    tone(BUZZER_PIN, 1000, 200); // Sound the buzzer at 1000Hz for 200ms<br>    digitalWrite(LED_PIN, HIGH); // Turn on the LED<br>    delay(1000);                 // Wait for 1 second<br>    digitalWrite(LED_PIN, LOW);  // Turn off the LED<br>  } else {<br>    // Display an insufficient funds message<br>    lcd.print(&quot;Insufficient&quot;);<br>    lcd.setCursor(0, 1); // Move to the second row<br>    lcd.print(&quot;Funds!&quot;);<br><br>    // Sound the buzzer to indicate an error<br>    tone(BUZZER_PIN, 500, 500); // Sound the buzzer at 500Hz for 500ms<br>    delay(2000); // Wait for 2 seconds<br>  }<br>}<br><br>void handleUnregisteredCard() {<br>  lcd.clear(); // Clear the LCD screen<br>  lcd.print(&quot;Invalid Card!&quot;); // Display an invalid card message<br>  lcd.setCursor(0, 1);        // Move to the second row<br>  lcd.print(&quot;Get Valid Card!&quot;);<br><br>  // Sound the buzzer and flash the LED 3 times<br>  for (int i = 0; i &lt; 3; i++) {<br>    tone(BUZZER_PIN, 500, 200); // Sound the buzzer at 500Hz for 200ms<br>    digitalWrite(LED_PIN, HIGH); // Turn on the LED<br>    delay(200);                  // Wait for 200ms<br>    digitalWrite(LED_PIN, LOW);  // Turn off the LED<br>    delay(200);                  // Wait for 200ms<br>  }<br>}<br><br>void resetSystem() {<br>  lcd.clear(); // Clear the LCD screen<br>  lcd.print(&quot;Bus Ticketing&quot;); // Display the system title<br>  lcd.setCursor(0, 1);        // Move to the second row<br>  lcd.print(&quot;Fare: N&quot;);<br>  lcd.print(busFare);         // Display the bus fare<br>  delay(2000); // Wait for 2 seconds<br><br>  lcd.clear(); // Clear the LCD screen<br>  lcd.print(&quot;Swipe Your Card&quot;); // Prompt the user to swipe their card<br>}</pre><h3>Testing and Results</h3><ol><li>Power the Arduino and swipe the RFID card.</li><li>For a valid card:</li></ol><ul><li>The fare is deducted, and the balance is displayed.</li><li>The buzzer and LED indicate success.</li></ul><p>3. For an invalid card:</p><ul><li>An error message is shown, and the buzzer and LED alert the user.</li></ul><h3>Advantages of RFID Ticketing Systems</h3><ul><li><strong>Speed and Convenience:</strong> No need for line-of-sight scanning like barcodes.</li><li><strong>Durability:</strong> Tags are robust and resistant to wear.</li><li><strong>Versatility:</strong> This can be integrated with larger transportation networks.</li></ul><h3>Video Demonstration</h3><p>For a live demonstration of the project in action, watch my YouTube video: <a href="https://youtu.be/LV67xSQB_hM">Click here</a></p><p><strong>Wrapping Up</strong><br>This project demonstrates how to interface RFID with Arduino to create a functional bus or train ticketing system. The integration of RFID’s non-contact communication simplifies and enhances the user experience, making it an ideal choice for modern ticketing solutions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d48f39ce203" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Make a Pomodoro Study Clock Using Arduino]]></title>
            <link>https://medium.com/@simeonclinton10/how-to-make-a-pomodoro-study-clock-using-arduino-9d8994386f78?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d8994386f78</guid>
            <category><![CDATA[arduino-projects]]></category>
            <category><![CDATA[pomodoro-timer]]></category>
            <category><![CDATA[time-management]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[diy-projects]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Sat, 04 Jan 2025 16:05:30 GMT</pubDate>
            <atom:updated>2025-01-04T16:05:30.568Z</atom:updated>
            <content:encoded><![CDATA[<p>The Pomodoro technique is a widely used time management strategy that alternates focused study sessions with short breaks. We will design and build a customizable Pomodoro timer using an Arduino in this project. This timer tracks time and integrates interactive features like LED indicators and LCD messages to improve productivity. Explore how incorporating this tool can enhance your study efficiency and contribute to global educational goals.</p><h3>Introduction</h3><p>The Pomodoro technique is a time management method consisting of 25-minute work or study sessions followed by 5-minute breaks. After four study sessions, you take a longer break, typically 15 or 20 minutes, then repeat the process. Named after a tomato-shaped kitchen timer (“pomodoro” means tomato in Italian), this technique promotes focused work and regular breaks to maximize productivity.</p><p>This project aligns with the United Nations Sustainable Development Goals (SDGs), particularly Goal 4: <strong>Quality Education</strong> — ensuring inclusive and equitable quality education and promoting lifelong learning opportunities for all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*-sca_g1E66k4HR1z6nOsUw.jpeg" /><figcaption>Image Credit: Clinton Emerhana, Diary of an Embedded Systems Lover</figcaption></figure><h3>Materials Required</h3><ol><li>Arduino Uno</li><li>16x2 LCD (standard, non-I2C)</li><li>Breadboard</li><li>Push button</li><li>Resistors (220 ohms for LEDs, 10k ohms for pull-down button)</li><li>LEDs (2: green and red)</li><li>Jumper wires</li><li>Potentiometer (10k ohms) for LCD contrast adjustment</li><li>USB cable</li></ol><h3>Circuit Setup</h3><ul><li>RS → Arduino pin 12</li><li>Enable (E) → Arduino pin 11</li><li>D4 → Arduino pin 5</li><li>D5 → Arduino pin 4</li><li>D6 → Arduino pin 3</li><li>D7 → Arduino pin 2</li><li>VSS → GND</li><li>VDD → 5V</li><li>RW → GND</li><li>Contrast (Vo) → Potentiometer wiper</li></ul><h3>Additional Connections</h3><ul><li>Green LED → Arduino pin 6 (with 220-ohm resistor)</li><li>Red LED → Arduino pin 7 (with 220-ohm resistor)</li><li>Button → Arduino pin 8 (with a 10k-ohm pull-down resistor)</li><li>5V and GND rails on the breadboard powered by the Arduino</li></ul><h3>Circuit Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*pYyoJ-c6_6KUseetuik4sQ.png" /><figcaption><strong>Breadboard diagram for the Pomodoro timer using Tinkercard</strong></figcaption></figure><h3>Code Upload with Detailed Comments for Clarity</h3><ol><li>Open the Arduino IDE on your computer.</li><li>Copy the following code into the editor:</li></ol><pre>#include &lt;LiquidCrystal.h&gt; // Include the LiquidCrystal library to control the LCD<br><br>// Initialize variables to track time and study session count<br>int seconds = 0;<br>int minutes = 0;<br>int count = 0;<br><br>// Define constants for study, short break, long break durations, and session repeats<br>const int study_minutes = 1; <br>const int short_break_minutes = 1; <br>const int long_break_minutes = 1; <br>const int repeats = 2;<br><br>// Temporary variable for break durations<br>int break_duration;<br><br>// Initialize pins for the LCD and other components<br>LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Connect LCD to specified pins<br>const int led1 = 6; // LED for study mode<br>const int led2 = 7; // LED for break mode<br>const int button = 8; // Button to start the timer<br><br>void setup() // Runs once at the start<br>{<br>  lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows<br>  <br>  // Set LED pins as output and button pin as input<br>  pinMode(led1, OUTPUT);<br>  pinMode(led2, OUTPUT);<br>  pinMode(button, INPUT);<br><br>  // Display a message prompting the user to start<br>  lcd.print(&quot;Press button&quot;);<br>  lcd.setCursor(0, 1); // Move cursor to the second row<br>  lcd.print(&quot;to start&quot;);<br><br>  // Wait until the button is pressed to begin<br>  while (digitalRead(button) == LOW) {<br>    // Do nothing, just wait<br>  }<br>}<br><br>void loop() // Main logic runs continuously<br>{<br>  count = 0; // Reset session count<br><br>  // Loop through study and break periods<br>  while (count &lt; repeats) {<br>    // Display &quot;Study time!&quot; and activate study LED<br>    lcd.clear();<br>    lcd.print(&quot;Study time!&quot;);<br>    digitalWrite(led1, HIGH);<br>    digitalWrite(led2, LOW);<br><br>    // Reset time counters<br>    seconds = 0;<br>    minutes = 0;<br><br>    // Count and display time for study period<br>    while (minutes &lt; study_minutes) {<br>      seconds = 0;<br>      while (seconds &lt; 60) {<br>        lcd.setCursor(0, 1); // Move to the second row<br>        if (minutes &lt; 10) lcd.print(&quot;0&quot;); // Add leading zero if needed<br>        lcd.print(minutes);<br>        lcd.print(&quot;:&quot;);<br>        if (seconds &lt; 10) lcd.print(&quot;0&quot;); // Add leading zero if needed<br>        lcd.print(seconds);<br>        delay(1000); // Wait for one second<br>        seconds++;<br>      }<br>      minutes++; // Increment minutes after 60 seconds<br>    }<br><br>    // Prepare for a break<br>    lcd.clear();<br>    lcd.setCursor(0, 0); // Move to the first row<br>    digitalWrite(led1, LOW);<br>    digitalWrite(led2, HIGH);<br><br>    // Determine if it&#39;s a short or long break<br>    if (count == (repeats - 1)) {<br>      break_duration = long_break_minutes; // Last break is a long break<br>      lcd.print(&quot;Long break!&quot;);<br>    } else {<br>      break_duration = short_break_minutes; // Regular short break<br>      lcd.print(&quot;Short break!&quot;);<br>    }<br><br>    // Reset time counters for the break<br>    lcd.setCursor(0, 1); // Move to the second row<br>    seconds = 0;<br>    minutes = 0;<br><br>    // Count and display time for the break period<br>    while (minutes &lt; break_duration) {<br>      seconds = 0;<br>      while (seconds &lt; 60) {<br>        lcd.setCursor(0, 1);<br>        if (minutes &lt; 10) lcd.print(&quot;0&quot;); // Add leading zero if needed<br>        lcd.print(minutes);<br>        lcd.print(&quot;:&quot;);<br>        if (seconds &lt; 10) lcd.print(&quot;0&quot;); // Add leading zero if needed<br>        lcd.print(seconds);<br>        delay(1000); // Wait for one second<br>        seconds++;<br>      }<br>      minutes++; // Increment minutes after 60 seconds<br>    }<br><br>    count++; // Increment session count after each study and break cycle<br>  }<br>}</pre><h3>Variations and Customization</h3><ol><li><strong>Countdown Timer:</strong> Modify the code to count down instead of up.</li><li><strong>Session Display:</strong> Show “Session X/Y” messages.</li><li><strong>Custom Case:</strong> Build a case using cardboard, wood, or 3D printing to house the timer.</li><li><strong>User Customization:</strong> Add potentiometers or additional buttons to adjust session durations.</li><li><strong>Voice Control:</strong> Incorporate voice commands using additional modules like the Elechouse Voice Recognition Module.</li></ol><h3>Video Demonstration</h3><p>For a live demonstration of the project in action, watch my YouTube video: <a href="https://youtu.be/ixfZbMyqpHQ"><strong>Click Here</strong></a>.</p><h3>Wrapping Up</h3><p>This Pomodoro timer project is an excellent way to improve time management while learning electronics and programming concepts. With a non-I2C LCD, you can understand pin-heavy connections and manual configurations. Customize this project further to enhance its functionality and usability.</p><h3>References</h3><ul><li><a href="https://docs.arduino.cc/">Arduino Documentation</a></li><li><a href="https://www.arduino.cc/en/Tutorial/HelloWorld">LiquidCrystal Library Examples</a></li><li><a href="https://www.undp.org/sustainable-development-goals/quality-education">UN Sustainable Development Goals (Goal 4)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d8994386f78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Arduino Automatic Pill Dispenser]]></title>
            <link>https://medium.com/@simeonclinton10/building-an-arduino-automatic-pill-dispenser-cb5dd2b2090f?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb5dd2b2090f</guid>
            <category><![CDATA[arduino-projects]]></category>
            <category><![CDATA[electronics-design]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[health-technology]]></category>
            <category><![CDATA[diy-medicine-dispenser]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Tue, 31 Dec 2024 05:33:18 GMT</pubDate>
            <atom:updated>2024-12-31T05:33:18.954Z</atom:updated>
            <content:encoded><![CDATA[<p>This article demonstrates how to build an <strong>Arduino Automatic Pill Dispenser</strong> using an Arduino UNO, a DS3231 Real-Time Clock (RTC) Module, a pushbutton with a 10K pull-up resistor, a buzzer controlled by a 2N2222 transistor, an LED with a 220-ohm limiting resistor, and a servo motor to dispense pills. This project is ideal for individuals who require medication at precise intervals, offering a cost-effective and automated solution.</p><h3>Materials Needed</h3><ul><li>Arduino UNO</li><li>DS3231 Real-Time Clock (RTC) Module</li><li>Pushbutton</li><li>10K ohm resistor (pull-up)</li><li>LED</li><li>220-ohm resistor</li><li>Buzzer</li><li>2N2222 transistor</li><li>Servo motor</li><li>Breadboard</li><li>Jumper wires</li><li>USB cable for Arduino UNO</li><li>External 5V power supply (if needed for the servo)</li></ul><h3>Wiring the Circuit</h3><p>Follow these wiring instructions carefully:</p><h3>1. DS3231 RTC Module</h3><ul><li><strong>VCC</strong>: Connect to 5V on Arduino.</li><li><strong>GND</strong>: Connect to GND on Arduino.</li><li><strong>SCL</strong>: Connect to A5 (I2C clock line).</li><li><strong>SDA</strong>: Connect to A4 (I2C data line).</li></ul><p>Below is the schematic diagram for the DS3231 RTC and Arduino UNO interface. Ensure you connect the components as illustrated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZ5ATHFacU1wh3ssdll3_Q.png" /></figure><h3>2. Servo Motor</h3><ul><li><strong>Signal (Yellow/White wire)</strong>: Connect to pin 6 on Arduino.</li><li><strong>Power (Red wire)</strong>: Connect to 5V.</li><li><strong>Ground (Black wire)</strong>: Connect to GND.</li></ul><h3>3. Pushbutton with Pull-Up Resistor</h3><ul><li>One terminal of the pushbutton: Connect to pin 9 on Arduino.</li><li>Other terminal of the pushbutton: Connect to GND.</li><li>Pull-up resistor (10K ohm): Connect between pin 9 and 5V.</li></ul><h3>4. Buzzer with Transistor</h3><ul><li><strong>Buzzer positive terminal</strong>: Connect to the collector of the 2N2222 transistor.</li><li><strong>Buzzer negative terminal</strong>: Connect to GND.</li><li><strong>Base of the transistor</strong>: Connect to pin 8 on Arduino through a 1K ohm resistor.</li><li><strong>Emitter of the transistor</strong>: Connect to GND.</li></ul><h3>5. LED with Limiting Resistor</h3><ul><li><strong>Positive terminal (anode)</strong>: Connect to pin 7 on Arduino through a 220-ohm resistor.</li><li><strong>Negative terminal (cathode)</strong>: Connect to GND.</li></ul><h3>6. LCD Display</h3><ul><li>Connect the LCD pins as follows:</li><li><strong>RS</strong>: Pin 12 on Arduino.</li><li><strong>EN</strong>: Pin 11 on Arduino.</li><li><strong>D4</strong>: Pin 5 on Arduino.</li><li><strong>D5</strong>: Pin 4 on Arduino.</li><li><strong>D6</strong>: Pin 3 on Arduino.</li><li><strong>D7</strong>: Pin 2 on Arduino.</li><li><strong>VSS</strong>: Connect to GND.</li><li><strong>VDD</strong>: Connect to 5V.</li><li><strong>V0</strong>: Connect to a 10K potentiometer for contrast adjustment.</li><li><strong>RW</strong>: Connect to GND.</li></ul><h3>CAD Design for the Physical Frame</h3><p>Below is the computer-aided design (CAD) for the Arduino automatic pill dispenser that serves a guide to help you design the frame to hold the pill compartments and the servo motor using plastic materials or cardboard paper. Noted that the CAD of this project was designed with Fusion360 software. Here’s an example of how the frame could look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAzQl62R22jIBw4EW0gqoQ.jpeg" /></figure><p>The frame should have:</p><ul><li>Compartments for pills.</li><li>Space for the servo motor to rotate and align with the compartments.</li><li>A base to securely mount the Arduino, RTC module, and other components.</li></ul><h3>Code Upload with Detailed Comments for Clarity</h3><ol><li>Open the Arduino IDE on your computer.</li><li>Copy the following code into the editor:</li></ol><pre>#include &lt;Servo.h&gt;<br>#include &lt;LiquidCrystal.h&gt;<br>#include &lt;Wire.h&gt;<br><br>#define DS3231_I2C_ADDRESS 0x68<br><br>// Servo and LCD setup<br>Servo servo; // create servo object<br>const int servoPin = 6;<br>const int buttonPin = 9;<br>const int ledPin = 7;<br>const int buzzerPin = 8;<br>int angle = 0;<br>int angleIncrement = 45;  // default 45 degrees for 4 compartments<br>int newAngle;<br>int buttonState;<br>int movementDelay = 50;<br><br>const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;<br>LiquidCrystal lcd(rs, en, d4, d5, d6, d7);<br><br>// Function prototypes<br>void setDS3231time(byte, byte, byte, byte, byte, byte, byte);<br>void readDS3231time(byte*, byte*, byte*, byte*, byte*, byte*, byte*);<br>void alertUser();<br>void updateLCD();<br>byte decToBcd(byte);<br>byte bcdToDec(byte);<br><br>// Time variables<br>byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;<br><br>void setup() {<br>  Wire.begin();<br>  Serial.begin(9600);<br><br>  // Set initial time here: DS3231 seconds, minutes, hours, day, date, month, year<br>  setDS3231time(0, 0, 12, 2, 1, 12, 23); // Adjust this for your initial time<br><br>  pinMode(buttonPin, INPUT_PULLUP);<br>  pinMode(ledPin, OUTPUT);<br>  pinMode(buzzerPin, OUTPUT);<br>  digitalWrite(ledPin, LOW);<br>  digitalWrite(buzzerPin, LOW);<br>  <br>  servo.attach(servoPin);<br>  servo.write(angle); // Initialize servo position<br>  lcd.begin(16, 2);<br>}<br><br>void loop() {<br>  // Update time variables<br>  readDS3231time(&amp;second, &amp;minute, &amp;hour, &amp;dayOfWeek, &amp;dayOfMonth, &amp;month, &amp;year);<br>  updateLCD();<br><br>  // Debugging<br>  Serial.print(&quot;Current Time: &quot;);<br>  Serial.print(hour);<br>  Serial.print(&quot;:&quot;);<br>  Serial.print(minute);<br>  Serial.print(&quot;:&quot;);<br>  Serial.println(second);<br><br>  // Rotate servo at specific times<br>  if (second == 0) { // Trigger once per minute<br>    newAngle = angle + angleIncrement;<br>    if (newAngle &lt;= 180) {<br>      while (angle &lt; newAngle) {<br>        angle++;<br>        servo.write(angle);<br>        delay(movementDelay);<br>      }<br>      alertUser(); // Alert the user<br>    } else {<br>      while (angle &gt; 0) {<br>        angle--;<br>        servo.write(angle);<br>        delay(movementDelay);<br>      }<br>    }<br>  }<br>}<br><br>// Utility to set DS3231 time<br>void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year) {<br>  Wire.beginTransmission(DS3231_I2C_ADDRESS);<br>  Wire.write(0); // Point to timekeeping register<br>  Wire.write(decToBcd(second));<br>  Wire.write(decToBcd(minute));<br>  Wire.write(decToBcd(hour));<br>  Wire.write(decToBcd(dayOfWeek));<br>  Wire.write(decToBcd(dayOfMonth));<br>  Wire.write(decToBcd(month));<br>  Wire.write(decToBcd(year));<br>  Wire.endTransmission();<br>}<br><br>// Utility to read DS3231 time<br>void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) {<br>  Wire.beginTransmission(DS3231_I2C_ADDRESS);<br>  Wire.write(0); // Start at register 0<br>  Wire.endTransmission();<br>  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);<br><br>  *second = bcdToDec(Wire.read() &amp; 0x7F);<br>  *minute = bcdToDec(Wire.read());<br>  *hour = bcdToDec(Wire.read() &amp; 0x3F);<br>  *dayOfWeek = bcdToDec(Wire.read());<br>  *dayOfMonth = bcdToDec(Wire.read());<br>  *month = bcdToDec(Wire.read());<br>  *year = bcdToDec(Wire.read());<br>}<br><br>// Alert the user and wait for button press<br>void alertUser() {<br>  lcd.clear();<br>  lcd.setCursor(0, 0);<br>  lcd.print(&quot;Take medicine!&quot;);<br>  digitalWrite(ledPin, HIGH);<br>  digitalWrite(buzzerPin, HIGH);<br><br>  // Wait for the button to be pressed<br>  while (digitalRead(buttonPin) == HIGH) {<br>    delay(10); // Debounce<br>  }<br><br>  // Turn off LED and buzzer<br>  digitalWrite(ledPin, LOW);<br>  digitalWrite(buzzerPin, LOW);<br>  delay(1000); // Additional debounce delay<br>  lcd.clear();<br>}<br><br>// Update the LCD with the current time and date<br>void updateLCD() {<br>  lcd.setCursor(0, 0);<br>  lcd.print(&quot;Time: &quot;);<br>  if (hour &lt; 10) lcd.print(&quot;0&quot;);<br>  lcd.print(hour);<br>  lcd.print(&quot;:&quot;);<br>  if (minute &lt; 10) lcd.print(&quot;0&quot;);<br>  lcd.print(minute);<br>  lcd.print(&quot;:&quot;);<br>  if (second &lt; 10) lcd.print(&quot;0&quot;);<br>  lcd.print(second);<br><br>  lcd.setCursor(0, 1);<br>  lcd.print(&quot;Date: &quot;);<br>  if (dayOfMonth &lt; 10) lcd.print(&quot;0&quot;);<br>  lcd.print(dayOfMonth);<br>  lcd.print(&quot;/&quot;);<br>  if (month &lt; 10) lcd.print(&quot;0&quot;);<br>  lcd.print(month);<br>  lcd.print(&quot;/20&quot;);<br>  lcd.print(year);<br>}<br><br>// Helper functions for BCD conversion<br>byte decToBcd(byte val) {<br>  return ((val / 10 * 16) + (val % 10));<br>}<br><br>byte bcdToDec(byte val) {<br>  return ((val / 16 * 10) + (val % 16));<br>}</pre><h3>Video Demonstration</h3><p>For a live demonstration of the project in action, watch my YouTube video: <a href="https://youtu.be/2b_bSMHLv-0"><strong>Click Here</strong></a>.</p><h3>Wrapping Up</h3><p>This Automatic Pill Dispenser provides an efficient way to ensure timely medication intake. It is a helpful tool for caregivers and individuals managing complex medication schedules.</p><p>Feel free to leave questions, suggest new projects, and share your feedback in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb5dd2b2090f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Energy-Efficient Lighting System with Arduino]]></title>
            <link>https://medium.com/@simeonclinton10/building-an-energy-efficient-lighting-system-with-arduino-8406809b153f?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/8406809b153f</guid>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[energy-efficiency]]></category>
            <category><![CDATA[smart-home-automation]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[energy-savings]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Mon, 23 Dec 2024 04:30:46 GMT</pubDate>
            <atom:updated>2025-01-04T15:03:58.387Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial will guide you through creating a simple energy-efficient light. It’s perfect for beginners looking to get started with Arduino programming.</p><h4>Components Required</h4><p>To build this system, the following components are required:</p><ul><li>Arduino Uno</li><li>LDR (Light Dependent Resistor)</li><li>PIR motion sensor</li><li>Pushbutton</li><li>BC547 transistor</li><li>Resistor (100kΩ for the LDR, 10kΩ pull-up resistor for the pushbutton, and 1kΩ resistor for biasing the base of the transistor)</li><li>5Volts DC Light (or LED lights)</li><li>Jumper wires and a breadboard</li></ul><h4>How It Works</h4><p>The system uses the LDR to detect darkness. When the ambient light falls below a predefined threshold, the LDR signals the Arduino. Simultaneously, the PIR sensor checks for human motion. If both conditions are met, the system turns on the light for a specified duration. A pushbutton adds a manual override feature, allowing users to toggle the light ON or OFF regardless of the sensor inputs.</p><h4>Circuit Setup</h4><ol><li>Connect the LDR to the Arduino’s analog input pin A0, with one leg connected to 5V and the other to ground through a 10kΩ resistor.</li><li>Wire the PIR motion sensor to digital pin 2.</li><li>Attach the pushbutton to digital pin 3, using an internal pull-up resistor.</li><li>Connect the relay module (or LED) to digital pin 13.</li><li>Power the system using a USB cable or external power source.</li></ol><p>Circuit Diagram</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*vXvFghTDcyw1b8cOoEZMuw.png" /><figcaption><strong>Circuit diagram for the Energy-efficient Light</strong></figcaption></figure><p>Code Upload with Detailed Comments for Clarity</p><ol><li>Open the Arduino IDE on your computer.</li><li>Copy the following code into the editor:</li></ol><pre>// Pin assignments<br>const int ldrPin = A0;       // Analog pin for LDR<br>const int pirPin = 2;        // Digital pin for PIR motion sensor<br>const int buttonPin = 3;     // Digital pin for pushbutton<br>const int lightPin = 13;     // Digital pin for the bulb/LED<br><br>// Thresholds and states<br>const int ldrThreshold = 500;   // LDR threshold for darkness (adjust as needed)<br>bool manualOverride = false;    // Tracks the manual override state<br><br>void setup() {<br>  pinMode(pirPin, INPUT);              // Set PIR sensor pin as input<br>  pinMode(buttonPin, INPUT_PULLUP);    // Set pushbutton pin with internal pull-up resistor<br>  pinMode(lightPin, OUTPUT);           // Set light pin as output<br>  digitalWrite(lightPin, LOW);         // Ensure the light is OFF initially<br>  <br>  Serial.begin(9600);                  // Initialize Serial Monitor for debugging<br>}<br><br>void loop() {<br>  // Read sensor values<br>  int ldrValue = analogRead(ldrPin);       // Get light intensity from LDR<br>  int pirValue = digitalRead(pirPin);      // Get motion detection state from PIR sensor<br>  int buttonState = digitalRead(buttonPin); // Get pushbutton state<br><br>  // Manual override: Toggle light state on button press<br>  static bool lastButtonState = HIGH;      // Stores the previous button state<br>  if (buttonState == LOW &amp;&amp; lastButtonState == HIGH) { <br>    manualOverride = !manualOverride;     // Toggle override state<br>    digitalWrite(lightPin, manualOverride ? HIGH : LOW); // Update light based on override state<br>    delay(50);                            // Debounce delay to avoid multiple toggles<br>  }<br>  lastButtonState = buttonState;          // Update the last button state<br><br>  // Skip sensor logic if manual override is active<br>  if (manualOverride) {<br>    return; // Exit the loop function<br>  }<br><br>  // Sensor-based control: Check for darkness and motion<br>  if (ldrValue &lt; ldrThreshold &amp;&amp; pirValue == HIGH) {<br>    digitalWrite(lightPin, HIGH);         // Turn ON the light<br>    delay(5000);                          // Keep the light ON for 5 seconds<br>    digitalWrite(lightPin, LOW);          // Turn OFF the light<br>  } else {<br>    digitalWrite(lightPin, LOW);          // Ensure the light is OFF if conditions are not met<br>  }<br><br>  // Debugging output (optional)<br>  Serial.print(&quot;LDR: &quot;); <br>  Serial.print(ldrValue);                // Print LDR value<br>  Serial.print(&quot; | PIR: &quot;); <br>  Serial.print(pirValue);                // Print PIR state<br>  Serial.print(&quot; | Button: &quot;); <br>  Serial.print(buttonState);             // Print button state<br>  Serial.print(&quot; | Override: &quot;); <br>  Serial.println(manualOverride);        // Print override state<br>}</pre><h4>Testing and Calibration</h4><p>Testing is essential to ensure the system works correctly. Start by calibrating the LDR threshold to match your ambient light conditions. Monitor the serial output to observe LDR and PIR readings. Test the pushbutton functionality to verify the manual override feature. Simulate real-world scenarios to ensure the system behaves as expected.</p><h3>Video Demonstration</h3><p>For a live demonstration of the project in action, watch my YouTube video: <a href="https://www.youtube.com/watch?app=desktop&amp;v=mZWztJ9Sr5o"><strong>Click Here</strong></a>.</p><h4>Wrapping Up</h4><p>This project demonstrates how simple electronic components, combined with Arduino, can create an intelligent and energy-efficient lighting system. Such systems contribute to sustainability and energy conservation, aligning with global efforts to reduce carbon footprints. By integrating additional features like remote control or IoT connectivity, the system can be further enhanced for smart home applications.</p><p><a href="https://youtu.be/mZWztJ9Sr5o">For more information, you can watch the video here to see a hands-on demonstration</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8406809b153f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Post Soil Moisture Readings to ThingSpeak Using ESP32 and a Soil Moisture Sensor]]></title>
            <link>https://medium.com/@simeonclinton10/how-to-post-soil-moisture-readings-to-thingspeak-using-esp32-and-a-soil-moisture-sensor-ac30dcd84244?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac30dcd84244</guid>
            <category><![CDATA[iot-projects]]></category>
            <category><![CDATA[esp32-tutorial]]></category>
            <category><![CDATA[soil-moisture-sensor]]></category>
            <category><![CDATA[thingspeak]]></category>
            <category><![CDATA[smart-agriculture]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Mon, 02 Sep 2024 11:09:17 GMT</pubDate>
            <atom:updated>2024-09-02T11:09:17.686Z</atom:updated>
            <content:encoded><![CDATA[<p>In this project, we’ll learn how to build an IoT-based soil moisture monitoring system using an ESP32 and a soil moisture sensor. The system measures soil moisture levels and posts the readings to the ThingSpeak cloud platform, where you can monitor the data remotely. This tutorial will guide you through the code step by step to help you understand how everything works.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWqP3gK8o5pA&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWqP3gK8o5pA&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=google" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d56590776249c2aa757a1494930c8eb/href">https://medium.com/media/1d56590776249c2aa757a1494930c8eb/href</a></iframe><p>ThingSpeak lets you publish your sensor readings to their website and plot them in charts with timestamps. Then, you can access your readings from anywhere in the world.</p><h3>Preparing Arduino IDE</h3><p>For this tutorial, we’ll program the ESP32 using the Arduino core. So, make sure you have the ESP32 add-on installed in your Arduino IDE:</p><ul><li><a href="https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/">Installing the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)</a></li></ul><h3>Installing the ThingSpeak Library</h3><p>To send sensor readings to ThingSpeak, we’ll use the <a href="https://github.com/mathworks/thingspeak-arduino">thingspeak-arduino library</a>. library. You can install this library through the Arduino Library Manager. Go to <strong>Sketch </strong>&gt; <strong>Include Library</strong> &gt; <strong>Manage Libraries…</strong> and search for “<strong>ThingSpeak</strong>” in the Library Manager. Install the ThingSpeak library by MathWorks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*9aVUJwSDtYCB2oyjjyWYZQ.png" /></figure><h3>Building the Circuit</h3><p>To exemplify how to send data to ThingSpeak, we’ll send sensor readings from a soil moisture sensor. Therefore, you need to connect a soil moisture sensor to your ESP32.</p><h3>Parts Required</h3><p>To complete this tutorial you need the following parts:</p><ul><li><strong>NodeMCU ESP32 Board</strong>: The brain of our project, capable of Wi-Fi connectivity.</li><li><strong>Soil Moisture Sensor</strong>: This sensor will measure the moisture level in the soil.</li><li><strong>Soil Moisture Probes</strong>: These probes are inserted into the soil to obtain moisture readings.</li><li><strong>Connecting Wires</strong>: These will connect the sensor to the ESP32.</li><li><strong>Breadboard</strong>: A prototyping board to easily connect everything.</li></ul><h3>Schematic Diagram</h3><p>To wire the soil moisture sensor to your ESP32 on the breadboard, connect the sensor’s VCC to the 3.3V pin, GND to a GND pin, and the signal output to GPIO pin 34 on the ESP32.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*QPkRnJNHW9RnXl4Sj2ONtA.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWqP3gK8o5pA&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWqP3gK8o5pA&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=google" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d56590776249c2aa757a1494930c8eb/href">https://medium.com/media/1d56590776249c2aa757a1494930c8eb/href</a></iframe><h3>ThingSpeak — Getting Started</h3><p><a href="https://thingspeak.com/">Go to ThingSpeak</a> and click the “<strong>Get Started For Free</strong>” button to create a new account. This account is linked to a Mathworks account. So, if you already have a Mathworks account, you should log in with that account.</p><h3>Creating New Channel</h3><p>After your account is ready, sign in, open the “<strong>Channels</strong>” tab, and select “<strong>My Channels</strong>“.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*IUKg3SNuiIH6bUwbI5fEQQ.png" /></figure><p>Press the “New Channel” button to create a new channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*4CWQV0DFwu764yn-Ok5xqA.png" /></figure><p>Type a name for your channel and add a description. In this example, we’ll just publish the temperature. If you want to publish multiple readings (like humidity and pressure), you can enable more fields as you’ll see later in this tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*GsxemD76pPsj9IvpfBI-iQ.png" /></figure><p>Click the <strong>Save Channel</strong> button to create and save your channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*Z7MQ_ywU6VJnbmFti0ETzQ.png" /></figure><p>When you’re done, press the “<strong>Save</strong>” button.</p><h3>API Key</h3><p>To send values from the ESP32 to ThingSpeak, obtain the Write API Key. Open the ‘<strong>API Keys’</strong> tab and copy the Write API Key to a safe place, as you’ll need it shortly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*6XKNp0P0-gBdrt-KLtEVBg.png" /></figure><h3>ESP32 Publish Sensor Readings to ThingSpeak — Code</h3><p>Copy the following code to your Arduino IDE</p><pre>#include &lt;WiFi.h&gt;<br>#include &lt;HTTPClient.h&gt;<br>#include &quot;ThingSpeak.h&quot;<br><br>const char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;; // Your WiFi network SSID<br>const char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;; // Your WiFi network password<br>const char* server = &quot;http://api.thingspeak.com/update&quot;; // ThingSpeak server URL<br><br>const char* api_key = &quot;XXXXXXXXXXXXXXXX&quot;; // ThingSpeak channel write API key<br><br>// Soil moisture sensor settings<br>#define SOIL_MOISTURE_PIN 34  // Pin where the soil moisture sensor is connected<br><br><br>void setup() {<br>  Serial.begin(115200);<br>  <br>  // Initialize WiFi<br>  WiFi.begin(ssid, password);<br>  Serial.print(&quot;Connecting to WiFi&quot;);<br>  while (WiFi.status() != WL_CONNECTED) {<br>    delay(1000);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println(&quot;Connected!&quot;);<br><br>}<br><br>void loop() {<br>  // Read soil moisture value<br>  int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);<br>  float soilMoisturePercentage = (100 - ((soilMoistureValue / 4095.0) * 100));<br><br><br>  // Display readings on the Serial Monitor<br>  Serial.print(&quot;Soil Moisture: &quot;);<br>  Serial.println(soilMoisturePercentage);<br><br><br>  // Upload data to ThingSpeak<br>  if (WiFi.status() == WL_CONNECTED) { // Check if connected to WiFi<br>    HTTPClient http; // Declare HTTP client object<br><br>    String url = server; <br>    url += &quot;?api_key=&quot; + String(api_key); // Add API key to the URL<br>    url += &quot;&amp;field1=&quot; + String(soilMoisturePercentage); // Add soil moisture value<br><br>    http.begin(url); // Initialize the HTTP connection<br>    int httpResponseCode = http.GET(); // Send HTTP GET request<br><br>    if (httpResponseCode &gt; 0) { // Check if the request was successful<br>      String payload = http.getString(); // Get the response payload<br>      //Serial.println(&quot;HTTP Response code: &quot; + String(httpResponseCode)); // Print the HTTP response code<br>      //Serial.println(&quot;Payload: &quot; + payload); // Print the response payload<br>    } else {<br>      Serial.println(&quot;Error in sending request&quot;); // Print error message if request failed<br>    }<br><br>    http.end(); // End the HTTP connection<br>  } else {<br>    Serial.println(&quot;WiFi Disconnected&quot;); // Print message if not connected to WiFi<br>  }<br><br>  delay(30000); // Wait for 30 seconds before sending the next reading<br>}<br><br></pre><p>To make the code work, you need to insert your network credentials in the following variables:</p><pre>const char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;   <br>const char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;  </pre><p>Finally, you need to insert the Write API key you’ve gotten from the previous steps:</p><pre>const char * api_key = &quot;XXXXXXXXXXXXXXXX&quot;;</pre><h3>How the Code Works</h3><h3>Step 1: Setting Up the ESP32</h3><p>First, let’s configure the ESP32 to connect to your Wi-Fi network. The code snippet below shows how to initialize the Wi-Fi module:</p><pre>#include &lt;WiFi.h&gt;<br>#include &lt;HTTPClient.h&gt;<br>#include &quot;ThingSpeak.h&quot;<br><br>const char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;; // Your WiFi network SSID<br>const char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;; // Your WiFi network password<br><br>void setup() {<br>  Serial.begin(115200);<br>  <br>  // Initialize WiFi<br>  WiFi.begin(ssid, password);<br>  Serial.print(&quot;Connecting to WiFi&quot;);<br>  while (WiFi.status() != WL_CONNECTED) {<br>    delay(1000);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println(&quot;Connected!&quot;);<br>}</pre><p>In the ‘setup()’ function, we initiate the serial communication at 115200 baud rate and begin the process of connecting to the Wi-Fi network. The ESP32 attempts to connect to the network with the given SSID and password. The while loop checks the connection status, and once connected, it prints &quot;Connected!&quot; on the Serial Monitor.</p><h3>Step 2: Reading Soil Moisture Levels</h3><p>Next, we need to read the soil moisture levels using the sensor connected to the ESP32. The following code captures the sensor data:</p><pre>#define SOIL_MOISTURE_PIN 34  // Pin where the soil moisture sensor is connected<br><br>void loop() {<br>  // Read soil moisture value<br>  int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);<br>  float soilMoisturePercentage = (100 - ((soilMoistureValue / 4095.0) * 100));<br><br>  // Display readings on the Serial Monitor<br>  Serial.print(&quot;Soil Moisture: &quot;);<br>  Serial.println(soilMoisturePercentage);<br>  <br>  // Upload data to ThingSpeak (covered in the next step)<br>  ...<br>}</pre><p>The ‘analogRead()’ function reads the analog value from the soil moisture sensor connected to pin 34 of the ESP32. This value is converted to a percentage, with higher values indicating drier soil. The moisture percentage is then printed to the Serial Monitor.</p><h3>Step 3: Uploading Data to ThingSpeak</h3><p>Once we have the soil moisture readings, we can upload the data to ThingSpeak. The code snippet below shows how to send an HTTP GET request to the ThingSpeak server:</p><pre>const char* server = &quot;http://api.thingspeak.com/update&quot;; // ThingSpeak server URL<br>const char* api_key = &quot;XXXXXXXXXXXXXXXX&quot;; // ThingSpeak channel write API key<br><br>void loop() {<br>  ...<br>  // Upload data to ThingSpeak<br>  if (WiFi.status() == WL_CONNECTED) { // Check if connected to WiFi<br>    HTTPClient http; // Declare HTTP client object<br><br>    String url = server; <br>    url += &quot;?api_key=&quot; + String(api_key); // Add API key to the URL<br>    url += &quot;&amp;field1=&quot; + String(soilMoisturePercentage); // Add soil moisture value<br><br>    http.begin(url); // Initialize the HTTP connection<br>    int httpResponseCode = http.GET(); // Send HTTP GET request<br><br>    if (httpResponseCode &gt; 0) { // Check if the request was successful<br>      String payload = http.getString(); // Get the response payload<br>      //Serial.println(&quot;HTTP Response code: &quot; + String(httpResponseCode)); // Print the HTTP response code<br>      //Serial.println(&quot;Payload: &quot; + payload); // Print the response payload<br>    } else {<br>      Serial.println(&quot;Error in sending request&quot;); // Print error message if request failed<br>    }<br><br>    http.end(); // End the HTTP connection<br>  } else {<br>    Serial.println(&quot;WiFi Disconnected&quot;); // Print message if not connected to WiFi<br>  }<br><br>  delay(30000); // Wait for 30 seconds before sending the next reading<br>}</pre><p>Here’s what’s happening:</p><ul><li>We check if the ESP32 is still connected to the Wi-Fi.</li><li>If connected, we create an HTTP client object and build the URL by appending the API key and the soil moisture reading to the base ThingSpeak URL.</li><li>We then send an HTTP GET request to ThingSpeak, and if successful, the data is uploaded to the cloud.</li><li>The ‘httpResponseCode&#39; indicates whether the request was successful.</li><li>Finally, the connection is closed, and the loop is delayed for 30 seconds before taking the next reading.</li></ul><h3>Demonstration</h3><p>After entering your network credentials, channel number, and API key, upload the code to your board.</p><p>Open the Serial Monitor at a baud rate of 115200 and press the onboard RST button. After 30 seconds, the device should connect to Wi-Fi and begin publishing readings to ThingSpeak.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*sNFhDapn1rLCMlF15yTWxQ.png" /></figure><p>Go to your ThingSpeak account to the channel you’ve just created, and you’ll see the temperature readings being published and plotted on the chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*lMMbYmgBnYnuRHzCRDmOeA.png" /></figure><p>Now, you can access those readings from anywhere around the globe by logging into your ThingSpeak account.</p><p><strong>Wrapping Up</strong></p><p>This project demonstrates how to post soil moisture readings to a cloud-based platform like ThingSpeak using an ESP32 and a soil moisture sensor. The setup allows you to remotely monitor the moisture levels in your garden or farm, enabling better irrigation management. This tutorial lays the foundation for expanding your IoT projects and exploring more advanced features, such as triggering alerts or controlling water pumps based on moisture levels.</p><p>Feel free to leave questions, suggest new projects, and share your feedback in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac30dcd84244" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Easy Guide to Arduino Programming: “Twinkle Twinkle Little Star” Project]]></title>
            <link>https://medium.com/@simeonclinton10/an-easy-guide-to-arduino-programming-twinkle-twinkle-little-star-project-0bc38c861751?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bc38c861751</guid>
            <category><![CDATA[tech-tutorials]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[programming-concepts]]></category>
            <category><![CDATA[coding-basics]]></category>
            <category><![CDATA[arduino-programming]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Mon, 19 Aug 2024 16:17:23 GMT</pubDate>
            <atom:updated>2024-08-19T16:26:51.792Z</atom:updated>
            <content:encoded><![CDATA[<p>Mastering the basics of Arduino programming can seem challenging, but it becomes more manageable by breaking down key concepts like variables, conditional statements, loops, functions, arrays, and strings. In this article, we’ll guide you through a hands-on project — creating a “Twinkle, Twinkle, Little Star” melody using an Arduino. This project reinforces your understanding of these essential programming concepts and introduces you to reading sheet music, helping you bridge the gap between code and music. Let’s break down the details to understand how these concepts work together to create something educational and enjoyable.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FV5f4ML2rOBY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DV5f4ML2rOBY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FV5f4ML2rOBY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c5373f97b28b24271c16364b8ea2057/href">https://medium.com/media/1c5373f97b28b24271c16364b8ea2057/href</a></iframe><p><strong>Components Needed</strong></p><ul><li><strong>Arduino UNO</strong></li><li><strong>Piezo Buzzer</strong></li><li><strong>Breadboard and Jumper Wires</strong></li><li><strong>USB Cable</strong> to connect Arduino to your computer</li><li><strong>Arduino IDE</strong> (download from <a href="https://www.arduino.cc/en/software">here</a>)</li></ul><h3>Understanding Sheet Music</h3><p>Before we start coding, let’s understand the sheet music for “Twinkle Twinkle Little Star.”</p><h4>The Basics of Sheet Music:</h4><ol><li><strong>Staff:</strong> The five lines where the notes sit.</li><li><strong>Clefs:</strong></li></ol><ul><li><strong>Treble Clef (𝄞):</strong> Used for higher-pitched notes.</li><li><strong>Bass Clef (𝄢):</strong> Used for lower-pitched notes.</li></ul><p><strong>3. Notes and Rests:</strong> Indicate the pitch and duration of a sound.</p><ul><li><strong>Whole Note (𝅝):</strong> 4 beats</li><li><strong>Half Note (𝅗𝅥):</strong> 2 beats</li><li><strong>Quarter Note (𝅘𝅥):</strong> 1 beat</li></ul><p><strong>Reading Sheet Music</strong></p><p>Understanding how to read sheet music helps you fully grasp the melody’s implementation. Sheet music represents musical notes, rhythms, and dynamics, which can then be translated into code.</p><ul><li><strong>Notes and Pitches:</strong> Each note on the staff represents a different pitch. In our project, these pitches correspond to specific frequencies used in the tone function.</li><li><strong>Rhythm and Duration:</strong> The length of time a note is held is represented by the note’s duration (e.g., quarter note, half note). In the code, we’ve stored these durations in the ‘noteDurations’ array.</li><li><strong>Playing the Melody:</strong> By understanding the relationship between sheet music and the code, you can experiment with different melodies and rhythms, enhancing your understanding of both music and programming.</li></ul><p><strong>“Twinkle Twinkle Little Star” Sheet Music Breakdown:</strong></p><pre>C C G G A A G2 | F F E E D D C2 |<br>G G F F E E D2 | G G F F E E D2 |<br>C C G G A A G2 | F F E E D D C2 |</pre><p>This tells us which notes to play and how long each note should be held.</p><p><strong>Arduino Programming Concepts</strong></p><h4>Variables:</h4><p>Variables are like storage containers in programming. They hold values that your program can use and change. In our project, we’ll use variables to store the notes and their durations.</p><h4>Conditional Statements:</h4><p>These are like decision-makers in your code. They help execute different blocks of code based on certain conditions. For instance, you can use conditional statements to check if a button is pressed or if a certain time has passed.</p><h4>Loops:</h4><p>Loops help repeat a set of instructions until a condition is met. We will use loops to play each note of the song one by one.</p><h4>Functions:</h4><p>Functions are like mini-programs within your program. They perform specific tasks, which can be reused.</p><h4>Functions:</h4><p>Functions are like mini-programs within your program. They perform specific tasks, which can be reused.</p><h4>Arrays and Strings:</h4><p>Arrays are collections of variables stored together. Strings are sequences of characters. We’ll use arrays to store our notes and their durations.</p><p><strong>Circuit diagram</strong></p><p>This diagram shows how to connect the Arduino UNO to a piezo buzzer using a breadboard, jumper wires, and a USB cable for power and programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*gf6k7O1Uxm5XuR_PgR0a9w.png" /><figcaption><strong>Arduino UNO and Piezo Buzzer Circuit Setup: Connecting components on a breadboard for sound output.</strong></figcaption></figure><h3>Let’s Code “Twinkle Twinkle Little Star”</h3><ol><li><strong>Setting Up the Circuit:</strong></li></ol><ul><li>Connect the piezo buzzer to pin 8 on your Arduino.</li><li>The other pin of the buzzer goes to the ground (GND).</li></ul><p><strong>2. Writing the Code:</strong></p><p>Open the Arduino IDE and write the following code:</p><pre>const int buzzer = 8; // Pin connected to the buzzer<br><br>// Notes and their corresponding frequencies<br>int melody[] = {<br>  262, 262, 392, 392, 440, 440, 392,<br>  349, 349, 330, 330, 294, 294, 262,<br>  392, 392, 349, 349, 330, 330, 294,<br>  392, 392, 349, 349, 330, 330, 294,<br>  262, 262, 392, 392, 440, 440, 392,<br>  349, 349, 330, 330, 294, 294, 262<br>};<br><br>// Note durations (4 means quarter note, 2 means half note)<br>int noteDurations[] = {<br>  4, 4, 4, 4, 4, 4, 2,<br>  4, 4, 4, 4, 4, 4, 2,<br>  4, 4, 4, 4, 4, 4, 2,<br>  4, 4, 4, 4, 4, 4, 2,<br>  4, 4, 4, 4, 4, 4, 2,<br>  4, 4, 4, 4, 4, 4, 2<br>};<br><br>void setup() {<br>  pinMode(buzzer, OUTPUT); // Set buzzer as an output<br>}<br><br>void loop() {<br>  for (int thisNote = 0; thisNote &lt; 42; thisNote++) {<br>    int noteDuration = 1000 / noteDurations[thisNote];<br>    tone(buzzer, melody[thisNote], noteDuration);<br><br>    // Pause between notes to distinguish them<br>    int pauseBetweenNotes = noteDuration * 1.30;<br>    delay(pauseBetweenNotes);<br><br>    // Stop the tone playing<br>    noTone(buzzer);<br>  }<br>}</pre><p><strong>How the Code Works</strong><br><strong>1. Variables</strong></p><ul><li><strong>‘buzzer’</strong> stores the PIN where the buzzer is connected.</li><li><strong>‘melody[]’</strong> is an array storing the frequencies of the notes.</li><li><strong>‘noteDurations[]’ </strong>is an array storing how long each note should be played.</li></ul><p><strong>2. Setup Function:</strong></p><ul><li><strong>‘pinMode(buzzer, OUTPUT);’ </strong>sets the buzzer pin as an output.</li></ul><p><strong>3. Loop Function:</strong></p><ul><li>The <strong>‘for’</strong> loop iterates over each note in the <strong>‘melody’ </strong>array.</li><li><strong>‘tone(buzzer, melody[thisNote], noteDuration);’</strong> plays the note.</li><li><strong>‘delay(pauseBetweenNotes);’</strong> pauses between notes to make them distinct.</li><li><strong>‘noTone(buzzer);’</strong> stops the tone before the next note.</li></ul><h4>Wrapping Up</h4><p>This project teaches you to build a simple melody player with Arduino while reinforcing fundamental programming concepts. Combining variables, conditional statements, loops, functions, arrays, and strings lets you create more amazing projects. With practice, you’ll find that these concepts become second nature, opening the door to more complex and rewarding projects in the future. Feel free to leave questions, suggest new projects, and share your feedback in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bc38c861751" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Unpredictable LED Patterns with a Push Button: Mastering Random Numbers in Arduino]]></title>
            <link>https://medium.com/@simeonclinton10/create-unpredictable-led-patterns-with-a-push-button-mastering-random-numbers-in-arduino-30eb4901885b?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/30eb4901885b</guid>
            <category><![CDATA[led-blink]]></category>
            <category><![CDATA[electronics-for-beginners]]></category>
            <category><![CDATA[push-button-switches]]></category>
            <category><![CDATA[arduino-programming]]></category>
            <category><![CDATA[random-numbers]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 10:34:06 GMT</pubDate>
            <atom:updated>2024-08-18T10:34:06.583Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine pressing a button and watching your LEDs light up in random colors. Isn’t that exciting? Understanding random numbers in Arduino programming can open up endless creative possibilities. This tutorial shows you how to create random LED blinking patterns with a push button, breaking it down so even beginners can easily follow along.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMZuYz9k1L6c%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMZuYz9k1L6c&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMZuYz9k1L6c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/62aee4fbab6a21ce6ba8e8b12399596b/href">https://medium.com/media/62aee4fbab6a21ce6ba8e8b12399596b/href</a></iframe><h4>Components Needed</h4><ul><li><strong>3 LEDs</strong>: Red, Green, Blue</li><li><strong>3 Resistors</strong>: 220 ohms</li><li><strong>1 Push Button</strong></li><li><strong>1 Pull-up Resistor</strong>: 10k ohms (for the button)</li><li><strong>Arduino UNO</strong></li><li><strong>Breadboard and Jumper Wires</strong></li></ul><p><strong>Circuit Diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*vhEKNT_QjxfPz2vpqOALFg.png" /><figcaption><strong>Circuit Diagram for the Unpredictable LED Patterns with a Push Button.</strong></figcaption></figure><h4>Setting Up Your Circuit</h4><ol><li><strong>Connect the LEDs</strong>: Place the LEDs into the breadboard. Connect the LEDs’ positive (anode) legs to Arduino’s digital pins 8, 9, and 10 digital pins 8, 9, and 10 on the Arduino development board. Attach each negative (cathode) leg to a 220-ohm resistor, and then to the ground (GND) on the Arduino.</li><li><strong>Wire the Button</strong>: Connect one side of the push button to pin 7 and the other side to the ground (GND) with a pull-up resistor. This keeps the button input stable.</li></ol><h4>The Code: A Step-by-Step Guide</h4><pre>// Define pin numbers for the LEDs and button<br>const int redLED = 8;      // Red LED connected to pin 8<br>const int greenLED = 9;    // Green LED connected to pin 9<br>const int blueLED = 10;    // Blue LED connected to pin 10<br>const int buttonPin = 7;   // Push button connected to pin 7<br><br>// Variable to keep track of the button state<br>int buttonState = 0;<br><br>void setup() {<br>  // Set LED pins as outputs<br>  pinMode(redLED, OUTPUT);<br>  pinMode(greenLED, OUTPUT);<br>  pinMode(blueLED, OUTPUT);<br><br>  // Set button pin as input with internal pull-up resistor<br>  pinMode(buttonPin, INPUT_PULLUP);<br>}<br><br>void loop() {<br>  // Read the button state<br>  buttonState = digitalRead(buttonPin);<br><br>  // Check if the button is pressed<br>  if (buttonState == LOW) {  // Button pressed (LOW state due to pull-up resistor)<br>    // Generate a random number between 1 and 3<br>    int ledToLight = random(1, 4);<br><br>    // Turn off all LEDs<br>    digitalWrite(redLED, LOW);<br>    digitalWrite(greenLED, LOW);<br>    digitalWrite(blueLED, LOW);<br><br>    // Light up the LED based on the random number<br>    if (ledToLight == 1) {<br>      digitalWrite(redLED, HIGH); // Turn on red LED<br>    } else if (ledToLight == 2) {<br>      digitalWrite(greenLED, HIGH); // Turn on green LED<br>    } else if (ledToLight == 3) {<br>      digitalWrite(blueLED, HIGH); // Turn on blue LED<br>    }<br><br>    // Pause for 500 milliseconds to see the LED change<br>    delay(500);<br>  }<br>}</pre><h4>How the Code Works</h4><ul><li><strong>Pin Definitions</strong>: We assign pins to the push button and LEDs.</li><li><strong>Setup Function</strong>: Initializes pins as outputs (for LEDs) and input (for the button), with an internal pull-up resistor to ensure stable readings.</li><li><strong>Loop Function</strong>: Checks if the button is pressed. When pressed, it generates a random number to decide which LED lights up, then pauses briefly to make the change visible.</li></ul><h4>Watch and Learn</h4><p>Ready to see it in action? Watch the YouTube video <a href="https://youtu.be/MZuYz9k1L6c">here</a>, where I demonstrate how the LEDs blink randomly with each push of the button. It is an engaging way to see random numbers in action.</p><h4><strong>Wrapping Up</strong></h4><p>With this project, you’ve learned how to use random numbers to create unpredictable patterns with LEDs. This is just the beginning — experiment with different setups and discover the creative patterns you can build.</p><p>Feel free to drop your questions and share your projects. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30eb4901885b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Arduino Programming with LED Sequence Control: A Beginner’s Guide to Arrays and Strings]]></title>
            <link>https://medium.com/@simeonclinton10/mastering-arduino-programming-with-led-sequence-control-a-beginners-guide-to-arrays-and-strings-08a0660da24a?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/08a0660da24a</guid>
            <category><![CDATA[arrays-in-c]]></category>
            <category><![CDATA[arduino-programming]]></category>
            <category><![CDATA[arduino-ide]]></category>
            <category><![CDATA[led]]></category>
            <category><![CDATA[arduino-projects]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Sat, 17 Aug 2024 21:38:26 GMT</pubDate>
            <atom:updated>2024-08-17T21:38:26.182Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine you are trying to light up a series of LEDs in a specific pattern. Manually coding each LED to blink one after the other would be exhausting, not to mention inefficient. That’s where the magic of arrays and strings in Arduino programming comes into play. In this guide, I’ll show you how to use these powerful tools to create an LED sequence control project, making your code cleaner and easier to manage. This isn’t just a quick tutorial; it’s a step towards mastering the basics of Arduino programming.</p><p>👉 Watch the full project demo on YouTube: LED Sequence Control using Arrays and Strings. This video demonstrates how the four LEDs (two red, one green, and one blue) blink in sequence, all powered by 220-ohm resistors. Make sure to check it out in the link below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FtNxp5_v4GbU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtNxp5_v4GbU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FtNxp5_v4GbU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b887a657be738143c9a49c9e48277f39/href">https://medium.com/media/b887a657be738143c9a49c9e48277f39/href</a></iframe><p><strong>Understanding Arrays and Strings</strong></p><p>In programming, arrays and strings are essential tools that help us manage multiple data points efficiently. Arrays allow us to store a collection of variables — like the pins connected to LEDs — in a single, easily accessible location. Strings, on the other hand, are used to handle text. But in this project, we’ll focus on arrays to control the LED sequence.</p><p><strong>Components Needed:</strong></p><ul><li>2 x Red LEDs</li><li>1 x Green LED</li><li>1 x Blue LED</li><li>4 x 220-ohm resistors</li><li>Arduino UNO</li><li>Breadboard and jumper wires</li></ul><p><strong>Circuit Diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*pcYAvRdxJNaGiu1nxJCT-w.png" /><figcaption><strong>Circuit diagram for the LED Sequence Control.</strong></figcaption></figure><p><strong>Setting Up the Circuit</strong></p><p>Connect each LED to a separate digital pin on the Arduino, and make sure to place a 220-ohm resistor in series with each LED to prevent them from burning out. Here’s how the connection looks:</p><ul><li>Red LED 1 → Pin 2</li><li>Green LED → Pin 3</li><li>Blue LED → Pin 4</li><li>Red LED 2 → Pin 5</li></ul><p>Ground all the LEDs by connecting the other leg of each LED to the GND pin on your Arduino.</p><p><strong>Writing the Code</strong></p><p>Now, let’s dive into the code that will control this sequence of LEDs. I’ll break down each line below to help you understand how arrays simplify this process.</p><pre>// Define the LED pins in an array for easy access<br>int ledPins[] = {2, 3, 4, 5};  // Array storing the pin numbers for each LED<br><br>// Define the number of LEDs<br>int ledCount = 4;  // We have four LEDs connected<br><br>void setup() {<br>  // Initialize each pin as an output<br>  for (int i = 0; i &lt; ledCount; i++) {<br>    pinMode(ledPins[i], OUTPUT);  // Set each pin in the array to OUTPUT mode<br>  }<br>}<br><br>void loop() {<br>  // Turn on each LED one by one<br>  for (int i = 0; i &lt; ledCount; i++) {<br>    digitalWrite(ledPins[i], HIGH);  // Turn on the LED at the current index<br>    delay(500);  // Wait for 500 milliseconds<br>    digitalWrite(ledPins[i], LOW);  // Turn off the LED<br>  }<br>  <br>  // Now, let&#39;s make the LEDs blink in reverse order<br>  for (int i = ledCount - 1; i &gt;= 0; i--) {<br>    digitalWrite(ledPins[i], HIGH);  // Turn on the LED at the current index<br>    delay(500);  // Wait for 500 milliseconds<br>    digitalWrite(ledPins[i], LOW);  // Turn off the LED<br>  }<br>}</pre><p><strong>How the Code Works</strong></p><ul><li>Array Declaration: ‘int ledPins[] = {2, 3, 4, 5};’ :This line creates an array named ‘ledPins’ that stores the pin numbers where the LEDs are connected. Instead of declaring each pin individually, we store them in an array, making our code cleaner and easier to manage.</li><li>LED Count: ‘int ledCount = 4;’: We define the total number of LEDs, which is helpful for controlling the for-loops later.</li><li>Setup Function: The ‘setup()’ function runs once when the program starts. Here, we use a for-loop to set each pin in the ‘ledPins’ array as an output. The loop runs from 0 to ‘ledCount — 1’, initializing each pin accordingly.</li><li>Loop Function: This is where the magic happens. The first for-loop turns on each LED in sequence, from the first to the last, with a 500ms delay between each. The second for-loop does the same, but in reverse order, creating a back-and-forth blinking effect.</li></ul><p><strong>Wrapping Up</strong></p><p>Arrays simplify your code and create new possibilities for easily managing multiple outputs. This project builds your comfort with arrays in Arduino programming and prepares you for more advanced projects in the future. Don’t forget to watch the full demo on YouTube: <a href="https://youtu.be/tNxp5_v4GbU">LED Sequence Control using Arrays and Strings</a>. It’s a visual walkthrough that complements what you’ve just learned and will help solidify your understanding. Remember, mastering these basics is crucial as you advance in Arduino programming. Keep experimenting, and soon, you’ll be creating even more complex sequences with ease.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08a0660da24a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Arduino Programming: Multiple LED Blink Patterns with Functions]]></title>
            <link>https://medium.com/@simeonclinton10/mastering-arduino-programming-multiple-led-blink-patterns-with-functions-e09882ed43f6?source=rss-b3811760f632------2</link>
            <guid isPermaLink="false">https://medium.com/p/e09882ed43f6</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[arduino-code]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[led]]></category>
            <category><![CDATA[arduino-tutorial]]></category>
            <dc:creator><![CDATA[Clinton Emerhana]]></dc:creator>
            <pubDate>Sat, 17 Aug 2024 04:46:29 GMT</pubDate>
            <atom:updated>2024-08-17T04:46:29.942Z</atom:updated>
            <content:encoded><![CDATA[<p>Are you ready to take your Arduino programming to the next level? Picture yourself controlling a symphony of lights, each one responding to your command, as you uncover the secrets of coding with vibrant red, green, and blue LEDs. Learning to use functions in Arduino can turn your basic projects into impressive displays of creativity and logic. This article will explore multiple LED blink patterns that will not only add flair to your workspace but also strengthen your understanding of programming fundamentals.</p><p><strong>Watch the Magic Unfold</strong></p><p>Before we jump into the details, check out my YouTube video below showcasing this project. Watch as each LED springs to life with synchronized and alternating patterns, illustrating how functions simplify complex tasks in Arduino programming.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FeSTnU1UFC58%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeSTnU1UFC58&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FeSTnU1UFC58%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c40042c993bca279b5b944fa81202f5a/href">https://medium.com/media/c40042c993bca279b5b944fa81202f5a/href</a></iframe><p><strong>Understanding Functions</strong></p><p>Functions allow us to break down complex code into smaller, reusable blocks. This not only makes our code easier to read but also lets us reuse code efficiently. In this project, we’ll use functions to create three distinct LED patterns: simultaneous blinking, alternating blinking, and a wave effect.</p><p><strong>Components Needed</strong></p><ul><li>Arduino UNO</li><li>Red, Green, and Blue LEDs</li><li>220-ohm resistors (one for each LED)</li><li>Breadboard and jumper wires</li></ul><p><strong>Circuit Diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*27XPkz0fOsof6qaSO7cmKw.png" /><figcaption><strong>Circuit diagram for the Multiple LED Blink Pattern.</strong></figcaption></figure><p><strong>Setting Up the Circuit</strong></p><ol><li>Connect each LED to a digital pin on the Arduino:</li></ol><ul><li>Red LED to pin 8</li><li>Green LED to pin 9</li><li>Blue LED to pin 10</li></ul><p>2. Attach a 220-ohm resistor to the negative leg of each LED and connect it to the ground.</p><p>3. Ensure all components are securely placed on the breadboard.</p><p><strong>Writing the Arduino Code</strong></p><p>Let’s write the code to control the LEDs using functions. We’ll start by defining our functions for each LED pattern.</p><pre>// Define LED pins<br>const int redLED = 8;<br>const int greenLED = 9;<br>const int blueLED = 10;<br><br>// Setup function to initialize LED pins as outputs<br>void setup() {<br>  pinMode(redLED, OUTPUT);    // Set red LED pin as output<br>  pinMode(greenLED, OUTPUT);  // Set green LED pin as output<br>  pinMode(blueLED, OUTPUT);   // Set blue LED pin as output<br>}<br><br>// Loop function to repeatedly execute LED patterns<br>void loop() {<br>  simultaneousBlink();  // Call function for simultaneous blinking<br>  delay(1000);          // Wait for a second<br>  alternatingBlink();   // Call function for alternating blinking<br>  delay(1000);          // Wait for a second<br>  waveEffect();         // Call function for wave effect<br>  delay(1000);          // Wait for a second<br>}<br><br>// Function for simultaneous blinking of all LEDs<br>void simultaneousBlink() {<br>  digitalWrite(redLED, HIGH);   // Turn on red LED<br>  digitalWrite(greenLED, HIGH); // Turn on green LED<br>  digitalWrite(blueLED, HIGH);  // Turn on blue LED<br>  delay(500);                   // Wait for half a second<br>  digitalWrite(redLED, LOW);    // Turn off red LED<br>  digitalWrite(greenLED, LOW);  // Turn off green LED<br>  digitalWrite(blueLED, LOW);   // Turn off blue LED<br>  delay(500);                   // Wait for half a second<br>}<br><br>// Function for alternating blinking of LEDs<br>void alternatingBlink() {<br>  digitalWrite(redLED, HIGH);   // Turn on red LED<br>  digitalWrite(greenLED, LOW);  // Ensure green LED is off<br>  digitalWrite(blueLED, LOW);   // Ensure blue LED is off<br>  delay(500);                   // Wait for half a second<br>  digitalWrite(redLED, LOW);    // Turn off red LED<br>  digitalWrite(greenLED, HIGH); // Turn on green LED<br>  digitalWrite(blueLED, LOW);   // Ensure blue LED is off<br>  delay(500);                   // Wait for half a second<br>  digitalWrite(redLED, LOW);    // Ensure red LED is off<br>  digitalWrite(greenLED, LOW);  // Turn off green LED<br>  digitalWrite(blueLED, HIGH);  // Turn on blue LED<br>  delay(500);                   // Wait for half a second<br>}<br><br>// Function for wave effect of LEDs<br>void waveEffect() {<br>  for (int i = 0; i &lt; 3; i++) {    // Repeat the wave effect 3 times<br>    digitalWrite(redLED, HIGH);    // Turn on red LED<br>    delay(200);                    // Wait for 0.2 seconds<br>    digitalWrite(redLED, LOW);     // Turn off red LED<br>    digitalWrite(greenLED, HIGH);  // Turn on green LED<br>    delay(200);                    // Wait for 0.2 seconds<br>    digitalWrite(greenLED, LOW);   // Turn off green LED<br>    digitalWrite(blueLED, HIGH);   // Turn on blue LED<br>    delay(200);                    // Wait for 0.2 seconds<br>    digitalWrite(blueLED, LOW);    // Turn off blue LED<br>  }<br>}</pre><p><strong>How the Code Works</strong></p><ul><li><strong>Simultaneous Blink:</strong> All LEDs light up and turn off together, creating a unified flash of colors.</li><li><strong>Alternating Blink: </strong>The LEDs take turns lighting up, creating a sequential pattern that moves from one LED to the next.</li><li><strong>Wave Effect: </strong>Each LED lights up one after the other, mimicking a wave pattern that repeats several times.</li></ul><p><strong>Bringing It All Together</strong></p><p>By mastering functions, you gain the ability to create diverse and captivating LED patterns with minimal effort. Functions not only simplify your code but also enhance its readability and maintainability, allowing you to build more sophisticated Arduino projects.</p><p><strong>Wrapping Up</strong></p><p>This project demonstrates how functions can simplify and organize your code, making complex tasks manageable and reusable. By experimenting with different patterns, you can create your own unique LED sequences and deepen your understanding of Arduino programming.</p><p>For a step-by-step visual guide, don’t forget to watch the <a href="https://youtu.be/eSTnU1UFC58">YouTube video</a> to see the LED patterns in action and explore more Arduino projects. Also, follow my medium page for more projects and updates. Feel free to leave questions. suggest new projects, and share your feedback in the comments. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e09882ed43f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>