Electronics, GPIO, and Sensors

Golden Rule

Raspberry Pi GPIO is powerful, but it is not rugged. Treat the pins carefully.

Safety Rules

RuleWhy it matters
GPIO is 3.3V logicMany 5V modules can damage pins
Use resistors with LEDs and buttonsPrevents overcurrent
Do not drive motors directly from GPIOUse transistor, driver board, or HAT
Share a common ground between Pi and external circuitsSignals need common reference
Double-check pin numberingBCM and board numbering are different

BCM vs Physical Pin Numbers

Numbering styleExampleBest use
BCMGPIO17, GPIO27Software and most tutorials
PhysicalPin 11, Pin 13Wiring diagrams

Pick one style mentally and stay consistent. Software examples usually use BCM numbering.

Useful Starter Components

  • LEDs and resistor pack
  • momentary push buttons
  • DHT22 or BME280 environmental sensor
  • relay module for switching low-duty loads
  • small OLED display
  • ultrasonic sensor
  • servo motor with separate power

Common Interfaces

InterfaceBest for
GPIO digital input/outputLEDs, buttons, relays
I2CSensors, OLED displays, real-time clocks
SPIFast displays, ADCs, some sensors
UARTSerial modules, GPS, microcontroller communication
1-WireTemperature probes like DS18B20

Enabling Interfaces

Use raspi-config or equivalent configuration menu when needed:

sudo raspi-config

Enable interfaces such as I2C, SPI, serial, and camera as required.

Example: Reading an I2C Sensor

A common pattern is:

  1. enable I2C
  2. install tools
  3. confirm the device appears on the bus
  4. use a Python library to read it
sudo apt install -y i2c-tools
sudo i2cdetect -y 1

If the address appears, your wiring is probably good.

Sensor Project Pattern

Most useful Pi sensor projects follow this flow:

sensor -> collection script -> local storage -> API/dashboard -> alert or action

Examples:

  • temperature sensor -> time series log -> chart -> heater/fan decision
  • motion sensor -> event trigger -> camera snapshot -> notification
  • soil moisture sensor -> threshold check -> pump relay -> schedule override

Displays and Human Interfaces

Good Display Options

DisplayGood for
Small OLEDstatus text, tiny dashboards
HDMI monitorkiosk dashboards or local desktop
Official touchscreenwall panels, appliance-style UI
E-paperultra-low-power status board

Good Input Options

  • push buttons for simple appliances
  • rotary encoder for menu control
  • touchscreen for kiosk experience
  • phone/browser UI for richer controls

Motor and Relay Caution

Motors, solenoids, pumps, and many relays can create electrical noise or draw too much current.

Use:

  • dedicated power supplies when appropriate
  • flyback protection if the board does not include it
  • driver boards or motor controllers
  • opto-isolated relay modules when switching external loads

Troubleshooting Hardware Projects

SymptomLikely cause
Sensor not detectedwrong address, wrong protocol, loose wiring
Random rebootsweak power supply or electrical noise
Servo acts strangelyunderpowered or sharing bad ground
Values look impossiblewiring mistake, wrong pull-up, bad calibration
Works once then failshot-plugging mistakes or script leaving pins in bad state

A Strong Beginner Build

Build an environmental monitor with:

  • BME280 over I2C
  • OLED status display
  • Python collection loop
  • simple web dashboard
  • optional fan or relay output

That one build teaches wiring, buses, software structure, services, and UI.

Next Step

Once you are comfortable with the hardware side, move to 06-services-web-apps-and-apis.md to make your Pi projects visible and usable over the network.