Digital Input, Analog Input, and Sensor Change Detection
This week I learned how to use Arduino to connect the physical world with code.
The main idea:
Input → Processing → Output
Example:
Button ↓ Arduino ↓ LED
A sensor collects information from the environment, Arduino processes the data, and then controls an output device.
Hardware Arduino Uno / Nano Breadboard USB cable LED 220Ω resistor Push button Potentiometer Photoresistor (LDR) Jumper wires Software Arduino IDE Serial Monitor


The interaction is:
Pushbutton
↓
Arduino UNO
↓
white LED / blue LED
code
int buttonPin = 2;
int led1 = 3;
int led2 = 4;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
int buttonState = digitalRead(buttonPin);
if(buttonState == LOW) {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
}
else {
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
}
}