<?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: Arduino ESP32 Raspberry Pi Tutorials</title>
    <description>The latest articles on DEV Community by Arduino ESP32 Raspberry Pi Tutorials (@arduino_getstarted_f52a1a).</description>
    <link>https://dev.to/arduino_getstarted_f52a1a</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4193036%2F66bf7469-f054-435d-ae5a-bc6740df819c.png</url>
      <title>DEV Community: Arduino ESP32 Raspberry Pi Tutorials</title>
      <link>https://dev.to/arduino_getstarted_f52a1a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arduino_getstarted_f52a1a"/>
    <language>en</language>
    <item>
      <title>Arduino Nano ESP32 - Soil Moisture Sensor Pump</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Mon, 16 Nov 2026 10:30:42 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/arduino-nano-esp32-soil-moisture-sensor-pump-3ei4</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/arduino-nano-esp32-soil-moisture-sensor-pump-3ei4</guid>
      <description>&lt;p&gt;This build turns a soil moisture reading into an automatic watering decision. An Arduino Nano ESP32 checks a capacitive soil moisture sensor and switches a relay that controls a 12V pump, so the plant gets watered only when the soil is actually dry, with no code loop on your laptop needed once it's flashed.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-soil-moisture-sensor-pump" rel="noopener noreferrer"&gt;Arduino Nano ESP32 - Soil Moisture Sensor Pump&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://store.arduino.cc/products/nano-esp32" rel="noopener noreferrer"&gt;Arduino Nano ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF575PW9" rel="noopener noreferrer"&gt;USB Cable Type-A to Type-C (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3V1TFM" rel="noopener noreferrer"&gt;USB Cable Type-C to Type-C (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Capacitive Soil Moisture Sensor&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0B1ZHXXXD" rel="noopener noreferrer"&gt;Relay&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CSCQXQMF" rel="noopener noreferrer"&gt;12V Pump&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Vinyl Tube&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPGC5GTQ" rel="noopener noreferrer"&gt;DC Power Jack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CSCVHN4M" rel="noopener noreferrer"&gt;Screw Terminal Expansion Board for Arduino Nano&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0D2KB3QRP" rel="noopener noreferrer"&gt;Breakout Expansion Board for Arduino Nano&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGMVJNS" rel="noopener noreferrer"&gt;Power Splitter for Arduino Nano ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzoojorkn49z8s7hebedj.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzoojorkn49z8s7hebedj.jpg" alt="Arduino Nano ESP32 - Soil Moisture Sensor Pump wiring diagram" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The sensor's analog output pin connects to A2 on the Arduino Nano ESP32, and the relay's control input connects to D2. The pump itself isn't driven directly by the microcontroller pin, since it needs more current and a separate 12V supply than a GPIO can provide; the relay acts as an electrically controlled switch, letting the low-power D2 pin toggle the higher-power 12V circuit that the pump and power adapter are on. A screw terminal expansion board is a handy option if you want the wiring to stay put instead of relying on breadboard friction.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The Arduino periodically reads the moisture value from the sensor. If that value is above a set threshold, the soil is considered dry and the board activates the relay, turning the pump on. If the value is at or below the threshold, the soil is wet enough, so the relay is deactivated and the pump turns off. This repeats continuously, so the pump responds automatically as the soil dries out or gets watered.&lt;/p&gt;

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

&lt;p&gt;The sketch sets the ADC attenuation so the analog input can read up to roughly 3.3V, then in the loop it calls &lt;code&gt;analogRead()&lt;/code&gt; on &lt;code&gt;SENSOR_PIN&lt;/code&gt; to get a moisture value. That value is compared against &lt;code&gt;THRESHOLD&lt;/code&gt;: above it, &lt;code&gt;digitalWrite()&lt;/code&gt; sets &lt;code&gt;RELAY_PIN&lt;/code&gt; &lt;code&gt;HIGH&lt;/code&gt; to turn the pump on, otherwise it's set &lt;code&gt;LOW&lt;/code&gt; to turn it off. Each reading and the resulting action gets printed to the Serial Monitor, and the loop waits one second before repeating.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;arduino-nano-esp32-soil-moisture-sensor-pump.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * This Arduino Nano ESP32 code was developed by newbiely.com
 *
 * This Arduino Nano ESP32 code is made available for public use without any restriction
 *
 * For comprehensive instructions and wiring diagrams, please visit:
 * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-soil-moisture-sensor-pump
 */&lt;/span&gt;

&lt;span class="cp"&gt;#define RELAY_PIN    D2 // The Arduino Nano ESP32 pin that connects to relay&lt;/span&gt;
&lt;span class="cp"&gt;#define SENSOR_PIN A2 // The Arduino Nano ESP32 pin that connects to AOUT pin of moisture sensor&lt;/span&gt;
&lt;span class="cp"&gt;#define THRESHOLD 1500   // =&amp;gt; CHANGE YOUR THRESHOLD HERE&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// set the ADC attenuation to 11 dB (up to ~3.3V input)&lt;/span&gt;
  &lt;span class="nf"&gt;analogSetAttenuation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ADC_11db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RELAY_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;analogRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SENSOR_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// read the analog value from soild moisture sensor&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Serial&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="s2"&gt;"The soil moisture is DRY =&amp;gt; activate pump"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RELAY_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&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="nc"&gt;Serial&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="s2"&gt;"The soil moisture is WET =&amp;gt; deactivate the pump"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RELAY_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;Serial&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="s2"&gt;" ("&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&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="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;delay&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="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;A lot of cheap capacitive soil moisture sensors are unreliable regardless of the version printed on them; one built around the TLC555I chip has tested reliably, so it's worth checking which chip is on your sensor if readings look erratic. The &lt;code&gt;THRESHOLD&lt;/code&gt; value in the code is just a placeholder and needs to be set from an actual calibration of your sensor in dry versus wet soil, otherwise the pump may run constantly or never turn on at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-soil-moisture-sensor-pump" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-soil-moisture-sensor-pump&lt;/a&gt;&lt;/p&gt;

</description>
      <category>esp32</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Arduino Nano 33 IoT - Ultrasonic Sensor - Servo Motor</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Mon, 16 Nov 2026 04:00:39 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/arduino-nano-33-iot-ultrasonic-sensor-servo-motor-4ebi</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/arduino-nano-33-iot-ultrasonic-sensor-servo-motor-4ebi</guid>
      <description>&lt;p&gt;This build turns an ultrasonic distance sensor into a trigger for a servo motor on the Arduino Nano 33 IoT. Wave your hand in front of the sensor and the servo swings to 90 degrees; move away and it returns to 0. It's a compact example of reading an analog-ish sensor through timing and using that value to drive a motor, a pattern you'll reuse for all sorts of proximity-triggered hardware.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-ultrasonic-sensor-servo-motor" rel="noopener noreferrer"&gt;Arduino Nano 33 IoT - Ultrasonic Sensor - Servo Motor&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Arduino Nano 33 IoT&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ43NLS4" rel="noopener noreferrer"&gt;Micro USB Cable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BDFLPZ2R" rel="noopener noreferrer"&gt;Ultrasonic Sensor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPFXTZ73" rel="noopener noreferrer"&gt;Servo Motor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPGC5GTQ" rel="noopener noreferrer"&gt;DC Power Jack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CSCVHN4M" rel="noopener noreferrer"&gt;Screw Terminal Expansion Board for Arduino Nano&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0D2KB3QRP" rel="noopener noreferrer"&gt;Breakout Expansion Board for Arduino Nano&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGNG56V" rel="noopener noreferrer"&gt;Power Splitter for Arduino Nano&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9i85qjcug3p1za8a2wvd.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9i85qjcug3p1za8a2wvd.jpg" alt="Arduino Nano 33 IoT - Ultrasonic Sensor - Servo Motor wiring diagram" width="799" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect the ultrasonic sensor's TRIG pin to GPIO 5 and its ECHO pin to GPIO 4 on the Nano 33 IoT. The servo motor's signal pin goes to GPIO 2. If you want the wiring to stay put, a Screw Terminal Expansion Board lets you land each wire in a terminal instead of a breadboard, using the same pin numbers. Note that the board's 5V pin is actually VUSB, it only outputs 5V once you've closed the VUSB solder jumper on the bottom of the board and the board is powered over USB.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The ultrasonic sensor measures distance by sound. The Arduino sends a short pulse out on TRIG, the sensor emits an ultrasonic burst, and ECHO goes high for exactly as long as it takes the echo to bounce back. Reading that pulse width with &lt;code&gt;pulseIn()&lt;/code&gt; and multiplying by a constant gives the distance in centimeters. The sketch compares this distance against a threshold of 50cm: closer than that, the servo rotates to 90 degrees; farther, it returns to 0.&lt;/p&gt;

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

&lt;p&gt;The loop fires a 10-microsecond pulse on &lt;code&gt;TRIG_PIN&lt;/code&gt;, times the echo with &lt;code&gt;pulseIn()&lt;/code&gt;, and converts that duration into centimeters. It then calls &lt;code&gt;servo.write()&lt;/code&gt; with either 90 or 0 depending on whether the distance is under &lt;code&gt;DISTANCE_THRESHOLD&lt;/code&gt;. Each reading is also printed to the Serial Monitor so you can watch the distance values update as you move your hand, which is handy for sanity-checking the sensor before trusting the servo's behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;arduino-nano-33-iot-ultrasonic-sensor-servo-motor.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * This Arduino Nano 33 IoT code was developed by newbiely.com
 *
 * This Arduino Nano 33 IoT code is made available for public use without any restriction
 *
 * For comprehensive instructions and wiring diagrams, please visit:
 * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-ultrasonic-sensor-servo-motor
 */&lt;/span&gt;

&lt;span class="cp"&gt;#include &amp;lt;Servo.h&amp;gt;&lt;/span&gt;

&lt;span class="cp"&gt;#define TRIG_PIN  5  // The Arduino Nano 33 IoT pin connected to Ultrasonic Sensor's TRIG pin&lt;/span&gt;
&lt;span class="cp"&gt;#define ECHO_PIN  4  // The Arduino Nano 33 IoT pin connected to Ultrasonic Sensor's ECHO pin&lt;/span&gt;
&lt;span class="cp"&gt;#define SERVO_PIN 2  // The Arduino Nano 33 IoT pin connected to Servo Motor's pin&lt;/span&gt;
&lt;span class="cp"&gt;#define DISTANCE_THRESHOLD  50 // centimeters&lt;/span&gt;

&lt;span class="nc"&gt;Servo&lt;/span&gt; &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// create servo object to control a servo&lt;/span&gt;

&lt;span class="c1"&gt;// variables will change:&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;duration_us&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;distance_cm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// initialize serial port&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TRIG_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// set Arduino Nano 33 IoT pin to output mode&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ECHO_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;INPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// set Arduino Nano 33 IoT pin to input mode&lt;/span&gt;
  &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SERVO_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// attaches the servo on pin 9 to the servo object&lt;/span&gt;
  &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&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="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// generate 10-microsecond pulse to TRIG pin&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TRIG_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;delayMicroseconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TRIG_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// measure duration of pulse from ECHO pin&lt;/span&gt;
  &lt;span class="n"&gt;duration_us&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pulseIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ECHO_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// calculate the distance&lt;/span&gt;
  &lt;span class="n"&gt;distance_cm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.017&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;duration_us&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;distance_cm&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;DISTANCE_THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// rotate servo motor to 90 degree&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&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="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// rotate servo motor to 0 degree&lt;/span&gt;

  &lt;span class="c1"&gt;// print the value to Serial Monitor&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&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="s2"&gt;"distance: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&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="n"&gt;distance_cm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" cm"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;If the servo doesn't move, check that it's getting enough current, Arduino pins aren't meant to power a motor directly, and for multiple servos a driver like the PCA9685 is recommended to avoid overloading the board. If the Serial Monitor shows wildly inaccurate or zero distances, double check the TRIG and ECHO wiring, since swapping them gives &lt;code&gt;pulseIn()&lt;/code&gt; nothing to measure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-ultrasonic-sensor-servo-motor" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-ultrasonic-sensor-servo-motor&lt;/a&gt;&lt;/p&gt;

</description>
      <category>arduino</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Arduino MKR WiFi 1010 - LCD</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Sun, 15 Nov 2026 10:30:34 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/arduino-mkr-wifi-1010-lcd-1j9</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/arduino-mkr-wifi-1010-lcd-1j9</guid>
      <description>&lt;p&gt;This one covers wiring up an LCD I2C character display to the Arduino MKR WiFi 1010, so you can print text and sensor readings without a pile of wires. I2C lets the display talk to the board over just two signal lines instead of the eight or so you'd need for a parallel LCD, which is a nice win when you're already short on pins.&lt;/p&gt;

&lt;p&gt;The MKR WiFi 1010 runs on 3.3V logic, so the display matters here: most I2C LCDs on the market are built for 5V and can damage the board if you use them directly.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-lcd" rel="noopener noreferrer"&gt;Arduino MKR WiFi 1010 - LCD&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Arduino MKR WiFi 1010&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ43NLS4" rel="noopener noreferrer"&gt;Micro USB Cable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H74SS1B4" rel="noopener noreferrer"&gt;LCD I2C Display 3.3V&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGNBC2Y" rel="noopener noreferrer"&gt;LCD I2C 20x4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPGC5GTQ" rel="noopener noreferrer"&gt;DC Power Jack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fil2f0kuv84yt3yqja0jd.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fil2f0kuv84yt3yqja0jd.jpg" alt="Arduino MKR WiFi 1010 - LCD wiring diagram" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The LCD I2C module has four pins. VCC goes to the board's 3.3V pin, GND goes to ground. SCL carries the I2C clock signal and SDA carries the I2C data signal, both wired to the matching I2C pins on the MKR WiFi 1010. The wiring is slightly different depending on whether you power the board over USB or through the Vin pin, so check which diagram matches your setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;I2C is a two-wire protocol: SCL is the clock the board uses to time communication, and SDA is the line the actual data travels on. This lets the LCD and the board exchange information using just those two signal wires plus power and ground, instead of wiring up every single data line separately.&lt;/p&gt;

&lt;p&gt;The LCD screen itself is addressed like a grid: rows and columns, both starting at 0. When you place the cursor at a given column and row, that's where the next text you send will start appearing.&lt;/p&gt;

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

&lt;p&gt;The sketch uses the DIYables_LCD_I2C library. You create a DIYables_LCD_I2C object representing your display, call a setup function to initialize it, then use the cursor-positioning function to pick a column and row, followed by a print-style call to display your message at that spot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;arduino-mkr-wifi-1010-lcd.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;DIYables_LCD_I2C.h&amp;gt;&lt;/span&gt;

&lt;span class="nc"&gt;DIYables_LCD_I2C&lt;/span&gt; &lt;span class="nf"&gt;lcd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&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="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Create an LCD object with I2C address 0x27, supporting 16 columns and 2 rows&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Start the LCD display connected via I2C&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;backlight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Enable the LCD backlight&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;              &lt;span class="c1"&gt;// Erase all text from the display&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCursor&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// Position the cursor at column 0, row 0&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&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="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// Output the text "Hello" at the current cursor location&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCursor&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// Move the cursor to column 2, row 1&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&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="s2"&gt;"newbiely.com"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Display "newbiely.com" starting at the current cursor position&lt;/span&gt;
  &lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                  &lt;span class="c1"&gt;// Pause for 2000 milliseconds to allow the message to be seen&lt;/span&gt;

  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                  &lt;span class="c1"&gt;// Remove all content from the display&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCursor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&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="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// Set the cursor to column 3, row 0&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&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="s2"&gt;"DIYables"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// Print "DIYables" beginning at the current position&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCursor&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// Place the cursor at column 0, row 1&lt;/span&gt;
  &lt;span class="n"&gt;lcd_i2c&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="s2"&gt;"www.diyables.io"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Show "www.diyables.io" starting at the new cursor position&lt;/span&gt;
  &lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                      &lt;span class="c1"&gt;// Wait for 2000 milliseconds before refreshing the display&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;If your LCD screen is blank, double check the wiring before assuming the code is at fault, there's a dedicated checklist for exactly that symptom. Also be careful with voltage: most I2C LCDs sold are 5V parts, and running one off the MKR WiFi 1010 can damage the board, so stick with a 3.3V-rated display.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-lcd" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-lcd&lt;/a&gt;&lt;/p&gt;

</description>
      <category>arduino</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>ESP32 - Rotary Encoder Servo Motor</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Sun, 15 Nov 2026 04:00:39 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/esp32-rotary-encoder-servo-motor-108e</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/esp32-rotary-encoder-servo-motor-108e</guid>
      <description>&lt;p&gt;This build lets you turn a rotary encoder knob and watch a servo motor sweep to match it. It is a good first project for connecting a physical input to a physical output through an ESP32, without needing a motor driver since a servo takes a simple PWM-like signal directly.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://esp32io.com/tutorials/esp32-rotary-encoder-servo-motor" rel="noopener noreferrer"&gt;ESP32 - Rotary Encoder Servo Motor&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DRBKM49W" rel="noopener noreferrer"&gt;38-pin ESP32 ESP-WROOM-32 Dev Module - Narrow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GQXZ2RK1" rel="noopener noreferrer"&gt;38-pin ESP32 ESP-WROOM-32 Dev Module - Wide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GWN1K4P5" rel="noopener noreferrer"&gt;30-pin ESP32 ESP-WROOM-32 Dev Module - Wide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0G5P177F8" rel="noopener noreferrer"&gt;ESP32 Uno-form board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0G5NCCHSH" rel="noopener noreferrer"&gt;ESP32 S3 Uno-form board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF575PW9" rel="noopener noreferrer"&gt;USB Cable Type-A to Type-C (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3V1TFM" rel="noopener noreferrer"&gt;USB Cable Type-C to Type-C (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPFXTZ73" rel="noopener noreferrer"&gt;Servo Motor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF57FT4J" rel="noopener noreferrer"&gt;Rotary Encoder&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0F5GJWPPZ" rel="noopener noreferrer"&gt;Screw Terminal Expansion Board for ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DYDN7LSZ" rel="noopener noreferrer"&gt;Breakout Expansion Board for ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGMVJNS" rel="noopener noreferrer"&gt;Power Splitter for ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DZXCNJTP" rel="noopener noreferrer"&gt;DIYables ESP32 Starter Kit (ESP32 included)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H8XVCLSJ" rel="noopener noreferrer"&gt;DIYables ESP32 S3 Starter Kit (ESP32 S3 included)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyvc6zv93yppr225oe14p.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyvc6zv93yppr225oe14p.jpg" alt="ESP32 - Rotary Encoder Servo Motor wiring diagram" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect the rotary encoder's CLK pin to GPIO25, DT pin to GPIO26, and SW pin to GPIO27 on the ESP32. The servo motor's signal wire goes to GPIO33. If you plan to drive several servos at once, it is worth using a PCA9685 16-channel PWM driver module instead, since it saves MCU pins and keeps the wiring simpler. Check the referenced power tutorial if you are unsure how to supply power to the ESP32 and the servo properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;A rotary encoder has two output pins, CLK and DT, that pulse as you turn the knob. By reading which one changes first, the code figures out whether you turned clockwise or counter-clockwise. Each pulse nudges a counter and an angle value up or down by 2 degrees. That angle is sent to the servo, which moves its shaft to match, so turning the knob one way sweeps the servo one direction and turning it back sweeps it the other way, clamped between 0 and 180 degrees.&lt;/p&gt;

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

&lt;p&gt;The sketch uses the &lt;code&gt;ESP32Servo&lt;/code&gt; library to control the servo through &lt;code&gt;servo.attach()&lt;/code&gt; and &lt;code&gt;servo.write()&lt;/code&gt;. In &lt;code&gt;setup()&lt;/code&gt;, the encoder pins are set as inputs and the servo starts centered at 90 degrees. In &lt;code&gt;loop()&lt;/code&gt;, the code watches for the CLK pin's rising edge, checks the DT pin to decide direction, adjusts the angle accordingly, clamps it to the 0-180 range, and calls &lt;code&gt;servo.write()&lt;/code&gt; to move the motor, while printing the counter and angle to the serial monitor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;esp32-rotary-encoder-servo-motor.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * This ESP32 code is created by esp32io.com
 *
 * This ESP32 code is released in the public domain
 *
 * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-rotary-encoder-servo-motor
 */&lt;/span&gt;

&lt;span class="cp"&gt;#include &amp;lt;ESP32Servo.h&amp;gt;&lt;/span&gt;

&lt;span class="cp"&gt;#define CLK_PIN 25 // ESP32 pin GPIO25 connected to the rotary encoder's CLK pin&lt;/span&gt;
&lt;span class="cp"&gt;#define DT_PIN  26 // ESP32 pin GPIO26 connected to the rotary encoder's DT pin&lt;/span&gt;
&lt;span class="cp"&gt;#define SW_PIN  27 // ESP32 pin GPIO27 connected to the rotary encoder's SW pin&lt;/span&gt;
&lt;span class="cp"&gt;#define SERVO_PIN 33 // ESP32 pin GPIO33 connected to the servo motor&lt;/span&gt;

&lt;span class="cp"&gt;#define DIRECTION_CW 0   // clockwise direction&lt;/span&gt;
&lt;span class="cp"&gt;#define DIRECTION_CCW 1  // counter-clockwise direction&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;direction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DIRECTION_CW&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;CLK_state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;prev_CLK_state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Servo&lt;/span&gt; &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// create servo object to control a servo&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// configure encoder pins as inputs&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CLK_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;INPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DT_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;INPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// read the initial state of the rotary encoder's CLK pin&lt;/span&gt;
  &lt;span class="n"&gt;prev_CLK_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;digitalRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CLK_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SERVO_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// attaches the servo on pin 9 to the servo object&lt;/span&gt;
  &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// read the current state of the rotary encoder's CLK pin&lt;/span&gt;
  &lt;span class="nc"&gt;CLK_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;digitalRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CLK_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// If the state of CLK is changed, then pulse occurred&lt;/span&gt;
  &lt;span class="c1"&gt;// React to only the rising edge (from LOW to HIGH) to avoid double count&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CLK_state&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;prev_CLK_state&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nc"&gt;CLK_state&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// if the DT state is HIGH&lt;/span&gt;
    &lt;span class="c1"&gt;// the encoder is rotating in counter-clockwise direction =&amp;gt; decrease the counter&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;digitalRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DT_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;direction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DIRECTION_CCW&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// you can change this resolution&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="c1"&gt;// the encoder is rotating in clockwise direction =&amp;gt; increase the counter&lt;/span&gt;
      &lt;span class="n"&gt;direction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DIRECTION_CW&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// you can change this resolution&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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;angle&lt;/span&gt; &lt;span class="o"&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;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// sets the servo angle according to the counter&lt;/span&gt;
    &lt;span class="n"&gt;servo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nc"&gt;Serial&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="s2"&gt;"COUNTER: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Serial&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="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Serial&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="s2"&gt;" | ANGLE: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// save last CLK state&lt;/span&gt;
  &lt;span class="n"&gt;prev_CLK_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CLK_state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://esp32io.com/tutorials/esp32-rotary-encoder-servo-motor" rel="noopener noreferrer"&gt;https://esp32io.com/tutorials/esp32-rotary-encoder-servo-motor&lt;/a&gt;&lt;/p&gt;

</description>
      <category>esp32</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>ESP32 C3 Super Mini - Controls Car via Web</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Sat, 14 Nov 2026 10:30:36 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/esp32-c3-super-mini-controls-car-via-web-1b50</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/esp32-c3-super-mini-controls-car-via-web-1b50</guid>
      <description>&lt;p&gt;This build turns a 2WD RC car into a robot you drive from a browser tab. The ESP32 C3 Super Mini has WiFi built in, so there's no extra module to wire up. It runs a web server for the control page and a WebSocket server for commands, so when you press an arrow button the car reacts immediately instead of waiting on a page reload.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-controls-car-via-web" rel="noopener noreferrer"&gt;ESP32 C3 Super Mini - Controls Car via Web&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GQXF1NH2" rel="noopener noreferrer"&gt;ESP32 C3 Super Mini&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF575PW9" rel="noopener noreferrer"&gt;USB Cable Type-A to Type-C (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3V1TFM" rel="noopener noreferrer"&gt;USB Cable Type-C to Type-C (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H28ZYVYP" rel="noopener noreferrer"&gt;L9110S Motor Driver Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;IR Remote Controller Kit&lt;/li&gt;
&lt;li&gt;CR2025 Battery (for IR Remote controller)&lt;/li&gt;
&lt;li&gt;1.5V AA Battery (for ESP32 C3 Super Mini and Car)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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%2Fnewbiely.com%2Fimages%2Ftutorial%2Fesp32-c3-super-mini-l9110s-2wd-rc-car-wiring-diagram.jpg" 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%2Fnewbiely.com%2Fimages%2Ftutorial%2Fesp32-c3-super-mini-l9110s-2wd-rc-car-wiring-diagram.jpg" alt="ESP32 C3 Super Mini - Controls Car via Web wiring diagram" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Four GPIO pins go to the L9110S motor driver, two per motor: GPIO5 and GPIO6 drive motor A, GPIO7 and GPIO10 drive motor B. Never wire a motor straight to a GPIO pin, it needs far more current than a pin can supply, which is exactly why the L9110S driver sits in between.&lt;/p&gt;

&lt;p&gt;The L9110S has no onboard 5V regulator, so you power the whole circuit from one source: four 1.5V AA batteries wired to VCC and GND on the L9110S give 6V for the motors and the board. The ESP32 C3 Super Mini only tolerates 3.3V on its GPIO pins, so never connect a 5V or 6V line to one directly. Keep GPIO8 and GPIO9 free since they're boot pins, and leave GPIO20/GPIO21 alone since they're the Serial Monitor UART.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Type the board's IP address into a browser, and the web server sends back the control page with HTML, CSS and JavaScript. That JavaScript then opens a WebSocket connection to the board. Every time you press or release an arrow button, it sends a small command number over that connection instead of reloading the page.&lt;/p&gt;

&lt;p&gt;On the ESP32 C3 Super Mini side, the WebSocket server reads each command number and sets the four L9110S pins HIGH or LOW accordingly, which spins the motors forward, backward, or turns the car by running only one wheel.&lt;/p&gt;

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

&lt;p&gt;The project uses two files: an .ino file with the board logic, and an index.h file holding the webpage's HTML, CSS and JavaScript as a string, so the page content stays separate from the control code. The sketch uses the DIYables ESP32 WebServer library to connect to WiFi, serve the page, and open a WebSocket server on port 81.&lt;/p&gt;

&lt;p&gt;Incoming WebSocket messages are parsed as command numbers, CMD_FORWARD, CMD_BACKWARD, CMD_LEFT, CMD_RIGHT, CMD_STOP, each mapped to a function that drives the four motor pins. Comments in the sketch walk through each part.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;esp32-c3-super-mini-controls-car-via-web.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * This ESP32 C3 Super Mini code was developed by newbiely.com
 *
 * This ESP32 C3 Super Mini code is made available for public use without any restriction
 *
 * For comprehensive instructions and wiring diagrams, please visit:
 * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-controls-car-via-web
 */&lt;/span&gt;

&lt;span class="cp"&gt;#include &amp;lt;DIYables_ESP32_WebServer.h&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include "index.h"&lt;/span&gt;

&lt;span class="cp"&gt;#define CMD_STOP 0&lt;/span&gt;
&lt;span class="cp"&gt;#define CMD_FORWARD 1&lt;/span&gt;
&lt;span class="cp"&gt;#define CMD_BACKWARD 2&lt;/span&gt;
&lt;span class="cp"&gt;#define CMD_LEFT 4&lt;/span&gt;
&lt;span class="cp"&gt;#define CMD_RIGHT 8&lt;/span&gt;

&lt;span class="cp"&gt;#define MOTOR_A_IA_PIN 5   // The ESP32 C3 SuperMini pin connected to the A-IA pin of the L9110S (Motor A)&lt;/span&gt;
&lt;span class="cp"&gt;#define MOTOR_A_IB_PIN 6   // The ESP32 C3 SuperMini pin connected to the A-IB pin of the L9110S (Motor A)&lt;/span&gt;
&lt;span class="cp"&gt;#define MOTOR_B_IA_PIN 7   // The ESP32 C3 SuperMini pin connected to the B-IA pin of the L9110S (Motor B)&lt;/span&gt;
&lt;span class="cp"&gt;#define MOTOR_B_IB_PIN 10  // The ESP32 C3 SuperMini pin connected to the B-IB pin of the L9110S (Motor B)&lt;/span&gt;

&lt;span class="c1"&gt;// WiFi credentials&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="no"&gt;WIFI_SSID&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_WIFI_SSID"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="no"&gt;WIFI_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_WIFI_PASSWORD"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Create web server instance&lt;/span&gt;
&lt;span class="nc"&gt;DIYables_ESP32_WebServer&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;DIYables_ESP32_WebSocket&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;webSocket&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Web Page handlers&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;handleHome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;WiFiClient&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;QueryParams&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;jsonData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HTML_CONTENT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// HTML_CONTENT is from index.h&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// WebSocket event handlers&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;onWebSocketOpen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"New WebSocket connection"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Send welcome message&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Connected to ESP32 WebSocket Server!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;onWebSocketMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;DataType&lt;/span&gt; &lt;span class="n"&gt;dataType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;uint16_t&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&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="s2"&gt;"command: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;CMD_STOP&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Stop"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nc"&gt;CAR_stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;CMD_FORWARD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Move Forward"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nc"&gt;CAR_moveForward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;CMD_BACKWARD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Move Backward"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nc"&gt;CAR_moveBackward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;CMD_LEFT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Turn Left"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nc"&gt;CAR_turnLeft&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;CMD_RIGHT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Turn Right"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nc"&gt;CAR_turnRight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Unknown command"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;onWebSocketClose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;CloseCode&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;uint16_t&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"WebSocket client disconnected"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;115200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;delay&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="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ESP32 C3 SuperMini Web Server and WebSocket Server"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Configure web server routes&lt;/span&gt;
  &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addRoute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;handleHome&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Start web server with WiFi connection&lt;/span&gt;
  &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;WIFI_SSID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;WIFI_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Enable WebSocket functionality&lt;/span&gt;
  &lt;span class="n"&gt;webSocket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enableWebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;webSocket&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nullptr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Set up WebSocket event handlers&lt;/span&gt;
    &lt;span class="n"&gt;webSocket&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;onOpen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onWebSocketOpen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;webSocket&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;onMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onWebSocketMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;webSocket&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;onClose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onWebSocketClose&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&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="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Failed to start WebSocket server"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Then handle HTTP requests&lt;/span&gt;
  &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handleClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Handle WebSocket&lt;/span&gt;
  &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handleWebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;CAR_moveForward&lt;/span&gt;&lt;span class="p"&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;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;CAR_moveBackward&lt;/span&gt;&lt;span class="p"&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;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;CAR_turnLeft&lt;/span&gt;&lt;span class="p"&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;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;CAR_turnRight&lt;/span&gt;&lt;span class="p"&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;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;CAR_stop&lt;/span&gt;&lt;span class="p"&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;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_A_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IA_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MOTOR_B_IB_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;If no IP address prints, double check the WiFi name and password; the board only joins 2.4GHz networks, not 5GHz. If the page won't open, make sure your phone and the board are on the same WiFi network. Missing button images just mean no internet access, since those load from the web.&lt;/p&gt;

&lt;p&gt;If the car drives the wrong way, swap the two motor wires on the L9110S output terminal. If the motors stall as soon as they start, the AA batteries are likely weak, swap in fresh ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-controls-car-via-web" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-controls-car-via-web&lt;/a&gt;&lt;/p&gt;

</description>
      <category>esp32</category>
      <category>electronics</category>
      <category>iot</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>ESP32 S3 - GPS</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Sat, 14 Nov 2026 04:00:30 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/esp32-s3-gps-3n45</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/esp32-s3-gps-3n45</guid>
      <description>&lt;p&gt;The NEO-6M GPS module is a cheap, reliable way to give your ESP32 S3 project a sense of place. Wire it up over UART, parse the NMEA sentences with the TinyGPSPlus library, and you get latitude, longitude, altitude, speed, and UTC date-time in your Serial Monitor. From there it's a short step to distance calculations, geofencing, or logging a track.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/esp32-s3/esp32-s3-gps" rel="noopener noreferrer"&gt;ESP32 S3 - GPS&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GYQLV7HT" rel="noopener noreferrer"&gt;ESP32 S3 WROOM N16R8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GWN6F8VT" rel="noopener noreferrer"&gt;ESP32 S3 SuperMini Dev Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0G5NCCHSH" rel="noopener noreferrer"&gt;ESP32 S3 Uno-form Board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GQXW2L9G" rel="noopener noreferrer"&gt;ESP32 S3 Camera Board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF575PW9" rel="noopener noreferrer"&gt;USB Cable Type-A to Type-C (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3V1TFM" rel="noopener noreferrer"&gt;USB Cable Type-C to Type-C (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H74TX2QZ" rel="noopener noreferrer"&gt;Screw Terminal Expansion Board for ESP32 S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H74NFV38" rel="noopener noreferrer"&gt;Breakout Expansion Board for ESP32 S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGMVJNS" rel="noopener noreferrer"&gt;Power Splitter for ESP32 S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H8XVCLSJ" rel="noopener noreferrer"&gt;DIYables ESP32 S3 Starter Kit (ESP32 S3 included)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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%2Fnewbiely.com%2Fimages%2Ftutorial%2Fesp32-s3-gps-module-wiring-diagram.jpg" 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%2Fnewbiely.com%2Fimages%2Ftutorial%2Fesp32-s3-gps-module-wiring-diagram.jpg" alt="ESP32 S3 - GPS wiring diagram" width="800" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The NEO-6M has four pins: VCC, GND, TX, and RX. Connect VCC to the ESP32 S3's 5V pin, not 3.3V, so the module's onboard regulator works correctly and gets a reliable satellite lock. Connect GND to ground. The module's TX goes to a Serial RX pin on the ESP32 S3, and its RX goes to a Serial TX pin, since the module talks TTL serial at 3.3V logic which the ESP32 S3 accepts directly.&lt;/p&gt;

&lt;p&gt;In the sketch, Serial2 is set up on GPIO 18 and GPIO 17. Place the module near a window or outdoors, since GPS signals don't pass through walls or metal enclosures.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The NEO-6M is a GPS receiver that locks onto satellite signals and streams standard NMEA-0183 sentences (GGA, RMC, VTG, GLL) over a serial line at 9600 bps by default. It tracks up to 22 satellites across 50 channels and gets you position accuracy around 2.5 meters once it has a fix.&lt;/p&gt;

&lt;p&gt;The ESP32 S3 reads that raw text stream on a second hardware serial port, keeping the primary serial port free for the Arduino IDE Serial Monitor. The TinyGPSPlus library does the actual parsing, turning the sentences into usable numbers.&lt;/p&gt;

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

&lt;p&gt;The reading sketch opens Serial2 at the GPS module's baud rate and feeds every incoming byte into a TinyGPSPlus object with gps.encode(). Once that object has a valid fix, the sketch prints latitude, longitude, altitude, speed in km/h, and UTC date-time to the Serial Monitor, checking isValid() on each field since some data may not be ready yet.&lt;/p&gt;

&lt;p&gt;A second sketch builds on this by calling TinyGPSPlus's built-in distanceBetween() function to compute the distance from your current position to a fixed reference point, printed in meters and kilometers, no extra math library needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;esp32-s3-gps.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * This ESP32 S3 code was developed by newbiely.com
 *
 * This ESP32 S3 code is made available for public use without any restriction
 *
 * For comprehensive instructions and wiring diagrams, please visit:
 * https://newbiely.com/tutorials/esp32-s3/esp32-s3-gps
 */&lt;/span&gt;

&lt;span class="cm"&gt;/*
 * This ESP32-S3 code is created by esp32io.com
 *
 * This ESP32-S3 code is released in the public domain
 *
 * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-gps
 */&lt;/span&gt;

&lt;span class="cp"&gt;#include &amp;lt;TinyGPS++.h&amp;gt;&lt;/span&gt;

&lt;span class="cp"&gt;#define GPS_BAUDRATE 9600  // The default baudrate of NEO-6M is 9600&lt;/span&gt;

&lt;span class="nc"&gt;TinyGPSPlus&lt;/span&gt; &lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// the TinyGPS++ object&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Serial2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;GPS_BAUDRATE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;SERIAL_8N1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ESP32 - GPS module"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Serial2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;available&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Serial2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"- latitude: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"- longitude: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lng&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"- altitude: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;altitude&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;altitude&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;meters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
          &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INVALID"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&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="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"- location: INVALID"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"- speed: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&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="nf"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="n"&gt;gps&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="nf"&gt;kmph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" km/h"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&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="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INVALID"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"- GPS date&amp;amp;time: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;gps&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;isValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;year&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"-"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;month&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"-"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;day&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="n"&gt;gps&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;hour&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;":"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="n"&gt;gps&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;minute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&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="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;":"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gps&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;second&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&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="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INVALID"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;millis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;gps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charsProcessed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"No GPS data received: check wiring"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;If the Serial Monitor keeps printing "No GPS data received: check wiring" after five seconds, double check the TX/RX crossover and the 5V connection. If wiring looks right but you're not getting a fix, give the module a clear view of the sky, indoors near a window at minimum, since concrete and metal block satellite signals. A cold start can also just take a while the first time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/esp32-s3/esp32-s3-gps" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/esp32-s3/esp32-s3-gps&lt;/a&gt;&lt;/p&gt;

</description>
      <category>esp32</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Arduino Mega - Buzzer</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Fri, 13 Nov 2026 10:30:48 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/arduino-mega-buzzer-24cm</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/arduino-mega-buzzer-24cm</guid>
      <description>&lt;p&gt;A 12V active buzzer is loud enough for an alarm, but it needs 12V and more current than a GPIO pin can supply, so the Arduino Mega can't drive it directly. You need something in between to switch that 12V on and off, and this tutorial shows two options: a relay, which is simple but clicks every time it switches, and a MOSFET module, which switches silently and fast enough for quick alarm beeps.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/arduino-mega/arduino-mega-buzzer" rel="noopener noreferrer"&gt;Arduino Mega - Buzzer&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Arduino MEGA&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GTPSYSTZ" rel="noopener noreferrer"&gt;DIYables MEGA Development Board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPFZNST2" rel="noopener noreferrer"&gt;USB 2.0 cable type A/B (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGMJ1RM" rel="noopener noreferrer"&gt;USB 2.0 cable type C/B (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0B1ZHXXXD" rel="noopener noreferrer"&gt;Relay&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CM63HJHQ" rel="noopener noreferrer"&gt;12V Active Buzzer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPGC5GTQ" rel="noopener noreferrer"&gt;DC Power Jack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPG2H4V2" rel="noopener noreferrer"&gt;Screw Terminal Block Shield for Arduino Uno/Mega&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GWNBDSCX" rel="noopener noreferrer"&gt;Sensors/Servo Expansion Shield for Arduino Mega&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard Shield for Arduino Mega&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ47G4GN" rel="noopener noreferrer"&gt;Enclosure for Arduino Mega&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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%2Fnewbiely.com%2Fimages%2Ftutorial%2Farduino-mega-12v-active-buzzer-wiring-diagram.jpg" 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%2Fnewbiely.com%2Fimages%2Ftutorial%2Farduino-mega-12v-active-buzzer-wiring-diagram.jpg" alt="Arduino Mega - Buzzer wiring diagram" width="800" height="530"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The 12V active buzzer has two wires: black goes to the ground of the 12V power supply, red goes to +12V. Instead of wiring the buzzer straight to the supply, you put a relay between the buzzer and the 12V power, and the Arduino Mega controls that relay through &lt;code&gt;RELAY_PIN&lt;/code&gt; (pin 3 in the code). The Arduino itself never carries the 12V current, it just tells the relay when to close the circuit. For the MOSFET version, the buzzer and MOSFET module connections replace the relay, and if your buzzer is a magnetic type with a coil inside, add a flyback diode (1N4007 or 1N5819) across it, stripe side to buzzer +, other side to buzzer −.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The buzzer makes noise whenever it gets 12V, so all the Arduino has to do is open and close that power path. A relay is an electromechanical switch, so you hear a click each time it toggles, which is fine for slow beeps. A MOSFET module is a solid-state switch with no moving parts, so it switches silently and much faster, which matters if you want many short alarm beeps in a row instead of one slow on/off cycle.&lt;/p&gt;

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

&lt;p&gt;The relay version turns the buzzer on for two seconds and off for five seconds, repeating forever, using &lt;code&gt;digitalWrite()&lt;/code&gt; on &lt;code&gt;RELAY_PIN&lt;/code&gt;. The MOSFET version is built for a real alarm pattern: 10 fast beeps, then one long beep, then three seconds of silence, then it repeats. In both cases the buzzer is only ever fully on or fully off, driven with &lt;code&gt;digitalWrite()&lt;/code&gt;. Don't use &lt;code&gt;analogWrite()&lt;/code&gt; to try to control volume, since an active buzzer generates its own tone internally and PWM just makes it sound weak or distorted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;arduino-mega-buzzer.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * This Arduino Mega code was developed by newbiely.com
 *
 * This Arduino Mega code is made available for public use without any restriction
 *
 * For comprehensive instructions and wiring diagrams, please visit:
 * https://newbiely.com/tutorials/arduino-mega/arduino-mega-buzzer
 */&lt;/span&gt;

&lt;span class="cp"&gt;#define RELAY_PIN 3  // The Arduino Mega pin that controls the buzzer via relay&lt;/span&gt;

&lt;span class="c1"&gt;// the setup function runs once when you press reset or power the board&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// initialize digital pin D4 as an output.&lt;/span&gt;
  &lt;span class="nf"&gt;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RELAY_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// the loop function runs over and over again forever&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&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;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RELAY_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// turn on buzzer 2 seconds&lt;/span&gt;
  &lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RELAY_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// turn off buzzer 5 seconds&lt;/span&gt;
  &lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;If you want slow, occasional beeps, the relay is fine and the click isn't a problem. If you're after rapid alarm-style beeping, the relay's clicking and switching speed get in the way, so switch to the MOSFET module instead. If you're using a magnetic buzzer with a MOSFET, skip the flyback diode and you risk damaging the MOSFET from voltage spikes when the coil switches off. Keep the 12V adapter unplugged while wiring, and only plug it in after the code is uploaded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/arduino-mega/arduino-mega-buzzer" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/arduino-mega/arduino-mega-buzzer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>arduino</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>ESP8266 - Potentiometer Piezo Buzzer</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Fri, 13 Nov 2026 04:00:45 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/esp8266-potentiometer-piezo-buzzer-2m1b</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/esp8266-potentiometer-piezo-buzzer-2m1b</guid>
      <description>&lt;p&gt;This build turns a potentiometer knob into a volume-less switch for a piezo buzzer: turn the knob past a certain point and the buzzer sounds, turn it back and it goes quiet. It is a good first project for reading analog input and driving a digital output on the ESP8266, and a stepping stone toward tone-based alarms or melodies.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/esp8266/esp8266-potentiometer-piezo-buzzer" rel="noopener noreferrer"&gt;ESP8266 - Potentiometer Piezo Buzzer&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GYQTMRV7" rel="noopener noreferrer"&gt;ESP8266 NodeMCU ESP-12F&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GYQNH2JH" rel="noopener noreferrer"&gt;ESP8266 D1 Mini NodeMCU ESP-12F&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0G5P2JDR8" rel="noopener noreferrer"&gt;ESP8266 NodeMCU ESP-12E (Uno-form)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ43NLS4" rel="noopener noreferrer"&gt;Micro USB Cable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H4V3S8VQ" rel="noopener noreferrer"&gt;ESP8266 NodeMCU ESP-12F (SMD-form)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF575PW9" rel="noopener noreferrer"&gt;USB Cable Type-A to Type-C (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3V1TFM" rel="noopener noreferrer"&gt;USB Cable Type-C to Type-C (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Potentiometer&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0F4PRHWNH" rel="noopener noreferrer"&gt;10k Ohm Trimmer Potentiometer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GF7FKPVB" rel="noopener noreferrer"&gt;Potentiometer Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DLNDDL4H" rel="noopener noreferrer"&gt;Potentiometer Module with Knob&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CM63HJHQ" rel="noopener noreferrer"&gt;3-24V Active Piezo Buzzer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0D8BBPV2S" rel="noopener noreferrer"&gt;Active Piezo Buzzer Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGP95K4" rel="noopener noreferrer"&gt;Passive Piezo Buzzer Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CSD1KYZW" rel="noopener noreferrer"&gt;Screw Terminal Expansion Board for ESP8266&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdobiaafg9z7t9fgg5obb.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdobiaafg9z7t9fgg5obb.jpg" alt="ESP8266 - Potentiometer Piezo Buzzer wiring diagram" width="800" height="642"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The potentiometer's wiper (middle pin) connects to the ESP8266's analog input, &lt;code&gt;A0&lt;/code&gt;. The piezo buzzer's signal pin connects to &lt;code&gt;D8&lt;/code&gt;, which is configured as a digital output. You can build this on a breadboard or wire it directly, point to point, without one.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;A potentiometer is a variable resistor with three pins; turning the knob changes the voltage at the middle pin, which the ESP8266 reads as an analog value through &lt;code&gt;analogRead()&lt;/code&gt;. The piezo buzzer is a simple output device that makes sound when it receives a signal. The sketch compares the potentiometer's analog reading against a fixed threshold: above it, the buzzer pin is driven &lt;code&gt;HIGH&lt;/code&gt; and the buzzer sounds; at or below it, the pin goes &lt;code&gt;LOW&lt;/code&gt; and the buzzer stays silent.&lt;/p&gt;

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

&lt;p&gt;In &lt;code&gt;setup()&lt;/code&gt;, &lt;code&gt;BUZZER_PIN&lt;/code&gt; is set to output mode. The &lt;code&gt;loop()&lt;/code&gt; function continuously reads the potentiometer's analog value on &lt;code&gt;A0&lt;/code&gt; and checks it against &lt;code&gt;ANALOG_THRESHOLD&lt;/code&gt;, which is set to 1000. If the reading exceeds the threshold, &lt;code&gt;digitalWrite()&lt;/code&gt; turns the buzzer on; otherwise it turns it off. A variant of this sketch compares a converted voltage value instead of the raw analog reading, and another variant plays a melody once the threshold is crossed, using a separate &lt;code&gt;pitches.h&lt;/code&gt; file you create in the Arduino IDE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;esp8266-potentiometer-piezo-buzzer.ino&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * This ESP8266 NodeMCU code was developed by newbiely.com
 *
 * This ESP8266 NodeMCU code is made available for public use without any restriction
 *
 * For comprehensive instructions and wiring diagrams, please visit:
 * https://newbiely.com/tutorials/esp8266/esp8266-potentiometer-piezo-buzzer
 */&lt;/span&gt;

&lt;span class="cp"&gt;#define POTENTIOMETER_PIN  A0 // The ESP8266 pin connected to Potentiometer pin&lt;/span&gt;
&lt;span class="cp"&gt;#define BUZZER_PIN         D8 // The ESP8266 pin connected to Buzzer's pin&lt;/span&gt;
&lt;span class="cp"&gt;#define ANALOG_THRESHOLD   1000&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&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;pinMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BUZZER_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Configure the ESP8266 pin to the output mode&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;analog_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;analogRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;POTENTIOMETER_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// read the input on analog pin&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;analog_value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;ANALOG_THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BUZZER_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;HIGH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// turn on Piezo Buzzer&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="nf"&gt;digitalWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BUZZER_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;LOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// turn off Piezo Buzzer&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/esp8266/esp8266-potentiometer-piezo-buzzer" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/esp8266/esp8266-potentiometer-piezo-buzzer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>esp8266</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>ESP32 MicroPython LDR Module</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Thu, 12 Nov 2026 10:30:50 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/esp32-micropython-ldr-module-jhb</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/esp32-micropython-ldr-module-jhb</guid>
      <description>&lt;p&gt;An LDR light sensor module lets your ESP32 react to ambient light, going dark-triggered or measuring brightness as a number. It gives you both a simple digital HIGH/LOW signal and a raw analog reading, so you can pick whichever fits your project, a night light trigger or a light level logger.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/esp32-micropython/esp32-micropython-ldr-module" rel="noopener noreferrer"&gt;ESP32 MicroPython LDR Module&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DRBKM49W" rel="noopener noreferrer"&gt;38-pin ESP32 ESP-WROOM-32 Dev Module - Narrow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GQXZ2RK1" rel="noopener noreferrer"&gt;38-pin ESP32 ESP-WROOM-32 Dev Module - Wide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GWN1K4P5" rel="noopener noreferrer"&gt;30-pin ESP32 ESP-WROOM-32 Dev Module - Wide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0G5P177F8" rel="noopener noreferrer"&gt;ESP32 Uno-form board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0G5NCCHSH" rel="noopener noreferrer"&gt;ESP32 S3 Uno-form board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF575PW9" rel="noopener noreferrer"&gt;USB Cable Type-A to Type-C (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3V1TFM" rel="noopener noreferrer"&gt;USB Cable Type-C to Type-C (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BXKJPV67" rel="noopener noreferrer"&gt;LDR Light Sensor Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0F5GJWPPZ" rel="noopener noreferrer"&gt;Screw Terminal Expansion Board for ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DYDN7LSZ" rel="noopener noreferrer"&gt;Breakout Expansion Board for ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGMVJNS" rel="noopener noreferrer"&gt;Power Splitter for ESP32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DZXCNJTP" rel="noopener noreferrer"&gt;DIYables ESP32 Starter Kit (ESP32 included)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H8XVCLSJ" rel="noopener noreferrer"&gt;DIYables ESP32 S3 Starter Kit (ESP32 S3 included)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa6bsb3z1qvjkmzfmqnvt.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa6bsb3z1qvjkmzfmqnvt.jpg" alt="ESP32 MicroPython LDR Module wiring diagram" width="799" height="510"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The module has four pins. Connect VCC to the ESP32's 3.3V to 5V supply and GND to ground. The DO pin is the digital output, and the AO pin is the analog output. You can wire just one of them or both at once, depending on whether you want a simple light/dark signal or a continuous reading. In the example code, DO connects to GPIO13.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The module has a potentiometer that sets a light threshold. On the DO pin, the output goes LOW when the surrounding light is brighter than that threshold, and HIGH when it's dimmer, so you can read it like a simple switch. A DO-LED on the board mirrors this: it's lit when there's light and off in the dark. The AO pin instead gives you a varying reading, lower when there's more light and higher as it gets darker, which is useful if you want to measure light level rather than just detect its presence.&lt;/p&gt;

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

&lt;p&gt;The MicroPython sketch sets up GPIO13 as a digital input connected to the DO pin. In a loop, it calls &lt;code&gt;value()&lt;/code&gt; on that pin: a reading of 1 means no light is present, and 0 means light is present, so the code prints the opposite message for each state. A short &lt;code&gt;sleep&lt;/code&gt; keeps the output from flooding the console. A separate version of the code reads from the AO pin instead, giving you a numeric light level rather than a simple present/not-present state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;esp32-micropython-ldr-module.py&lt;/strong&gt;&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="s2"&gt;"""
This ESP32 MicroPython code was developed by newbiely.com
This ESP32 MicroPython code is made available for public use without any restriction
For comprehensive instructions and wiring diagrams, please visit:
https://newbiely.com/tutorials/esp32-micropython/esp32-micropython-ldr-module
"""&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Pin&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;utime&lt;/span&gt;  &lt;span class="c1"&gt;# For timing functions&lt;/span&gt;

&lt;span class="no"&gt;DO_PIN&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;13&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="no"&gt;IN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# The ESP32 pin GPIO13 connected to the DO pin of the LDR module&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;light_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DO_PIN&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Read the digital value from the pin&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;light_state&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"The light is NOT present"&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;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"The light is present"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;utime&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="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Add a small delay to avoid spamming the output&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/esp32-micropython/esp32-micropython-ldr-module" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/esp32-micropython/esp32-micropython-ldr-module&lt;/a&gt;&lt;/p&gt;

</description>
      <category>micropython</category>
      <category>esp32</category>
      <category>electronics</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Arduino MicroPython Joystick</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Thu, 12 Nov 2026 04:00:42 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/arduino-micropython-joystick-4d9k</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/arduino-micropython-joystick-4d9k</guid>
      <description>&lt;p&gt;A joystick is just two potentiometers and a button wired together, but it is a handy way to get 2D input into a microcontroller project. This guide walks through wiring a joystick to an Arduino Giga R1 WiFi and reading its position and button state with MicroPython, using the DIYables_MicroPython_Joystick library.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/arduino-micropython/arduino-micropython-joystick" rel="noopener noreferrer"&gt;Arduino MicroPython Joystick&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Arduino Giga R1 WiFi&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CF575PW9" rel="noopener noreferrer"&gt;USB Cable Type-A to Type-C (for USB-A PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3V1TFM" rel="noopener noreferrer"&gt;USB Cable Type-C to Type-C (for USB-C PC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ37P5RQ" rel="noopener noreferrer"&gt;Joystick&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BPG2H4V2" rel="noopener noreferrer"&gt;Screw Terminal Block Shield for Arduino Uno/Mega/Giga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0GWNBDSCX" rel="noopener noreferrer"&gt;Sensors/Servo Expansion Shield for Arduino Mega/Giga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard Shield for Arduino Mega/Giga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Enclosure for Arduino Giga&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DHGMVJNS" rel="noopener noreferrer"&gt;Power Splitter for Arduino Giga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvan05lbpx28cqvj2pizw.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvan05lbpx28cqvj2pizw.jpg" alt="Arduino MicroPython Joystick wiring diagram" width="799" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The joystick has five pins. GND goes to ground, and VCC connects to the Arduino's 3.3V supply. VRX and VRY are analog outputs for the horizontal and vertical position, and each connects to an ADC-capable pin on the Arduino. SW is the pushbutton pin; it's normally open, so a pull-up resistor keeps it HIGH when the button is untouched and pulls it LOW when pressed, giving you a clean digital signal instead of a floating pin.&lt;/p&gt;

&lt;p&gt;In the example code, VRX goes to A0, VRY to A1, and SW to D2.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The joystick is really two potentiometers arranged at right angles, one for each axis. Moving it left or right changes the voltage on VRX between 0V and 3.3V, and the Arduino's ADC converts that into a value from 0 to 4095. Moving it up or down does the same thing on VRY. When the joystick sits in its neutral position, both readings center around the middle of that range, which is how you detect direction and magnitude of movement.&lt;/p&gt;

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

&lt;p&gt;The script creates a Joystick object from the VRX, VRY and SW pins, then calls joystick.loop() in every iteration, which handles debouncing the button (you can tune the debounce time with set_debounce_time()). From there it reads the X and Y axis values with read_x() and read_y(), checks is_pressed() and is_released() to catch button transitions, and keeps a running count of presses with get_press_count(). The loop prints all of this to the Thonny shell so you can see the raw coordinates and button activity as you move the stick.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;arduino-micropython-joystick.py&lt;/strong&gt;&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="s2"&gt;"""
This Arduino MicroPython script was developed by newbiely.com
This Arduino MicroPython script is made available for public use without any restriction
For comprehensive instructions and wiring diagrams, please visit:
https://newbiely.com/tutorials/arduino-micropython/arduino-micropython-joystick
"""&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nc"&gt;DIYables_MicroPython_Joystick&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Joystick&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Pin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;ADC&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="no"&gt;VRX_PIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'A0'&lt;/span&gt; &lt;span class="c1"&gt;# The Arduino Giga R1 WiFi's pin connected to VRX pin of joystick&lt;/span&gt;
&lt;span class="no"&gt;VRY_PIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'A1'&lt;/span&gt; &lt;span class="c1"&gt;# The Arduino Giga R1 WiFi's pin connected to VRY pin of joystick&lt;/span&gt;
&lt;span class="no"&gt;SW_PIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'D2'&lt;/span&gt;  &lt;span class="c1"&gt;# The Arduino Giga R1 WiFi's pin connected to SW pin of joystick&lt;/span&gt;

&lt;span class="n"&gt;joystick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Joystick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pin_x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;VRX_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pin_y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;VRY_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pin_button&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;SW_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Configure the debounce time if necessary (default is 50ms)&lt;/span&gt;
&lt;span class="n"&gt;joystick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_debounce_time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# debounce time set to 100 milliseconds&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;joystick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Must be called frequently to process button debouncing&lt;/span&gt;

    &lt;span class="c1"&gt;# Read the analog values from the X and Y axes&lt;/span&gt;
    &lt;span class="n"&gt;x_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joystick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;y_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joystick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;press_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joystick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_press_count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Check if the button has been pressed or released&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;joystick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_pressed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Button Pressed"&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;joystick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_released&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Button Released"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Print the joystick's X and Y coordinates, and pressed count&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'Joystick Position - X: {x_value}, Y: {y_value}, pressed count: {press_count}'&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="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Delay to reduce the output frequency, note that, long delay can make it miss the thump press&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/arduino-micropython/arduino-micropython-joystick" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/arduino-micropython/arduino-micropython-joystick&lt;/a&gt;&lt;/p&gt;

</description>
      <category>micropython</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Raspberry Pi - Button</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Wed, 11 Nov 2026 10:30:47 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/raspberry-pi-button-3mf3</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/raspberry-pi-button-3mf3</guid>
      <description>&lt;p&gt;A push button looks trivial but trips up a lot of beginners because of two things: floating inputs and mechanical chatter. This walks through wiring a button to a Raspberry Pi and reading its state in Python, using the internal pull-up resistor so you don't need any extra parts beyond the button itself.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-button" rel="noopener noreferrer"&gt;Raspberry Pi - Button&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi 5&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard-mount Button with Cap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard-mount Button Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CM63R39Q" rel="noopener noreferrer"&gt;Panel-mount Push Button&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ3WM7K1" rel="noopener noreferrer"&gt;Push Button Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DL2RCCJG" rel="noopener noreferrer"&gt;Screw Terminal Block Shield for Raspberry Pi&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Raspberry Pi Prototyping Base Plate &amp;amp; Breadboard Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;DIYables USB Type-A to Type-B Cable&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqfad6tieqp692p9by6x9.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqfad6tieqp692p9by6x9.jpg" alt="Raspberry Pi - Button wiring diagram" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A button has four pins, but internally they're linked in pairs, so only two are actually independent. Connect one of those two pins to GND and the other to a Raspberry Pi GPIO pin, for example pin 16. For a panel-mount button the idea is the same; if you want tidier connections, a Screw Terminal Block Shield for the Raspberry Pi makes it easier to secure the wires instead of relying on breadboard jumpers.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Inside the button there are two pins, call them A and B. When the button is not pressed, A and B are disconnected. Pressing the button connects them. Since one pin is wired to GND and the other to a GPIO pin, this turns a mechanical press into an electrical change you can read in code.&lt;/p&gt;

&lt;p&gt;Using the Raspberry Pi's internal pull-up resistor on that GPIO pin means the pin reads HIGH when the button is untouched, and LOW the moment it's pressed, with no external resistor needed.&lt;/p&gt;

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

&lt;p&gt;In Python, &lt;code&gt;GPIO.setup()&lt;/code&gt; configures the pin as an input with &lt;code&gt;pull_up_down=GPIO.PUD_UP&lt;/code&gt;, enabling the internal pull-up. From there, &lt;code&gt;GPIO.input()&lt;/code&gt; returns the current state, and because of the pull-up wiring, a LOW reading means the button is pressed. One script just polls and prints the state continuously; a second script is built around detecting the moment of a press rather than just the current level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;raspberry-pi-button.py&lt;/strong&gt;&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="s2"&gt;"""
This Raspberry Pi code was developed by newbiely.com
This Raspberry Pi code is made available for public use without any restriction
For comprehensive instructions and wiring diagrams, please visit:
https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-button
"""&lt;/span&gt;


&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;RPi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;GPIO&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="no"&gt;GPIO&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="c1"&gt;# Define the GPIO pin connected to the button&lt;/span&gt;
&lt;span class="no"&gt;BUTTON_PIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;

&lt;span class="c1"&gt;# Set the GPIO mode to BCM&lt;/span&gt;
&lt;span class="no"&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="no"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BCM&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the pushbutton pin as an input with a pull-up resistor&lt;/span&gt;
&lt;span class="c1"&gt;# The pull-up input pin will be HIGH when the switch is open and LOW when the switch is closed.&lt;/span&gt;
&lt;span class="no"&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="no"&gt;BUTTON_PIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&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="no"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PUD_UP&lt;/span&gt;&lt;span class="p"&gt;)&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="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Read the state of the switch/button&lt;/span&gt;
        &lt;span class="n"&gt;button_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;GPIO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BUTTON_PIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Print out the button's state&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;button_state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Small delay to avoid unnecessary printing&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="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;KeyboardInterrupt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\nExiting..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Clean up GPIO settings&lt;/span&gt;
    &lt;span class="no"&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="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;If you skip the pull-up or pull-down resistor, the input pin floats, meaning it picks up random noise and the value it reports has nothing to do with whether the button is actually pressed. Using the internal pull-up as described avoids this entirely.&lt;/p&gt;

&lt;p&gt;The other common issue is chattering: mechanically, a single press can cause the pin to flicker between LOW and HIGH several times in rapid succession, so your code sees multiple presses instead of one. This is a known physical quirk of switches, not a bug in your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-button" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-button&lt;/a&gt;&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Raspberry Pi Pico - Blink LED</title>
      <dc:creator>Arduino ESP32 Raspberry Pi Tutorials</dc:creator>
      <pubDate>Wed, 11 Nov 2026 04:00:41 +0000</pubDate>
      <link>https://dev.to/arduino_getstarted_f52a1a/raspberry-pi-pico-blink-led-31hp</link>
      <guid>https://dev.to/arduino_getstarted_f52a1a/raspberry-pi-pico-blink-led-31hp</guid>
      <description>&lt;p&gt;This one's the hardware equivalent of printing "hello world": blink an LED with a Raspberry Pi Pico running MicroPython. It is a small build, but it gets you comfortable with digital output pins, basic wiring, and flashing MicroPython code onto the board, which you will reuse in pretty much every other Pico project.&lt;/p&gt;

&lt;p&gt;The full tutorial, with every detail and the line-by-line code explanation, is on our site: &lt;a href="https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-blink-led" rel="noopener noreferrer"&gt;Raspberry Pi Pico - Blink LED&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi Pico W&lt;/li&gt;
&lt;li&gt;Raspberry Pi Pico&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DQ43NLS4" rel="noopener noreferrer"&gt;Micro USB Cable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0BXKM8PN3" rel="noopener noreferrer"&gt;LED Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0DLNDH4Z8" rel="noopener noreferrer"&gt;LED (red)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0F6T2RTQ6" rel="noopener noreferrer"&gt;LED Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0H29526SX" rel="noopener noreferrer"&gt;Button and LED Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0D2KH3GP1" rel="noopener noreferrer"&gt;220Ω Resistor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/breadboard" rel="noopener noreferrer"&gt;Breadboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/categories/jumper-wires" rel="noopener noreferrer"&gt;Jumper Wires&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://diyables.io/dp/B0CWZQ13M1" rel="noopener noreferrer"&gt;DIYables Sensor Kit (18 sensors/displays)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wiring
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fksk8nmww5nzoj569qqlv.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fksk8nmww5nzoj569qqlv.jpg" alt="Raspberry Pi Pico - Blink LED wiring diagram" width="800" height="632"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An LED has two legs: the cathode (-) and the anode (+). Connect the cathode to GND (0V). Connect the anode to a Pico GPIO pin, GP13 in this example, through a 220Ω resistor to limit current. If you use the LED Module instead of a bare LED, you can skip the separate resistor since it's already built in, which makes wiring simpler.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;With the cathode tied to GND, the LED's state depends on what you put on the anode. Drive that pin to GND and the LED stays off. Drive it to VCC (power) and the LED lights up. A Pico GPIO pin configured as digital output lets your code flip that pin between GND and VCC, which is exactly how software toggles a physical LED. You can also dim the LED by sending it a PWM signal instead of a plain on/off voltage.&lt;/p&gt;

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

&lt;p&gt;The code declares &lt;code&gt;GP13&lt;/code&gt; as a digital output using &lt;code&gt;Pin(13, Pin.OUT)&lt;/code&gt;, then toggles that pin's value to turn the LED off and on, creating the blink pattern. The full MicroPython sketch with comments explaining each step is shown below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;raspberry-pi-pico-blink-led.py&lt;/strong&gt;&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="s2"&gt;"""
This Raspberry Pi Pico MicroPython code was developed by newbiely.com
This Raspberry Pi Pico code is made available for public use without any restriction
For comprehensive instructions and wiring diagrams, please visit:
https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-blink-led
"""&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Pin&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sleep&lt;/span&gt;

&lt;span class="n"&gt;led&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;13&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="no"&gt;OUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;led&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;value&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;# Turn the LED on&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 1 second&lt;/span&gt;
    &lt;span class="n"&gt;led&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;value&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;# Turn the LED off&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 1 second&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that go wrong
&lt;/h2&gt;

&lt;p&gt;Before flashing code, make sure Thonny IDE and MicroPython firmware are installed on your Pico, and that Thonny is set to the MicroPython (Raspberry Pi Pico) interpreter under Tools, Options. If the LED never lights, double check the cathode is on GND and the anode is wired through the resistor to the correct GPIO pin, since a reversed LED simply won't conduct.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full tutorial
&lt;/h2&gt;

&lt;p&gt;The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: &lt;a href="https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-blink-led" rel="noopener noreferrer"&gt;https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-blink-led&lt;/a&gt;&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>electronics</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
