Lesson 7: Input/Output & Hardware Integration – Sensors, Motors, and LEDs

Lesson 7: Input/Output and Hardware Integration – Circuits and Coding 101


📌 Introduction

Welcome back to Lesson 7 of Circuits and Coding 101! Today, we’re diving into input/output (I/O) and hardware integration.


We’ll explore how to connect and control various components using your microcontroller.


🎯 What You’ll Learn Today

  • Digital and Analog I/O – Working with LEDs, buttons, and sensors
  • PWM (Pulse Width Modulation) – Advanced output control
  • Hardware Integration – Controlling motors and using transistors
  • Hands-on exercises – RGB LEDs, potentiometers, and motors


🔌 Digital Input/Output

What is Digital I/O?

Digital I/O interacts with components like LEDs, buttons, and switches using simple HIGH (1) and LOW (0) signals.


📌 Key Functions:


💡 Hands-On Exercise 1: Controlling an RGB LED

🔧 Steps for Breadboard Setup

Circuit Diagram

  • Connect the RGB LED to pins 9, 10, and 11 through 220Ω resistors.
  • Connect the common cathode (or anode) to GND (or VCC).

💻 Code:

📊 Analog Input/Output

What is Analog I/O?

Analog I/O allows you to work with a range of values instead of just HIGH and LOW.


📌 Key Functions:

💡 Hands-On Exercise 2: Adjusting LED Brightness with a Potentiometer


🔧 Steps for Breadboard Setup:

Circuit Diagram

  • Connect the potentiometer to pin A05V, and GND.
  • Connect an LED to pin 9 through a resistor.

💻 Code:

⚡ PWM (Pulse Width Modulation)

What is PWM?

PWM allows us to simulate an analog output by rapidly switching a digital pin on and off.


💡 Hands-On Exercise 3: Motor Speed Control with PWM

🔧 Steps for Breadboard Setup:

Circuit Diagram

  1. Connect the motor to a transistor (e.g., NPN) with:
  2. Collector → Motor
  3. Emitter → GND
  4. Base → pin 9 via a 1kΩ resistor


💻 Code:

✅ Wrap-Up & Next Steps

What You Learned Today:

  • How to use digital and analog I/O.
  • How to control LEDs, motors, and sensors using PWM.
  • Built projects for real-world hardware integration.

🎉 Great job! Next, we’ll explore advanced components like keypads and rotary encoders.

🔔 See you next time, and happy coding!