Introduction to IoT

Unit 2: Getting Started with Arduino & Hardware

From unboxing an Arduino UNO to blinking your first LED โ€” master the hardware foundations, understand the ATMega328 microcontroller, and write your first embedded C sketch.

โฑ๏ธ Time to Complete: 6โ€“8 hours  |  ๐Ÿ’ฐ Earning Potential: โ‚น3,000โ€“โ‚น12,000/project  |  ๐Ÿ“ 30 MCQs (Bloom's Mapped)

๐Ÿ’ผ Jobs this unlocks: IoT Developer (โ‚น4โ€“8 LPA)  |  Embedded Systems Engineer (โ‚น5โ€“10 LPA)  |  Hardware Prototyper (โ‚น3โ€“6 LPA)

Section 1

Opening Hook โ€” The โ‚น500 Board That Powers a Billion-Dollar Industry

๐Ÿ”Œ How a Tiny Blue Board Changed Everything

In 2005, a group of Italian engineers at the Interaction Design Institute Ivrea created a small, inexpensive circuit board for their design students. They called it Arduino โ€” named after a local bar. That โ‚น500 board has since sold over 10 million units and sparked a global maker revolution that powers smart homes, industrial IoT, agricultural automation, and even space experiments.

In India alone, Arduino-based projects are driving Smart Agriculture (automated irrigation in Rajasthan), Smart Cities (Pune's IoT traffic management), and Healthcare (low-cost pulse oximeters built during COVID-19 by engineering students). Companies like Tata Elxsi, Wipro IoT, and Bosch India use Arduino for rapid prototyping before scaling to production hardware.

What if YOU could build this? What if you could take a โ‚น500 board, connect a few wires, write 10 lines of code, and make a physical LED blink โ€” your first step towards building real-world IoT products? That's exactly what this chapter teaches you.

๐Ÿ‡ฎ๐Ÿ‡ณ Tata Elxsi๐Ÿ‡ฎ๐Ÿ‡ณ Wipro IoT๐Ÿ‡ฎ๐Ÿ‡ณ Bosch India๐Ÿ‡ฎ๐Ÿ‡ณ L&T Smart World๐ŸŒ Arduino.cc๐Ÿ‡ฎ๐Ÿ‡ณ ISRO (experimental payloads)
Arduino UNO is the most popular microcontroller board on the planet. Over 10 million official boards have been sold, and an estimated 30+ million clones are in use worldwide. In India, you can buy a fully functional UNO clone for โ‚น350โ€“โ‚น500 on Amazon.in or Robu.in โ€” making embedded systems accessible to every engineering student.
Section 2

Learning Outcomes โ€” Bloom's Taxonomy Mapped

Bloom's LevelLearning Outcome
๐Ÿ”ต RememberList the key components of an Arduino UNO board and recall the ATMega328 specifications (32 KB Flash, 2 KB SRAM, 16 MHz)
๐Ÿ”ต UnderstandExplain how the setup() and loop() functions work together in an Arduino sketch, and describe the role of each AVR pin
๐ŸŸข ApplyWrite and upload the Blink sketch to an Arduino UNO, correctly selecting board and COM port in the IDE
๐ŸŸข AnalyzeCompare digital vs analog pins, differentiate PWM-capable pins, and trace the pin mapping between Arduino labels and ATMega328 physical pins
๐ŸŸ  EvaluateDiagnose common Arduino upload errors (COM port not found, driver issues, wrong board selected) and apply fixes
๐ŸŸ  CreateDesign and implement a multi-LED pattern sketch using digitalWrite(), analogWrite(), and timing functions
Section 3

Concept Explanation โ€” Setting Up & First Sketch

1. Setting Up the Arduino Board

Think of the Arduino UNO as a tiny, programmable computer. It doesn't have a screen or keyboard โ€” instead, it has pins that connect to LEDs, sensors, motors, and other electronic components. Your laptop talks to it through a USB cable.

๐Ÿ”Œ Connecting Your Arduino UNO

Step 1 โ€” Unbox: You'll find the Arduino UNO board, a USB Type-B cable (the same type used for printers), and sometimes a small breadboard.

Step 2 โ€” Connect via USB: Plug the USB-B end into the Arduino and the USB-A end into your laptop. The board's green ON LED should light up immediately โ€” this confirms the board is receiving power (5V via USB).

Step 3 โ€” Check Power: The Arduino UNO can be powered in three ways:

Power SourceVoltageBest For
USB Cable5V from laptopDevelopment & uploading code
DC Barrel Jack7โ€“12V external adapterStandalone projects (no laptop)
Vin Pin7โ€“12V from batteryPortable/field projects

Step 4 โ€” Observe: When freshly purchased, most Arduino boards come pre-loaded with the Blink sketch. The built-in LED (pin 13) should be blinking on and off every 1 second. If it is โ€” your board is working!

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ARDUINO UNO (Top View) โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” [USB-B] โ”‚ โ”‚ โ”‚RESET โ”‚ โ”‚ ATMega328P โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚Buttonโ”‚ โ”‚ (28-pin DIP) โ”‚ โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ IC โ”‚ โ”‚ [DC Jack] โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ—‰ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ DIGITAL PINS (D0-D13) โ”‚ โ”‚ โ”Œโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ” โ”‚ โ”‚ โ”‚0โ”‚1โ”‚2โ”‚3โ”‚4โ”‚5โ”‚6โ”‚7โ”‚8โ”‚9โ”‚10โ”‚11โ”‚12โ”‚13โ”‚ โ”‚ โ”‚ โ””โ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”ดโ”€โ”€โ”ดโ”€โ”€โ”ดโ”€โ”€โ”ดโ”€โ”€โ”˜ โ”‚ โ”‚ ~ ~ ~ ~ ~ ~ โ† PWM (~) โ”‚ โ”‚ โ”‚ โ”‚ ANALOG PINS (A0-A5) POWER โ”‚ โ”‚ โ”Œโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚A0โ”‚A1โ”‚A2โ”‚A3โ”‚A4โ”‚A5โ”‚ โ”‚5V โ”‚3.3โ”‚GNDโ”‚Vinโ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”ดโ”€โ”€โ”ดโ”€โ”€โ”ดโ”€โ”€โ”ดโ”€โ”€โ”ดโ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ [ON LED] [L LED (pin13)] [TX LED] [RX LED] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Don't have an Arduino board yet? Use the free online simulator Tinkercad Circuits (tinkercad.com). It has a virtual Arduino UNO with full simulation โ€” you can write code, connect virtual components, and test everything without buying hardware. Perfect for starting out.

2. Arduino IDE โ€” Your Programming Environment

Analogy: If the Arduino board is a car's engine, the Arduino IDE is the steering wheel and dashboard. It's where you write instructions (code), check for errors, and send the code to the board.

๐Ÿ’ป Installing & Configuring the Arduino IDE

Step 1 โ€” Download: Go to arduino.cc/en/software โ†’ Download Arduino IDE 2.x (recommended) for your OS (Windows / macOS / Linux).

Step 2 โ€” Install: Run the installer. On Windows, click "Yes" on all driver installation prompts โ€” these install the USB-to-Serial drivers that let your laptop communicate with the board.

Step 3 โ€” Open IDE: Launch Arduino IDE. You'll see a blank code editor with two default functions: setup() and loop().

Step 4 โ€” Select Board: Go to Tools โ†’ Board โ†’ Arduino AVR Boards โ†’ Arduino Uno.

Step 5 โ€” Select Port: Go to Tools โ†’ Port โ†’ Select the COM port that says "Arduino Uno" next to it (e.g., COM3 (Arduino Uno) on Windows or /dev/ttyACM0 on Linux).

Step 6 โ€” Test: Click the โœ“ (Verify) button. If no errors appear, your IDE is ready!

IDE FeatureShortcutWhat It Does
Verify (โœ“)Ctrl+RCompiles your code and checks for syntax errors โ€” does NOT upload
Upload (โ†’)Ctrl+UCompiles AND sends the code to the Arduino board via USB
Serial MonitorCtrl+Shift+MOpens a console to send/receive text data from the board
Serial PlotterCtrl+Shift+LGraphically plots numeric data from the board in real-time
Forgetting to select the correct Board AND Port is the #1 beginner error. If you see "avrdude: stk500_recv(): programmer is not responding", it almost always means the wrong COM port is selected or the USB cable is charge-only (no data wires). Always check Tools โ†’ Board and Tools โ†’ Port before uploading.

3. Preparing a Sketch โ€” setup() and loop()

In Arduino, a program is called a "sketch". Every sketch has exactly two mandatory functions:

๐Ÿ“ The Two Pillars of Every Arduino Sketch

void setup() โ€” Runs once when the board powers on or resets. Use it for one-time initialisation: setting pin modes, starting serial communication, configuring libraries.

Analogy: Like the morning routine before you start working โ€” brush teeth, get dressed, eat breakfast. You do it once, then you're ready.

void loop() โ€” Runs continuously, forever, in an infinite loop. This is where your main logic lives: read sensors, make decisions, control outputs.

Analogy: Like a security guard who checks the gate, walks the perimeter, checks the gate again โ€” on repeat, 24/7, until the power is cut.

Arduino C
// Minimal Sketch Structure

void setup() {
  // Runs ONCE at startup
  // Initialize pins, serial, etc.
}

void loop() {
  // Runs FOREVER in a loop
  // Read sensors, control LEDs, etc.
}
The Arduino language is actually C/C++ with a simplified wrapper. When you click "Upload", the Arduino IDE uses the avr-gcc compiler behind the scenes to convert your code into machine instructions (hex file) that the ATMega328 processor can understand. The setup() and loop() are called from a hidden main() function.

In software programming, the first program is always "Hello World." In hardware/embedded programming, the first program is always Blink โ€” making an LED turn ON and OFF repeatedly. It proves your board works, your IDE is configured correctly, and you can write + upload code.

๐Ÿ’ก Step-by-Step: Blink the Built-in LED (Pin 13)

Step 1: Open Arduino IDE โ†’ File โ†’ Examples โ†’ 01.Basics โ†’ Blink (or type the code below manually).

Step 2: Understand the code โ€” read every line and its comment below.

Step 3: Click Verify (โœ“) โ€” you should see "Done compiling." at the bottom.

Step 4: Click Upload (โ†’) โ€” you should see "Done uploading." The TX/RX LEDs on the board will flash rapidly during upload.

Step 5: Observe โ€” the small orange LED labelled "L" on the board (connected to pin 13) should now blink: ON for 1 second, OFF for 1 second, repeat.

Arduino C โ€” Blink Sketch
/*
 * Blink Sketch โ€” The "Hello World" of Arduino
 * Turns the built-in LED (pin 13) ON for 1 second,
 * then OFF for 1 second, repeatedly.
 *
 * No external components needed โ€” uses the onboard LED.
 */

void setup() {
  // Initialize digital pin 13 as an OUTPUT
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);   // Turn LED ON  (5V on pin 13)
  delay(1000);                // Wait 1000 ms (1 second)
  digitalWrite(13, LOW);    // Turn LED OFF (0V on pin 13)
  delay(1000);                // Wait 1000 ms (1 second)
}
FunctionWhat It DoesParameters
pinMode(pin, mode)Configures a pin as INPUT or OUTPUTpin: 0โ€“13 or A0โ€“A5; mode: INPUT, OUTPUT, INPUT_PULLUP
digitalWrite(pin, value)Sets a digital pin to HIGH (5V) or LOW (0V)pin: the pin number; value: HIGH or LOW
delay(ms)Pauses the program for a given number of millisecondsms: time in milliseconds (1000 = 1 second)
Modify the Blink sketch: Change delay(1000) to delay(200). What happens? Now try delay(50). Can you make the LED appear to be "always on" by going fast enough? (Hint: This is the principle behind PWM โ€” Pulse Width Modulation, which we'll study later.)

5. Troubleshooting โ€” When Things Go Wrong

Welcome to the real world of hardware. Things will go wrong. Here's a troubleshooting guide for the most common issues:

ProblemCauseFix
"COM port not found"Driver not installed or cable is charge-onlyInstall CH340 driver (for clones) from sparks.gogo.co.nz/ch340.html. Use a data-capable USB cable.
"avrdude: stk500_recv(): programmer is not responding"Wrong board/port selected, or board is brickedCheck Tools โ†’ Board = "Arduino Uno". Check Tools โ†’ Port. Try pressing Reset button on board right before upload.
"Board at COM3 is not available"USB cable disconnected or port in use by another appReconnect USB. Close Serial Monitor/Plotter in another IDE window. Close PuTTY/Tera Term.
LED doesn't blinkCode has errors, or wrong pin numberVerify code compiles. Ensure you're using pin 13 (or LED_BUILTIN constant).
"Access denied" on COM portPort locked by another applicationOn Linux: add user to dialout group. On Windows: check Device Manager for conflicts.
Board not detected at allDefective board or USB port issueTry a different USB port. Try a different USB cable. Test on another computer.
The #1 rule of hardware debugging: "Is it plugged in?" 90% of Arduino issues are physical โ€” loose USB cable, wrong cable type (charge-only vs data), dead USB port, or a dirty connection. Always check the physical layer first before blaming the code.
Chinese clone boards (CH340/CH341 chip) need a separate driver. Official Arduino boards use an FTDI or ATMega16U2 for USB communication. But most cheap clones from Amazon India use a CH340G chip. If your board shows up as an "Unknown Device" in Device Manager, you need to manually install the CH340 driver. This trips up 80% of beginners in India who buy clone boards.
Section 4

Concept Explanation โ€” Architecture & Internals

6. Arduino UNO Architecture โ€” Block Diagram

The Arduino UNO is more than just a microcontroller. It's a complete development board with voltage regulation, USB communication, clock oscillator, and pin headers โ€” all designed so you can focus on programming without worrying about circuit design.

๐Ÿ—๏ธ Arduino UNO Block Diagram

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ARDUINO UNO BLOCK DIAGRAM โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ USB-B โ”‚โ”€โ”€โ”€โ”€โ”€โ†’โ”‚ USB-to-Serialโ”‚โ”€โ”€โ”€โ”€โ”€โ†’โ”‚ ATMega328P โ”‚ โ”‚ โ”‚ โ”‚ Connectorโ”‚ โ”‚ (ATMega16U2 โ”‚ TX/RXโ”‚ (Main MCU) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ or CH340) โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ 32KB โ”‚ โ”‚ โ”‚ โ”‚ โ–ผ โ”‚ โ”‚ Flash โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚ โ”‚ โ”‚ 5V โ”‚โ”€โ”€โ”€โ”€โ”€โ†’โ”‚ Voltage โ”‚โ”€โ”€โ”€โ”€โ”€โ†’โ”‚ โ”‚ 2KB โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ from USB โ”‚ โ”‚ Regulator โ”‚ VCC โ”‚ โ”‚ SRAM โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ (AMS1117) โ”‚ โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ 1KB โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ EEPROM โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ DC Jack โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ (7-12V) โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ 16 MHz โ”‚โ”€โ”€โ”€โ”€โ”€โ†’โ”‚ XTAL1/XTAL2โ”‚ โ”‚ โ”‚ โ”‚ Crystal โ”‚ CLK โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ Oscillator โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ–ผ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ GPIO PIN HEADERS โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚ โ”‚ Digital I/O โ”‚ Analog Input โ”‚ Power Pins โ”‚ โ”‚ โ”‚ โ”‚ D0โ€“D13 โ”‚ A0โ€“A5 โ”‚ 5V, 3.3V, โ”‚ โ”‚ โ”‚ โ”‚ (6 PWM ~) โ”‚ (10-bit ADC)โ”‚ GND, Vin โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ RESET โ”‚ โ”‚ ON LED โ”‚ โ”‚ TX/RX LEDโ”‚ โ”‚ L LED โ”‚ โ”‚ โ”‚ โ”‚ Button โ”‚ โ”‚ (Power) โ”‚ โ”‚(Data I/O)โ”‚ โ”‚(Pin 13) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
ComponentPart NumberFunction
Main MCUATMega328PRuns your Arduino sketch; contains Flash, SRAM, EEPROM, ADC, timers
USB-to-SerialATMega16U2 (official) / CH340G (clone)Converts USB signals to Serial (UART) for communication with the MCU
Voltage RegulatorAMS1117 (5V & 3.3V)Steps down input voltage (7โ€“12V from DC jack) to stable 5V/3.3V for the MCU
Crystal Oscillator16 MHz ceramic resonatorProvides the clock signal โ€” the "heartbeat" that synchronises all operations
Reset ButtonTactile switchRestarts the MCU โ€” re-runs setup() then loop()

7. AVR ATMega328P โ€” The Brain of Arduino UNO

The ATMega328P is an 8-bit AVR microcontroller made by Microchip (formerly Atmel). It's the chip that actually executes your code. Understanding its pin layout is essential for advanced projects.

๐Ÿง  ATMega328P โ€” Key Specifications

SpecificationValueWhat It Means
Architecture8-bit AVR (RISC)Simple, fast instruction set; one instruction per clock cycle
Clock Speed16 MHzExecutes 16 million instructions per second
Flash Memory32 KB (0.5 KB bootloader)Stores your program (sketch). Non-volatile โ€” survives power off
SRAM2 KBWorking memory for variables during execution. Volatile โ€” lost on power off
EEPROM1 KBNon-volatile storage for settings/data that persist across resets
Digital I/O Pins23 (14 on Arduino headers)Can be set as INPUT or OUTPUT; read/write digital HIGH/LOW
Analog Input Channels6 (A0โ€“A5)10-bit ADC: converts analog voltage (0โ€“5V) to digital value (0โ€“1023)
PWM Channels6 (pins 3, 5, 6, 9, 10, 11)Simulates analog output using rapid ON/OFF switching
Operating Voltage5VLogic HIGH = 5V, Logic LOW = 0V
Package28-pin DIPThrough-hole package; easy to replace if damaged

ATMega328P โ€” 28-Pin DIP Diagram

ATMega328P-PU (28-Pin DIP) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ””โ”€โ”€โ”˜ โ”‚ (RESET) PC6 1โ”‚โ— 28โ”‚PC5 (A5 / SCL) (RXD) PD0 2โ”‚ 27โ”‚PC4 (A4 / SDA) (TXD) PD1 3โ”‚ 26โ”‚PC3 (A3) (INT0) PD2 4โ”‚ 25โ”‚PC2 (A2) (INT1) PD3 5โ”‚ ATMega328P 24โ”‚PC1 (A1) (T0) PD4 6โ”‚ 23โ”‚PC0 (A0) VCC 7โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” 22โ”‚GND GND 8โ”‚ โ”‚ โ”‚ 21โ”‚AREF (XTAL1) PB6 9โ”‚ โ”‚ AVR โ”‚ 20โ”‚AVCC (XTAL2) PB7 10โ”‚ โ”‚ โ”‚ 19โ”‚PB5 (D13 / SCK) (T1) PD5 11โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 18โ”‚PB4 (D12 / MISO) (AIN0) PD6 12โ”‚ 17โ”‚PB3 (D11~ / MOSI) (AIN1) PD7 13โ”‚ 16โ”‚PB2 (D10~) (ICP) PB0 14โ”‚ 15โ”‚PB1 (D9~) โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Pin 1 marker: โ— (notch/dot on physical IC) ~ indicates PWM-capable pin
The ATMega328P on Arduino UNO is in a removable DIP socket. If you accidentally burn the chip (rare but possible with wrong wiring), you can buy a replacement ATMega328P with bootloader pre-loaded for โ‚น150โ€“โ‚น200 and simply swap it. No soldering needed.

8. Pin Mapping โ€” Arduino โ†” AVR ATMega328

Arduino uses simplified pin names (D0, D1, A0, etc.) that map to specific physical pins on the ATMega328P chip. Understanding this mapping is crucial when you read datasheets or design custom PCBs.

Digital Pins (D0โ€“D13)

Arduino PinATMega328 PinPort/BitPWM?Special Function
D0Pin 2PD0โŒRX (Serial Receive)
D1Pin 3PD1โŒTX (Serial Transmit)
D2Pin 4PD2โŒINT0 (External Interrupt 0)
D3Pin 5PD3โœ… ~INT1 (External Interrupt 1)
D4Pin 6PD4โŒT0 (Timer 0 external)
D5Pin 11PD5โœ… ~T1 (Timer 1 external)
D6Pin 12PD6โœ… ~AIN0 (Analog Comparator +)
D7Pin 13PD7โŒAIN1 (Analog Comparator โˆ’)
D8Pin 14PB0โŒICP1 (Input Capture)
D9Pin 15PB1โœ… ~OC1A (Timer 1 output)
D10Pin 16PB2โœ… ~SS (SPI Slave Select)
D11Pin 17PB3โœ… ~MOSI (SPI Master Out)
D12Pin 18PB4โŒMISO (SPI Master In)
D13Pin 19PB5โŒSCK (SPI Clock) + Built-in LED

Analog Pins (A0โ€“A5)

Arduino PinATMega328 PinPort/BitADC ChannelSpecial Function
A0Pin 23PC0ADC0โ€”
A1Pin 24PC1ADC1โ€”
A2Pin 25PC2ADC2โ€”
A3Pin 26PC3ADC3โ€”
A4Pin 27PC4ADC4SDA (I2C Data)
A5Pin 28PC5ADC5SCL (I2C Clock)
Analog pins A0โ€“A5 can also be used as digital pins! You can call pinMode(A0, OUTPUT) and digitalWrite(A0, HIGH) on them. This gives you up to 20 digital I/O pins total (D0โ€“D13 + A0โ€“A5). This is documented but often overlooked by beginners.

PWM Pins Summary

PWM (Pulse Width Modulation) pins are marked with a tilde (~) on the Arduino board. They can simulate analog output by rapidly switching between HIGH and LOW.

PWM PinTimer UsedFrequencyNotes
D3, D11Timer 2 (8-bit)~490 HzShared timer โ€” changing one affects the other
D5, D6Timer 0 (8-bit)~980 Hzโš ๏ธ Also used by delay() and millis()
D9, D10Timer 1 (16-bit)~490 HzBest for precise timing and Servo control

9. Data Types & Essential Functions

Arduino uses C/C++ data types. Here are the most important ones you'll use in IoT projects:

Core Data Types

TypeSizeRangeUse Case
int2 bytesโˆ’32,768 to 32,767Pin numbers, counters, sensor values
unsigned int2 bytes0 to 65,535Only positive values; larger range
long4 bytesโˆ’2,147,483,648 to 2,147,483,647Large numbers, millis() return type
float4 bytesยฑ3.4ร—10ยณโธ (6โ€“7 decimal digits)Temperature readings, voltage calculations
char1 byteโˆ’128 to 127 (or ASCII character)Single characters, serial data
bool / boolean1 bytetrue (1) or false (0)Flags, ON/OFF states
byte1 byte0 to 255Raw data, register values
StringVariableDynamic character arrayText messages, LCD display strings

Essential Arduino Functions

FunctionCategorySyntaxDescription
pinMode()Digital I/OpinMode(pin, mode)Set pin as INPUT, OUTPUT, or INPUT_PULLUP
digitalWrite()Digital I/OdigitalWrite(pin, val)Write HIGH (5V) or LOW (0V) to a pin
digitalRead()Digital I/OdigitalRead(pin)Returns HIGH or LOW โ€” reads button/switch state
analogRead()Analog I/OanalogRead(pin)Returns 0โ€“1023 (10-bit ADC) from analog pin
analogWrite()Analog I/OanalogWrite(pin, val)PWM output: val = 0โ€“255 (0% to 100% duty cycle)
delay()Timingdelay(ms)Pause execution for ms milliseconds
millis()Timingmillis()Returns ms since board started โ€” non-blocking timing
Serial.begin()CommunicationSerial.begin(baud)Start serial at given baud rate (usually 9600)
Serial.println()CommunicationSerial.println(data)Send data to Serial Monitor with newline
map()Mathmap(val,fromL,fromH,toL,toH)Re-maps a number from one range to another
Arduino C โ€” Reading a Sensor
// Example: Read a temperature sensor on A0 and print to Serial Monitor

int sensorPin = A0;       // Analog pin connected to sensor
int sensorValue = 0;      // Variable to store the reading
float voltage = 0.0;      // Converted voltage value
float temperatureC = 0.0; // Temperature in Celsius

void setup() {
  Serial.begin(9600);     // Start serial communication at 9600 baud
}

void loop() {
  sensorValue = analogRead(sensorPin);       // Read analog value (0-1023)
  voltage = sensorValue * (5.0 / 1023.0);     // Convert to voltage (0-5V)
  temperatureC = voltage * 100.0;             // LM35: 10mV per ยฐC

  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" ยฐC");

  delay(1000);  // Read every 1 second
}
Using float on Arduino is slow and memory-heavy. The ATMega328 has no hardware floating-point unit (FPU), so every float operation is done in software โ€” using ~10ร— more clock cycles than int operations. For IoT projects where speed matters, use integer math and fixed-point arithmetic. Only use float when you need decimal precision (like temperature calculations).
Use millis() instead of delay() for real IoT projects. delay() blocks the entire program โ€” nothing else can run during the wait. millis() lets you check elapsed time without blocking, so your code can multitask (read sensors AND control LEDs simultaneously). This is called non-blocking programming โ€” essential for IoT.
Section 5

Learn by Doing โ€” 3-Tier Lab Structure

๐ŸŸข Tier 1 โ€” GUIDED TASK: Blink an External LED on a Breadboard

โฑ๏ธ 30โ€“45 minutesBeginnerZero prior knowledge assumed

Components Needed:

  • Arduino UNO + USB cable
  • 1ร— Red LED
  • 1ร— 220ฮฉ resistor (Red-Red-Brown-Gold)
  • Breadboard + 2 jumper wires

Step 1: Identify LED Polarity

An LED has two legs: the longer leg is the Anode (+) and the shorter leg is the Cathode (โˆ’). Current flows from Anode to Cathode.

Step 2: Build the Circuit

  1. Insert the LED into the breadboard
  2. Connect a 220ฮฉ resistor from the Anode (long leg) to Arduino pin 8 using a jumper wire
  3. Connect the Cathode (short leg) to Arduino GND using a jumper wire

Step 3: Write the Code

Arduino C
int ledPin = 8;  // External LED connected to pin 8

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
}

Step 4: Upload & Observe

Upload the code. Your external LED should blink ON/OFF every 0.5 seconds.

๐ŸŽ‰ Congratulations! You've built your first real hardware circuit. This is the foundation of every IoT project.

๐ŸŸก Tier 2 โ€” SEMI-GUIDED: Traffic Light Simulation (3 LEDs)

โฑ๏ธ 45โ€“60 minutesIntermediateHints provided, you fill the gaps

Your Mission:

Build a traffic light using 3 LEDs (Red, Yellow, Green) that cycles through the standard traffic sequence.

Hints:

  1. Connections: Red LED โ†’ pin 4, Yellow LED โ†’ pin 3, Green LED โ†’ pin 2. Each with a 220ฮฉ resistor to GND.
  2. Sequence: Green ON for 5 sec โ†’ Yellow ON for 2 sec โ†’ Red ON for 5 sec โ†’ repeat.
  3. Key functions: pinMode(), digitalWrite(), delay().
  4. Remember: Turn OFF the previous LED before turning ON the next one.
Stretch Goal: Add a pedestrian button (push button on pin 7 with INPUT_PULLUP). When pressed, the traffic light should go Red immediately for 10 seconds to let pedestrians cross. Use digitalRead().

๐Ÿ”ด Tier 3 โ€” OPEN CHALLENGE: Smart Night Light with LDR Sensor

โฑ๏ธ 1โ€“2 hoursAdvancedNo instructions โ€” real-world mini-project

The Brief:

Build a smart night light that automatically turns ON an LED when it gets dark and turns it OFF when there's enough light. This mimics real-world street lighting IoT systems.

  1. Use an LDR (Light Dependent Resistor) connected to analog pin A0
  2. Use a voltage divider circuit with a 10Kฮฉ resistor
  3. Read the LDR value using analogRead()
  4. Set a threshold (experiment to find the right value)
  5. Turn ON an LED when the reading is below the threshold (dark)
  6. Print the sensor value to Serial Monitor for debugging
  7. Bonus: Use analogWrite() to make the LED brightness proportional to darkness (PWM dimming)
This exact project โ€” automated lighting with LDR โ€” is a real IoT product. Companies sell "smart dusk-to-dawn" switches for โ‚น500โ€“โ‚น2,000. You just built the prototype for โ‚น100 in components. Students in India have won hackathons and Smart India Hackathon (SIH) with enhanced versions of this project.
Section 6

Industry Spotlight โ€” A Day in the Life

๐Ÿ‘จโ€๐Ÿ’ป Rahul Verma, 24 โ€” IoT Prototyping Engineer at Tata Elxsi, Bangalore

Background: B.Tech ECE from NIT Bhopal. Built Arduino projects since 2nd year. Won Smart India Hackathon 2024 with an IoT-based water quality monitoring system. Got placed at Tata Elxsi through campus recruitment.

A Typical Day:

9:00 AM โ€” Team standup. Review progress on a smart agriculture PoC (Proof of Concept) for a government project in Maharashtra.

10:00 AM โ€” Test soil moisture sensor integration with Arduino Mega. Calibrate readings against lab-grade moisture meter. Document threshold values.

11:30 AM โ€” Write firmware in Arduino IDE. Implement non-blocking sensor reading using millis(). Add Wi-Fi data transmission via ESP32 module.

1:00 PM โ€” Lunch. Discuss with the cloud team about AWS IoT Core integration for the sensor data pipeline.

2:00 PM โ€” Debug a relay switching circuit. The motor pump isn't activating when soil is dry. Issue: GPIO pin set to INPUT instead of OUTPUT. Classic!

4:00 PM โ€” Prepare a demo for the client โ€” show real-time sensor data on a Grafana dashboard. Arduino โ†’ ESP32 โ†’ MQTT โ†’ AWS โ†’ Grafana.

5:30 PM โ€” Learning hour: studying STM32 microcontrollers for production-grade designs (the next step beyond Arduino prototyping).

DetailInfo
Tools Used DailyArduino IDE, VS Code + PlatformIO, Multimeter, Logic Analyser, AWS IoT Core
Entry Salary (2024)โ‚น5โ€“8 LPA + benefits
Mid-Level (3โ€“5 yrs)โ‚น10โ€“18 LPA
Senior (7+ yrs)โ‚น20โ€“40 LPA
Companies HiringTata Elxsi, Wipro IoT, Bosch India, L&T Smart World, Continental, Samsung R&D, Qualcomm India, Honeywell
Section 7

Earn With It โ€” Freelance & Income Roadmap

๐Ÿ’ฐ Your Earning Path After This Chapter

Portfolio Piece: "Arduino-Based Smart Night Light with LDR" โ€” a working hardware project with code on GitHub, circuit diagram, and a demo video.

Beginner Gig Ideas:

โ€ข Arduino-based attendance system for schools/colleges โ€” โ‚น3,000โ€“โ‚น8,000

โ€ข Smart plant watering system for homes/offices โ€” โ‚น2,000โ€“โ‚น5,000

โ€ข LED display projects for local shops โ€” โ‚น2,000โ€“โ‚น6,000

โ€ข IoT prototype for B.Tech/M.Tech final year projects โ€” โ‚น3,000โ€“โ‚น10,000

PlatformBest ForTypical Rate
Freelancer.comArduino/IoT prototype projects$50โ€“$300/project (โ‚น4,000โ€“โ‚น25,000)
FiverrQuick Arduino code/circuit gigs$20โ€“$100/gig (โ‚น1,600โ€“โ‚น8,000)
InternshalaIndian student internships in IoT/embeddedโ‚น5,000โ€“โ‚น15,000/month
College ProjectsFinal year project help for other studentsโ‚น3,000โ€“โ‚น12,000/project
Local ShopsAutomation projects for small businessesโ‚น5,000โ€“โ‚น20,000/project

โฑ๏ธ Time to First Earning: 3โ€“4 weeks (complete all labs, build one portfolio project, list on Fiverr/Freelancer)

Your unfair advantage in India: Most engineering students study Arduino only in theory for exams. If you can show a working project with a demo video and GitHub code, you're in the top 5% of students. Companies and freelance clients care about demonstrable skills, not marks. Build. Document. Share.
Section 8

MCQ Assessment Bank โ€” 30 Questions (Bloom's Mapped)

Remember / Identify (Q1โ€“Q6)

Q1

What microcontroller chip is used on the Arduino UNO board?

  1. ATMega2560
  2. ATMega328P
  3. ESP8266
  4. STM32F103
Remember
โœ… Answer: (B) ATMega328P โ€” The Arduino UNO uses the ATMega328P, an 8-bit AVR microcontroller running at 16 MHz with 32 KB Flash memory.
Q2

How much Flash memory does the ATMega328P have?

  1. 8 KB
  2. 16 KB
  3. 32 KB
  4. 64 KB
Remember
โœ… Answer: (C) 32 KB โ€” The ATMega328P has 32 KB of Flash (program memory), of which 0.5 KB is used by the bootloader, leaving 31.5 KB for your sketch.
Q3

What is the clock speed of the Arduino UNO?

  1. 8 MHz
  2. 12 MHz
  3. 16 MHz
  4. 20 MHz
Remember
โœ… Answer: (C) 16 MHz โ€” The Arduino UNO uses a 16 MHz crystal oscillator, executing approximately 16 million instructions per second.
Q4

How much SRAM does the ATMega328P have?

  1. 512 bytes
  2. 1 KB
  3. 2 KB
  4. 4 KB
Remember
โœ… Answer: (C) 2 KB โ€” SRAM (Static RAM) is the working memory for variables during program execution. It is volatile and lost when power is removed.
Q5

Which function in an Arduino sketch runs only once at startup?

  1. loop()
  2. main()
  3. setup()
  4. init()
Remember
โœ… Answer: (C) setup() โ€” The setup() function runs once when the board powers on or is reset. It's used for one-time initialisation like pinMode() and Serial.begin().
Q6

Which pin on the Arduino UNO has a built-in LED?

  1. Pin 0
  2. Pin 7
  3. Pin 11
  4. Pin 13
Remember
โœ… Answer: (D) Pin 13 โ€” The built-in LED (labelled "L" on the board) is connected to digital pin 13 (PB5 on the ATMega328P). It can also be referenced using the constant LED_BUILTIN.

Understand / Explain (Q7โ€“Q12)

Q7

What is the purpose of the pinMode() function?

  1. Sets the voltage level of a pin
  2. Configures a pin as INPUT or OUTPUT
  3. Reads the analog value on a pin
  4. Starts serial communication
Understand
โœ… Answer: (B) โ€” pinMode(pin, mode) configures whether a pin will be used to read inputs (INPUT) or drive outputs (OUTPUT). This must be done in setup() before using digitalRead() or digitalWrite().
Q8

Why does analogRead() return values between 0 and 1023?

  1. Because the ADC has 8-bit resolution
  2. Because the ADC has 10-bit resolution (2ยนโฐ = 1024 levels)
  3. Because the maximum voltage is 10.23V
  4. Because there are 1023 analog pins
Understand
โœ… Answer: (B) โ€” The ATMega328P has a 10-bit ADC (Analog-to-Digital Converter). 2ยนโฐ = 1024, so it maps 0Vโ€“5V to values 0โ€“1023. Each step represents approximately 4.88 mV.
Q9

What does the delay(1000) function call do?

  1. Delays for 1 microsecond
  2. Delays for 100 milliseconds
  3. Delays for 1000 milliseconds (1 second)
  4. Delays for 1000 seconds
Understand
โœ… Answer: (C) โ€” delay() takes milliseconds as its argument. 1000 ms = 1 second. During this time, the processor is blocked and cannot execute other code.
Q10

What is the role of the USB-to-Serial converter (ATMega16U2 or CH340) on the Arduino UNO?

  1. It runs the user's sketch code
  2. It converts USB signals to UART serial for communication with the main MCU
  3. It regulates voltage from 12V to 5V
  4. It stores the bootloader firmware
Understand
โœ… Answer: (B) โ€” The USB-to-Serial chip translates USB protocol from your laptop into UART serial (TX/RX) signals that the ATMega328P can understand. This enables code uploading and Serial Monitor communication.
Q11

Why is a 220ฮฉ resistor used in series with an LED connected to an Arduino pin?

  1. To increase the LED brightness
  2. To limit current and prevent the LED from burning out
  3. To convert analog signal to digital
  4. To filter noise from the power supply
Understand
โœ… Answer: (B) โ€” An LED without a current-limiting resistor would draw too much current from the Arduino pin (max 40 mA per pin), potentially damaging both the LED and the microcontroller. A 220ฮฉ resistor limits the current to approximately 14 mA at 5V (safe for most LEDs).
Q12

What happens if you upload code with the wrong board selected in the Arduino IDE?

  1. The code uploads successfully but runs slower
  2. The IDE automatically detects the correct board
  3. The upload may fail with "programmer not responding" or produce unpredictable behavior
  4. Nothing happens โ€” the board ignores incorrect code
Understand
โœ… Answer: (C) โ€” Selecting the wrong board causes the IDE to use incorrect upload settings (baud rate, protocol, memory layout), leading to upload failures or, in rare cases, code that compiles for a different architecture and behaves unpredictably.

Apply / Implement (Q13โ€“Q18)

Q13

To make an LED on pin 9 fade smoothly, which function should you use?

  1. digitalWrite(9, 128)
  2. analogWrite(9, 128)
  3. analogRead(9)
  4. digitalRead(9)
Apply
โœ… Answer: (B) โ€” analogWrite(pin, value) generates a PWM signal. Pin 9 is PWM-capable (~). A value of 128 gives a 50% duty cycle, making the LED glow at half brightness. digitalWrite() only accepts HIGH/LOW, not intermediate values.
Q14

What is the correct way to read a push button connected to pin 7 with an internal pull-up resistor?

  1. pinMode(7, OUTPUT); int val = digitalRead(7);
  2. pinMode(7, INPUT_PULLUP); int val = digitalRead(7);
  3. pinMode(7, INPUT); int val = analogRead(7);
  4. analogWrite(7, HIGH);
Apply
โœ… Answer: (B) โ€” INPUT_PULLUP enables the ATMega328's internal pull-up resistor (~20Kฮฉ to VCC). The pin reads HIGH when the button is open and LOW when pressed. This eliminates the need for an external pull-up resistor.
Q15

To convert an analogRead() value (0โ€“1023) to voltage (0.0โ€“5.0V), which formula is correct?

  1. voltage = analogRead(A0) * 1023.0 / 5.0;
  2. voltage = analogRead(A0) * 5.0 / 1023.0;
  3. voltage = analogRead(A0) / 5.0;
  4. voltage = analogRead(A0) + 5.0;
Apply
โœ… Answer: (B) โ€” The formula value * (5.0 / 1023.0) maps the 10-bit ADC range (0โ€“1023) to the voltage range (0Vโ€“5V). Each ADC unit = 5.0/1023 โ‰ˆ 0.00488V.
Q16

You want to send sensor data from Arduino to a computer. What should be in setup()?

  1. Serial.println(9600);
  2. Serial.begin(9600);
  3. Serial.read();
  4. Serial.write(9600);
Apply
โœ… Answer: (B) โ€” Serial.begin(9600) initialises serial communication at 9600 baud (bits per second). This must be called in setup() before using Serial.print(), Serial.println(), or Serial.read().
Q17

Which of these pins can be used for PWM output on the Arduino UNO?

  1. Pins 2, 4, 7, 8
  2. Pins 3, 5, 6, 9, 10, 11
  3. Pins A0, A1, A2, A3
  4. All digital pins (0โ€“13)
Apply
โœ… Answer: (B) โ€” Only 6 pins support PWM on the UNO: 3, 5, 6, 9, 10, and 11 (marked with ~ on the board). These use Timer 0, Timer 1, and Timer 2 hardware to generate the PWM signal.
Q18

What value does digitalRead() return when a button connected with INPUT_PULLUP is pressed?

  1. HIGH
  2. LOW
  3. 1023
  4. 255
Apply
โœ… Answer: (B) LOW โ€” With INPUT_PULLUP, the pin is pulled HIGH by default (via internal resistor). When the button is pressed, it connects the pin to GND, making it read LOW. This is called "active LOW" logic.

Analyze / Compare (Q19โ€“Q23)

Q19

What is the key difference between delay() and millis() for timing?

  1. delay() is more accurate than millis()
  2. delay() blocks execution; millis() allows non-blocking timing
  3. millis() can only measure up to 1 second
  4. They are functionally identical
Analyze
โœ… Answer: (B) โ€” delay() halts the entire program for the specified duration. millis() returns the time elapsed since board startup, allowing you to check time without blocking โ€” enabling multitasking in IoT applications.
Q20

Comparing digitalWrite() and analogWrite(): which statement is correct?

  1. digitalWrite() outputs 0โ€“255 levels; analogWrite() outputs HIGH/LOW only
  2. digitalWrite() outputs only HIGH (5V) or LOW (0V); analogWrite() outputs 0โ€“255 duty cycle levels via PWM
  3. Both functions work on all 20 pins of the UNO
  4. analogWrite() reads sensor values; digitalWrite() sends data
Analyze
โœ… Answer: (B) โ€” digitalWrite() is binary (ON/OFF). analogWrite() uses PWM to simulate analog output with 256 brightness/speed levels (0 = always OFF, 255 = always ON). analogWrite() only works on PWM pins (~).
Q21

Why do PWM pins 5 and 6 on Arduino UNO run at ~980 Hz while others run at ~490 Hz?

  1. They use a faster crystal oscillator
  2. They share Timer 0, which has a different prescaler setting because it's also used by delay() and millis()
  3. They have dedicated hardware for higher frequency
  4. It's a manufacturing defect
Analyze
โœ… Answer: (B) โ€” Timer 0 (used by pins 5 and 6) has a prescaler of 64 by default, set by the Arduino core library to support delay() and millis(). This results in a ~980 Hz PWM frequency, while Timer 1 and Timer 2 (other PWM pins) use a prescaler giving ~490 Hz.
Q22

An Arduino UNO is connected to a laptop via USB but the COM port doesn't appear. Which factor is LEAST likely to cause this?

  1. The USB cable is charge-only (no data wires)
  2. The CH340 driver is not installed (for clone boards)
  3. The Arduino sketch has a syntax error
  4. The USB port on the laptop is malfunctioning
Analyze
โœ… Answer: (C) โ€” Syntax errors in your sketch do not affect COM port detection. The COM port is a hardware/driver-level connection. A charge-only cable, missing drivers, or a dead USB port are all valid hardware causes for COM port issues.
Q23

What is the advantage of using the LED_BUILTIN constant instead of the number 13?

  1. LED_BUILTIN makes the LED brighter
  2. LED_BUILTIN is portable โ€” it maps to the correct pin on any Arduino board, not just UNO
  3. LED_BUILTIN enables PWM on pin 13
  4. There is no difference; they are always the same
Analyze
โœ… Answer: (B) โ€” LED_BUILTIN is a board-specific constant defined in the Arduino core. On UNO it's 13, but on other boards (e.g., Arduino Mega, Leonardo) the built-in LED may be on a different pin. Using the constant makes your code portable.

Evaluate / Judge (Q24โ€“Q27)

Q24

A student's LED blinks correctly on Tinkercad simulator but doesn't work on the real Arduino UNO. What is the MOST likely cause?

  1. The simulator uses different code syntax
  2. A hardware issue: incorrect wiring, missing resistor, or wrong pin connection
  3. The ATMega328P chip is incompatible with LED circuits
  4. Tinkercad uses a different programming language
Evaluate
โœ… Answer: (B) โ€” If the code works in simulation, the logic is correct. Real-world issues are almost always hardware: reversed LED polarity, loose connections, wrong pin number, missing GND connection, or a charge-only USB cable.
Q25

A project needs to read 8 analog sensors simultaneously. Is the Arduino UNO suitable?

  1. Yes โ€” it has 8 analog pins
  2. No โ€” it only has 6 analog input pins (A0โ€“A5), so you'd need a multiplexer or a different board
  3. Yes โ€” you can use digital pins for analog reading
  4. No โ€” Arduino cannot read analog sensors at all
Evaluate
โœ… Answer: (B) โ€” The UNO has exactly 6 analog inputs (A0โ€“A5). For 8 sensors, you need an analog multiplexer (CD4051), or upgrade to Arduino Mega (16 analog pins). Note: "simultaneously" isn't truly possible anyway โ€” the single ADC reads pins sequentially.
Q26

Evaluate this code: int x = 40000; โ€” What problem will this cause on Arduino UNO?

  1. No problem โ€” int can store 40000
  2. Integer overflow โ€” int on AVR is 16-bit (max 32,767), so 40000 will wrap around to a negative value
  3. Compilation error โ€” 40000 is not a valid number
  4. The program will crash immediately
Evaluate
โœ… Answer: (B) โ€” On Arduino UNO (AVR), int is 16-bit (range: โˆ’32,768 to 32,767). The value 40,000 exceeds this range and wraps around due to two's complement overflow, storing โˆ’25,536. Use unsigned int (0โ€“65,535) or long instead.
Q27

A student uses delay(60000) to wait 1 minute between sensor readings. Why is this a poor design choice for an IoT system?

  1. delay() cannot accept values larger than 10000
  2. The entire MCU is blocked for 60 seconds โ€” it cannot respond to button presses, sensor alerts, or incoming serial data during that time
  3. It will drain the battery faster
  4. delay() is not accurate enough for 60 seconds
Evaluate
โœ… Answer: (B) โ€” delay() is a blocking function. During 60 seconds of delay, the Arduino cannot read sensors, respond to button interrupts, or process serial commands. IoT systems need responsiveness. Use millis()-based timing for non-blocking waits.

Create / Design (Q28โ€“Q30)

Q28

You need to design a circuit where an LED's brightness varies with a potentiometer. Which combination of functions is correct?

  1. digitalRead() on potentiometer pin + digitalWrite() on LED pin
  2. analogRead() on potentiometer pin + analogWrite() on LED pin (with value mapped from 0โ€“1023 to 0โ€“255)
  3. analogRead() on both pins
  4. Serial.read() on potentiometer pin + Serial.write() on LED pin
Create
โœ… Answer: (B) โ€” Read the potentiometer (analog input) with analogRead() (returns 0โ€“1023), then use map(val, 0, 1023, 0, 255) to scale the value, and analogWrite() to control LED brightness via PWM. The LED must be on a PWM pin (~).
Q29

To build an Arduino-based temperature alarm that buzzes when temperature exceeds 40ยฐC, which sensor + output combination is most appropriate?

  1. Push button (digital input) + LED (digital output)
  2. LM35 temperature sensor (analog input on A0) + Piezo buzzer (digital output on pin 8)
  3. Potentiometer (analog input) + Servo motor (PWM output)
  4. Photoresistor (analog input) + Relay (digital output)
Create
โœ… Answer: (B) โ€” The LM35 outputs 10 mV per ยฐC (linear), read via analogRead(). Convert to temperature using temp = (analogRead(A0) * 5.0 / 1023.0) * 100. If temp > 40, activate the buzzer using digitalWrite(8, HIGH).
Q30

You want to create a data logger that records temperature every 5 seconds and stores 1000 readings. Where should the data be stored on Arduino UNO?

  1. Flash memory (32 KB) โ€” it has enough space
  2. SRAM (2 KB) โ€” use an array of 1000 floats
  3. EEPROM (1 KB) โ€” write each reading with EEPROM.write()
  4. External SD card module โ€” 1000 float values (4 KB) exceed EEPROM capacity, and SRAM can't persist data
Create
โœ… Answer: (D) โ€” 1000 float values = 4000 bytes, exceeding EEPROM (1 KB) and most of SRAM (2 KB). Flash memory is for program storage, not runtime data. An SD card module provides virtually unlimited storage and data can be read on a computer later. This is the standard approach for IoT data loggers.
Section 9

Short Answer Questions (8 Questions)

๐Ÿ“ Q1: Explain the difference between setup() and loop() in an Arduino sketch. (3 marks)

Answer:

setup() is called once when the Arduino is powered on or reset. It is used for one-time initialisation tasks such as setting pin modes (pinMode()), starting serial communication (Serial.begin()), and initialising libraries or variables.

loop() is called repeatedly after setup() finishes. It runs continuously in an infinite loop for the entire runtime of the program. All main logic โ€” reading sensors, controlling outputs, making decisions โ€” goes here.

Analogy: setup() is like setting up a shop before opening (arranging shelves, switching on lights). loop() is like running the shop all day โ€” serving customers, restocking, until you close.

๐Ÿ“ Q2: List the three power supply options for the Arduino UNO and state the voltage range for each. (3 marks)

Answer:

1. USB Cable: Provides 5V directly from the laptop/computer. Best for development and code uploading.

2. DC Barrel Jack: Accepts 7โ€“12V from an external DC adapter. The onboard voltage regulator (AMS1117) steps it down to 5V. Best for standalone projects without a laptop.

3. Vin Pin: Accepts 7โ€“12V from an external battery or power source connected directly to the Vin header pin. The voltage regulator handles the conversion. Best for portable or field-deployed projects.

Note: Input below 7V may cause unstable operation. Input above 12V may overheat the voltage regulator.

๐Ÿ“ Q3: What is the function of the CH340 chip found on Arduino UNO clones? Why do clones require a separate driver? (3 marks)

Answer:

The CH340 (or CH341) is a USB-to-Serial converter chip used on low-cost Arduino clone boards. It converts USB signals from the computer into UART serial signals (TX/RX) that the ATMega328P microcontroller can understand. This enables code uploading and Serial Monitor communication.

Official Arduino boards use an ATMega16U2 or FTDI chip for this purpose, whose drivers come pre-installed with Windows and macOS. However, the CH340 is a third-party Chinese chip that is not included in the standard OS driver packages, so users must manually download and install the CH340 driver from the manufacturer's website. Without this driver, the board appears as "Unknown Device" in Device Manager and no COM port is assigned.

๐Ÿ“ Q4: What is PWM? Name all PWM-capable pins on the Arduino UNO. (3 marks)

Answer:

PWM (Pulse Width Modulation) is a technique that simulates analog output using digital pins. The pin rapidly switches between HIGH (5V) and LOW (0V) at a fixed frequency. The ratio of ON-time to total cycle time is called the duty cycle.

  • 0% duty cycle (value 0) = always OFF = 0V average
  • 50% duty cycle (value 128) = ON half the time = ~2.5V average
  • 100% duty cycle (value 255) = always ON = 5V average

PWM-capable pins on Arduino UNO: 3, 5, 6, 9, 10, 11 โ€” marked with a tilde (~) on the board.

Use cases: LED dimming, motor speed control, servo positioning, audio tone generation.

๐Ÿ“ Q5: Describe the three types of memory in the ATMega328P and state their sizes. (4 marks)

Answer:

Memory TypeSizeVolatile?Purpose
Flash32 KBNon-volatileStores the compiled sketch (program code). Survives power cycles. 0.5 KB reserved for bootloader.
SRAM2 KBVolatileWorking memory for variables, arrays, stack, and heap during program execution. Data is lost when power is removed.
EEPROM1 KBNon-volatileLong-term storage for settings and calibration data that must persist across power cycles. Limited write cycles (~100,000).

Analogy: Flash = a textbook (stores instructions permanently). SRAM = a whiteboard (used during class, erased after). EEPROM = a locker (stores personal items that persist even when you leave the room).

๐Ÿ“ Q6: What is the role of the 16 MHz crystal oscillator on the Arduino UNO? (2 marks)

Answer:

The 16 MHz crystal oscillator provides the clock signal โ€” the precise timing reference that synchronises all operations inside the ATMega328P. It generates 16 million pulses per second, and each pulse triggers the execution of one instruction.

Without the crystal, the microcontroller would have no sense of timing โ€” it wouldn't know when to execute the next instruction, how long a delay() should last, or at what speed to send serial data. The crystal is essentially the "heartbeat" of the processor.

๐Ÿ“ Q7: Explain the difference between analogRead() and analogWrite(). Can they be used on the same pins? (3 marks)

Answer:

analogRead(pin) reads an analog voltage (0โ€“5V) from an analog input pin (A0โ€“A5) and converts it to a digital value (0โ€“1023) using the built-in 10-bit ADC. Used for reading sensors like temperature, light, and potentiometers.

analogWrite(pin, value) generates a PWM output signal on specific digital pins (3, 5, 6, 9, 10, 11) with a duty cycle from 0 (0%) to 255 (100%). Used for controlling LED brightness and motor speed.

They cannot be used on the same pins. analogRead() only works on A0โ€“A5 (analog input pins). analogWrite() only works on PWM-capable digital pins (3, 5, 6, 9, 10, 11). Despite the similar names, they are entirely different operations โ€” one reads an analog value, the other generates a PWM digital output.

๐Ÿ“ Q8: A student connects an LED directly to pin 13 and GND without a resistor. What could happen and why? (3 marks)

Answer:

Without a current-limiting resistor, the LED would attempt to draw excessive current from the Arduino pin. Each GPIO pin can supply a maximum of 40 mA (absolute max), and the recommended operating current is 20 mA.

Possible consequences:

  • The LED may burn out โ€” its maximum forward current (typically 20 mA) will be exceeded
  • The GPIO pin on the ATMega328P could be damaged due to overcurrent
  • In severe cases, the entire microcontroller could be permanently damaged

Note: Pin 13 on the Arduino UNO has a built-in resistor (1 Kฮฉ) connected to the onboard LED, which provides some protection. However, this is specific to pin 13 only โ€” all other pins require an external resistor (typically 220ฮฉโ€“330ฮฉ).

Formula: R = (V_supply โˆ’ V_LED) / I_LED = (5V โˆ’ 2V) / 0.015A = 200ฮฉ โ†’ use 220ฮฉ (standard value).

Section 10

Long Answer Questions (3 Questions)

๐Ÿ“– Q1: Describe the complete architecture of the Arduino UNO board. Explain the role of each major component with a block diagram. (10 marks)

Answer:

The Arduino UNO is an open-source microcontroller development board based on the ATMega328P. It provides a complete development environment with power management, USB communication, clock generation, and accessible I/O pins.

Major Components & Their Roles:

1. ATMega328P (Main Microcontroller): The brain of the Arduino UNO. An 8-bit AVR RISC microcontroller running at 16 MHz. Contains 32 KB Flash (program storage), 2 KB SRAM (runtime variables), 1 KB EEPROM (persistent data), a 10-bit ADC (6 channels), 3 timers, SPI, I2C, and UART interfaces. It executes the setup() and loop() functions that constitute your sketch.

2. USB-to-Serial Converter (ATMega16U2 / CH340G): Acts as a bridge between the USB port on your laptop and the UART serial interface (pins 0/TX and 1/RX) on the ATMega328P. Enables code uploading from the Arduino IDE and two-way serial communication via Serial Monitor. Official boards use ATMega16U2; clones typically use CH340G (requires separate driver installation).

3. Voltage Regulators (AMS1117): Two regulators provide stable 5V and 3.3V outputs from the 7โ€“12V DC jack input. The 5V line powers the ATMega328P and digital I/O. The 3.3V line is available on a header pin for 3.3V peripherals (e.g., some sensors and modules). When powered via USB, the 5V comes directly from the USB bus.

4. 16 MHz Crystal Oscillator: Provides the precise clock signal for the ATMega328P. Every instruction execution, timer tick, ADC conversion, and serial baud rate calculation depends on this 16 MHz reference. Connected to XTAL1 and XTAL2 pins of the MCU.

5. Digital I/O Pins (D0โ€“D13): 14 digital pins that can be configured as INPUT or OUTPUT using pinMode(). 6 of these (3, 5, 6, 9, 10, 11) support PWM output. Pins D0 and D1 double as hardware serial (TX/RX). Pins D2 and D3 support external hardware interrupts (INT0, INT1).

6. Analog Input Pins (A0โ€“A5): 6 analog input channels connected to the 10-bit ADC. Convert analog voltages (0โ€“5V) to digital values (0โ€“1023). Pins A4 and A5 double as I2C bus (SDA/SCL). All analog pins can also be used as digital I/O if needed.

7. Power Pins: Include 5V output, 3.3V output, GND (3 pins), Vin (raw input voltage), and IOREF. The RESET pin can be used to externally reset the board.

8. Status LEDs: ON LED (power indicator), L LED (connected to pin 13), TX LED (blinks during data transmission), RX LED (blinks during data reception).

9. Reset Button: Pulls the RESET pin of the ATMega328P low, restarting the program from setup(). Useful during debugging or when the program hangs.

10. ICSP Header: 6-pin header for In-Circuit Serial Programming. Used to program the ATMega328P directly (bypassing the bootloader) using an external programmer. Also used to reflash the ATMega16U2 firmware.

๐Ÿ“– Q2: Explain the complete pin mapping between Arduino UNO labels (D0โ€“D13, A0โ€“A5) and the ATMega328P physical pins. Include port registers, PWM capabilities, and special functions. (10 marks)

Answer:

The Arduino UNO simplifies pin naming by using labels like D0, D1, A0, etc. However, internally, these map to specific physical pins on the 28-pin ATMega328P DIP package. Each pin belongs to one of three 8-bit I/O ports: Port B (PB0โ€“PB5), Port C (PC0โ€“PC5), and Port D (PD0โ€“PD7).

Digital Pins Mapping:

ArduinoATMega PinPortPWMSpecial Function
D0Pin 2PD0โ€”Hardware Serial RX
D1Pin 3PD1โ€”Hardware Serial TX
D2Pin 4PD2โ€”External Interrupt INT0
D3Pin 5PD3~External Interrupt INT1, Timer2 OC2B
D4Pin 6PD4โ€”Timer0 external T0
D5Pin 11PD5~Timer0 OC0B
D6Pin 12PD6~Timer0 OC0A
D7Pin 13PD7โ€”โ€”
D8Pin 14PB0โ€”Timer1 Input Capture ICP1
D9Pin 15PB1~Timer1 OC1A
D10Pin 16PB2~SPI Slave Select (SS)
D11Pin 17PB3~SPI MOSI, Timer2 OC2A
D12Pin 18PB4โ€”SPI MISO
D13Pin 19PB5โ€”SPI SCK, Built-in LED

Analog Pins Mapping:

ArduinoATMega PinPortADC ChannelSpecial Function
A0Pin 23PC0ADC0Also usable as Digital I/O
A1Pin 24PC1ADC1Also usable as Digital I/O
A2Pin 25PC2ADC2Also usable as Digital I/O
A3Pin 26PC3ADC3Also usable as Digital I/O
A4Pin 27PC4ADC4I2C SDA (Data line)
A5Pin 28PC5ADC5I2C SCL (Clock line)

Port Register Architecture:

Each port has three 8-bit registers:

  • DDRx (Data Direction Register) โ€” Sets each bit as INPUT (0) or OUTPUT (1). Equivalent to pinMode().
  • PORTx (Output Register) โ€” Sets the output value. Writing 1 = HIGH, 0 = LOW. Equivalent to digitalWrite().
  • PINx (Input Register) โ€” Reads the current pin state. Equivalent to digitalRead().

Direct port manipulation (PORTD |= B00100000;) is approximately 50ร— faster than digitalWrite() because it bypasses the Arduino library's pin lookup and safety checks. This is critical in time-sensitive IoT applications like driving LED matrices or reading high-speed sensors.

PWM Capabilities:

The 6 PWM pins are driven by 3 hardware timers:

  • Timer 0 (8-bit): Drives pins 5 and 6 at ~980 Hz. Also used by delay() and millis().
  • Timer 1 (16-bit): Drives pins 9 and 10 at ~490 Hz. Best for precise timing applications.
  • Timer 2 (8-bit): Drives pins 3 and 11 at ~490 Hz. Used by the tone() function.

๐Ÿ“– Q3: Design a complete Arduino project: "Smart Temperature Monitor with Alert System." Provide the circuit description, complete code, and explain each section. (10 marks)

Answer:

Project Overview:

Build a temperature monitoring system that reads an LM35 temperature sensor, displays the temperature on Serial Monitor, and activates a buzzer + red LED when temperature exceeds a threshold (e.g., 35ยฐC). A green LED stays ON when temperature is normal.

Components Required:

  • Arduino UNO + USB cable
  • LM35 temperature sensor
  • 1ร— Red LED + 220ฮฉ resistor
  • 1ร— Green LED + 220ฮฉ resistor
  • 1ร— Piezo buzzer
  • Breadboard + jumper wires

Circuit Connections:

ComponentPin Connection
LM35 VccArduino 5V
LM35 OutputArduino A0
LM35 GNDArduino GND
Green LED (Anode)Pin 3 via 220ฮฉ resistor
Red LED (Anode)Pin 5 via 220ฮฉ resistor
Buzzer (+)Pin 8
All GNDsArduino GND (common ground)

Complete Code:

Arduino C โ€” Smart Temperature Monitor
/*
 * Smart Temperature Monitor with Alert System
 * Reads LM35 sensor, displays temp on Serial Monitor.
 * Green LED = normal. Red LED + Buzzer = overheat alert.
 */

// Pin definitions
const int sensorPin  = A0;   // LM35 output connected to A0
const int greenLED   = 3;    // Green LED on pin 3 (PWM)
const int redLED     = 5;    // Red LED on pin 5 (PWM)
const int buzzerPin  = 8;    // Buzzer on pin 8

// Configuration
const float THRESHOLD = 35.0;  // Alert temperature in ยฐC

// Variables
int   sensorValue  = 0;
float voltage      = 0.0;
float temperatureC = 0.0;

void setup() {
  // Configure pin modes
  pinMode(greenLED,  OUTPUT);
  pinMode(redLED,    OUTPUT);
  pinMode(buzzerPin, OUTPUT);

  // Start serial communication
  Serial.begin(9600);
  Serial.println("=== Smart Temperature Monitor ===");
  Serial.print("Alert Threshold: ");
  Serial.print(THRESHOLD);
  Serial.println(" ยฐC");
  Serial.println("--------------------------------");
}

void loop() {
  // Step 1: Read sensor
  sensorValue = analogRead(sensorPin);

  // Step 2: Convert to voltage (0-5V)
  voltage = sensorValue * (5.0 / 1023.0);

  // Step 3: Convert to temperature (LM35: 10mV per ยฐC)
  temperatureC = voltage * 100.0;

  // Step 4: Display on Serial Monitor
  Serial.print("Temp: ");
  Serial.print(temperatureC, 1);  // 1 decimal place
  Serial.print(" ยฐC  |  ADC: ");
  Serial.print(sensorValue);

  // Step 5: Check threshold and activate alerts
  if (temperatureC >= THRESHOLD) {
    // ALERT MODE: Red LED ON, Green OFF, Buzzer ON
    digitalWrite(redLED,    HIGH);
    digitalWrite(greenLED,  LOW);
    digitalWrite(buzzerPin, HIGH);
    Serial.println("  โš ๏ธ ALERT! OVERHEAT!");
  } else {
    // NORMAL MODE: Green LED ON, Red OFF, Buzzer OFF
    digitalWrite(greenLED,  HIGH);
    digitalWrite(redLED,    LOW);
    digitalWrite(buzzerPin, LOW);
    Serial.println("  โœ… Normal");
  }

  // Step 6: Wait before next reading
  delay(2000);  // Read every 2 seconds
}

Code Explanation:

1. Pin Definitions: Using const int makes pin assignments readable and easy to change. Storing pin numbers in constants is best practice โ€” avoids "magic numbers" in code.

2. setup(): Configures all output pins and starts serial at 9600 baud. Prints a header to Serial Monitor so the user knows the system is running and what the threshold is.

3. ADC Reading: analogRead(A0) returns 0โ€“1023. The formula value ร— (5.0 / 1023.0) converts this to voltage (0โ€“5V).

4. Temperature Conversion: The LM35 outputs 10 mV per ยฐC. So voltage ร— 100 gives temperature in Celsius. At 25ยฐC, the LM35 outputs 250 mV (0.25V), and analogRead() returns approximately 51.

5. Decision Logic: A simple if-else compares the temperature against the threshold. In alert mode, the red LED and buzzer activate. In normal mode, only the green LED is on.

6. Timing: delay(2000) ensures the sensor is read every 2 seconds. For production use, this should be replaced with millis()-based non-blocking timing.

Expected Serial Monitor Output:

=== Smart Temperature Monitor === Alert Threshold: 35.0 ยฐC -------------------------------- Temp: 28.3 ยฐC | ADC: 58 โœ… Normal Temp: 29.1 ยฐC | ADC: 60 โœ… Normal Temp: 36.2 ยฐC | ADC: 74 โš ๏ธ ALERT! OVERHEAT! Temp: 35.8 ยฐC | ADC: 73 โš ๏ธ ALERT! OVERHEAT! Temp: 34.1 ยฐC | ADC: 70 โœ… Normal
Section 11

Chapter Summary

๐Ÿ”‘ Key Takeaways from Unit 2

โœ… The Arduino UNO is a development board based on the ATMega328P microcontroller (8-bit, 16 MHz, 32 KB Flash, 2 KB SRAM, 1 KB EEPROM).

โœ… Every Arduino sketch has two mandatory functions: setup() (runs once) and loop() (runs forever).

โœ… The Blink sketch is the "Hello World" of hardware โ€” uses pinMode(), digitalWrite(), and delay().

โœ… The UNO has 14 digital pins (D0โ€“D13), 6 analog pins (A0โ€“A5), and 6 PWM pins (3, 5, 6, 9, 10, 11).

โœ… analogRead() converts 0โ€“5V to 0โ€“1023 (10-bit ADC). analogWrite() outputs PWM 0โ€“255 on ~ pins.

โœ… Common issues: wrong COM port, charge-only USB cables, missing CH340 drivers (for clone boards).

โœ… The ATMega328P has 28 pins in DIP package, with Port B, C, and D registers for I/O.

โœ… Use millis() for non-blocking timing in real IoT projects instead of delay().

โœ… Arduino-based IoT prototyping is a marketable skill โ€” freelance projects range from โ‚น3,000โ€“โ‚น20,000.

Section 12

Earning Checkpoint โ€” Skills Audit

Skill LearnedTool / PlatformPortfolio OutputEarning Ready?
Arduino Board SetupArduino IDE + USBโ€”โฌœ Foundation skill โ€” not billable alone
Blink SketchArduino IDEFirst working sketchโฌœ Foundation โ€” proves you can program hardware
Digital I/O (LED + Button)Arduino + breadboardTraffic Light Simulationโœ… Yes โ€” can build LED displays for shops
Analog Sensor ReadingLM35 + LDR + ArduinoSmart Night Lightโœ… Yes โ€” IoT monitoring prototypes
Serial CommunicationSerial Monitor + ArduinoTemperature data loggerโœ… Yes โ€” sensor data visualization
ATMega328 ArchitectureConceptualโ€”โœ… Yes โ€” interview ready (embedded roles)
Pin Mapping & PWMConceptual + hands-onLED fade / motor controlโœ… Yes โ€” custom circuit design projects
TroubleshootingArduino IDE + driversDebug documentationโœ… Yes โ€” technical support gigs
Minimum Viable Earning Setup after this chapter: A working Arduino project (with code on GitHub + a demo video) + a Fiverr/Freelancer profile with "Arduino IoT Prototyping" gig = you can earn โ‚น3,000โ€“โ‚น12,000/project while still in college. 80% of engineering students in India have never built a real hardware project โ€” you're already ahead.
Section 13

What's Next โ€” Unit 3 Preview

๐Ÿš€ Coming Up in Unit 3: Sensors, Actuators & IoT Communication

Now that you can set up an Arduino and write basic sketches, Unit 3 dives deeper into the IoT ecosystem:

  • Sensors: Temperature (DHT11/22), Ultrasonic (HC-SR04), PIR Motion, Gas (MQ-2), Soil Moisture
  • Actuators: Servo motors, DC motors with L298N driver, Relay modules
  • Communication: Wi-Fi with ESP8266/ESP32, Bluetooth with HC-05, MQTT protocol
  • Cloud Integration: Sending sensor data to ThingSpeak, Blynk, and AWS IoT Core
  • Real Projects: Smart Home automation, Weather Station, Intruder Detection System

Prerequisite: Complete all 3 labs in this chapter and have a working Blink + External LED circuit before moving on.

โœ… Unit 2 complete. Ready for Unit 3: Sensors, Actuators & IoT Communication!

[QR: Link to EduArtha video tutorial โ€” Arduino Setup & Hardware Basics]