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 32

Controlling Stepper Motor With Remote

Command opposite stepper rotations with the kit remote’s VOL keys.

Decode NEC remote commands while accounting for blocking motor moves.

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 28BYJ-48 is a small geared unipolar stepper that advances its output shaft when coil phases are energized in sequence. Small round motor can with mounting tabs, offset geared shaft and a five-wire plug on typical unipolar versions. Read its voltage label; 5 V and other winding variants exist.
  • The ULN2003 driver board lets low-power logic switch unipolar stepper coils by sinking their current through a Darlington transistor array. ULN2003-marked IC on a PCB with motor socket, input pins and often phase LEDs. Verify motor socket wiring and the board power/ground labels.
  • A breadboard power module distributes regulated low-voltage rails to compatible breadboard power strips. Board spanning breadboard rails with power socket, selector jumpers and pin contacts. Check rail polarity against the breadboard printed marks.
  • A source-listed 9 V, 1 A DC adapter supplies a compatible device’s power input; it is not a 5 V logic rail. Plug-in adapter with DC barrel cable and 9 V/1 A label. Read polarity symbol and barrel dimensions.
  • Male-to-female jumper leads make removable point-to-point connections for low-current prototype signals. Pin at one end and socket at the other. Check intact insulation and snug contacts before use.
  • 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.
  • The AstroAI meter measures electrical quantities through selectable probe circuits; its exact model, fuse arrangement and safety category remain unverified. AstroAI-branded handheld display with rotary selector and COM/voltage/current sockets. Read the actual model number and socket legends before choosing its manual.
  • An infrared receiver carrier converts a modulated remote-control light signal into digital pulse timing. Black or blue PCB with a three-lead IR detector and header. Receiver housings and three-pin packages have different pin orders between models.
  • An IR handheld remote transmits button commands as timed infrared bursts to a compatible receiver. Handheld button pad with a dark/clear IR emitter window at the front and battery compartment on the rear.

Assembly

  1. Disconnect all power and plug the matching 5 V five-wire motor into the driver’s keyed socket.
  2. Set the breadboard supply rail to 5 V; verify it before connecting the driver. Use the 9 V adapter at its DC input and leave its USB socket unused.
  3. Keep motor +5 V separate from Mega 5 V; join their grounds. Connect USB, then motor power.
  4. Connect the receiver’s signal to D12 and use the matching VOL+ / VOL− remote.
Illustration © ELEGOO. All rights reserved.
Illustration © ELEGOO. All rights reserved. Open full-size ↗

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

Code

Download complete PlatformIO project
ZIP includes platformio.ini, src/main.cpp, and bundled libraries (Stepper, IRremote).

Extract the ZIP, then open its lesson-32-project/workspaces/lesson-32 folder in VS Code. Keep the adjacent third-party folder in place.

PlatformIO configuration
platformio.ini
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
lib_deps =
  file://../../third-party/Stepper
  file://../../third-party/IRremote
main.cpp
#include <Arduino.h>
#include <Stepper.h>
#define DECODE_NEC  // Only decode the protocol used by the supplied kit remote.
#include <IRremote.hpp>  // IRremote 4.x implementation; use its global IrReceiver object.
const uint8_t RECEIVER_PIN = 12;
const int ROTOR_STEPS = 32;  // These are internal rotor steps, not output-shaft steps.
Stepper motor(ROTOR_STEPS, 8, 10, 9, 11);
uint32_t previousCode = 0;
bool havePreviousCode = false;
void releaseMotor() {
  for (uint8_t pin = 8; pin <= 11; ++pin) digitalWrite(pin, LOW);
}
void setup() { IrReceiver.begin(RECEIVER_PIN, DISABLE_LED_FEEDBACK); }
void loop() {
  if (!IrReceiver.decode()) return;
  uint32_t code = IrReceiver.decodedIRData.decodedRawData;
  // Test only the repeat bit. Other flags do not mean "repeat the last button".
  if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
    if (!havePreviousCode) { IrReceiver.resume(); return; }
    code = previousCode;
  } else { previousCode = code; havePreviousCode = true; }
  motor.setSpeed(500);  // 32-step rotor RPM: about 7.8 nominal geared-output RPM, not 500.
  switch (code) {
    case 0xB946FF00: motor.step(-2048); delay(2000); break;  // VOL+
    case 0xEA15FF00: motor.step(2048); delay(2000); break;   // VOL-
  }
  // Preserve blocking moves and the two-second hold; new IR frames wait until this finishes.
  IrReceiver.resume();
  releaseMotor();  // Stop coil current after the accepted frame is processed.
}

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

Expected behavior

VOL+ commands −2048 full steps and VOL− commands +2048; each move is followed by a 2 s hold, then coil release. The 500 RPM setting refers to the 32-step rotor, about 7.8 nominal output RPM. Input is not serviced during a blocking move/hold.

Experiments & Challenges

  • Compare a short VOL press with a held key, allowing the full move and hold time to finish.

Troubleshooting

  • No response: confirm the NEC raw codes in the source match this remote; the IR signal uses D12, not Lesson 14’s D11.