Lesson 6: Debugging & Troubleshooting – Fixing Code and Circuits

Lesson 6: Debugging and Troubleshooting – Circuits and Coding 101


📌 Introduction

Welcome back to Lesson 6 of Circuits and Coding 101! Today, we’re focusing on a critical skill: debugging and troubleshooting.


Every programmer encounters errors, but learning how to identify and fix them will make you unstoppable.


🎯 What You’ll Learn Today

  1. Common programming errors and how to fix them
  2. Debugging techniques using the Serial Monitor
  3. Using libraries to simplify your code
  4. Hands-on exercises – Debugging a 7-segment display and using an OLED screen


🐞 What is Debugging?

Definition: Debugging is the process of finding and fixing errors in your code or circuits.


Why is it important?

  • Mistakes happen—it’s part of learning!
  • Debugging allows us to pinpoint which portions of code or circuitry that is causing errors.
  • Debugging improves problem-solving and critical thinking skills.


📌 Types of Errors:

  • Syntax Errors: Typos or missing characters in code.
  • Logic Errors: The program runs but doesn’t behave as expected.
  • Hardware Errors: Miswiring or faulty components.


🛠️ Systematic Debugging

✔️ Steps to Debug Effectively:

  • Break your code or circuit into smaller parts and test each separately.
  • Use the Serial Monitor to observe what’s happening in your code.
  • Check your wiring carefully and double-check connections.
  • Simplify - Remove unnecessary code or components to isolate the issue.


📚 What Are Libraries?

Definition: Libraries are collections of pre-written code that simplify using specific components.


Why use libraries?

They save time by handling complex tasks for you.

For example, the Adafruit_SSD1306 library makes working with OLED displays easy.


📌 How to Add Libraries in Arduino IDE:

Using the Library Manager:

  1. Go to Sketch > Include Library > Manage Libraries.
  2. Search for the library you need (e.g., Adafruit SSD1306) and click Install.

Using a ZIP File:

  1. Download the library ZIP file.
  2. Go to Sketch > Include Library > Add .ZIP Library and select the file.


💡 Hands-On Exercise 1: Debugging a 7-Segment Display

🔧 Steps for Breadboard Setup:

  1. Connect the 4-digit 7-segment display to your Arduino.
  2. Wire the module according to the datasheet.


💻 Code:


🖥️ Hands-On Exercise 2: Using an OLED for Debugging


🔧 Steps for Breadboard Setup:

Connect the OLED display:

  1. GND → Arduino GND
  2. VCC → Arduino 5V or 3.3V
  3. SCK → Arduino SCL (A5)
  4. SDA → Arduino SDA (A4)

Circuit Diagram