9

Lesson 9: Digital Inputs/Outputs and LEDs

Learn to control LEDs and read buttons for robot interaction

Learning Objectives

Knowledge Goals:

  • Understanding digital HIGH/LOW signals
  • pinMode() and digitalWrite() functions
  • Button reading with pull-up resistors

Skill Goals:

  • Building circuits on breadboards
  • Input/output programming
  • Hardware debugging skills

Lesson Content

1 Digital Outputs and LEDs (20 minutes)

Digital Output Basics:

  • • pinMode() sets pin as INPUT or OUTPUT
  • • digitalWrite() sets pin HIGH (5V) or LOW (0V)
  • • LEDs need current-limiting resistors
  • • Perfect for robot status indicators
// Basic LED control
int ledPin = 13;  // Built-in LED on pin 13

void setup() {
    pinMode(ledPin, OUTPUT);  // Set as output
    Serial.begin(9600);
    Serial.println("🤖 LED Control System Ready!");
}

void loop() {
    digitalWrite(ledPin, HIGH);  // Turn LED on
    Serial.println("💡 LED ON");
    delay(1000);
    
    digitalWrite(ledPin, LOW);   // Turn LED off
    Serial.println("⚫ LED OFF");
    delay(1000);
}

2 Digital Inputs and Buttons (20 minutes)

Button Input Basics:

  • • digitalRead() reads HIGH or LOW from pins
  • • INPUT_PULLUP enables internal pull-up resistor
  • • Button pressed = LOW, released = HIGH (with pull-up)
  • • Essential for robot user interfaces

3 Breadboard and Circuit Building (15 minutes)

Breadboard Basics:

  • • Solderless prototyping platform for testing circuits
  • • Horizontal rows are connected internally
  • • Power rails run vertically on the sides
  • • Use jumper wires to make connections
  • • Perfect for robot control circuits

Safety and Best Practices:

  • • Always disconnect power when building circuits
  • • Use appropriate resistor values for LEDs (220Ω-1kΩ)
  • • Keep wires organized and neat
  • • Double-check connections before powering on
  • • Test one component at a time

Assessment & Homework

Quick Check (In Class):

  • • Can student build circuits on breadboard?
  • • Do they understand digital I/O programming?
  • • Can they combine inputs and outputs effectively?

Homework Assignment:

LED Control System

Create a simple LED control system using buttons. Include multiple LEDs with different patterns and user control options.

← Previous: Lesson 8
📝 Take Lesson 9 Quiz Next: Lesson 10 →