Browsing the ATmega328P Datasheet
The Arduino Uno R3 is built around the ATmega328P microcontroller from Microchip (formerly Atmel). I reviewed the official datasheet to understand the hardware capabilities before programming. Here are the key specs I found:
📄 Datasheet: ATmega328P Official Datasheet (PDF)
- Architecture: 8-bit AVR RISC
- Clock Speed: 16 MHz (external crystal on the Uno)
- Flash Memory: 32 KB (0.5 KB used by bootloader)
- SRAM: 2 KB
- EEPROM: 1 KB
- Digital I/O Pins: 14 (6 provide PWM output)
- Analog Input Pins: 6 (10-bit ADC, 0–1023 range)
- Operating Voltage: 5V
- Communication: UART (Serial), SPI, I2C (TWI)
- Built-in LED: Pin 13
- USB Interface: ATmega16U2 handles USB-to-serial conversion
Compared to the ESP32-C6, the Uno is simpler — no WiFi or Bluetooth built in. But it runs at 5V logic, which makes it easier to interface with many sensors and modules directly without level shifting.
The Program — Button-Controlled LED with Serial Communication
This program uses a pushbutton as local input and an LED as local output on the Arduino Uno R3. Each press of the button toggles the LED on or off using a simple state counter. The Arduino communicates with the computer over USB (UART serial), sending status messages that can be viewed in the Serial Monitor.
Learning Resources: I learned about button debouncing and state management from the Arduino Built-in Examples and the Arduino Serial Communication documentation.
Wiring
- LED: Pin 8 → 220Ω resistor → LED anode (+) → LED cathode (−) → GND
- Button: Pin 7 → one leg of button, other leg → 5V (with pull-down resistor to GND)
- USB cable: Connected to computer for uploading code (wired serial communication)
Note on Wiring: For this demonstration, I used a breadboard for quick prototyping and testing. In future projects, I plan to use a proper PCB with built-in inputs and outputs (like the Qpad or custom sensor shields) for more reliable connections and cleaner integration.
Arduino Code
// Arduino Uno R3 — Button Toggle LED with Serial Communication
// Local I/O: pushbutton (input on pin 7) + LED (output on pin 8)
// Communication: USB serial for bidirectional messages
unsigned const LED = 8;
unsigned const BUTTON = 7;
unsigned int bState = 0;
bool ledOn = false;
void setup() {
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
Serial.println("Arduino Uno R3 - Button Toggle LED");
Serial.println("Press button to toggle LED");
Serial.println("Send '1' to turn ON, '0' to turn OFF");
}
void loop() {
// Check for serial commands from computer
if (Serial.available() > 0) {
char cmd = Serial.read();
if (cmd == '1') {
digitalWrite(LED, HIGH);
ledOn = true;
Serial.println("LED turned ON via serial");
} else if (cmd == '0') {
digitalWrite(LED, LOW);
ledOn = false;
Serial.println("LED turned OFF via serial");
}
}
// Check for button press
if (digitalRead(BUTTON) == 1) {
ledOn = !ledOn;
digitalWrite(LED, ledOn ? HIGH : LOW);
if (ledOn) {
Serial.println("Button pressed - LED ON");
} else {
Serial.println("Button pressed - LED OFF");
}
delay(300); // Debounce delay
}
}
How It Works
- LED (pin 8): Configured as OUTPUT — this is the local output device.
- Button (pin 7): Configured as INPUT — this is the local input device. When pressed,
digitalReadreturns1(HIGH). - Serial Communication: The board sends status messages to the computer and listens for commands ('1' to turn LED on, '0' to turn it off). This demonstrates bidirectional communication, not just code upload.
- Toggle logic: Each button press flips the
ledOnboolean, turning the LED on or off. - Debounce: The 300ms delay prevents multiple triggers from a single press.
Serial Monitor Communication
Open the Serial Monitor (Tools → Serial Monitor or Ctrl/Cmd+Shift+M) and set the baud rate to 9600. You'll see messages every time the button is pressed or when you send commands from the computer:
Example Serial Monitor output showing bidirectional communication
Try it: Type 1 in the Serial Monitor input box and press Enter — the LED turns on and you get a confirmation message. Type 0 and the LED turns off. This demonstrates true bidirectional communication between the microcontroller and computer.
Tinkercad Circuit
Before building the physical circuit, I prototyped it in Tinkercad to verify the wiring and test the code in simulation:
Tinkercad circuit simulation — Arduino Uno R3 with LED on pin 8 and pushbutton on pin 7
Video — Working Demo
Here's the circuit running on the real Arduino Uno R3. Each button press toggles the LED on or off — you can see the state change immediately after each press, with the 100ms delay preventing accidental double-triggers.
Arduino Uno R3 — pushbutton toggling the LED on and off
This demonstrates local interaction with both an input device (pushbutton) and an output device (LED), with the code uploaded via wired USB serial communication.