<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shilleh</title>
    <description>The latest articles on DEV Community by Shilleh (@shilleh).</description>
    <link>https://dev.to/shilleh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1045503%2Ffc861dbf-7606-4dba-8f85-387ca9a406a8.JPG</url>
      <title>DEV Community: Shilleh</title>
      <link>https://dev.to/shilleh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shilleh"/>
    <language>en</language>
    <item>
      <title>How to Use L298N Motor Driver with Raspberry Pi Pico W</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Fri, 01 Nov 2024 02:17:14 +0000</pubDate>
      <link>https://dev.to/shilleh/how-to-use-l298n-motor-driver-with-raspberry-pi-pico-w-334m</link>
      <guid>https://dev.to/shilleh/how-to-use-l298n-motor-driver-with-raspberry-pi-pico-w-334m</guid>
      <description>&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/wPOV1CMlhWs"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll explore how to control DC motors using the L298N motor driver and the Raspberry Pi Pico W, with code written in MicroPython. The L298N is a powerful dual H-bridge motor driver that lets you control the direction and speed of two DC motors simultaneously. It’s commonly used in robotics and automation projects because it can handle higher currents and voltages than a microcontroller alone, making it an essential component for projects that involve motors.&lt;/p&gt;

&lt;p&gt;In this project, we’ll connect the L298N to the Raspberry Pi Pico W, using GPIO pins to control the motor’s direction and a PWM (Pulse Width Modulation) pin to control the motor’s speed. By the end of this tutorial, you’ll have a functioning motor that can move forward and backward, with speed control based on your input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What You’ll Need:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/products/raspberry-pi-pico-2w-presoldered-headers" rel="noopener noreferrer"&gt;Raspberry Pi Pico W&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/products/shillehtek-l298n-motor-driver-controller-board" rel="noopener noreferrer"&gt;L298N motor driver&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/AEDIKO-Motor-Gearbox-Shaft-200RPM/dp/B099Z85573" rel="noopener noreferrer"&gt;DC motor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Power source(e.g., 12V battery pack)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/products/shillehtek-400-point-breadboard" rel="noopener noreferrer"&gt;Breadboard (optional)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/products/50cm-alligator-clips-test-leads-double-ended-electrical-jumper-wire" rel="noopener noreferrer"&gt;Alligator Jumper Wires&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/products/shillehtek-120pcs-multicolored-dupont-wire" rel="noopener noreferrer"&gt;ShillehTek Jumper Wires&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use the L298N Motor Driver?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The L298N motor driver makes it possible to control high-power motors using the low-power outputs of microcontrollers like the Raspberry Pi Pico W. It can independently control the speed and direction of two motors. The driver is particularly useful for handling larger currents and voltages that would otherwise damage a microcontroller’s GPIO pins. The H-bridge design allows you to control the direction of current flow, enabling you to easily reverse motor direction.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Step 1: Connecting the L298N to the Raspberry Pi Pico W&lt;/u&gt;&lt;/p&gt;

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

&lt;p&gt;Before we dive into the code, let’s wire up the Pico W and the L298N motor driver:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Power Connections:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect your 12V power supply to the 12V IN and GND pins of the L298N driver.&lt;/li&gt;
&lt;li&gt;Connect Pico W to separate power supply externally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Motor Control Connections:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IN3 on the L298N to GPIO 14 on the Pico W (for motor direction control).&lt;/li&gt;
&lt;li&gt;IN4 on the L298N to GPIO 15 on the Pico W (for motor direction control).&lt;/li&gt;
&lt;li&gt;ENB on the L298N to GPIO 13 on the Pico W (for PWM speed control).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Motor Connection:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect the DC motor’s leads to the OUT3 and OUT4 terminals on the L298N motor driver.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Writing the MicroPython Code
&lt;/h2&gt;

&lt;p&gt;Now that the wiring is complete, let’s write the MicroPython code to control the motor. The following script allows us to move the motor forward and backward while controlling the speed using PWM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PWM&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sleep&lt;/span&gt;

&lt;span class="c1"&gt;# Motor pins
&lt;/span&gt;&lt;span class="n"&gt;in3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# IN3 connected to GPIO 14
&lt;/span&gt;&lt;span class="n"&gt;in4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# IN4 connected to GPIO 15
&lt;/span&gt;&lt;span class="n"&gt;enb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PWM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;      &lt;span class="c1"&gt;# ENB connected to GPIO 13 for PWM control
&lt;/span&gt;&lt;span class="n"&gt;enb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;freq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# Set PWM frequency to 1 kHz
# Motor functions
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;motor_forward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;in3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;high&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;          &lt;span class="c1"&gt;# Set IN3 high
&lt;/span&gt;    &lt;span class="n"&gt;in4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;low&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;           &lt;span class="c1"&gt;# Set IN4 low
&lt;/span&gt;    &lt;span class="n"&gt;enb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;duty_u16&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Set motor speed (0-65535 for duty cycle)
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;motor_backward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;in3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;low&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;           &lt;span class="c1"&gt;# Set IN3 low
&lt;/span&gt;    &lt;span class="n"&gt;in4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;high&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;          &lt;span class="c1"&gt;# Set IN4 high
&lt;/span&gt;    &lt;span class="n"&gt;enb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;duty_u16&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Set motor speed (0-65535 for duty cycle)
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;motor_stop&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;in3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;low&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;           &lt;span class="c1"&gt;# Stop motor
&lt;/span&gt;    &lt;span class="n"&gt;in4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;low&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;           &lt;span class="c1"&gt;# Stop motor
&lt;/span&gt;    &lt;span class="n"&gt;enb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;duty_u16&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# Disable motor (set PWM duty cycle to 0)
# Main loop to test motor
&lt;/span&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Moving forward&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;motor_forward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;32768&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Set speed to 50% (PWM value)
&lt;/span&gt;        &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Stopping&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;motor_stop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Moving backward&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;motor_backward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;32768&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Set speed to 50% (PWM value)
&lt;/span&gt;        &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Stopping&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;motor_stop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;KeyboardInterrupt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;motor_stop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Program stopped&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Breakdown:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IN3 and IN4: These pins control the direction of the motor. If IN3 is high and IN4 is low, the motor moves forward. If IN3 is low and IN4 is high, the motor moves backward.&lt;/li&gt;
&lt;li&gt;ENB: This is the enable pin for the motor connected to OUT3 and OUT4. By using PWM (Pulse Width Modulation) on this pin, we can control the motor’s speed.&lt;/li&gt;
&lt;li&gt;duty_u16(): This function controls the duty cycle of the PWM signal. A value of 65535 represents 100% speed, while 0 represents no speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The motor_forward, motor_backward, and motor_stop functions allow us to easily control the motor’s movement and speed. You can modify the duty_u16 value to control the speed of the motor as needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Running the Code
&lt;/h2&gt;

&lt;p&gt;Once the wiring and code are ready, you can upload this script to the Raspberry Pi Pico W using a MicroPython editor like Thonny. After running the code, the motor should alternate between moving forward and backward with a 2-second pause in between.&lt;/p&gt;

&lt;p&gt;You can modify the motor_forward() and motor_backward() functions to adjust the speed and movement duration as per your project’s requirements.&lt;/p&gt;

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

&lt;p&gt;This tutorial covers the basics of controlling a DC motor with the L298N and Raspberry Pi Pico W. From here, you can expand on this by adding additional motors, sensors, or controls to build more complex robotics projects. You could, for example, add a joystick or buttons to control the motor interactively or integrate line-following sensors to create a basic robot.&lt;/p&gt;

&lt;p&gt;Motor control with MicroPython is a fun and practical way to get started with robotics, and the L298N motor driver offers the flexibility to drive motors with precision. I hope this tutorial helped you get your motor up and running. Stay tuned for more projects!&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>python</category>
      <category>micropython</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Sun, 06 Oct 2024 12:30:38 +0000</pubDate>
      <link>https://dev.to/shilleh/controlling-an-led-with-a-snap-using-the-ky-037-sound-sensor-and-raspberry-pi-4581</link>
      <guid>https://dev.to/shilleh/controlling-an-led-with-a-snap-using-the-ky-037-sound-sensor-and-raspberry-pi-4581</guid>
      <description>&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/TPzVoMPwThk"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Welcome back to part 2 of our KY-037 sound sensor tutorial series! In part 1, we successfully set up the KY-037 sound sensor with a Raspberry Pi to detect sound using its digital output. If you haven’t gone through that tutorial yet, I recommend starting there, as this guide builds upon the previous one.&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll go a step further by integrating an LED that turns on and off based on sound detection. With just a snap of your fingers or a clap, the LED will react accordingly. This project is a fun and interactive way to learn how to control physical components with sound, making it perfect for beginner IoT enthusiasts.&lt;/p&gt;

&lt;p&gt;— — -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at &lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;YouTube — Shilleh&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at &lt;a href="https://buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;Buy Me A Coffee&lt;/a&gt; to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hire Expert IoT Services:&lt;/strong&gt; For personalized assistance with your IoT projects, hire me on &lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;UpWork&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Gather Your Components
&lt;/h2&gt;

&lt;p&gt;To get started, you’ll need the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;KY-037 Sound Sensor: Available at &lt;a href="https://shillehtek.com/products/shillehtek-ky-037-sound-sensor-module" rel="noopener noreferrer"&gt;ShillehTek&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Raspberry Pi (any model with GPIO pins): I’m using a Raspberry Pi 4B.&lt;/li&gt;
&lt;li&gt;3 Male-to-Female Jumper Wires: For connecting the sensor to the Raspberry Pi.&lt;/li&gt;
&lt;li&gt;1 LED: Any color will work, but I’ll be using a red LED.&lt;/li&gt;
&lt;li&gt;1 220-ohm Resistor: To prevent the LED from drawing too much current.&lt;/li&gt;
&lt;li&gt;Breadboard (optional): For organizing your connections.&lt;/li&gt;
&lt;li&gt;A thin screwdriver: For adjusting the potentiometer on the KY-037 sensor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Wiring the KY-037 Sound Sensor and LED to the Raspberry Pi
&lt;/h2&gt;

&lt;p&gt;Before we dive into the wiring, let’s first understand our setup. The sound sensor will detect a snap or clap and send a digital signal to the Raspberry Pi. The Pi will then process this signal and decide whether to turn the LED on or off.&lt;/p&gt;

&lt;p&gt;Here’s how you’ll wire the components:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wiring the KY-037 Sound Sensor:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VCC (Power) pin of the KY-037 connects to pin 2 (5V) on the Raspberry Pi.&lt;/li&gt;
&lt;li&gt;GND (Ground) pin of the KY-037 connects to pin 6 (Ground) on the Raspberry Pi.&lt;/li&gt;
&lt;li&gt;D0 (Digital Output) pin of the KY-037 connects to GPIO 4 on the Raspberry Pi (pin 7 in physical pin layout).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Wiring the LED:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect the longer leg (positive) of the LED to GPIO 17 on the Raspberry Pi (pin 11 in physical layout).&lt;/li&gt;
&lt;li&gt;Connect the shorter leg (negative) of the LED to one end of the 220-ohm resistor.&lt;/li&gt;
&lt;li&gt;Connect the other end of the resistor to GND on the Raspberry Pi (pin 9 in physical layout).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your setup should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KY-037 to Raspberry Pi:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VCC -&amp;gt; 5V (Pin 2)&lt;/li&gt;
&lt;li&gt;GND -&amp;gt; GND (Pin 6)&lt;/li&gt;
&lt;li&gt;D0 -&amp;gt; GPIO 4 (Pin 7)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;LED to Raspberry Pi:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Long Leg (Anode) -&amp;gt; GPIO 17 (Pin 11)&lt;/li&gt;
&lt;li&gt;Short Leg (Cathode) -&amp;gt; 220-ohm Resistor -&amp;gt; GND (Pin 9)&lt;/li&gt;
&lt;li&gt;In summary, the GPIO pin acts as a power source when set to High, allowing the LED to be powered and controlled through software.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt; Make sure to connect the resistor to prevent too much current from flowing through the LED, which could damage it.&lt;/p&gt;

&lt;p&gt;As I mentioned in Part 1, you should fine-tune the potentiometer to the point just below the detection threshold, allowing a snap to easily push it past the limit and trigger a response.&lt;/p&gt;

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

&lt;p&gt;Here is how it looks in real life:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Step 3: Writing the Python Code
&lt;/h2&gt;

&lt;p&gt;Now that we have our components connected, let’s write the Python script to control the LED based on sound detection.&lt;/p&gt;

&lt;p&gt;Create a new Python file called &lt;code&gt;sound_led_control.py&lt;/code&gt; on your Raspberry Pi and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RPi.GPIO&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="c1"&gt;# Set up GPIO pin numbering mode and define pins for sensor and LED
&lt;/span&gt;&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setmode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;BCM&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;SOUND_SENSOR_PIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;  &lt;span class="c1"&gt;# GPIO pin number connected to D0 pin of KY-037
&lt;/span&gt;&lt;span class="n"&gt;LED_PIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;  &lt;span class="c1"&gt;# GPIO pin number connected to LED
&lt;/span&gt;
&lt;span class="c1"&gt;# Set up the pins
&lt;/span&gt;&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SOUND_SENSOR_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pull_up_down&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PUD_DOWN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Configure sound sensor pin as input
&lt;/span&gt;&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LED_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Configure LED pin as output
&lt;/span&gt;
&lt;span class="c1"&gt;# Initialize LED state
&lt;/span&gt;&lt;span class="n"&gt;led_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="c1"&gt;# Function to toggle LED based on sound detection
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;toggle_led&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;led_state&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;led_state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LED_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Turn off the LED
&lt;/span&gt;        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LED turned OFF&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LED_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Turn on the LED
&lt;/span&gt;        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LED turned ON&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;led_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;led_state&lt;/span&gt;  &lt;span class="c1"&gt;# Toggle the state
&lt;/span&gt;
&lt;span class="c1"&gt;# Main loop to check for sound detection and toggle LED
&lt;/span&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Starting sound sensor program. Snap or clap to toggle the LED.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SOUND_SENSOR_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# Sound detected
&lt;/span&gt;            &lt;span class="nf"&gt;toggle_led&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Wait for a second to avoid multiple toggles on one sound
&lt;/span&gt;&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;KeyboardInterrupt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Program interrupted. Cleaning up GPIO settings.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cleanup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# Clean up all GPIO settings
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation of the Code:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Setup:&lt;/strong&gt; We configure the sound sensor pin as an input and the LED pin as an output.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global LED State:&lt;/strong&gt; We keep track of whether the LED is on or off using the &lt;code&gt;led_state&lt;/code&gt; variable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;toggle_led() Function:&lt;/strong&gt; This function toggles the LED based on its current state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Main Loop:&lt;/strong&gt; The loop continuously checks for sound detection. If a sound is detected, it calls &lt;code&gt;toggle_led()&lt;/code&gt; and then waits for 1 second to avoid rapid toggling.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: Running the Code
&lt;/h2&gt;

&lt;p&gt;Once you’ve copied the code into &lt;code&gt;sound_led_control.py&lt;/code&gt;, it’s time to run it! Open a terminal on your Raspberry Pi and navigate to the directory where the file is located. Then, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 sound_led_control.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see a message in the terminal saying, “Starting sound sensor program. Snap or clap to toggle the LED.”&lt;/p&gt;

&lt;p&gt;Testing: Try snapping your fingers or clapping near the sensor. The LED should turn on or off with each snap or clap, depending on its current state. If the LED isn’t responding as expected, adjust the potentiometer on the KY-037 to fine-tune its sensitivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Conclusion and What’s Next?
&lt;/h2&gt;

&lt;p&gt;Congratulations! You’ve successfully created a sound-activated LED control system using the KY-037 sound sensor and Raspberry Pi. In this tutorial, we learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to wire the KY-037 sound sensor and an LED to the Raspberry Pi.&lt;/li&gt;
&lt;li&gt;How to write a Python script to toggle the LED based on sound detection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This project can serve as the foundation for more advanced sound-activated systems, such as creating a sound-responsive smart home lighting system or building an interactive sound-based game.&lt;/p&gt;

&lt;p&gt;In the next tutorial, we’ll explore connecting multiple sound sensors to create more complex systems or use the analog output of the KY-037 for measuring sound intensity. Until then, keep experimenting and learning!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Support and Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don’t forget to check out my YouTube Channel for more tutorials.&lt;/li&gt;
&lt;li&gt;Consider supporting me on Buy Me a Coffee to help fund future content creation.&lt;/li&gt;
&lt;li&gt;For custom projects or professional consulting, feel free to hire me on Upwork.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding, and see you in the next tutorial!&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Getting Started with KY-037 Sound Sensor &amp; Raspberry Pi</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Thu, 03 Oct 2024 21:24:18 +0000</pubDate>
      <link>https://dev.to/shilleh/getting-started-with-ky-037-sound-sensor-raspberry-pi-33o</link>
      <guid>https://dev.to/shilleh/getting-started-with-ky-037-sound-sensor-raspberry-pi-33o</guid>
      <description>&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/P5hbVwG6eBs"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, I’ll guide you through setting up the KY-037 sound sensor with a Raspberry Pi using Python. This tutorial focuses on wiring and coding to measure the digital output signal of the sensor. The KY-037 is a highly versatile sensor that can detect sound levels and is often used in projects requiring sound-activated switches, noise monitoring systems, or smart home automation.&lt;/p&gt;

&lt;p&gt;If you’re not familiar with the KY-037, it has two types of outputs: a digital output and an analog output. The digital output is a simple on/off signal (0 for no sound detected, 1 for sound detected), making it ideal for applications that need to trigger actions when a specific sound threshold is reached — such as clapping to turn on a light. The analog output, on the other hand, provides a range of values representing sound intensity, making it useful for scenarios that require more precise sound measurements. We’ll cover the analog output in a future tutorial, as it’s less commonly used for basic sound detection applications.&lt;/p&gt;

&lt;p&gt;Overall, this sensor is incredibly useful because it’s cost-effective, easy to set up, and versatile enough for a variety of sound-based detection projects. Whether you’re building a sound-activated alarm system or experimenting with noise sensitivity in different environments, the KY-037 is a great sensor to start with.&lt;/p&gt;

&lt;p&gt;— — -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at &lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;YouTube — Shilleh&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at &lt;a href="https://buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;Buy Me A Coffee&lt;/a&gt; to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hire Expert IoT Services:&lt;/strong&gt; For personalized assistance with your IoT projects, hire me on &lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;UpWork&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Wiring the KY-037 Sound Sensor to the Raspberry Pi
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Components Needed:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ShillehTek KY-037 Sound Sensor&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Raspberry Pi&lt;/strong&gt; (any model with GPIO pins). I used a 4B model.&lt;/li&gt;
&lt;li&gt;3 Jumper Wires (Male-to-Female)&lt;/li&gt;
&lt;li&gt;A thin screwdriver or blade (for adjusting the potentiometer)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wiring Diagram:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect the VCC pin of the KY-037 to pin 4 (5V) on the Raspberry Pi.&lt;/li&gt;
&lt;li&gt;Connect the GND pin of the KY-037 to pin 6 (Ground) on the Raspberry Pi.&lt;/li&gt;
&lt;li&gt;Connect the D0 (Digital Output) pin of the KY-037 to GPIO 4 on the Raspberry Pi (pin 7 if you’re using a physical pin layout).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your setup should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KY-037       Raspberry Pi
-----------------------------
VCC  ----&amp;gt;   5V (Pin 2)
GND  ----&amp;gt;   GND (Pin 4)
D0   ----&amp;gt;   GPIO 4 (Pin 7)

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

&lt;/div&gt;



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

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

&lt;p&gt;**Important Note:&lt;br&gt;
**Before we run the code, make sure you have a small blade or screwdriver handy. The KY-037 sound sensor has a potentiometer (a small screw-like component) that you’ll need to adjust while the code is running to get the sensitivity just right. Once the code is running we should reduce or increase sensitivity depending on the output we get in the logs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbq2bdu8g27i3ykwltms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbq2bdu8g27i3ykwltms.png" alt=" " width="800" height="963"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Understanding the Python Code and Running It
&lt;/h2&gt;

&lt;p&gt;Now that we have the hardware set up, let’s go through the Python script used to read the KY-037’s digital output. This script will help us detect sound and print whether sound has been detected in real time.&lt;/p&gt;

&lt;p&gt;You can simply copy this code onto the Raspberry Pi in any Python file and run it.&lt;/p&gt;

&lt;p&gt;Now that we have the hardware set up, let’s go through the Python script used to read the KY-037’s digital output. This script will help us detect sound and print whether sound has been detected in real time.&lt;/p&gt;

&lt;p&gt;You can simply copy this code onto the Raspberry Pi in any Python file and run it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import RPi.GPIO as GPIO
import time

# Set up GPIO pin numbering mode and the sound sensor pin
GPIO.setmode(GPIO.BCM)
SOUND_SENSOR_PIN = 4  # GPIO pin number (adjust as needed)
GPIO.setup(SOUND_SENSOR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# Function to check and print sound detection status
def detect_sound():
    sound_detected = GPIO.input(SOUND_SENSOR_PIN)  # Read the digital signal

    # The KY-037 module has a potentiometer (small screw-like component) that adjusts the sensitivity.
    # Tuning this potentiometer is crucial to get accurate readings. Turning it clockwise increases sensitivity,
    # which means the sensor will detect lower sound levels and produce more "1" (sound detected) outputs.
    # Turning it counter-clockwise decreases sensitivity, making it less likely to detect sound (producing more "0" outputs).
    # If the sensor is only showing "1" (sound detected) values, rotate the potentiometer counter-clockwise
    # (you may need to rotate it up to 100 times) until you start seeing "0" values. This adjustment sets the sensitivity threshold
    # so that it can correctly detect and respond to sound changes.

    if sound_detected == 1:
        print("Sound detected!")  # Sound detected
    else:
        print("No sound detected.")  # No sound detected

# Main program loop
try:
    print("Tuning your KY-037 sound sensor: Adjust the potentiometer to get accurate 0/1 readings.")
    print("If you see only 'Sound detected!' messages, reduce sensitivity by rotating the screw counter-clockwise.")
    while True:
        detect_sound()  # Check sound sensor status
except KeyboardInterrupt:
    print("Program interrupted. Cleaning up GPIO settings.")
    GPIO.cleanup()  # Clean up all GPIO settings
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; By default, the RPi.GPIO library should already be pre-installed on the Raspberry Pi OS. However, if it’s not available, you can install it using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install python3-rpi.gpio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tuning the Sensor While the Code is Running! Important
&lt;/h2&gt;

&lt;p&gt;With the code running, this is where you’ll start adjusting the potentiometer. Use a thin blade or screwdriver to rotate the potentiometer slowly. If the output constantly shows Sound detected!, reduce the sensitivity by rotating the screw counter-clockwise. You should aim to see the output fluctuate between Sound detected! and No sound detected. when there is a change in the sound environment.&lt;/p&gt;

&lt;p&gt;When I first got my sensor I saw this in the logs. Meaning it was sensitive.&lt;/p&gt;

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

&lt;p&gt;After rotations counter clockwise (many of them). I finally saw these values.&lt;/p&gt;

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

&lt;p&gt;You can adjust it to the point where it is right in between, so when you talk or make any noise, it will briefly show “Sound Detected” and then switch back to “No Sound Detected.” This is the sweet spot we need for our next tutorial, where we can snap and trigger an LED to turn on or off.&lt;br&gt;
Play around with it as you like — the world is yours.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please note that it could take dozens of rotations to finally see the value change! Yes, I know it can be frustrating, but be patient with these KY-037s, as their factory default is usually set to the highest sensitivity. I had to turn mine about 100 times counterclockwise before I saw it finally change from “Sound Detected” to “No Sound Detected.”&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Conclusion and What’s Next?
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we successfully connected and tuned the ShillehTek KY-037 sound sensor with the Raspberry Pi. &lt;/p&gt;

&lt;p&gt;We covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wiring the sensor to the Raspberry Pi&lt;/li&gt;
&lt;li&gt;Running a Python script to read the digital output&lt;/li&gt;
&lt;li&gt;Tuning the potentiometer for accurate sound detection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next tutorial, we’ll take it a step further and use the KY-037 to control an LED, turning it on and off with a snap of your fingers! Don’t forget to subscribe to my YouTube channel for more cool tutorials, and feel free to reach out if you have any questions or need help with your project.&lt;br&gt;
If you’re interested in purchasing this sensor, you can get it directly from the ShillehTek Amazon store. Also, if you need custom projects or help with similar electronics, you can hire me on Upwork!&lt;/p&gt;

&lt;p&gt;Good luck, my friends.&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Post to Reddit Using Python</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Wed, 25 Sep 2024 15:11:13 +0000</pubDate>
      <link>https://dev.to/shilleh/how-to-post-to-reddit-using-python-1413</link>
      <guid>https://dev.to/shilleh/how-to-post-to-reddit-using-python-1413</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/jhAW4VG7sOs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll walk through how to automate posting to Reddit using Python. This guide is designed for beginners looking to interact with Reddit’s API programmatically, whether for personal use, bot creation, or automating your social media workflows. By the end, you’ll be able to post to a subreddit with a script that handles authentication.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a Reddit App
&lt;/h2&gt;

&lt;p&gt;To interact with Reddit’s API, you’ll need to register an app. Here’s how to do it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the Reddit Developer Console: Head to reddit.com/prefs/apps.&lt;/li&gt;
&lt;li&gt;Click ‘Create App’: At the bottom of the page, find the “Create App” button.&lt;/li&gt;
&lt;li&gt;Fill in the App Details:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Name: Choose a descriptive name.&lt;/li&gt;
&lt;li&gt;App Type: Select ‘script’ since we’ll be using this for a single user.&lt;/li&gt;
&lt;li&gt;Description: Optional, but you can leave this blank.&lt;/li&gt;
&lt;li&gt;Redirect URI: Set this to &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; or any placeholder URI. We do not need this now, but in a later tutorial we will use this to enable a more secure form of authentication for our app called OAuth, which requires a redirect URL.&lt;/li&gt;
&lt;li&gt;Personal Use Script (Client ID) and Secret: After creating the app, you’ll get these keys. Keep them safe!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of what I filled in down below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9a6vfy8ytii1v10aja8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9a6vfy8ytii1v10aja8w.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Install the Required Libraries
&lt;/h2&gt;

&lt;p&gt;In your Python environment, install the praw library, which is used for interacting with Reddit's API. You should have pip on your computer if you have been working with Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install praw
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Write the Python Script
&lt;/h2&gt;

&lt;p&gt;Now let’s create the Python script that will authenticate and post content to Reddit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import praw
# Reddit API credentials
reddit = praw.Reddit(
    client_id='your_client_id',
    client_secret='your_client_secret',
    user_agent='your_app_name',
    username='your_reddit_username',
    password='your_reddit_password'
)
# Subreddit to post to
subreddit_name = "test"  # Change to your desired subreddit
# Title and content of the post
title = "My first automated post using Python!"
selftext = "Hello Reddit! This post was made using a Python script."
# Submit the post
subreddit = reddit.subreddit(subreddit_name)
subreddit.submit(title=title, selftext=selftext)
print(f"Posted to Reddit: {title}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Explanation of the Script
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;praw:&lt;/strong&gt; This is the Python library that simplifies Reddit API interactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reddit API credentials:&lt;/strong&gt; Replace the placeholders with your app’s credentials (Client ID, Client Secret, etc.).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of an app with all of the credentials. You can see the client id is under “personal use script”., quite long and random.&lt;/p&gt;

&lt;p&gt;You can place the username and password of your reddit account in there as well. FYI this method I am showing you will not work with two-factor, if you are interested leave a comment and we can work on a more advanced methodology. For now you will have to disable two factor auth on your account to get this to work.&lt;/p&gt;

&lt;p&gt;Finally you should place the secret in the secret section and for the user agent just put the name of the app! In my case that would be test-shilleh&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpva2boa8ghqztos8vuig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpva2boa8ghqztos8vuig.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subreddit:&lt;/strong&gt; Define the subreddit you want to post to. You can use a test subreddit like &lt;code&gt;r/test&lt;/code&gt; for practice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Submit the post:&lt;/strong&gt; The &lt;code&gt;submit()&lt;/code&gt; method handles posting to the subreddit with a title and a body (&lt;code&gt;selftext&lt;/code&gt;). For link posts, you can pass a url instead of &lt;code&gt;selftext&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Run the Script
&lt;/h2&gt;

&lt;p&gt;Once you’ve set up everything, simply run your Python script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python post_to_reddit.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is set up correctly, you should see your post in the subreddit you specified!&lt;/p&gt;

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

&lt;p&gt;Automating your Reddit posts can streamline your workflow and save you time. In this tutorial, we walked through how to create a Reddit app, use &lt;code&gt;praw&lt;/code&gt; to authenticate, and post to a subreddit with a simple script. Feel free to extend this by adding more advanced features like fetching data from an API or scheduling your posts.&lt;/p&gt;

&lt;p&gt;If you found this tutorial helpful, consider subscribing for more Python and automation content!&lt;/p&gt;

</description>
      <category>reddit</category>
      <category>python</category>
      <category>api</category>
      <category>automation</category>
    </item>
    <item>
      <title>How to Measure Heart Rate and Blood Oxygen Levels with MAX30102 Sensor on a Raspberry Pi Using Python</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Sat, 24 Aug 2024 23:58:22 +0000</pubDate>
      <link>https://dev.to/shilleh/how-to-measure-heart-rate-and-blood-oxygen-levels-with-max30102-sensor-on-a-raspberry-pi-using-python-50hc</link>
      <guid>https://dev.to/shilleh/how-to-measure-heart-rate-and-blood-oxygen-levels-with-max30102-sensor-on-a-raspberry-pi-using-python-50hc</guid>
      <description>&lt;p&gt;The MAX30102 is a compact, powerful sensor that allows you to measure heart rate and blood oxygen levels (SpO2) with high precision. This tutorial will guide you through connecting the MAX30102 sensor to a Raspberry Pi, setting up the necessary software, and writing Python code to obtain accurate heart rate and SpO2 readings. This is Part 1 of a series. In the next post, we’ll set up a Flask app to display the data in real time!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What You Will Need&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi (any model with I2C support)&lt;/li&gt;
&lt;li&gt;MAX30102 Heart Rate and SpO2 sensor&lt;/li&gt;
&lt;li&gt;Jumper wires&lt;/li&gt;
&lt;li&gt;Breadboard (optional, for easier connections)&lt;/li&gt;
&lt;li&gt;Internet connection for downloading software and libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;— — -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at &lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;YouTube — Shilleh&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at &lt;a href="https://buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;Buy Me A Coffee&lt;/a&gt; to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hire Expert IoT Services:&lt;/strong&gt; For personalized assistance with your IoT projects, hire me on &lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;UpWork&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShillehTekAmazon Store:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/stores/page/F0566360-4583-41FF-8528-6C4A15190CD6?channel=yt" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — US&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.ca/stores/page/036180BA-2EA0-4A49-A174-31E697A671C2?channel=canada" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Canada&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.co.jp/stores/page/C388A744-C8DF-4693-B864-B216DEEEB9E3?channel=japan" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Japan&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Wiring the MAX30102 Sensor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8b32t0hlkc9k336yui1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8b32t0hlkc9k336yui1t.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wiring Connections for MAX30102 Sensor:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VCC: Connect to 3.3V (Pin 1) on the Raspberry Pi — Power&lt;/li&gt;
&lt;li&gt;GND: Connect to GND (Pin 6) on the Raspberry Pi — Ground&lt;/li&gt;
&lt;li&gt;SDA: Connect to SDA (GPIO 2, Pin 3) on the Raspberry Pi — I2C Data&lt;/li&gt;
&lt;li&gt;SCL: Connect to SCL (GPIO 3, Pin 5) on the Raspberry Pi — I2C Clock
Optionally you can use a breadboard as well or connect directly to the sensor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmvw7xm6wi13rtb3uogg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmvw7xm6wi13rtb3uogg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If using a breadboard, the connection would look like above. Where the sensor is inserted into the breadboard, along with jumper wires.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Enable I2C on Raspberry Pi&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before diving into the code, ensure that the I2C interface is enabled on your Raspberry Pi:&lt;/p&gt;

&lt;p&gt;Open the terminal and run the Raspberry Pi configuration tool:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo raspi-config


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

&lt;/div&gt;

&lt;p&gt;Navigate to Interface Options &amp;gt; I2C and select Yes to enable the I2C interface.&lt;/p&gt;

&lt;p&gt;Reboot the Raspberry Pi to apply the changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Download and Set Up the MAX30102 Library&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Download the MAX30102 library and its dependencies. You can find the library here: &lt;a href="https://github.com/doug-burrell/max30102" rel="noopener noreferrer"&gt;MAX30102 GitHub Repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Clone the repository to your Raspberry Pi’s Desktop, you can go to the link and download and unzip the repo&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7avb94lfqfi6597xnh83.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7avb94lfqfi6597xnh83.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or you can clone the code on your computer using git&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

cd ~/Desktop
git clone https://github.com/doug-burrell/max30102.git


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

&lt;/div&gt;

&lt;p&gt;Navigate to the directory where you downloaded the repository, you can use the cd command in the terminal&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

cd max30102


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

&lt;/div&gt;

&lt;p&gt;Unzip all the files and ensure they are in the same directory as your Python script to avoid any import errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Install Required Python Packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to install a few Python packages to interface with the MAX30102 sensor and handle I2C communication:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo apt-get update
sudo apt-get install -y python3-pip python3-smbus i2c-tools


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Python Code to Read Heart Rate and SpO2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the wiring complete and software installed, it’s time to write the Python script to read data from the sensor:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import max30102
import hrcalc
import time

# Initialize the MAX30102 sensor
m = max30102.MAX30102()

def read_sensor():
        while True:
            # Read data from the sensor
            red, ir = m.read_sequential()
            # Calculate heart rate and SpO2
            hr, hr_valid, spo2, spo2_valid = hrcalc.calc_hr_and_spo2(ir, red)

            # Check if valid readings are obtained
            if hr_valid and spo2_valid:
                print("Heart Rate: ", hr, "BPM")
                print("SpO2 Level: ", spo2, "%")
            else:
                print("Invalid readings. Please try again.")

            # Wait for a short time before reading again
            time.sleep(1)

if __name__ == "__main__":
    read_sensor()


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

&lt;/div&gt;

&lt;p&gt;How the Code Works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import Libraries: We import the max30102 library to interact with the sensor, hrcalc to perform heart rate and SpO2 calculations, and time for delays.&lt;/li&gt;
&lt;li&gt;Initialize the Sensor: The MAX30102() class initializes the sensor to begin readings.&lt;/li&gt;
&lt;li&gt;Read and Calculate: The read_sequential() function reads the raw red and IR light data. These values are then used to calculate the heart rate (hr) and SpO2 levels using hrcalc.calc_hr_and_spo2().&lt;/li&gt;
&lt;li&gt;Display Results: The script checks if the readings are valid and prints the heart rate and SpO2 level if they are. If not, it prompts the user to try again.&lt;/li&gt;
&lt;li&gt;Loop: The script runs in an infinite loop, continuously reading and displaying data until interrupted.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember to place your index finger gently on the sensor for the most accurate readings. Now you’re all set to work with your MAX30102 sensor in a controlled and efficient environment!&lt;/p&gt;

&lt;p&gt;Here is an example output you will see once you start placing your finger on the sensor, otherwise it will show invalid. Good luck!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pea5f5h7er825zsagh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pea5f5h7er825zsagh8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
You now have a working setup to measure heart rate and blood oxygen levels using a MAX30102 sensor and Raspberry Pi. This setup provides a solid foundation for further projects, such as creating a web interface to visualize data in real time. Stay tuned for Part 2, where we’ll build a Flask app to display these readings dynamically on a web page!&lt;/p&gt;

&lt;p&gt;Feel free to share your thoughts, questions, or improvements in the comments below.&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>beginners</category>
      <category>sensors</category>
      <category>programming</category>
    </item>
    <item>
      <title>Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Sat, 17 Aug 2024 01:24:16 +0000</pubDate>
      <link>https://dev.to/shilleh/getting-started-with-stm32-blue-pill-in-arduino-ide-using-a-usb-to-ttl-converter-write-your-first-program-4naj</link>
      <guid>https://dev.to/shilleh/getting-started-with-stm32-blue-pill-in-arduino-ide-using-a-usb-to-ttl-converter-write-your-first-program-4naj</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/G0FdOLbJV7M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill using the Arduino IDE and a DSD TECH SH-U09C5 USB to TTL converter. The STM32 Blue Pill is a powerful yet affordable microcontroller board based on the STM32F103C8T6 ARM Cortex-M3 processor. Known for its robustness and versatility, the Blue Pill is an excellent choice for hobbyists, makers, and professionals alike who are looking to harness the power of 32-bit ARM architecture in their projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the STM32 Blue Pill?
&lt;/h2&gt;

&lt;p&gt;The STM32 Blue Pill offers an impressive set of features at a fraction of the cost of similar microcontrollers. With a 72 MHz clock speed, 20 KB of RAM, and 64 KB of flash memory, it outperforms many 8-bit microcontrollers, making it suitable for more demanding applications such as real-time data processing, motor control, and advanced sensor integration. Its wide range of peripherals, including SPI, I2C, USART, and ADC, allows for seamless interfacing with various components, sensors, and modules.&lt;/p&gt;

&lt;p&gt;Additionally, the STM32 Blue Pill is well-supported by the open-source community, with a variety of development environments available, including the Arduino IDE. This makes it accessible even to those who are familiar with Arduino but want to step up to more advanced hardware.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use a USB to TTL Converter?
&lt;/h2&gt;

&lt;p&gt;Unlike many Arduino boards, the STM32 Blue Pill does not come with a built-in USB-to-serial converter, which is typically used for uploading code and debugging. Instead, the board is equipped with UART (Universal Asynchronous Receiver-Transmitter) pins that require an external converter to communicate with your computer. The DSD TECH SH-U09C5 USB to TTL converter acts as a bridge between your computer’s USB port and the UART pins on the Blue Pill, allowing you to upload code, monitor serial output, and debug your programs. This converter is an essential tool in working with the STM32 Blue Pill, enabling seamless communication between the board and your development environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qvvg6ik7auul8v92a57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qvvg6ik7auul8v92a57.png" alt="Image description" width="659" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Started with a Pre-Soldered Board
&lt;/h2&gt;

&lt;p&gt;For those looking to dive straight into development without the hassle of soldering, you can purchase pre-soldered STM32 Blue Pill boards at &lt;a href="https://www.amazon.com/stores/page/449449C5-66B0-4AC3-8550-912EA923FD81?ingress=2&amp;amp;visitId=8c1a7949-cd9f-49e3-ac55-9c39e7f831f6&amp;amp;ref_=ast_bln" rel="noopener noreferrer"&gt;Shillehtek&lt;/a&gt;. These boards come ready to use, so you can focus on building your projects right away.&lt;/p&gt;

&lt;p&gt;— — -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at &lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;YouTube — Shilleh&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at &lt;a href="https://buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;Buy Me A Coffee&lt;/a&gt; to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hire Expert IoT Services:&lt;/strong&gt; For personalized assistance with your IoT projects, hire me on &lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;UpWork&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShillehTekAmazon Store:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/stores/page/F0566360-4583-41FF-8528-6C4A15190CD6?channel=yt" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — US&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.ca/stores/page/036180BA-2EA0-4A49-A174-31E697A671C2?channel=canada" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Canada&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.co.jp/stores/page/C388A744-C8DF-4693-B864-B216DEEEB9E3?channel=japan" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Japan&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Connect the STM32 Blue Pill to the USB to TTL Converter
&lt;/h2&gt;

&lt;p&gt;To start, you’ll need to connect your STM32 Blue Pill to your computer using the DSD TECH SH-U09C5 USB to TTL converter. This converter will allow your computer to communicate with the STM32 Blue Pill via its UART interface.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fin9wauz691ecdb9x6018.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fin9wauz691ecdb9x6018.png" alt="Image description" width="775" height="623"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wiring Setup:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RXD (SH-U09C5) -&amp;gt; PA9 (RX on Blue Pill)&lt;/li&gt;
&lt;li&gt;TXD (SH-U09C5) -&amp;gt; PA10 (TX on Blue Pill)&lt;/li&gt;
&lt;li&gt;GND (SH-U09C5) -&amp;gt; GND (Blue Pill)&lt;/li&gt;
&lt;li&gt;VCC (SH-U09C5) -&amp;gt; 3.3V (Blue Pill)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Set the BOOT0 Jumper:&lt;/strong&gt;&lt;br&gt;
Set the BOOT0 jumper on the Blue Pill to the 1 position (this puts the Blue Pill into UART bootloader mode). See diagram below for bootloader mode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzmgm8ns6l4pjx0ntuk91.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzmgm8ns6l4pjx0ntuk91.png" alt="Image description" width="725" height="871"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to plug the TTL converter into power, you can simply plug it into your computer if it has a USB port!&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Install STM32 Support in Arduino IDE
&lt;/h2&gt;

&lt;p&gt;Before you can program the STM32 Blue Pill in the Arduino IDE, you need to install support for STM32 boards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Open Arduino IDE Preferences&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the Arduino IDE.&lt;/li&gt;
&lt;li&gt;Go to &lt;strong&gt;File &amp;gt; Preferences.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Add STM32 Board Manager URL&lt;/strong&gt;&lt;br&gt;
In the “Additional Boards Manager URLs” field, add the following URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json" rel="noopener noreferrer"&gt;https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;OK.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmvpqlgsstwr5itfege9v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmvpqlgsstwr5itfege9v.png" alt="Image description" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Install STM32 Boards&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to Tools &amp;gt; Board &amp;gt; Boards Manager.&lt;/li&gt;
&lt;li&gt;Search for STM32 and click Install next to the “STM32 MCU based boards” package.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 3: Select the STM32 Blue Pill Board in Arduino IDE
&lt;/h2&gt;

&lt;p&gt;After installing STM32 support, you’ll need to configure the Arduino IDE to use the correct settings for your STM32 Blue Pill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Select the Board&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Go to &lt;strong&gt;Tools &amp;gt; Board &amp;gt; STM32 Boards&lt;/strong&gt; and select &lt;strong&gt;Generic STM32F1 series&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configure Board Settings&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Under Tools &amp;gt; Board Part Number, select BluePill F103C8 (or BluePill F103CB if you have the 128KB flash version).&lt;/li&gt;
&lt;li&gt;Set the Upload Method to STM32CubeProgrammer (Serial).&lt;/li&gt;
&lt;li&gt;Set the Port to the port associated with the device.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 4: Install STM32CubeProgrammer
&lt;/h2&gt;

&lt;p&gt;STM32CubeProgrammer is required for uploading code to the STM32 Blue Pill via the serial interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Download and Install STM32CubeProgrammer&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download STM32CubeProgrammer from STMicroelectronics.&lt;/li&gt;
&lt;li&gt;Make sure you create a free account if you have not.&lt;/li&gt;
&lt;li&gt;Install it on your system following the on-screen instructions. It has downloads for different operating systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Set the Environment Variable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open a terminal and add the STM32CubeProgrammer path to the STM32_PRG_PATH environment variable.&lt;/p&gt;

&lt;p&gt;For macOS, add the following line to your ~/.zshrc or ~/.bash_profile file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export STM32_PRG_PATH=/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Apply the changes by running:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source ~/.zshrc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source ~/.bash_profile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Windows:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the Start Menu and search for “Environment Variables.”&lt;/li&gt;
&lt;li&gt;Select “Edit the system environment variables” from the search results.&lt;/li&gt;
&lt;li&gt;In the System Properties window, click on the “Environment Variables” button.&lt;/li&gt;
&lt;li&gt;Under “System variables” (or “User variables” if you prefer), click on “New.”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Variable Name:&lt;/strong&gt; STM32_PRG_PATH&lt;br&gt;
&lt;strong&gt;Variable Value:&lt;/strong&gt; The path to the STM32CubeProgrammer bin directory, such as:&lt;br&gt;
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin&lt;/p&gt;

&lt;p&gt;Click “OK” to save the new environment variable.&lt;/p&gt;

&lt;p&gt;Close the Environment Variables and System Properties windows.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5: Upload Your First Program
&lt;/h2&gt;

&lt;p&gt;Now that everything is set up, you’re ready to upload your first program to the STM32 Blue Pill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Write the Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open a new sketch in Arduino IDE and write a simple program. Here’s an example that prints a message to the Serial Monitor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void setup() {
  // Start the Serial communication at 9600 baud
  Serial.begin(9600);

  // Wait for the serial port to connect (necessary for some boards)
  while (!Serial) {
    ; // Wait
  }
}

void loop() {
  // Print a message to the Serial Monitor
  Serial.println("Hello, Blue Pill!");

  // Wait for 1 second
  delay(1000);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Reset the Blue Pill&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before clicking the upload button in Arduino IDE, press the Reset button on the Blue Pill board. This ensures that the board is ready to receive the program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Upload the Code&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the Upload button in Arduino IDE.&lt;/li&gt;
&lt;li&gt;After the upload completes you will see the onboard LED blink on intervals. If you want to upload another script you can hit the reset button and modify the script and upload again!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Troubleshooting&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you encounter issues with uploading:&lt;/li&gt;
&lt;li&gt;Ensure the correct port is selected.&lt;/li&gt;
&lt;li&gt;Check your wiring and jumper settings.&lt;/li&gt;
&lt;li&gt;Verify that the &lt;code&gt;STM32_PRG_PATH&lt;/code&gt; environment variable is correctly set.&lt;/li&gt;
&lt;li&gt;Ensure your board is authentic, like the board from STM32 ShillehTek Amazon Store. The board comes pre-soldered as well.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Congratulations! You’ve successfully set up and programmed your STM32 Blue Pill using the Arduino IDE and the DSD TECH SH-U09C5 USB to TTL converter. This powerful microcontroller opens up a world of possibilities for your projects, offering the performance of a 32-bit ARM Cortex-M3 processor at an affordable price. Whether you’re a beginner or an experienced developer, the STM32 Blue Pill is a versatile tool that can help you bring your ideas to life.&lt;/p&gt;

&lt;p&gt;If you found this tutorial helpful, be sure to check out more content on my YouTube channel, where I regularly share tips, tutorials, and project ideas to help you get the most out of your development boards and microcontrollers. Don’t forget to subscribe at &lt;a href="https://www.youtube.com/@mmshilleh/videos" rel="noopener noreferrer"&gt;MM Shilleh on YouTube&lt;/a&gt; to stay updated with the latest videos. Good luck with your projects!&lt;/p&gt;

</description>
      <category>arduino</category>
      <category>programming</category>
      <category>iot</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Fri, 09 Aug 2024 13:51:14 +0000</pubDate>
      <link>https://dev.to/shilleh/automate-task-scheduling-in-aws-with-lambda-step-functions-and-cloudwatch-44k7</link>
      <guid>https://dev.to/shilleh/automate-task-scheduling-in-aws-with-lambda-step-functions-and-cloudwatch-44k7</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ffoeBfk4mmM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, I’ll show you how to automatically schedule tasks in AWS at regular intervals using AWS Step Functions and CloudWatch with AWS Lambda. Learn how to chain your Lambda functions and schedule them to run whenever you need, essential for production-level applications requiring task automation, especially for ETLs.&lt;/p&gt;

&lt;p&gt;I’ll guide you through all the necessary AWS services, ensuring a seamless setup. This tutorial is perfect for both beginners and advanced programmers looking to automate their code tasks in AWS. While we’ll be using Python for the Lambdas, the concepts apply to any code or series of code you want to automate.&lt;/p&gt;

&lt;p&gt;The tools I demonstrate are just the tip of the iceberg. With AWS, you can define any behaviors or patterns you want to see, offering endless possibilities for automation and task scheduling.&lt;/p&gt;

&lt;p&gt;Don’t miss out on mastering this crucial skill for efficient cloud automation!&lt;/p&gt;

&lt;p&gt;— — -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at &lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;YouTube — Shilleh&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at &lt;a href="https://buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;Buy Me A Coffee&lt;/a&gt; to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hire Expert IoT Services:&lt;/strong&gt; For personalized assistance with your IoT projects, hire me on &lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;UpWork&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShillehTekAmazon Store:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/stores/page/F0566360-4583-41FF-8528-6C4A15190CD6?channel=yt" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — US&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.ca/stores/page/036180BA-2EA0-4A49-A174-31E697A671C2?channel=canada" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Canada&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.co.jp/stores/page/C388A744-C8DF-4693-B864-B216DEEEB9E3?channel=japan" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Japan&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1-) Setup Your Lambda Functions
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we’ll demonstrate how to work with a straightforward set of Python Lambda functions in AWS. While you can combine various Lambda functions to create more complex workflows, we’ll keep today’s example simple to help you get started.&lt;/p&gt;

&lt;p&gt;If you’re new to AWS Lambda, it’s a serverless computing service that allows you to run code without provisioning or managing servers. We’ll be creating two Lambda functions using Python 3.12 in AWS to illustrate the process. Here are the two Lambdas after creation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3akd3dhk6s1mt0p7v55p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3akd3dhk6s1mt0p7v55p.png" alt="Image description" width="800" height="926"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftoo74615bfyvh85au3qe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftoo74615bfyvh85au3qe.png" alt="Image description" width="800" height="916"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2-) Setup Your Step Function
&lt;/h2&gt;

&lt;p&gt;In this step, we’ll create a Step Function that orchestrates the execution of the two Lambda functions we just created. The images above show the two Lambda functions, &lt;code&gt;test-yt-1&lt;/code&gt; and &lt;code&gt;test-yt-2&lt;/code&gt;, along with the structure of the Step Function.&lt;/p&gt;

&lt;p&gt;Here’s how it works:&lt;/p&gt;

&lt;p&gt;Lambda Functions:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;test-yt-1&lt;/code&gt;: This Lambda function returns a simple JSON response with a status code of 200 and a message &lt;code&gt;"Hello from Lambda!"&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;test-yt-2&lt;/code&gt;: Similarly, this function returns a JSON response with a status code of 200 and a message &lt;code&gt;"Hello from Lambda Again!"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step Function Workflow:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Step Function starts by executing the first task, which corresponds to &lt;code&gt;test-yt-1&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;test-yt-1&lt;/code&gt; returns a status code of 200, the workflow proceeds to the next step.&lt;/li&gt;
&lt;li&gt;A Choice state evaluates the output of &lt;code&gt;test-yt-1&lt;/code&gt;. If the status code is 200, the workflow continues to &lt;code&gt;test-yt-2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Froj4ybxrc7g55degz5a6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Froj4ybxrc7g55degz5a6.png" alt="Image description" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After successfully executing &lt;code&gt;test-yt-2&lt;/code&gt;, the workflow ends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This example demonstrates a very simple flow, but AWS Step Functions offer much more flexibility. You can design all sorts of workflows with complex logic, branching, and error handling. Whether you want to run a series of tasks in sequence or parallel, or just a single task, Step Functions provide a powerful yet user-friendly interface to manage these processes.&lt;/p&gt;

&lt;p&gt;The visual editor in AWS makes it easy to create and manage these workflows with a nice graphical interface, allowing you to focus on your business logic without worrying about the underlying infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3-) CloudWatch Scheduler
&lt;/h2&gt;

&lt;p&gt;AWS CloudWatch Scheduler is a powerful tool that allows you to automatically trigger your workflows, Lambda functions, or other AWS services at specific intervals. It is essential for automating tasks that need to run at regular times, like daily reports, routine maintenance, or even triggering workflows based on specific patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why It’s Important
&lt;/h2&gt;

&lt;p&gt;By scheduling tasks, you can ensure that critical operations happen without manual intervention, reducing the risk of missed tasks and improving efficiency. Whether it’s running periodic data processing jobs or sending reminders, CloudWatch Scheduler enables you to focus on other tasks while ensuring that your processes run on time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up a Cron-Based Schedule
&lt;/h2&gt;

&lt;p&gt;In our example, we’ll use a cron-based schedule to trigger the Step Function. A cron expression is a string that defines the timing of the task. In the image above, we’ve set up a cron expression that triggers the function every 2 minutes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Cron Expressions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A cron expression consists of five fields separated by spaces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Minutes:&lt;/strong&gt; (0–59)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hours:&lt;/strong&gt; (0–23)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day of the Month:&lt;/strong&gt; (1–31)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Month:&lt;/strong&gt; (1–12)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day of the Week:&lt;/strong&gt; (0–7) (Sunday is both 0 and 7)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajb5qyf2bgedr37pjgzs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajb5qyf2bgedr37pjgzs.png" alt="Image description" width="800" height="673"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;**For instance, in our setup, &lt;code&gt;cron(0/2 * * * ? *)&lt;/code&gt;, the function is scheduled to run every 2 minutes. This means that once you deploy this schedule, AWS will automatically trigger your workflow at these intervals.&lt;/p&gt;

&lt;p&gt;You should select a target next for the step function. Be sure to select start execution and select your state machine. This should be all you need to initiate your processes at an automated interval! Very cool!**&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu12y9rm7c3me6m4z2gh0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu12y9rm7c3me6m4z2gh0.png" alt="Image description" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzjlysz1v07l8n0jo0sf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzjlysz1v07l8n0jo0sf.png" alt="Image description" width="800" height="725"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjqp9smdy6jwxo23xc3zi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjqp9smdy6jwxo23xc3zi.png" alt="Image description" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After setting up the cron expression and confirming the schedule, AWS CloudWatch Scheduler will take care of the rest, automatically invoking your Step Function according to the specified schedule. This automation ensures your tasks run consistently, providing peace of mind and freeing you from the need to remember to start tasks manually.&lt;/p&gt;

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

&lt;p&gt;In this tutorial, we’ve walked through the process of automating task scheduling in AWS using Step Functions, CloudWatch Scheduler, and Lambda. By chaining Lambda functions together and scheduling them to run at regular intervals, you’ve learned how to create a powerful automation workflow essential for production-level applications, such as ETL processes and other recurring tasks.&lt;/p&gt;

&lt;p&gt;We’ve covered the basics of setting up Lambda functions, designing a Step Function to manage their execution, and using CloudWatch Scheduler to trigger these workflows automatically. While our example was straightforward, the tools and techniques demonstrated here can be applied to far more complex scenarios, enabling you to design sophisticated automation flows with conditional logic, parallel execution, and error handling — all managed through an intuitive, visual interface.&lt;/p&gt;

&lt;p&gt;AWS provides a vast array of services that can help you define and automate almost any behavior or pattern you can imagine, making it an indispensable platform for cloud-based automation and task scheduling. By mastering these skills, you’ll be well-equipped to optimize and streamline your workflows, saving both time and effort.&lt;/p&gt;

&lt;p&gt;If you found this tutorial helpful, I encourage you to subscribe to our YouTube channel for more in-depth tutorials and insights. Don’t hesitate to ask any questions or share your thoughts in the comments — your feedback is always appreciated! For those who want to support our content creation efforts, consider buying me a coffee or exploring our services for personalized IoT project assistance.&lt;/p&gt;

&lt;p&gt;Thank you for following along, and I look forward to seeing you in the next tutorial!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>python</category>
      <category>cloud</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Implementing Google reCAPTCHA in a Simple React and Node.js App</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Tue, 23 Jul 2024 13:14:42 +0000</pubDate>
      <link>https://dev.to/shilleh/implementing-google-recaptcha-in-a-simple-react-and-nodejs-app-4j2i</link>
      <guid>https://dev.to/shilleh/implementing-google-recaptcha-in-a-simple-react-and-nodejs-app-4j2i</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0xd0Gfr-dYo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In today’s digital landscape, protecting your applications from bots and spam is crucial. One effective way to add an extra layer of security to your forms is by integrating Google reCAPTCHA.&lt;/p&gt;

&lt;p&gt;CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a type of challenge-response test used in computing to determine whether the user is human. It helps prevent automated software from performing actions that can degrade the quality of service.&lt;/p&gt;

&lt;p&gt;reCAPTCHA is a more advanced form of CAPTCHA developed by Google, which not only protects websites from spam and abuse but also helps digitize text, annotate images, and build machine learning datasets. It often involves identifying objects in images or simply checking a box that says “I’m not a robot.”&lt;/p&gt;

&lt;p&gt;A robot or automated script could, in theory, attempt to click a CAPTCHA checkbox, but modern CAPTCHA systems like reCAPTCHA use various techniques to distinguish human behavior from automated scripts. These techniques include:&lt;/p&gt;

&lt;p&gt;Behavior Analysis: reCAPTCHA analyzes user behavior, such as mouse movements, keystrokes, and the time taken to complete tasks, to determine if the user is human.&lt;br&gt;
Challenges: If the behavior analysis is inconclusive, reCAPTCHA may present additional challenges, such as identifying objects in images or solving puzzles, which are designed to be difficult for bots.&lt;br&gt;
Machine Learning: reCAPTCHA uses machine learning algorithms to continually improve its ability to differentiate between humans and bots based on data collected from users.&lt;br&gt;
These methods make it challenging for automated scripts to successfully bypass CAPTCHA systems.&lt;/p&gt;

&lt;p&gt;This blog post will walk you through the process of implementing Google reCAPTCHA in a simple React and Node.js application. We’ll cover both the frontend and backend, ensuring that reCAPTCHA verification is seamlessly integrated into your login process.&lt;/p&gt;

&lt;p&gt;Link to GH Project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/shillehbean/youtube-p2/tree/main/reCAPTCHA-react" rel="noopener noreferrer"&gt;https://github.com/shillehbean/youtube-p2/tree/main/reCAPTCHA-react&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;— — -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at &lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;YouTube — Shilleh&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at &lt;a href="https://buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;Buy Me A Coffee&lt;/a&gt; to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hire Expert IoT Services:&lt;/strong&gt; For personalized assistance with your IoT projects, hire me on &lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;UpWork&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShillehTekAmazon Store:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/stores/page/F0566360-4583-41FF-8528-6C4A15190CD6?channel=yt" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — US&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.ca/stores/page/036180BA-2EA0-4A49-A174-31E697A671C2?channel=canada" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Canada&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.co.jp/stores/page/C388A744-C8DF-4693-B864-B216DEEEB9E3?channel=japan" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Japan&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Step 1: Set Up Your React and Node.js Environment&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First, ensure you have Node.js and npm installed on your machine. If not, download and install them from &lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;https://nodejs.org/en&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create a New React App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a new React application using Create React App:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app recaptcha-demo
cd recaptcha-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Step 3: Install Necessary Packages&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We’ll use &lt;code&gt;react-google-recaptcha&lt;/code&gt; for integrating reCAPTCHA into our React app:&lt;/p&gt;

&lt;p&gt;Installing &lt;code&gt;ajv&lt;/code&gt; manually with &lt;code&gt;npm install --save-dev ajv@^7&lt;/code&gt; resolves a missing module error by ensuring the correct version is available for your project dependencies.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev ajv@^7
npm install react-google-recaptcha axios react-toastify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Create Your Node.js Backend&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set up your Node.js backend by creating a new directory and initializing a new Node.js project:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
mkdir backend
cd backend
npm init -y
npm install express axios dotenv cors jsonwebtoken express-async-handler
npm install --save-dev nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkirjw1p8z1namup1s25.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkirjw1p8z1namup1s25.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your directory structure should look like this.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Step 5: Set Up Google reCAPTCHA&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Go to the Google reCAPTCHA Admin Console at &lt;a href="https://www.google.com/recaptcha/admin/create" rel="noopener noreferrer"&gt;https://www.google.com/recaptcha/admin/create&lt;/a&gt; to register your site. You will receive a Site Key and a Secret Key. Save these keys for use in your application.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Step 6: Set Up Your Environment Variables&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Create a .env file in your backend directory and add your Google reCAPTCHA keys:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CAPTCHA_SECRET_KEY=your-secret-key
JWT_SECRET=anything
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Create a .env file in your React project directory and add your Google reCAPTCHA site key:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REACT_APP_CAPTCHA_SITE_KEY=your-site-key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Step 7: Create Backend Middleware for reCAPTCHA Verification&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;middleware&lt;/code&gt; directory and add &lt;code&gt;recaptchaMiddleware.js&lt;/code&gt; for handling reCAPTCHA verification:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// backend/middleware/recaptchaMiddleware.js
const axios = require('axios');
const asyncHandler = require('express-async-handler');
const verifyCaptcha = asyncHandler(async (req, res, next) =&amp;gt; {
  const { captcha } = req.body;
  if (!captcha) {
    return res.status(400).json({ message: 'Please complete the CAPTCHA' });
  }
  const secretKey = process.env.CAPTCHA_SECRET_KEY;
  try {
    const response = await axios.post(
      `https://www.google.com/recaptcha/api/siteverify?secret=${secretKey}&amp;amp;response=${captcha}`
    );
    if (response.data.success) {
      next();
    } else {
      return res.status(400).json({ message: 'CAPTCHA verification failed' });
    }
  } catch (error) {
    return res.status(500).json({ message: 'CAPTCHA verification error' });
  }
});
module.exports = { verifyCaptcha };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Create Your Express Server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set up an Express server and use the middleware for reCAPTCHA verification:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// backend/server.js
const express = require('express');
const dotenv = require('dotenv');
const cors = require('cors');
const { verifyCaptcha } = require('./middleware/recaptchaMiddleware');
const jwt = require('jsonwebtoken');

dotenv.config();
const app = express();
app.use(cors());
app.use(express.json());
app.post('/api/login', verifyCaptcha, (req, res) =&amp;gt; {
  const { email, password } = req.body;
  if (email === 'test@example.com' &amp;amp;&amp;amp; password === 'password') {
    const token = jwt.sign({ id: 1, email }, process.env.JWT_SECRET, { expiresIn: '1h' });
    res.json({ token });
  } else {
    res.status(401).json({ message: 'Invalid credentials' });
  }
});
const PORT = process.env.PORT || 5002;
app.listen(PORT, () =&amp;gt; console.log(`Server running on port ${PORT}`));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Step 9: Integrate reCAPTCHA in React&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In your React app, create a login form that includes the reCAPTCHA component:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/Login.js
import React, { useState } from 'react';
import axios from 'axios';
import ReCAPTCHA from 'react-google-recaptcha';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import './Login.css'; // Import the CSS file

const Login = () =&amp;gt; {
  const [formData, setFormData] = useState({ email: '', password: '', captcha: '' });
  const [isLoggedIn, setIsLoggedIn] = useState(false); // Add state for login status
  const { email, password, captcha } = formData;

  const onChange = (e) =&amp;gt; {
    setFormData({ ...formData, [e.target.name]: e.target.value });
  };

  const onCaptchaChange = (value) =&amp;gt; {
    setFormData({ ...formData, captcha: value });
  };

  const onSubmit = async (e) =&amp;gt; {
    e.preventDefault();
    if (!captcha) {
      toast.error('Please complete the CAPTCHA');
      return;
    }
    try {
      const response = await axios.post('http://localhost:5002/api/login', { email, password, captcha });
      toast.success('Login successful');
      setIsLoggedIn(true); // Set login status to true on success
      console.log(response.data); // Handle the response
    } catch (error) {
      toast.error(error.response.data.message || 'Login failed');
    }
  };

  return (
    &amp;lt;div className="login-container"&amp;gt;
      {isLoggedIn ? (
        &amp;lt;div className="success-message"&amp;gt;
          &amp;lt;h1&amp;gt;Login Successful&amp;lt;/h1&amp;gt;
        &amp;lt;/div&amp;gt;
      ) : (
        &amp;lt;form className="login-form" onSubmit={onSubmit}&amp;gt;
          &amp;lt;input
            type="email"
            name="email"
            value={email}
            onChange={onChange}
            placeholder="Email"
            required
          /&amp;gt;
          &amp;lt;input
            type="password"
            name="password"
            value={password}
            onChange={onChange}
            placeholder="Password"
            required
          /&amp;gt;
          &amp;lt;div className="captcha-container"&amp;gt;
            &amp;lt;ReCAPTCHA
              sitekey={process.env.REACT_APP_CAPTCHA_SITE_KEY}
              onChange={onCaptchaChange}
            /&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;button type="submit"&amp;gt;Login&amp;lt;/button&amp;gt;
        &amp;lt;/form&amp;gt;
      )}
      &amp;lt;ToastContainer position="top-right" autoClose={5000} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Login;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* src/Login.css */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f5f5f5;
  }

  .login-form {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    width: 300px;
  }

  .login-form input {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
  }

  .captcha-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
  }

  .login-form button {
    padding: 0.75rem;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }

  .login-form button:hover {
    background-color: #0056b3;
  }

  .success-message {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    text-align: center;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Step 10: Modify App.js file&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import Login from './Login';
import './App.css';  // Optionally, create this file for styling

const App = () =&amp;gt; {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Login&amp;lt;/h1&amp;gt;
      &amp;lt;Login /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Run npm start in the recaptcha-demo folder&lt;/p&gt;

&lt;p&gt;Run nodemon server.js in the backend folder&lt;/p&gt;

&lt;p&gt;You will see the following screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzoc6afhnagoqixdbb0o2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzoc6afhnagoqixdbb0o2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you login with the proper credentials and check the captcha you will see a success message&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg0osokkr79x5f1xgku6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg0osokkr79x5f1xgku6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw3xv2s9lynsoyh7f2tzo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw3xv2s9lynsoyh7f2tzo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It really is that simple thanks to Google’s library implementation! Be careful of the cost as scaling over 10,000 uses per month will begin to accrue a cost in your Google Cloud account if you setup a payment method, otherwise the Captcha will fail to work if you do not have payment setup.&lt;/p&gt;

&lt;p&gt;We went over Captcha v2 in this example but really you can use v3 and it will work similarly.&lt;/p&gt;

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

&lt;p&gt;Implementing Google reCAPTCHA in your React and Node.js applications is a straightforward process that can significantly enhance your application’s security. By following the steps outlined in this guide, you can ensure that your forms are protected against automated abuse and spam. Remember to test your implementation thoroughly in both development and production environments to ensure it works as expected.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>node</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Easily Use Selenium with AWS Lambda</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Sun, 14 Jul 2024 08:52:25 +0000</pubDate>
      <link>https://dev.to/shilleh/easily-use-selenium-with-aws-lambda-lml</link>
      <guid>https://dev.to/shilleh/easily-use-selenium-with-aws-lambda-lml</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/8XBkm9DD6Ic"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, I will guide you through the process of running Selenium with ChromeDriver inside an AWS Lambda function. This setup is useful for automating web scraping tasks, testing web applications, or performing any browser automation tasks on the cloud. By containerizing our application and deploying it to AWS Lambda, we ensure a scalable and serverless architecture. Let’s dive into the details.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We’re Doing
&lt;/h2&gt;

&lt;p&gt;We will create a Docker container that includes all the necessary dependencies for running Selenium and ChromeDriver. This container will be deployed as an AWS Lambda function. The Lambda function will perform a simple task: searching for “OpenAI” on Google and returning the titles of the search results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we start, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An AWS account&lt;/li&gt;
&lt;li&gt;A GitHub account&lt;/li&gt;
&lt;li&gt;Docker Desktop installed&lt;/li&gt;
&lt;li&gt;AWS CLI configured&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at YouTube — Shilleh.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at Buy Me A Coffee to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;Hire Expert IoT Services: For personalized assistance with your IoT projects, hire me on UpWork.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Amazon Store:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/stores/page/F0566360-4583-41FF-8528-6C4A15190CD6?channel=yt" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — US&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.ca/stores/page/036180BA-2EA0-4A49-A174-31E697A671C2?channel=canada" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Canada&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.co.jp/stores/page/C388A744-C8DF-4693-B864-B216DEEEB9E3?channel=japan" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Japan&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Project Files
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;1. main.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This Python script is the Lambda function that uses Selenium to perform browser automation.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import os
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options as ChromeOptions
from tempfile import mkdtemp

def lambda_handler(event, context):
    chrome_options = ChromeOptions()
    chrome_options.add_argument("--headless=new")
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-dev-shm-usage")
    chrome_options.add_argument("--disable-gpu")
    chrome_options.add_argument("--disable-dev-tools")
    chrome_options.add_argument("--no-zygote")
    chrome_options.add_argument("--single-process")
    chrome_options.add_argument(f"--user-data-dir={mkdtemp()}")
    chrome_options.add_argument(f"--data-path={mkdtemp()}")
    chrome_options.add_argument(f"--disk-cache-dir={mkdtemp()}")
    chrome_options.add_argument("--remote-debugging-pipe")
    chrome_options.add_argument("--verbose")
    chrome_options.add_argument("--log-path=/tmp")
    chrome_options.binary_location = "/opt/chrome/chrome-linux64/chrome"

    service = Service(
        executable_path="/opt/chrome-driver/chromedriver-linux64/chromedriver",
        service_log_path="/tmp/chromedriver.log"
    )

    driver = webdriver.Chrome(
        service=service,
        options=chrome_options
    )
    # Open a webpage
    driver.get('https://www.google.com')
    # Find the search box
    search_box = driver.find_element(By.NAME, 'q')
    # Enter a search query
    search_box.send_keys('OpenAI')
    # Submit the search query
    search_box.send_keys(Keys.RETURN)
    # Wait for the results to load
    time.sleep(2)
    # Get the results
    results = driver.find_elements(By.CSS_SELECTOR, 'div.g')
    # Print the titles of the results
    titles = [result.find_element(By.TAG_NAME, 'h3').text for result in results]
    # Close the WebDriver
    driver.quit()
    return {
        'statusCode': 200,
        'body': titles
    }


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;chrome_options: Configures Chrome to run headlessly and optimizes it for a containerized environment.&lt;/li&gt;
&lt;li&gt;driver.get: Navigates to Google.&lt;/li&gt;
&lt;li&gt;search_box: Finds the search input, enters “OpenAI”, and submits the form.&lt;/li&gt;
&lt;li&gt;results: Extracts and prints the titles of the search results.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Dockerfile
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;This Dockerfile creates an image with all the dependencies required to run Selenium with ChromeDriver.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

FROM amazon/aws-lambda-python:3.12
# Install chrome dependencies
RUN dnf install -y atk cups-libs gtk3 libXcomposite alsa-lib \
    libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \
    libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \
    xorg-x11-xauth dbus-glib dbus-glib-devel nss mesa-libgbm jq unzip
# Copy and run the chrome installer script
COPY ./chrome-installer.sh ./chrome-installer.sh
RUN chmod +x ./chrome-installer.sh
RUN ./chrome-installer.sh
RUN rm ./chrome-installer.sh
# Install selenium
RUN pip install selenium
# Copy the main application code
COPY main.py ./
# Command to run the Lambda function
CMD [ "main.lambda_handler" ]


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FROM amazon/aws-lambda-python:3.12: Uses AWS Lambda base image for Python 3.12.&lt;/li&gt;
&lt;li&gt;RUN dnf install -y: Installs the necessary dependencies for running Chrome.&lt;/li&gt;
&lt;li&gt;COPY ./chrome-installer.sh: Copies the Chrome installer script into the image.&lt;/li&gt;
&lt;li&gt;RUN ./chrome-installer.sh: Executes the script to install Chrome and ChromeDriver.&lt;/li&gt;
&lt;li&gt;RUN pip install selenium: Installs the Selenium Python package.&lt;/li&gt;
&lt;li&gt;COPY main.py: Copies the main.py script into the image.&lt;/li&gt;
&lt;li&gt;CMD [ “main.lambda_handler” ]: Specifies the command to run the Lambda function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. chrome-installer.sh
&lt;/h2&gt;

&lt;p&gt;This script installs the latest versions of Chrome and ChromeDriver.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#!/bin/bash
set -e

latest_stable_json="https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json"
# Retrieve the JSON data using curl
json_data=$(curl -s "$latest_stable_json")
latest_chrome_linux_download_url="$(echo "$json_data" | jq -r ".channels.Stable.downloads.chrome[0].url")"
latest_chrome_driver_linux_download_url="$(echo "$json_data" | jq -r ".channels.Stable.downloads.chromedriver[0].url")"
download_path_chrome_linux="/opt/chrome-headless-shell-linux.zip"
download_path_chrome_driver_linux="/opt/chrome-driver-linux.zip"
mkdir -p "/opt/chrome"
curl -Lo $download_path_chrome_linux $latest_chrome_linux_download_url
unzip -q $download_path_chrome_linux -d "/opt/chrome"
rm -rf $download_path_chrome_linux
mkdir -p "/opt/chrome-driver"
curl -Lo $download_path_chrome_driver_linux $latest_chrome_driver_linux_download_url
unzip -q $download_path_chrome_driver_linux -d "/opt/chrome-driver"
rm -rf $download_path_chrome_driver_linux


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

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Explanation:&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;curl -s: Fetches the latest stable versions of Chrome and ChromeDriver.&lt;/li&gt;
&lt;li&gt;mkdir -p: Creates directories to store the downloaded files.&lt;/li&gt;
&lt;li&gt;unzip -q: Extracts the downloaded files to the specified directories.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Building, Tagging, and Pushing the Docker Image&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Build the Docker Image:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;docker build -t selenium-chrome-driver .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tag the Docker Image:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;docker tag selenium-chrome-driver .dkr.ecr.us-east-1.amazonaws.com/docker-images:v1.0.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Push the Docker Image to AWS ECR:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin .dkr.ecr.us-east-1.amazonaws.com/docker-images&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;docker push .dkr.ecr.us-east-1.amazonaws.com/docker-images:v1.0.0&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;docker build: Builds the Docker image from the Dockerfile.&lt;/li&gt;
&lt;li&gt;docker tag: Tags the image with a specific version.&lt;/li&gt;
&lt;li&gt;docker push: Pushes the image to the specified AWS ECR repository.&lt;/li&gt;
&lt;li&gt;Deploying the Lambda Function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After pushing the image to AWS ECR, you can deploy it using AWS Lambda. Ensure you are logged into AWS and have the necessary permissions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6j27hdy8gizh17peafxp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6j27hdy8gizh17peafxp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Increase the configuration resources in the container so it does not time out or run out of memory.&lt;/p&gt;

&lt;p&gt;After running a test event we see a successful output! It worked :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2vk5mz3wnknhkn8l0mp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2vk5mz3wnknhkn8l0mp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;In this article, we walked through the process of setting up Selenium with ChromeDriver in an AWS Lambda function using Docker. This approach allows you to leverage the power of Selenium for browser automation in a serverless environment, ensuring scalability and efficiency. By containerizing the application, you can manage dependencies more effectively and deploy seamlessly to AWS Lambda.&lt;/p&gt;

&lt;p&gt;Feel free to experiment and expand this setup for your own browser automation needs. Goodluck, and do not forget to subscribe or support!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>python</category>
      <category>pip</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Connect MLX90614 Infrared to Raspberry Pi Pico</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Fri, 05 Jul 2024 21:50:53 +0000</pubDate>
      <link>https://dev.to/shilleh/how-to-connect-mlx90614-infrared-to-raspberry-pi-pico-44gc</link>
      <guid>https://dev.to/shilleh/how-to-connect-mlx90614-infrared-to-raspberry-pi-pico-44gc</guid>
      <description>&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/ckBF22AxZeg"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Products
&lt;/h2&gt;

&lt;p&gt;Here are the components used in this tutorial, available from &lt;a href="https://shillehtek.com" rel="noopener noreferrer"&gt;ShillehTek&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://shillehtek.com/products/pre-soldered-gy-906-mlx90614-baa-infrared-temperature-sensor" rel="noopener noreferrer"&gt;MLX90614 Pre-Soldered Infrared Temperature Sensor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shillehtek.com/products/raspberry-pi-pico-2w-presoldered-headers" rel="noopener noreferrer"&gt;Raspberry Pi Pico 2W with Pre-Soldered Headers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shillehtek.com/products/shillehtek-400-point-breadboard" rel="noopener noreferrer"&gt;400-Point Solderless Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shillehtek.com/products/shillehtek-120pcs-multicolored-dupont-wire" rel="noopener noreferrer"&gt;120pcs Multicolored Dupont Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this blog post, we’ll guide you through connecting the MLX90614 infrared temperature sensor to a Raspberry Pi Pico W using MicroPython. The MLX90614 sensor allows for non-contact temperature measurements, making it ideal for various applications. We’ll provide a step-by-step tutorial, including wiring, code, and testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at YouTube — Shilleh.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at Buy Me A Coffee to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;Hire Expert IoT Services: For personalized assistance with your IoT projects, hire me on UpWork.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Components Needed&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi Pico W&lt;/li&gt;
&lt;li&gt;MLX90614 Infrared Temperature Sensor&lt;/li&gt;
&lt;li&gt;Breadboard (optional)&lt;/li&gt;
&lt;li&gt;4 Jumper wires&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Wiring Diagram&lt;/strong&gt;&lt;br&gt;
Connect the MLX90614 to the Raspberry Pi Pico W as follows:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;MLX90614 VIN to Pico W 3.3V&lt;br&gt;
MLX90614 GND to Pico W GND&lt;br&gt;
MLX90614 SCL to Pico W GP1 (SCL)&lt;br&gt;
MLX90614 SDA to Pico W GP0 (SDA)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Library Code&lt;/strong&gt;&lt;br&gt;
Save the following library code in mlx90614.py and upload it to your Raspberry Pi Pico W.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
MicroPython MLX90614 IR temperature sensor driver
https://github.com/mcauser/micropython-mlx90614MIT License
Copyright (c) 2016 Mike CauserPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Software&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;AS IS&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ustructclass&lt;/span&gt; &lt;span class="n"&gt;SensorBase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read16&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;register&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readfrom_mem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;register&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ustruct&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unpack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;H&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;register&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read16&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;register&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;# apply measurement resolution (0.02 degrees per LSB)
&lt;/span&gt;  &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;02&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;# Kelvin to Celsius
&lt;/span&gt;  &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mf"&gt;273.15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_ambient_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_REGISTER_TA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_object_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_REGISTER_TOBJ1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_object2_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dual_zone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_REGISTER_TOBJ2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Device only has one thermopile&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;@property&lt;/span&gt;
 &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;ambient_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_ambient_temp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nd"&gt;@property&lt;/span&gt;
 &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;object_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_object_temp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nd"&gt;@property&lt;/span&gt;
 &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;object2_temp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_object2_temp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MLX90614&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SensorBase&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="n"&gt;_REGISTER_TA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x06&lt;/span&gt;
 &lt;span class="n"&gt;_REGISTER_TOBJ1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x07&lt;/span&gt;
 &lt;span class="n"&gt;_REGISTER_TOBJ2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x08def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i2c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mh"&gt;0x5a&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i2c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i2c&lt;/span&gt;
  &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;
  &lt;span class="n"&gt;_config1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readfrom_mem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;_dz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ustruct&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unpack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;H&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_config1&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dual_zone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;_dz&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;Falseclass&lt;/span&gt; &lt;span class="nc"&gt;MLX90615&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SensorBase&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="n"&gt;_REGISTER_TA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x26&lt;/span&gt;
 &lt;span class="n"&gt;_REGISTER_TOBJ1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x27def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i2c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mh"&gt;0x5b&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i2c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i2c&lt;/span&gt;
  &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;
  &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dual_zone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the following main code in a file named main.py and upload it to your Raspberry Pi Pico W.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;mlx90614&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;MLX90614&lt;/span&gt;&lt;span class="c1"&gt;# Initialize I2C bus
&lt;/span&gt;&lt;span class="n"&gt;i2c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;I2C&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sda&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;freq&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;# Scan for I2C devices
&lt;/span&gt;&lt;span class="n"&gt;devices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;devices&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I2C devices found:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;devices&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No I2C devices found&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;# Initialize the MLX90614 sensor
&lt;/span&gt;&lt;span class="n"&gt;sensor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MLX90614&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i2c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ambient_temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sensor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ambient_temp&lt;/span&gt;
    &lt;span class="n"&gt;object_temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sensor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object_tempprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Ambient Temperature: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ambient_temp&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;°C&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Object Temperature: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;object_temp&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;°C&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Running the Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Upload both mlx90614.py and main.py to your Raspberry Pi Pico W.&lt;br&gt;
Run the main.py script using Thonny IDE or another suitable MicroPython environment.&lt;br&gt;
&lt;strong&gt;Checking the Output&lt;/strong&gt;&lt;br&gt;
After running the script, you should see the ambient and object temperatures printed in the console every second. Ensure the temperatures are within realistic ranges to confirm the sensor is working correctly. You can point it at your skin closely to see if it changes the temperature reading. Goodluck on your project!&lt;/p&gt;

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

&lt;p&gt;By following this guide, you can easily connect the MLX90614 infrared temperature sensor to your Raspberry Pi Pico W and read temperature data using MicroPython. This setup allows for non-contact temperature measurements, which can be useful in various projects. Do not forget to subscribe or book a consulting slot on buymeacoffee if you have any questions!&lt;/p&gt;

</description>
      <category>micropython</category>
      <category>raspberrypi</category>
      <category>beginners</category>
      <category>iot</category>
    </item>
    <item>
      <title>How to Write your First C++ Program on the Raspberry Pi Pico</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Wed, 26 Jun 2024 00:13:45 +0000</pubDate>
      <link>https://dev.to/shilleh/how-to-write-your-first-c-program-on-the-raspberry-pi-pico-25h2</link>
      <guid>https://dev.to/shilleh/how-to-write-your-first-c-program-on-the-raspberry-pi-pico-25h2</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fqgeUPL7Z6M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Welcome to this comprehensive tutorial on setting up, building, and flashing a C++ project for the Raspberry Pi Pico W on macOS. The Raspberry Pi Pico W is a powerful microcontroller board based on the RP2040 microcontroller, featuring dual-core ARM Cortex-M0+ processors, flexible I/O options, and built-in Wi-Fi connectivity. This tutorial will guide you through the entire process, from installing the necessary tools to running a “Hello, World!” program that communicates over USB serial.&lt;/p&gt;

&lt;p&gt;In this guide, you will learn how to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up the development environment on macOS, including installing Homebrew, CMake, and the ARM GCC toolchain.&lt;/li&gt;
&lt;li&gt;Clone and initialize the Pico SDK, which provides essential libraries and tools for developing applications for the Raspberry Pi Pico W.&lt;/li&gt;
&lt;li&gt;Create a simple C++ project that prints “Hello, World!” to the serial console.&lt;/li&gt;
&lt;li&gt;Build and flash your project to the Pico W.&lt;/li&gt;
&lt;li&gt;Connect to the Pico W’s serial output using terminal applications such as screen and minicom.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you’re a seasoned developer or just getting started with microcontrollers, this tutorial will provide you with the knowledge and skills to begin developing applications for the Raspberry Pi Pico W on macOS.&lt;/p&gt;

&lt;p&gt;— — -&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Subscribe to our YouTube Channel:&lt;/strong&gt; Stay updated with our latest tutorials and project insights by subscribing to our channel at &lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;YouTube — Shilleh&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Us:&lt;/strong&gt; Your support is invaluable. Consider buying me a coffee at &lt;a href="https://buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;Buy Me A Coffee&lt;/a&gt; to help us continue creating quality content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hire Expert IoT Services:&lt;/strong&gt; For personalized assistance with your IoT projects, hire me on &lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;UpWork&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://shillehtek.com/collections/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShillehTekAmazon Store:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/stores/page/F0566360-4583-41FF-8528-6C4A15190CD6?channel=yt" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — US&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.ca/stores/page/036180BA-2EA0-4A49-A174-31E697A671C2?channel=canada" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Canada&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.amazon.co.jp/stores/page/C388A744-C8DF-4693-B864-B216DEEEB9E3?channel=japan" rel="noopener noreferrer"&gt;ShillehTek Amazon Store — Japan&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Set Up the Environment
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Install Prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Homebrew: Install Homebrew if you haven’t already:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CMake and ARM GCC Toolchain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install cmake gcc-arm-none-eabi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Clone the Pico SDK:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p ~/pico
cd ~/pico
git clone -b master https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set the Environment Variable:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set the PICO_SDK_PATH environment variable in your shell configuration file (~/.zshrc for Zsh or ~/.bashrc for Bash):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo 'export PICO_SDK_PATH=~/pico/pico-sdk' &amp;gt;&amp;gt; ~/.zshrc
source ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Create a C++ Project
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Create a Project Directory:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p ~/pico/my_project
cd ~/pico/my_project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create a CMakeLists.txt File:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
cmake_minimum_required(VERSION 3.13)

# Include the Pico SDK initialization script
include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake)

project(my_project)

# Initialize the Pico SDK
pico_sdk_init()

# Add your executable and source files
add_executable(my_project
    main.cpp
)

# Enable USB stdio and disable UART stdio
pico_enable_stdio_usb(my_project 1)
pico_enable_stdio_uart(my_project 0)

# Link the Pico SDK to your project
target_link_libraries(my_project pico_stdlib)

# Create map/bin/hex/uf2 files
pico_add_extra_outputs(my_project)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create a main.cpp File:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "pico/stdlib.h"
#include &amp;lt;cstdio&amp;gt; // Include the C standard IO functions

int main() {
    stdio_init_all(); // Initialize standard IO

    while (true) {
        printf("Hello, World!\n");
        sleep_ms(1000);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Build and Flash the Project
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Navigate to the Build Directory and Clean it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p build
cd build
rm -rf *
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Run CMake to Generate Build Files:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cmake ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Build the Project:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Flash the Firmware:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unplug the Pico W from your Mac.&lt;/li&gt;
&lt;li&gt;Hold down the BOOTSEL button.&lt;/li&gt;
&lt;li&gt;While holding the BOOTSEL button, plug the Pico W back into your Mac. The Pico should appear as a mass storage device (RPI-RP2).&lt;/li&gt;
&lt;li&gt;Copy the generated .uf2 file to the Pico:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp my_project.uf2 /Volumes/RPI-RP2/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that your UF2 file is on the device, your Pico W should start running it and logging to serial output. The next step shows you commands you can utilize to view the output of the program!&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify Serial Connection
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Using screen
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Set the TERM Environment Variable:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you encounter issues with the $TERM too long - sorry. error in screen, set the TERM environment variable to vt100 to ensure compatibility with screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export TERM=vt100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check for Serial Device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls /dev/tty.*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for a device like &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/dev/tty.usbmodemXXXX&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connect Using &lt;code&gt;screen&lt;/code&gt;:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;screen /dev/tty.usbmodemXXXX 115200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;View the Output:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If the Pico W is running your program correctly, you should see the “Hello, World!” messages being printed to the terminal every second.&lt;br&gt;
&lt;strong&gt;Exit screen:&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To exit screen, press Ctrl+A followed by K, and then confirm by pressing Y.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Congratulations! You have successfully set up your development environment, created and built a C++ project, and flashed it to your Raspberry Pi Pico W. You also learned how to connect to the Pico W’s serial output using screen and minicom, ensuring you can monitor and interact with your running programs.&lt;/p&gt;

&lt;p&gt;With these foundational skills, you’re now ready to explore the full potential of the Raspberry Pi Pico W. Whether you want to build IoT applications, create interactive devices, or experiment with embedded systems, the knowledge gained from this tutorial will serve as a solid starting point.&lt;/p&gt;

&lt;p&gt;Continue experimenting and building more complex projects, and don’t hesitate to explore the extensive documentation and resources available for the Raspberry Pi Pico W. Happy coding!&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>sdk</category>
      <category>programming</category>
      <category>cpp</category>
    </item>
    <item>
      <title>How to Use ThingSpeak with the Raspberry Pi Pico W</title>
      <dc:creator>Shilleh</dc:creator>
      <pubDate>Fri, 31 May 2024 23:41:15 +0000</pubDate>
      <link>https://dev.to/shilleh/how-to-use-thingspeak-with-the-raspberry-pi-pico-w-499m</link>
      <guid>https://dev.to/shilleh/how-to-use-thingspeak-with-the-raspberry-pi-pico-w-499m</guid>
      <description>&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/TPBf_Qaci8w"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, we'll learn how to use ThingSpeak, a popular IoT platform, with the Raspberry Pi Pico W to collect and visualize sensor data. We'll be using a BME280 sensor to measure temperature, pressure, and humidity and send this data to ThingSpeak for real-time monitoring and analysis.&lt;/p&gt;

&lt;p&gt;ThingSpeak is an open-source Internet of Things (IoT) platform that allows you to collect, store, analyze, visualize, and act on data from sensors or devices. It's particularly popular for its ease of use and integration with various hardware platforms like Raspberry Pi, Arduino, and ESP8266/ESP32.&lt;/p&gt;

&lt;p&gt;In the end, we will have a dashboard that looks as follows, a simple weather station with gauges and graphs that updates in real-time:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi Pico W&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shillehtek.com/products/bme280-pre-soldered-atmospheric-temperature-pressure-and-humidity-sensor" rel="noopener noreferrer"&gt;BME280 sensor from ShillehTek&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shillehtek.com/products/shillehtek-120pcs-multicolored-dupont-wire" rel="noopener noreferrer"&gt;Jumper wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://shillehtek.com/blogs/news/how-to-use-thingspeak-with-the-raspberry-pi-pico-w" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A computer with Thonny IDE installed&lt;/li&gt;
&lt;li&gt;Wi-Fi network credentials&lt;/li&gt;
&lt;li&gt;ThingSpeak account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Wiring the BME280 Sensor&lt;/strong&gt;&lt;br&gt;
If you are interested in using the BME280 specifically, there is another ShillehTek tutorial on YouTube here that quickly walks you through how to get setup.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/R5dY2a0C9Y0"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Before we get into the remainder, consider subscribing or supporting the channel. Also, be sure to checkout our various stores to shop products for Raspberry Pi, Arduino, ESP32, and DIY electronics at ShillehTek!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Subscribe:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@mmshilleh" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Support:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mmshilleh" rel="noopener noreferrer"&gt;https://buymeacoffee.com/mmshilleh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hire me at UpWork to build your IoT projects:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.upwork.com/freelancers/~017060e77e9d8a1157" rel="noopener noreferrer"&gt;https://buymeacoffee.com/mmshilleh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Visit ShillehTek Store for Arduino and Raspberry Pi Sensors and Pre-Soldered Components:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ShillehTek Website (Exclusive Discounts):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://shillehtek.com/collections/all" rel="noopener noreferrer"&gt;https://buymeacoffee.com/mmshilleh&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1-) Setting Up ThingSpeak
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create a ThingSpeak Account:&lt;/strong&gt; If you don't have one, sign up for a ThingSpeak account at thingspeak.com&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create a New Channel:&lt;/strong&gt; Go to the Channels tab and click "New Channel".Name your channel (e.g., "Pico W Weather Station"). Add three fields: Temperature, Pressure, and Humidity. Save the channel and note down the &lt;code&gt;Write API Key&lt;/code&gt;. You can get it in the API Keys tab.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Creating Visualizations -&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Numeric Display for Temperature:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to your channel view and click on the "Add Widget" button.&lt;/li&gt;
&lt;li&gt;Select "Numeric Display" from the widget options.&lt;/li&gt;
&lt;li&gt;Choose the field corresponding to Temperature.&lt;/li&gt;
&lt;li&gt;Save the widget to add it to your channel dashboard.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Graph for Pressure:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the "Add Visualizations" button.&lt;/li&gt;
&lt;li&gt;Choose the field corresponding to Pressure.&lt;/li&gt;
&lt;li&gt;Configure the time span and any other settings you prefer.&lt;/li&gt;
&lt;li&gt;Save the widget to add it to your channel dashboard.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Gauge for Humidity:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the "Add Widget" button.&lt;/li&gt;
&lt;li&gt;Select "Gauge" from the widget options.&lt;/li&gt;
&lt;li&gt;Choose the field corresponding to Humidity.&lt;/li&gt;
&lt;li&gt;Configure the gauge with appropriate min and max values (e.g., 0 to 100%).&lt;/li&gt;
&lt;li&gt;Save the widget to add it to your channel dashboard.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Now that you have all of this, you have the basis of what you need to start populating and visualizing the sensor data from the ShillehTek BME280 in ThingSpeak. If you are using another sensor, you can play around with other widgets and visualizations as needed, the interface is fairly straightforward.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2-) MicroPython Code
&lt;/h2&gt;

&lt;p&gt;Here's the full code to read data from the BME280 sensor and send it to ThingSpeak:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from machine import Pin, I2C
import network
import urequests
import time
from time import sleep
import bme280
import constants

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) 

ssid = constants.INTERNET_NAME
password = constants.INTERNET_PASSWORD
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
    pass

api_key = 'your_API_KEY'
base_url = 'https://api.thingspeak.com/update'

def read_sensor():
    bme = bme280.BME280(i2c=i2c)
    temperature, pressure, humidity = [float(i) for i in bme.values]
    return temperature, pressure, humidity

# Send data to ThingSpeak
while True:
    temperature, pressure, humidity = read_sensor()
    url = f"{base_url}?api_key={api_key}&amp;amp;field1={temperature}&amp;amp;field2={pressure}&amp;amp;field3={humidity}"
    response = urequests.get(url)
    print(response.text)
    time.sleep(15)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Import Libraries:&lt;/strong&gt; We import necessary libraries including network for Wi-Fi connectivity, urequests for HTTP requests, and bme280 for sensor interaction.&lt;br&gt;
&lt;strong&gt;Initialize I2C:&lt;/strong&gt; Set up I2C communication with the BME280 sensor.&lt;br&gt;
Connect to Wi-Fi: Use your Wi-Fi credentials to connect the Pico W to the internet.&lt;br&gt;
&lt;strong&gt;Read Sensor Data:&lt;/strong&gt; Define a function read_sensor to get temperature, pressure, and humidity readings from the BME280 sensor.&lt;br&gt;
&lt;strong&gt;Send Data to ThingSpeak:&lt;/strong&gt; In an infinite loop, read data from the sensor and send it to ThingSpeak every 15 seconds.&lt;br&gt;
If you are using the BME280 library, you need to modify the return values by removing all suffixes (e.g., 'C', 'hPa', '%') so that the data is interpretable by the IoT platform. Additionally, if you are using an earlier version of MicroPython, make sure you install urequests, as it may not come pre-installed with some versions.&lt;/p&gt;

&lt;p&gt;You also have the option to hardcode your Wi-Fi credentials directly into the code instead of using a constants file. Simply replace the placeholders with your actual Wi-Fi SSID and password.&lt;/p&gt;

&lt;p&gt;Once your script is running, you should see your ThingSpeak dashboard updating in real-time! This setup can be further customized to suit your specific needs. Additionally, ThingSpeak offers various other data integration and visualization options to explore.&lt;/p&gt;

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

&lt;p&gt;Congratulations! You have successfully set up your Raspberry Pi Pico W to send sensor data to ThingSpeak. This setup allows you to monitor environmental conditions in real-time from anywhere. ThingSpeak provides powerful tools for data analysis and visualization, making it an excellent choice for IoT projects. Happy tinkering! Also, do not forget to subscribe if you have not!&lt;/p&gt;

</description>
      <category>thingspeak</category>
      <category>raspberrypi</category>
      <category>programming</category>
      <category>python</category>
    </item>
  </channel>
</rss>
