Sensors allow microcontroller projects to measure and react to the real world. With the right sensor, an Arduino, ESP32, Raspberry Pi, or PIC microcontroller can detect temperature, distance, light, motion, pressure, current, water flow, sound, gas levels, weight, and many other physical conditions.
This page collects the sensor tutorials published on Teach Me Microcontrollers. Each guide is written for practical use, with wiring diagrams, sample code, explanations, and project ideas you can build on. Whether you are a beginner learning how to connect your first sensor or an engineer looking for a quick reference, these tutorials will help you understand both the hardware connection and the program behind it.
Browse All Sensor Tutorials
Use the tutorials below to learn how different sensors work and how to connect them to microcontroller boards.

Raspberry Pi Pico and HC-SR501 Motion Sensor
Now that we have set up the Raspberry Pi Pico for the Arduino environment, it’s time to build real projects. First on the list…

Using a Fingerprint Sensor
Fingerprint sensors are old technology but it wasn’t readily available to makers until it was cheap. With such a device, you could easily create…

How to Use MQ-4 Methane Gas Sensor
The MQ-4 is one of many gas sensors ready to be interfaced with microcontrollers. Just like the rest of the MQ sensors, the MQ-4…

Using the BH1750 (GY-30) Sensor with Arduino
The BH1750 is a light-intensity sensor that interfaces with a microcontroller through the I2C bus. It can directly provide lux values without further processing,…

ESP32 Turbidity Sensor
The ESP32 has become one of my favorite microcontrollers as it's compact, relatively cheap, and contains 125% higher memory than an Arduino UNO.

Ultrasonic Sensor and Temperature Compensation
If you've been using Arduino, you might have used or have heard about the ultrasonic sensor. Most of us use it for level/distance measurement…

MQ-135 Air Quality Sensor Tutorial
The MQ-135 “air quality” sensor is part of the MQ series of gas sensors that uses a chemical-sensitive element. The resistance of such elements…

Flame Sensor Project: Comprehensive Guide
Flame sensors are found from the simplest gas stoves to huge industrial plants. There are different types of fire sensors -- some cheap, some…

Sensor Display on ESP32 Web Server
Last time, I showed you how to setup the ESP32 development board with the Arduino programming environment. This time, I will be building a…

Arduino Magnetic Sensor Using Hall Effect
An Arduino magnetic sensor has several uses: for reading the speed of a rotating object, for door alarms and for navigation. In this tutorial,…

Send Sensor Data to ThingSpeak via ESP8266
In the previous tutorial, we set up a soil moisture sensor and have its data readable via WiFi. However, that data is only accessible…

WiFi Soil Moisture Sensor with Arduino Program
Plants need enough water to survive. But what if you forgot to water the plants? This multi-part ESP8266 tutorial aims to provide a simple…
Start Learning Sensor Modules
Most sensor modules are designed to make electronic measurements easier. Instead of building the full signal-conditioning circuit yourself, the module usually includes the sensor element, resistors, amplifiers, filters, voltage dividers, or interface circuits needed to connect it to a microcontroller.
Some sensors provide a simple digital output. These are useful when you only need to know if a condition is true or false, such as whether motion is detected, water is present, or a magnetic field is nearby.
Other sensors provide an analog output. These are useful when you need to measure a changing value, such as light level, voltage, pressure, flex, sound level, or current.
Many modern sensors use digital communication protocols such as I2C, SPI, UART, or 1-Wire. These sensors can send calibrated data directly to the microcontroller, which makes them useful for more advanced projects.
Arduino Sensor Tutorials
Arduino is often the easiest starting point for sensor projects. Many sensor modules work directly with Arduino Uno, Nano, and Mega boards, especially if they operate at 5 V or include voltage-compatible outputs.
In these tutorials, you will learn how to wire common sensors to Arduino boards, read their output, display the result, and use the sensor value to control LEDs, buzzers, motors, relays, LCDs, and other output devices.
ESP32 Sensor Tutorials
The ESP32 is a good choice for sensor projects that need Wi-Fi, Bluetooth, web servers, dashboards, data logging, or IoT features. However, ESP32 boards use 3.3 V logic, so sensor voltage compatibility is important.
For ESP32 sensor projects, always check whether the sensor output is safe for 3.3 V GPIO pins. Some 5 V sensor modules may need a voltage divider, level shifter, or a different wiring approach before connecting them to an ESP32 board.
Raspberry Pi Sensor Projects
Raspberry Pi boards are useful when a sensor project needs Linux, Python, networking, image processing, databases, or a web interface. Since Raspberry Pi GPIO pins are also 3.3 V only, you should avoid connecting 5 V sensor outputs directly to the GPIO header.
Raspberry Pi sensor tutorials usually focus on practical applications such as monitoring, automation, logging, and interactive projects.
Common Sensor Types
Teach Me Microcontrollers covers different types of sensors used in electronics and embedded systems projects, including:
- Temperature and humidity sensors
- Distance and proximity sensors
- Light and color sensors
- Motion and vibration sensors
- Water level and water flow sensors
- Current and voltage sensors
- Gas and air-quality sensors
- Load cell and force sensors
- Sound and microphone modules
- Magnetic and Hall-effect sensors
- Soil moisture and environmental sensors
Choosing the Right Sensor
Before choosing a sensor, check the supply voltage, output type, communication interface, accuracy, measurement range, and whether the sensor needs calibration. Also check whether your microcontroller has the required pins, such as analog inputs, I2C pins, SPI pins, UART pins, or interrupt-capable GPIO pins.
For simple beginner projects, digital and analog sensor modules are usually easier to use. For more accurate measurements, sensors with I2C or SPI interfaces are often better because they can provide processed data instead of raw analog values.
Sensor Tutorial FAQs
What is the easiest sensor to use with Arduino?
Simple digital sensors are usually the easiest to use with Arduino because they only require reading a HIGH or LOW signal. Examples include basic motion sensors, magnetic reed switches, tilt sensors, and some water detection modules. Analog sensors are also beginner-friendly if you understand how to use analogRead().
Can I use 5 V sensors with ESP32?
Not always. The ESP32 uses 3.3 V GPIO pins, so a 5 V output signal can damage the board. Some sensor modules can be powered by 5 V but still output 3.3 V-compatible signals, while others need a voltage divider or level shifter. Always check the module output before connecting it to an ESP32 pin.
Are sensor modules accurate?
Sensor modules are useful for learning and prototyping, but accuracy depends on the sensor type, module quality, calibration, power supply, wiring, and environment. For serious measurements, always check the datasheet and calibrate the sensor when needed.