IoT Arduino Basics

Arduino is an open-source electronics platform that makes microcontroller projects approachable. A small board, a free programming tool, and a huge community let beginners build a working device within an hour.

What Is on an Arduino Board

 ┌───────────────────────────────────────┐
 │ USB port      [Microcontroller chip]  │
 │ (power +                              │
 │  upload)      Digital pins 0-13       │
 │               Analog pins A0-A5       │
 │ Power pins: 3.3V  5V  GND             │
 └───────────────────────────────────────┘

Main Parts

  • Microcontroller: Runs your program.
  • Digital pins: Read or send on/off signals.
  • Analog pins: Read varying voltages from sensors.
  • USB port: Powers the board and uploads programs.
  • Power pins: Supply voltage to sensors and modules.

The Arduino Program Structure

Arduino programs are called sketches. Every sketch contains two functions that the board runs automatically.

setup()

The board runs setup() once at power-on. Use it to prepare pins and start communication.

loop()

The board runs loop() again and again forever. Place the main logic here, such as reading a sensor and switching an LED.

Your First Sketch: Blinking an LED

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

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

The code turns the built-in light on for one second and off for one second. The delay() function pauses the program for the given number of milliseconds.

The Upload Workflow

Write sketch ──► Verify (compile) ──► Connect USB ──► Upload ──► Board runs it
  1. Install the Arduino IDE on your computer.
  2. Connect the board with a USB cable.
  3. Select the board model and port in the tools menu.
  4. Paste the sketch and press Upload.
  5. Watch the LED blink.

Making It an IoT Device

A basic Arduino Uno has no built-in internet. Developers add connectivity in two ways:

  • Attach a Wi-Fi shield or an ESP8266 module.
  • Choose a connected board such as the Arduino Nano ESP32 or MKR WiFi 1010.

With Wi-Fi in place, the sketch reads a sensor and publishes the value to a cloud service every minute.

Pin Modes Explained

ModePurposeExample
INPUTRead a signalPush button
OUTPUTSend a signalLED or buzzer
INPUT_PULLUPRead with a built-in resistorDoor switch

Safe Practice Tips

  • Use a resistor with every external LED to protect the light and the pin.
  • Disconnect power before changing wires.
  • Respect the voltage limit of each pin and sensor.
  • Save each experiment as a separate sketch.

Ideas for Beginner Projects

  • Night lamp that glows when a light sensor reads darkness
  • Plant monitor that blinks when soil dries out
  • Distance meter that shows centimeters on a small screen

Reading a Sensor with Arduino

A potentiometer, which is a turn knob, makes a simple practice sensor. Connect the middle pin to analog pin A0 and the outer pins to 5V and GND. The code below reads the knob position as a number between 0 and 1023 and prints it to the screen on your computer.

void setup() {
  Serial.begin(9600);
}

void loop() {
  int value = analogRead(A0);
  Serial.println(value);
  delay(500);
}

Open the Serial Monitor in the IDE and turn the knob. The numbers rise and fall in step with your hand. The same pattern works for light sensors, temperature sensors, and moisture probes, so this tiny program forms the base of countless projects.

Common Beginner Errors

  • Selecting the wrong board or port stops the upload.
  • Forgetting a semicolon at the end of a line causes a compile error.
  • Mixing up pin numbers between the code and the wiring leaves the project silent.

Key Takeaway

Arduino turns electronics into a hands-on hobby. Master setup(), loop(), and pin modes, and you hold the foundation for every connected device that follows.