Loading

What Is Arduino?

Think about a TV remote. When you press the power button, something inside the remote sends a specific signal to your TV. Someone had to program that remote — someone wrote the instructions that say "when button A is pressed, blink this light and send this signal." Arduino lets you be that someone.

Arduino is a small computer on a board that you can program to sense the world, make decisions, and control things. Unlike your laptop which runs an operating system and hundreds of background programs, Arduino runs exactly one program — the one you write. Nothing more, nothing less. That simplicity is what makes it powerful for hardware projects.

Key Idea

Arduino is a microcontroller board — a tiny computer with no screen, no keyboard, no Windows. It runs one program at a time, reads sensors, and controls outputs like LEDs, motors, and relays. You write the program on your laptop and send it over USB.

Arduino Uno — A Quick Tour

  • Digital Pins (0–13) — can be input or output, carry 5V (HIGH) or 0V (LOW)
  • Analog Pins (A0–A5) — read variable voltages from sensors, return values 0–1023
  • Power Pins — 5V and 3.3V output, GND (ground), Vin for external power
  • USB Port — connects to your laptop to upload code and for serial communication
  • Reset Button — restarts your program from the beginning
  • ATmega328P chip — the actual microcontroller brain, 16 MHz, 32KB flash memory

Setting Up Arduino IDE

The Arduino IDE (Integrated Development Environment) is the software on your laptop where you write code and send it to the board. It is free and works on Windows, Mac, and Linux.

  1. Go to arduino.cc/en/software and download Arduino IDE 2.x for your operating system
  2. Install it — default settings are fine
  3. Plug your Arduino Uno into your laptop using a USB-B cable (the square-ish one)
  4. Open Arduino IDE → Tools → Board → Arduino AVR Boards → Arduino Uno
  5. Tools → Port → select the COM port that appeared when you plugged in (Windows usually shows COM3 or COM4)

The Blink Sketch — Hello World for Hardware

Every Arduino programmer starts here. The built-in LED on pin 13 blinks on and off. Simple? Yes. But it proves your board, cable, IDE, and drivers all work — which is everything you need before building anything real.

Arduino — Blink (fully commented)
// Everything inside setup() runs ONCE when Arduino powers on
void setup() {
  // Tell Arduino that pin 13 is an OUTPUT (we will send signals out)
  pinMode(13, OUTPUT);
}

// Everything inside loop() runs FOREVER, over and over
void loop() {
  digitalWrite(13, HIGH);  // Set pin 13 to 5V → LED turns ON
  delay(1000);             // Wait 1000 milliseconds (1 second)
  digitalWrite(13, LOW);   // Set pin 13 to 0V → LED turns OFF
  delay(1000);             // Wait 1 second
  // Loop repeats from the top — LED blinks every second
}

Click the Upload button (right arrow icon) and you should see the LED on the board start blinking. If it does — congratulations. You just programmed a computer.

Try This

Change both delay(1000) values to delay(100) and upload again. The LED now blinks 10 times per second — fast enough that it looks dim rather than blinking. Try different values and notice what happens.

Digital Pins — ON or OFF

Digital pins are the most straightforward pins on Arduino. They have exactly two states: HIGH (5V) or LOW (0V). Like a light switch — on or off, nothing in between.

Three Essential Functions

  • pinMode(pin, OUTPUT) — declare a pin as output (you send signals)
  • pinMode(pin, INPUT_PULLUP) — declare as input with internal pull-up resistor
  • digitalRead(pin) — read HIGH or LOW from an input pin
Always Use a Resistor with LEDs

A bare LED connected directly between 5V and GND will draw too much current and burn out within seconds. Always use a current-limiting resistor. For a standard LED at 5V: R = (5V - 2V) / 0.020A = 150 ohm. A 220 ohm resistor is safe for any standard LED on Arduino.

Button + LED Example

Arduino — Press button, LED turns on
// Connect: LED with 220 ohm resistor on pin 13
// Button between pin 2 and GND (INPUT_PULLUP handles the rest)

const int LED_PIN = 13;
const int BUTTON_PIN = 2;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  // INPUT_PULLUP: pin reads HIGH normally, LOW when button pressed
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  int buttonState = digitalRead(BUTTON_PIN);

  if (buttonState == LOW) {
    // Button is pressed (pulled to GND = LOW)
    digitalWrite(LED_PIN, HIGH);  // LED ON
  } else {
    // Button not pressed (pulled HIGH by internal resistor)
    digitalWrite(LED_PIN, LOW);   // LED OFF
  }
}

Analog Pins — Reading the Real World

The real world is not on/off. Temperature is 31.4 degrees, not "hot" or "cold." Light is "a bit dim," not just day or night. Analog pins let Arduino read these in-between values.

analogRead(A0) returns a number from 0 to 1023 — where 0 means 0V and 1023 means 5V. A potentiometer at halfway gives about 512.

Controlling LED Brightness with a Potentiometer

Arduino — Potentiometer controls LED brightness
// Potentiometer middle pin → A0
// Potentiometer outer pins → 5V and GND
// LED with 220 ohm resistor → pin 9 (PWM pin, marked with ~)

const int POT_PIN = A0;
const int LED_PIN = 9;  // Must be a PWM pin (~)

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);  // Open serial monitor to see values
}

void loop() {
  int potValue = analogRead(POT_PIN);  // 0 to 1023

  // map() converts from one range to another
  // potValue (0-1023) → brightness (0-255) for analogWrite
  int brightness = map(potValue, 0, 1023, 0, 255);

  analogWrite(LED_PIN, brightness);  // Set LED brightness

  Serial.print("Pot: ");
  Serial.print(potValue);
  Serial.print("  Brightness: ");
  Serial.println(brightness);

  delay(50);
}
Key Idea — PWM Pins

analogWrite() only works on PWM-capable pins — on Arduino Uno, these are pins 3, 5, 6, 9, 10, and 11. They are marked with a tilde (~) on the board. Using analogWrite() on a regular pin will not cause an error but will give unexpected results.

First Real Project: Temperature Alert System

Now let us build something that has a real use. This system reads temperature from an LM35 sensor, displays it over serial, and if the temperature goes above 35°C it turns on a buzzer and a red LED as an alert.

This is essentially what industrial temperature monitoring systems do — just at a much larger scale.

Components Needed

  • Arduino Uno
  • LM35 temperature sensor (3 pins: VCC, Output, GND)
  • Red LED + 220 ohm resistor
  • Piezo buzzer (active buzzer — the kind that beeps when you apply power)
  • Breadboard and jumper wires

Wiring

  • LM35 VCC → Arduino 5V
  • LM35 GND → Arduino GND
  • LM35 Output (middle pin) → Arduino A0
  • Red LED (with 220 ohm resistor in series) → Arduino pin 13
  • Buzzer positive → Arduino pin 8, buzzer negative → GND
Arduino — Temperature Alert System (complete working code)
// LM35 Temperature Alert System
// LM35 output: 10mV per degree Celsius
// At 25°C → 250mV, at 35°C → 350mV

const int TEMP_PIN = A0;
const int LED_PIN = 13;
const int BUZZER_PIN = 8;
const float ALERT_TEMP = 35.0;  // Alert above 35 degrees C

void setup() {
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Temperature Alert System Started");
}

void loop() {
  // Read analog value from LM35 (0 to 1023)
  int rawValue = analogRead(TEMP_PIN);

  // Convert to voltage: Arduino reference is 5V, 10-bit ADC
  // voltage = rawValue * (5.0 / 1023.0)
  float voltage = rawValue * (5.0 / 1023.0);

  // LM35: 10mV per degree → temperature = voltage / 0.010
  float temperature = voltage / 0.010;

  // Print to Serial Monitor (Tools → Serial Monitor in Arduino IDE)
  Serial.print("Temperature: ");
  Serial.print(temperature, 1);  // 1 decimal place
  Serial.println(" C");

  // Check if temperature exceeds alert threshold
  if (temperature > ALERT_TEMP) {
    digitalWrite(LED_PIN, HIGH);   // Red LED ON
    digitalWrite(BUZZER_PIN, HIGH); // Buzzer ON
    Serial.println("ALERT: Temperature too high!");
  } else {
    digitalWrite(LED_PIN, LOW);    // LED OFF
    digitalWrite(BUZZER_PIN, LOW); // Buzzer OFF
  }

  delay(1000);  // Check every 1 second
}

Upload this code, open the Serial Monitor (Ctrl+Shift+M) set to 9600 baud, and you will see live temperature readings. Touch the LM35 sensor with your fingers — body heat should push the reading up. Hold it long enough and the alert will trigger.

Extend It — Add an LCD Display

Add a 16x2 LCD with I2C module (just 4 wires — VCC, GND, SDA, SCL) and display the temperature live on the screen instead of only in the Serial Monitor. Search for the "LiquidCrystal_I2C" library in Arduino IDE Library Manager. This immediately makes your project presentable and demo-worthy.

← Previous
AI for Engineers
Next →
ESP32 vs Arduino