Control a DC Motor's Speed and Direction Over SMS with Arduino and SIM800L

Control a DC Motor's Speed and Direction Over SMS with Arduino and SIM800L

Wireless control is no longer a luxury — it’s an expectation. Whether you’re running an irrigation pump in a remote field or toggling a workshop conveyor from across the building, doing it without walking up to a switch saves time and, in some cases, keeps people out of harm’s way. In this build we wire up an Arduino Uno, a SIM800L GSM module and an L298N motor driver so that a plain text message from any mobile phone can spin a DC motor forward, reverse it, or change its speed.

No Wi‑Fi, no broadband, no cloud account. Just a SIM card with SMS credit and a 2G signal.

What You’ll Build

  • An SMS receiver based on SIM800L that listens for commands like FWD200, REV150 or STOP.
  • An Arduino sketch that parses each message and drives an L298N H‑bridge accordingly.
  • A safe 5 V ↔ 3.3 V interface using a bidirectional logic level shifter.
  • PWM-based speed control on pin D9 with a duty cycle from 0 to 255.

Bill of Materials

#ComponentQtyRole
1Arduino Uno1Main controller; parses SMS and outputs control signals.
2SIM800L GSM module1Receives SMS over the 2G cellular network.
3L298N motor driver1H‑bridge for direction and PWM speed control.
4Bidirectional logic level shifter1Safe UART between 5 V Arduino and 3.3 V SIM800L.
5DC motor (12 V typical)1The actuator under test.
6External battery / 12 V adapter1Powers the motor and SIM800L independently.
7Breadboard & jumper wiresPrototyping.
8USB cable + Arduino IDEProgramming and serial debugging.

Circuit Overview

The Arduino sits in the middle of two voltage worlds. On one side it talks to the L298N at 5 V logic, which is straightforward. On the other side it talks to the SIM800L, whose RX pin is only rated for ~3.3 V — driving it directly from a 5 V TX line is one of the most common ways to kill the module. A bidirectional level shifter handles that translation in both directions.

Design Notes Worth Remembering

  • Never share Arduino’s 5 V rail with the SIM800L. The module can pull short bursts of nearly 2 A during transmission. Give it its own supply (a 4 V Li‑ion or a dedicated buck converter works well) and tie the grounds together.
  • One common ground only. Arduino, level shifter, L298N, SIM800L and the external battery must all share GND, otherwise serial communication and PWM behaviour become unpredictable.
  • PWM on D9. D9 is a hardware PWM pin on the Uno and is wired to the L298N’s ENA input — that’s where speed control comes from.
  • Use the level shifter on both TX and RX. Even if Arduino TX → SIM800L RX is the dangerous direction, running both lines through the shifter keeps timing symmetric.

Wiring Tables

Arduino ↔ Level Shifter ↔ SIM800L

Arduino UnoLevel ShifterSIM800L
5 VHV
3.3 VLV
GNDGNDGND
D3 (TX)HV1 → LV1RX
D2 (RX)HV2 → LV2TX

Arduino ↔ L298N

Arduino UnoL298N
D5IN1
D6IN2
D9 (PWM)ENA
5 V+5 V logic
GNDGND

L298N ↔ Motor & Power

L298NConnection
OUT1, OUT2DC motor terminals
+12 V / VINExternal battery +
GNDExternal battery − (also tied to Arduino GND)

How the System Works

When power comes up, the Arduino opens a software serial port to the SIM800L and sends a short sequence of AT commands. These switch the module into text-mode SMS and ask it to push any new message straight to the serial line, instead of storing it on the SIM. From that point on, the Arduino just listens.

When you send a message like FWD200 from your phone, the GSM module emits a +CMT: notification followed by the message body. The sketch buffers characters until it sees a newline, then checks the line for one of three prefixes:

  • FWDnnn — IN1 HIGH, IN2 LOW, ENA = nnn
  • REVnnn — IN1 LOW, IN2 HIGH, ENA = nnn
  • STOP — IN1 LOW, IN2 LOW, ENA = 0

The number after FWD/REV is written directly to analogWrite() on D9, giving a duty cycle from 0 (stopped) to 255 (full speed).

The Arduino Sketch — Walkthrough

1. Serial setup

#include <SoftwareSerial.h>
SoftwareSerial gsm(3, 2);  // RX, TX

SoftwareSerial frees up the hardware UART for debug prints over USB while a separate pair of pins talks to the SIM800L.

2. Motor pins

#define ENA 9
#define IN1 5
#define IN2 6

pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
stopMotor();   // safe default

Always force the motor to a stopped state at boot — otherwise a stray bit on a floating output can briefly spin it on power-up.

3. SIM800L initialisation

gsm.println("AT");
gsm.println("AT+CMGF=1");          // text mode
gsm.println("AT+CSCS=\"GSM\"");    // GSM character set
gsm.println("AT+CNMI=2,2,0,0,0");  // push new SMS straight to serial

4. Reading messages

while (gsm.available()) {
  char c = gsm.read();
  if (c == '\n') {
    processLine(line);
    line = "";
  } else if (c != '\r') {
    line += c;
  }
}

5. Acting on the command

if (msg.startsWith("FWD"))      forward(getSpeed(msg));
else if (msg.startsWith("REV")) reverse(getSpeed(msg));
else if (msg.startsWith("STOP")) stopMotor();

getSpeed() simply parses the digits after the prefix and clamps them to the 0–255 PWM range.

Troubleshooting

SIM800L won’t answer AT

Almost always a power problem. The module needs a supply that can sustain ~2 A spikes at 3.7–4.2 V. Also confirm TX and RX aren’t swapped, and that your SoftwareSerial baud rate matches the module (typically 9600 after a fresh boot).

SMS never arrives

Check network registration with AT+CREG? — you want a response of +CREG: 0,1 or 0,5. If you see 0,2 the module is still searching: reposition the antenna or move closer to a window. Also verify AT+CMGF=1 succeeded.

Motor doesn’t move

Confirm the L298N has its own 12 V supply, not just the Arduino’s 5 V. Check the ENA jumper on the board — if it’s in place, the driver ignores PWM. Remove the jumper so D9 actually controls speed.

Motor spins the wrong way

Either swap IN1/IN2 in the sketch, or swap the motor wires at OUT1/OUT2. Both fixes are equally valid.

Speed never changes

Make sure ENA is wired to a PWM-capable pin (D3, D5, D6, D9, D10 or D11 on the Uno) and that you’re using analogWrite(), not digitalWrite(). Loose breadboard connections on ENA also produce this symptom.

Where This Is Useful

  • Agriculture: turn an irrigation pump on or off from home.
  • Industrial sites: operate motors in hazardous areas without sending a person in.
  • Gates and shutters: simple SMS-based access control with no internet dependency.
  • Home automation: curtains, blinds and exhaust fans in places where Wi-Fi doesn’t reach.

Closing Thoughts

What makes this project worth building isn’t the motor itself — it’s the pattern. Once you can route an SMS into a microcontroller and turn it into a hardware action, you can control almost anything: a relay bank, a solenoid valve, a string of lights, a second motor on a different command prefix (M2FWD, M2REV, etc.). The GSM layer is cheap, globally available, and works in places where IoT cloud platforms simply don’t.

FAQ

Why does the SIM800L need its own power supply?
Because it can draw close to 2 A in short bursts during network transmission. The Arduino’s 5 V regulator can’t source that and will brown-out, resetting your sketch mid-message.

What happens if I send an SMS that doesn’t match the format?
The sketch ignores it. There’s no error reply by default — you can add one with AT+CMGS if you want confirmation messages.

Can I control more than one motor?
Yes. Add another L298N (or use the second channel on the same board), assign a unique command prefix per motor (M1FWD, M2REV, etc.) and extend the parser. One SIM800L can serve all of them.

Does this need internet?
No. It runs entirely on 2G SMS. Any active SIM card with SMS allowance is enough — no data plan, no Wi-Fi.

How do I know the SIM800L has registered?
Send AT+CREG? over the serial monitor. +CREG: 0,1 means home network, 0,5 means roaming. 0,2 means it’s still searching; check antenna and signal.

How is direction set on the L298N?

  • IN1 = HIGH, IN2 = LOW → forward
  • IN1 = LOW, IN2 = HIGH → reverse
  • IN1 = IN2 → motor stopped (or braking, depending on ENA)
]]>
1001 2026-04-30 10:00:00 2026-04-30 10:00:00 open open dc-motor-speed-control-using-gsm-arduino publish 0 0 post 0

Post a Comment

0 Comments