Arduino Basics

A beginner-friendly electronics lab for learning wiring, coding, sensors, and real-world problem solving. Students learn how power moves through a circuit and how code turns inputs into outputs.

Big Idea

What Is Arduino?

Arduino is a small programmable board. You connect electronic parts to its pins, write code on a computer, upload the code through USB, and the board follows your instructions.

In a normal coding lesson, students see results on a screen. In Arduino lessons, they see a light blink, a sensor react, a buzzer beep, or a motor move. That makes coding easier to understand because the result is physical.

Basic Wiring Knowledge

Power

Power usually comes from the Arduino 5V pin or 3.3V pin. Many beginner parts need 5V, but some sensors require 3.3V.

Ground

GND completes the circuit. If a project has no common ground, the code may be correct but the part still will not work.

Signal

Signal wires carry information. A button may send HIGH or LOW. A sensor may send a changing value to an analog pin.

Breadboard

A breadboard lets students connect parts without soldering. Holes in the same connected row share electricity.

Resistors

Resistors limit current. LEDs usually need a resistor, such as 220 ohms, so the LED and Arduino pin are protected.

Dupont Wires

Use jumper wires to connect Arduino pins to the breadboard. A helpful habit is red for power, black for ground, and yellow or blue for signal.

Wiring habit: always trace the path out loud. Power goes to the part, the signal pin controls or reads the part, and ground completes the path.

LED Wiring Example

An LED has two legs. The longer leg is usually positive. The shorter leg goes to ground. A resistor should be placed in series with the LED.

Arduino Uno D8 GND Breadboard 220Ω LED
  1. Arduino D8 connects to a 220 ohm resistor.
  2. The resistor connects to the long leg of the LED.
  3. The short leg of the LED connects to GND.
  4. The code sends HIGH to D8 to turn the LED on and LOW to turn it off.

Arduino Coding — Basic Knowledge Checklist

Program Structure

setup() runs once when Arduino starts. loop() runs again and again. Braces group code, and semicolons end commands.

Comments

Use // for one comment line and /* ... */ for multiple lines. Comments explain thinking without changing the program.

Variables

int stores whole numbers, float stores decimals, bool stores true or false, and const protects values that should not change.

Digital Pins

pinMode() sets a pin as INPUT, OUTPUT, or INPUT_PULLUP. digitalWrite() sends HIGH or LOW.

Analog Input

analogRead(A0) reads changing sensor values. On Arduino Uno, the value is usually from 0 to 1023.

PWM Output

analogWrite() creates analog-style output for LED brightness or motor speed. On Uno, PWM values are 0 to 255.

Operators

Math uses + - * / %. Comparisons use == != > < >= <=. Remember: = assigns, while == compares.

If Decisions

if, else if, and else let Arduino choose an action based on a sensor value or button state.

Loops

for and while repeat code. They are useful for LED patterns, counting, and repeated checks.

Functions

Functions put repeated jobs into reusable pieces, such as turnOnLight() or beepAlarm().

Timing

delay(1000) waits one second. Later, millis() helps Arduino keep time while still doing other work.

Serial Monitor

Serial.begin(), Serial.print(), and Serial.println() help students see what the board is reading.

Reading Sensors

Digital sensors use digitalRead(). Analog sensors use analogRead(). Then students convert readings into decisions.

Libraries

#include <Servo.h> gives Arduino extra abilities for servo motors, LCD displays, ultrasonic sensors, LED matrices, and other modules.

Objects

With libraries, students can think: Library → Object → Command. Example: Servo gate;, then gate.write(90);.

Mapping Values

map() converts one range into another, such as potentiometer 0-1023 into servo angle 0-180.

State

Variables remember what is happening, such as bool gateOpen = false; or int parkingSpaces = 4;.

Debugging

Check wiring, pin numbers, braces, semicolons, compiler messages, and Serial.println(). Test one component at a time.

Concrete Coding Examples

1. Blink an LED

This example uses a digital output pin. HIGH turns the LED on. LOW turns it off.

const int LED = 8;

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

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

2. Button Controls an LED

The button is an input. Arduino reads the button, makes an if decision, and controls the LED output.

const int BUTTON = 2;
const int LED = 8;

void setup() {
  pinMode(BUTTON, INPUT);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int buttonState = digitalRead(BUTTON);
  Serial.println(buttonState);

  if (buttonState == HIGH) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }
}

3. Light Sensor Turns on an LED

A photoresistor gives an analog reading. Low numbers can mean the room is dark, so Arduino turns on the LED.

const int LIGHT_SENSOR = A0;
const int LED = 8;

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightValue = analogRead(LIGHT_SENSOR);
  Serial.println(lightValue);

  if (lightValue < 450) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }
}

4. Potentiometer Controls LED Brightness

The potentiometer reads 0-1023. map() changes that into a PWM brightness value from 0-255.

const int KNOB = A0;
const int LED = 5;

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int knobValue = analogRead(KNOB);
  int brightness = map(knobValue, 0, 1023, 0, 255);

  analogWrite(LED, brightness);
  Serial.println(brightness);
  delay(50);
}

5. Ultrasonic Sensor, Servo, LED, and Buzzer

This parking-gate style example shows the full beginner pattern: sensor input, logic decision, and several outputs.

#include <Servo.h>

Servo gate;
const int DISTANCE = A0;
const int LED = 8;
const int BUZZER = 9;

void setup() {
  gate.attach(10);
  pinMode(LED, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int distanceValue = analogRead(DISTANCE);
  Serial.println(distanceValue);

  if (distanceValue < 300) {
    gate.write(90);
    digitalWrite(LED, HIGH);
    tone(BUZZER, 440);
  } else {
    gate.write(0);
    digitalWrite(LED, LOW);
    noTone(BUZZER);
  }
}

Beginner Project Thinking

Parking gate:
Ultrasonic sensor → if decision → servo + LED + buzzer + LCD
Potentiometer project:
Potentiometer → analogRead() + map() → servo
Button project:
Button → digitalRead() + if → LED
Light alarm:
Photoresistor → analogRead() + threshold → LED or buzzer
The most important sentence for students: Arduino projects become easier when you can name the input, the logic, and the output.