Digital switching output
Examples: limit switches, digital Hall modules and threshold outputs. The logic state represents an event or condition.
Understand how sensors report digital states and measurements, how microcontrollers exchange data, and how to wire and troubleshoot I²C, SPI and UART interfaces.
A digital sensor may report a binary state, send a pulse whose timing carries information, or transmit a multi-bit measurement over a communication bus. Before wiring a module, identify its output type and the electrical requirements of the exact part.
Examples: limit switches, digital Hall modules and threshold outputs. The logic state represents an event or condition.
Examples: ultrasonic echo pulse, encoder output and frequency-output sensors. Timing or pulse count carries the measurement.
Examples: I²C, SPI and UART. The receiver interprets bits according to the bus rules and device protocol.
Digital logic is not necessarily 0 V and 5 V. A device specifies input thresholds and output levels. A 3.3 V controller and a 5 V sensor may not be directly compatible in both directions.
A push-pull output actively drives both HIGH and LOW. An open-drain/open-collector output actively pulls LOW but needs a pull-up resistor or another specified pull-up source to create HIGH.
Multiple open-drain devices can share a bus safely when designed correctly. Do not connect ordinary push-pull outputs together.
An open input can float: its voltage may wander and produce unpredictable readings. A pull-up provides a defined idle HIGH state. A pull-down can provide a defined LOW state when the circuit and device support that arrangement.
The 10 kΩ value is a teaching example, not a universal rule. The correct value depends on leakage, noise, speed, bus capacitance and device recommendations. A microcontroller's internal pull-up may be suitable for a simple button, but it is often too weak or poorly specified for a faster shared bus.
const byte buttonPin = 2;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
bool pressed = (digitalRead(buttonPin) == LOW);
Serial.println(pressed ? "PRESSED" : "RELEASED");
delay(50);
}With INPUT_PULLUP, the pin reads HIGH when the switch is open and LOW when the switch connects it to ground. Software debouncing may still be needed.
For a 3.3 V-only input, a 5 V HIGH may exceed the permitted pin voltage. Use a level shifter designed for the signal type. A resistor divider can sometimes reduce a one-way slow signal, but it is not a universal replacement for a proper bidirectional I²C level shifter.
Also check whether breakout boards already include pull-ups and which rail those resistors connect to.
I²C uses a clock line (SCL) and a data line (SDA). A controller initiates transfers, sends an address and controls the clock. Devices respond at their configured address. Both lines are typically open-drain/open-collector and require pull-ups to a suitable logic rail.
Conceptual shared-bus topology. The drawing groups each device's SDA and SCL connections; it is not a pin-by-pin breakout-board layout. Pull-ups may already be fitted to modules. Too many parallel pull-ups can make the effective resistance too low.
SPI commonly uses SCLK, MOSI, MISO and a chip-select (CS/SS) line for each peripheral. It is often fast and full-duplex, but uses more wires and has device-specific mode, timing and selection rules.
UART sends framed serial data without a shared clock. Both ends must agree on baud rate, data bits, parity and stop bits. TX connects to the other device's RX, and vice versa.
UART logic voltage is not automatically the same as RS-232 voltage. Do not connect a true RS-232 port directly to a microcontroller UART pin; use the appropriate transceiver.
| Interface | Signal wires | Clock | Typical strengths | Watch for |
|---|---|---|---|---|
| I²C | SDA, SCL | Shared clock | Multiple addressed devices, low pin count | Pull-ups, address conflicts, capacitance |
| SPI | SCLK, MOSI, MISO, CS | Shared clock | High throughput, full-duplex | More pins, CS and mode requirements |
| UART | TX, RX, GND | No shared clock | Simple point-to-point links, debugging | Matching format/baud and logic levels |
An I²C scanner asks the bus whether a device acknowledges each candidate address. It is a useful first diagnostic, but it does not identify a sensor model or prove that every register and measurement function works.
For a classic Arduino Uno R3, SDA is A4 and SCL is A5. Some newer boards expose dedicated SDA/SCL pins as well. Confirm the pinout of your board revision. Never assume a breakout's VCC pin accepts 5 V.
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin(); // Uno R3: SDA=A4, SCL=A5
Serial.println("I2C scanner");
}
void loop() {
byte found = 0;
for (byte address = 1; address < 127; address++) {
Wire.beginTransmission(address);
byte error = Wire.endTransmission();
if (error == 0) {
Serial.print("Found device at 0x");
if (address < 16) Serial.print("0");
Serial.println(address, HEX);
found++;
}
}
Serial.print("Devices found: ");
Serial.println(found);
delay(3000);
}Upload, open Serial Monitor at 9600 baud and note the addresses. The scan may miss devices that are unpowered, held in reset, using a different bus or not responding in the expected way.
Before connecting: check the breakout pin labels, supply range, logic voltage, pull-up arrangement and exact sensor datasheet. If the breakout pulls SDA/SCL up to 5 V, do not connect it to a 3.3 V-only controller unless the board is explicitly designed for that arrangement.
Many digital temperature, humidity and inertial sensors return calibrated digital measurements over I²C or SPI. The example below uses an Adafruit-compatible BME280 breakout and library. It is an example implementation, not a claim that every BME280 board has identical pin labels, voltage regulation or pull-ups.
Install the sensor library and its required bus/sensor dependency using the Arduino Library Manager. Confirm the I²C address from the board documentation or scanner. Common BME280 addresses are 0x76 or 0x77, depending on the SDO/address configuration.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
Wire.begin();
if (!bme.begin(0x76)) {
Serial.println("BME280 not found. Check wiring/address.");
while (true) { delay(100); }
}
}
void loop() {
Serial.print("Temperature: ");
Serial.print(bme.readTemperature());
Serial.println(" C");
Serial.print("Pressure: ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Humidity: ");
Serial.print(bme.readHumidity());
Serial.println(" %");
delay(1000);
}If the scanner reports 0x77, change the begin address. Use the exact library version and board configuration in your build record.
For a simple hardware-UART link, connect controller A TX to controller B RX, controller A RX to controller B TX, and GND to GND. Use compatible logic levels and choose a baud rate both sketches support. On an Uno, pins 0 and 1 are also used by the USB serial interface, so a separate UART arrangement or a board with an additional hardware UART may make debugging easier.
// Controller A: transmit a short message
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("SENSOR NODE READY");
delay(1000);
}
// Controller B: receive and display
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
String message = Serial.readStringUntil('\n');
Serial.print("Received: ");
Serial.println(message);
}
}These two sketches use the USB-connected hardware serial port on an Uno for illustration. When two Unos are connected together, use SoftwareSerial on suitable pins or a different hardware UART for the inter-board link, and keep USB serial available for the Serial Monitor. Avoid connecting two TX outputs together.
The product family name is not enough to select wiring or code. Read the exact module marking and datasheet.
UART sends each character as a framed group of bits. For a common 8-N-1 format, each byte uses one start bit, eight data bits and one stop bit: ten bits per character, excluding any pauses between characters.
Estimate excludes software delays, inter-message gaps and processing time.
At 9600 baud with 8-N-1, one character occupies approximately 10/9600 seconds, or 1.04 ms. Twenty continuous characters take about 20.8 ms.
Baud rate is the signalling rate in symbols per second. In ordinary binary UART, each symbol carries one bit, so the bit rate and baud rate are numerically equal. This is not always true for more advanced modulation systems.
Check supply and ground, SDA/SCL pin mapping, swapped wires, reset state, pull-ups, logic compatibility and whether the selected bus pins match the board. Confirm the sensor is actually an I²C device.
Check the address-select pin, breakout revision and datasheet. Some libraries expect a 7-bit address, while documentation may show an address byte including the read/write bit.
Bus capacitance, cable length, pull-up value, clock speed, noise and grounding can affect signal edges. Reduce speed and wiring length, then inspect the waveform if possible.
Check baud rate, data bits, parity, stop bits, crossed TX/RX wiring, common ground and voltage levels. Ensure both ends use the same serial format.
Check chip-select polarity, SPI mode (CPOL/CPHA), clock limit, bit order, MOSI/MISO direction and the device's power-up timing.
Check for a floating input, missing pull-up/down, poor ground, switch bounce, long noisy wires or an output that is open-drain but not pulled up.
Good debugging sequence: verify power, ground and pinout first; confirm electrical compatibility second; verify the physical bus signals third; only then investigate library calls, addresses and application logic.
Record the board revision, sensor part number, supply voltage, logic levels, pin mapping, bus speed, device address, library version and measured behaviour. A wiring diagram without the module identity can be misleading.
Explore these open lessons at your own pace. For personalised explanations, project-specific troubleshooting, guided practical training or masterclasses, EazyLife offers paid support tailored to your learning goals.
Free or sponsored lesson referrals may be available through active programmes; they are not guaranteed.