Browsing the ATmega328P Datasheet
The Arduino Uno R3 is built around the ATmega328P microcontroller from Microchip (formerly Atmel). Here are the key specs I found while browsing the datasheet:
- 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
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) for uploading the code, satisfying the wired communication requirement.
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)
Arduino Code
// Arduino Uno R3 — Button Toggle LED
// Local I/O: pushbutton (input on pin 7) + LED (output on pin 8)
// Wired communication: USB serial for code upload
unsigned const LED = 8;
unsigned const BUTTON = 7;
unsigned int bState = 0;
void setup() {
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
if (digitalRead(BUTTON) == 1) {
digitalWrite(LED, HIGH);
bState += 1;
if (bState % 2 == 0) {
digitalWrite(LED, LOW);
bState = 0;
}
delay(100);
}
}
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). - Toggle logic: Each button press increments
bState. On the first press (bState= 1, odd), the LED turns on. On the second press (bState= 2, even), the LED turns off and the counter resets to 0. - Delay: The 100ms delay acts as a simple debounce to prevent multiple triggers from a single press.
- Wired communication: The program is uploaded to the Arduino over USB, which uses the ATmega16U2 chip for USB-to-UART serial conversion.
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.