Labs · ELEGOO Mega 2560
Mega Components
Practical lessons 2–33: build circuits, read sensors, and explore complete commented C++ programs.
Start with Mega setup: VS Code + PlatformIO →
Hardware has not been bench-tested. Lesson 16 keeps the two sensor variants separate; QMI8658C assembly is blocked pending identification. Lesson 21 UID writing is software review only until a suitable owned test card is identified.
Blink
Configure a digital output and set its timing with delay().
Goal Blink the Mega’s onboard L LED once per second.
LED
Observe how series resistance changes LED current and brightness.
Goal Power a red LED through a resistor and compare three resistor values.
RGB LED
Mix colors by varying three PWM outputs.
Goal Fade a common-cathode RGB LED from red to green to blue and back.
Digital Inputs
Read active-low buttons with internal pull-ups.
Goal Use one button to turn an LED on and the other to turn it off.
Active buzzer
Switch a self-oscillating buzzer on and off.
Goal Play active-buzzer beeps with shortening intervals, followed by a five-second sound.
Passive Buzzer
Set sound frequency with tone() instead of a steady output.
Goal Play eight ascending notes through a passive buzzer.
Tilt Ball Switch
Read a mechanical contact using INPUT_PULLUP.
Goal Turn the onboard L LED on when the tilt switch closes.
Servo
Command servo positions while supplying motor power separately.
Goal Move an unloaded SG90 servo through 90°, 30°, 90° and 150°.
Ultrasonic Sensor Module
Convert an echo pulse duration into distance.
Goal Print the HC-SR04’s measured distance once per second.
Membrane Switch Module
Scan a row-and-column key matrix.
Goal Print each key pressed on a 4x4 membrane keypad.
DHT11 Temperature and Humidity Sensor
Poll a non-blocking sensor driver without delaying its state machine.
Goal Print temperature and relative humidity from a DHT11 module.
Analog Joystick Module
Read two analog channels and an active-low switch.
Goal Print the joystick’s X, Y and pushbutton readings.
IR Receiver Module
Decode NEC infrared messages using IRremote 4.1.2.
Goal Print the supplied remote’s button names and repeat indications.
MAX7219 LED Dot Matrix Module
Send display commands to a single MAX7219 module.
Goal Display “Arduino” letter by letter, then run row, column and individual-LED patterns.
IMU Module: MPU-6050 / QMI8658C
Choose the correct sensor address, register order and driver for the actual IMU.
Goal Print raw acceleration, angular-rate and temperature readings from the identified IMU.
HC-SR501 PIR Sensor
Read a PIR module’s digital output and observe its retrigger and hold timing.
Goal Light the Mega’s onboard L LED when the HC-SR501 reports motion.
Water Level Detection Sensor Module
Read an analog voltage and report only changes larger than ten ADC counts.
Goal Print changing conductivity-sensor readings in Serial Monitor.
Real Time Clock Module
Use I2C clock registers and distinguish setting time from keeping time.
Goal Print calendar time from an identified RTC once per second.
Sound Sensor Module
Distinguish an analog signal from a comparator threshold output.
Goal Print the microphone module’s analog samples while L follows its digital threshold output.
RC522 RFID Module
Use Mega SPI pins and distinguish reading an identifier from writing a tag.
Goal Read a tag’s UID, with the supplied UID-writing experiment kept as a separate option.
LCD Display
Drive a 16×2 LCD through its four-bit parallel interface.
Goal Show “Hello, World!” and elapsed seconds on a parallel LCD.
Thermometer
Convert an NTC divider voltage into an approximate temperature using stated coefficients.
Goal Show an illustrative thermistor temperature on the parallel LCD.
Eight LED with 74HC595
Shift a byte into a latched parallel-output register.
Goal Fill an eight-LED bar through a 74HC595, then clear and repeat.
The Serial Monitor
Receive ASCII commands and send confirmation messages over USB Serial.
Goal Switch individual bar LEDs on from Serial Monitor commands.
Photocell
Turn an analog divider reading into an eight-bit LED pattern.
Goal Change the number of lit bar LEDs with a photocell divider.
74HC595 and Segment Display
Map stored digit bits to physical display segments through a shift register.
Goal Count from 9 down to 0 on a single common-cathode seven-segment display.
Four Digital Seven Segment Display
Separate a shared segment pattern from digit selection and multiplexing.
Goal Show the same changing hexadecimal glyph on all four digits.
DC Motors
Control an H-bridge without putting motor current through GPIO pins.
Goal Run a small DC motor through direction, coast, brake and PWM sequences.
Relay
Separate a relay’s coil driver from its COM/NO load contacts.
Goal Switch a low-voltage DC motor on and off with a bare relay.
Stepper Motor
Sequence a five-wire unipolar stepper through its ULN2003 driver.
Goal Turn a geared stepper about one revolution in each direction.
Controlling Stepper Motor With Remote
Decode NEC remote commands while accounting for blocking motor moves.
Goal Command opposite stepper rotations with the kit remote’s VOL keys.
Controlling Stepper Motor With Rotary Encoder
Handle encoder edges without waiting inside an interrupt.
Goal Move a stepper with a rotary encoder and return to its counted starting point.