Lesson 8: Intermediate Logic and Algorithms – Circuits and Coding 101
📌 Introduction
Welcome back to Lesson 8 of Circuits and Coding 101! Today, we’re stepping into intermediate logic and algorithms.
This lesson will help you solve problems methodically and integrate more complexity into your circuits and programs.
🎯 What You’ll Learn Today
- Random numbers – Adding unpredictability to your programs
- Algorithms – How to process data and solve problems
- Multi-sensor integration – Using multiple inputs for smart outputs
- Interrupts – Making microcontrollers react instantly to external events
🎲 Random Numbers and Algorithms
Why use random numbers?
Random values are used in games, simulations, and creating unpredictable behavior in programs.
💻 Example Code:
📝 Introduction to Algorithms
What is an algorithm?
An algorithm is a set of step-by-step instructions to solve a problem.
📌 Example: Finding the Largest Number in an Array
Pseudocode:
- Start with a list of numbers.
- Assume the first number is the largest.
- Compare each number in the list to the current largest.
- If a number is larger, update the largest.
- Output the largest number.
💡 Hands-On Exercise 1: Sorting Numbers with Bubble Sort
💻 Code:
🔗 Multi-Sensor Integration and Smart Outputs
Let’s combine a temperature sensor and a light sensor to create a smart control system.
🔧 Steps for Breadboard Setup:
Circuit Diagram

- Connect a temperature sensor (e.g., LM35) to
pin A0. - Connect a photoresistor with a voltage divider to
pin A1. - Connect an RGB LED to
pins 9, 10, and 11.
💻 Code:
Hands-On Exercise 2: Interrupt-Driven Buzzer
What are interrupts?
Interrupts allow the microcontroller to respond immediately to external events.
🔧 Steps for Breadboard Setup:
Circuit Diagram

- Connect a button to
pin 2with a pull-down resistor. - Connect a passive buzzer to
pin 9.