A temperature sensor sitting next to a microcontroller does not automatically share its data. They need a communication protocol — a defined way of exchanging signals that both devices understand.
Why protocols matter
Different sensors have different data rates, connection distances, and pin count requirements. Protocols are standardized interfaces that let you connect sensors from different manufacturers to any microcontroller that supports the protocol.
GPIO: the simplest case
Some sensors communicate with a single digital pin. A PIR motion sensor outputs HIGH when it detects motion and LOW otherwise. A push button does the same. For simple binary sensors, you just read a GPIO pin value.
Analog sensors
A potentiometer or light-dependent resistor outputs a varying voltage. You read it with an ADC (Analog-to-Digital Converter) pin. The microcontroller converts the voltage to a digital value you can work with in code.
uint16_t adcValue = ADC_read(ADC_CHANNEL_0);
float voltage = adcValue * (3.3f / 4095.0f); // 12-bit ADC, 3.3V reference
Digital protocols
Most modern sensors use a digital protocol. The three most common are UART, SPI, and I2C. Each has trade-offs in terms of speed, pin count, and complexity. The right choice depends on your sensor and your requirements.
One-Wire protocol
Some sensors (like the DS18B20 temperature sensor) use a proprietary One-Wire protocol. As the name suggests, they only need one data wire (plus power and ground). They are convenient but slower and more complex to implement.
Reading a real sensor
Most sensor datasheets describe the communication protocol in detail. Read the datasheet. It tells you the protocol, timing requirements, command bytes, and how to interpret the response. Learning to read datasheets is one of the most valuable skills in embedded development.



