Site Guide

Find your way around the Engineering Club.

Know what you need? Search for a component, concept or project.

Around the site

Start

Labs

TestingExperimental

Build

Club

LearnExperimental

Go a little deeper

Entry points to larger collections. Use Search for individual records.

Learning paths & reference

Inside PiCrawlerExperimental

Inside Inventory

← Mega Components

ELEGOO MEGA · LESSON 25

The Serial Monitor

Switch individual bar LEDs on from Serial Monitor commands.

Receive ASCII commands and send confirmation messages over USB Serial.

Parts List

  • ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
  • A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
  • An 830-contact solderless breadboard joins inserted leads through hidden spring strips so circuits can be rebuilt without solder. Full-size rectangular board, center channel, numbered five-hole terminal groups and side power rails. Counted contact holes are not component units.
  • A green indicator LED converts forward current into visible light; use it for status indication with a series resistor. Green two-lead dome. Lead length may have been trimmed; confirm polarity with diode test.
  • A red indicator LED converts forward current into visible light; use it for status indication with a series resistor. Red two-lead dome; longer lead normally anode, flat edge normally cathode. Lead length may have been trimmed; confirm polarity with diode test.
  • A yellow indicator LED converts forward current into visible light; use it for status indication with a series resistor. Yellow two-lead dome. Lead length may have been trimmed; confirm polarity with diode test.
  • A blue indicator LED converts forward current into visible light; use it for status indication with a series resistor. Blue two-lead dome. Lead length may have been trimmed; confirm polarity with diode test.
  • 1 kΩ resistor provides a fixed opposition to current. Signal current limiting and transistor base drive is a common use when its unverified power and tolerance limits fit the circuit. Small axial body with one wire at each end. Find the labeled value compartment and measure an isolated loose part with a meter; the shared inventory image is a form reference.
  • 74HC595 accepts eight bits serially and latches them onto eight parallel logic outputs, expanding output control with a few GPIO lines. 16-pin DIP marked 74HC595/74HC595N with notch or pin-one dot. HC and HCT variants have different input thresholds.
  • 100 nF nonpolar ceramic capacitor stores electric-field energy. Local IC decoupling and short high-frequency supply disturbances are appropriate uses when voltage and circuit requirements are checked. Small non-polar disc, often marked 104; 104 means 100 nF, not 104 pF. Read the value and rating rather than estimating from body size.
  • Male-to-male jumper leads make removable point-to-point connections for low-current prototype signals. Pins at both ends; count individual leads rather than ribbon groups. Check intact insulation and snug contacts before use.

Assembly

  1. Disconnect USB and use the original LED layout, replacing the eight LED resistors with 1 kΩ and adding the IC bypass capacitor.
  2. Check the notch, MR→5 V, OE→GND and every LED polarity before reconnecting.
  3. Open PlatformIO Monitor at 9600 baud; type digits 0–7 to add LEDs and lowercase x to clear.
Illustration © ELEGOO. All rights reserved.
Illustration © ELEGOO. All rights reserved. Open full-size ↗

Reviewed connections

FromToNote
Mega D12,D11,D974HC595 14 DS,12 ST_CP,11 SH_CPData,latch,clock
74HC595 16 and 10 → 5 V; 8 and 13 → GNDPower, clear and enableNotch identifies pin 1; pin 9 Q7′ stays open
Q0..Q7 (15,1,2,3,4,5,6,7)One 1 kΩ then one LED anode per outputEach LED cathode → GND; replace all eight pictured 220 Ω values
100 nF across IC 16 / 8Supply bypassPlace close to the IC

Source-reviewed wiring. Hardware not bench-tested; firmware uploads have not been performed.

Code

PlatformIO configuration
platformio.ini
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600

Open PlatformIO Monitor at 9600 baud after Upload. Close Monitor before another Upload if the port is busy.

main.cpp
#include <Arduino.h>
const uint8_t LATCH_PIN = 11;  // ST_CP, IC pin 12, copies shifted bits to visible outputs.
const uint8_t CLOCK_PIN = 9;   // SH_CP, IC pin 11, advances the serial shift register.
const uint8_t DATA_PIN = 12;   // DS, IC pin 14, supplies one bit for each clock edge.
uint8_t leds = 0;  // Eight bits remember which LEDs should be on.
void updateShiftRegister() {
  digitalWrite(LATCH_PIN, LOW);
  // LSBFIRST sends bit 0 first; after eight clocks it reaches Q7, not Q0.
  shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, leds);
  digitalWrite(LATCH_PIN, HIGH);  // All outputs change together after the complete byte.
}

void setup() {

  pinMode(LATCH_PIN, OUTPUT); pinMode(DATA_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT);

  updateShiftRegister();
  Serial.begin(9600);
  Serial.println("Enter LED Number 0 to 7 or 'x' to clear");
}
void loop() {
  // available reports received bytes. read removes one byte from the USB serial buffer.
  if (Serial.available()) {
    const char ch = Serial.read();
    if (ch >= '0' && ch <= '7') {
      const uint8_t led = ch - '0';  // ASCII subtraction turns a digit character into 0..7.
      bitSet(leds, led); updateShiftRegister();
      Serial.print("Turned on LED "); Serial.println(led);
    }
    if (ch == 'x') {
      leds = 0; updateShiftRegister(); Serial.println("Cleared");
    }
    // Other characters, including a terminal's newline, are ignored. No wires use D0/D1.
  }
}

Source: SOURCE_RECONCILED. Compile: COMPILE_VERIFIED. Hardware: NOT_TESTED. Upload: NOT_PERFORMED.

Expected behavior

Each valid digit sets one bit and prints Turned on LED n; x prints Cleared. With LSBFIRST, bit 0 reaches Q7 and bit 7 reaches Q0; use those output labels to identify LEDs.

Experiments & Challenges

  • Send x035, then x, and observe that digit commands accumulate rather than toggle.

Troubleshooting

  • Wrong sequence: check data/latch/clock order and LSBFIRST; missing LEDs usually indicate polarity or an open resistor path.