How to Connect a Micro Servo Motor to Arduino MKR NB 1500

How to Connect a Micro Servo Motor to Arduino / Visits:5

In the ever-expanding universe of the Internet of Things (IoT), the ability to control the physical world from the digital realm is the ultimate superpower. For makers, hobbyists, and IoT pioneers, this often starts with a simple yet profound action: making something move. Enter the micro servo motor—a compact, precise, and incredibly versatile actuator that has become a cornerstone of robotics, automation, and interactive projects. When paired with a powerful, connectivity-focused board like the Arduino MKR NB 1500, you unlock the potential to create remotely controlled, battery-operated devices that can operate almost anywhere there's a cellular network.

This guide will walk you through everything you need to know to successfully connect and command a micro servo using this unique Arduino board. We'll move beyond basic wiring to explore the nuances of power management, network-enabled control, and practical applications that leverage the specific strengths of both components.


Why This Pairing? Understanding the Core Components

Before we dive into the wires and code, let's understand why combining a micro servo with the MKR NB 1500 is a particularly compelling idea.

The Humble Powerhouse: Micro Servo Motor 101

A micro servo motor (like the ubiquitous SG90 or MG90S) is not a simple DC motor. It is an integrated package containing: * A small DC motor * A gear train to reduce speed and increase torque * A control circuit * A potentiometer for positional feedback

This ensemble allows for precise angular control, typically over a 180-degree range. You send it a Pulse Width Modulation (PWM) signal, and it moves to and holds a specific position. This makes it perfect for tasks requiring controlled movement: steering a robot, positioning a sensor, opening a small latch, or animating a prototype.

Key Characteristics: * Low Power Consumption: Ideal for battery and IoT applications. * Compact Size: Fits into tight spaces in enclosures. * 3-Wire Control: Power (VCC, usually red), Ground (GND, usually brown or black), and Signal (usually orange or yellow).

The Cellular IoT Brain: Arduino MKR NB 1500

The Arduino MKR NB 1500 isn't your average microcontroller. It's built for deployments where Wi-Fi is unavailable or impractical. Its standout feature is the integrated NB-IoT (Narrowband IoT) and LTE-M cellular modem, allowing it to communicate over low-power, wide-area cellular networks.

Why it's great for servo projects: * Remote Control Anywhere: Control your servo from across the city or country via cellular data. * Battery-Friendly Design: The board's low-power architecture complements the servo's intermittent power needs. * Arduino Ecosystem: Full compatibility with the vast Arduino libraries and the familiar Servo.h library.

The Essential Hardware Connection

Connecting the servo physically is straightforward, but with the MKR NB 1500, power considerations are paramount.

What You'll Need

  • Arduino MKR NB 1500 board
  • Micro Servo Motor (e.g., SG90)
  • Jumper wires (Male-to-Female recommended)
  • An external 5V power source (e.g., a 5V/2A DC wall adapter or a beefy USB power bank)
  • A 100µF to 470µF electrolytic capacitor (highly recommended)

Step-by-Step Wiring Diagram

Warning: Do not power a servo directly from the MKR NB 1500's VCC pin. The servo can draw significant current (up to 500-700mA when stalled), which can brown out or damage the board's regulator.

Here is the safe and recommended wiring setup:

[External 5V Power Supply +] | |---[+ve lead of Capacitor]---| | | |---[Servo Red Wire (VCC)]-----| | [External 5V Power Supply -] | |---[-ve lead of Capacitor]---| | | |---[Servo Brown/Black Wire (GND)]---| | |---[MKR NB 1500 GND Pin] | [Servo Orange/Yellow Wire (Signal)]----------|---[MKR NB 1500 Pin 3 (or any PWM-capable pin)]

Explanation of Key Points:

  1. Dedicated Power Supply: The external 5V supply powers the servo directly. This isolates the high current demands from the sensitive microcontroller.
  2. Common Ground (CRITICAL): The ground from the external supply, the servo, and the MKR NB 1500 must all be connected together. This provides a common reference voltage for the control signal.
  3. Decoupling Capacitor: Soldered or placed close to the servo's power pins, this capacitor smooths out voltage spikes caused by the motor starting and stopping, protecting your circuit and ensuring cleaner operation.
  4. Signal Wire: Connected to a digital pin capable of PWM. On the MKR NB 1500, pins 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, A3, A4 support PWM.

Writing the Foundation: Basic Servo Control Code

With the hardware set up, let's write the basic software. This sketch will move the servo through its range of motion.

cpp

include <Servo.h>

// Create a servo object Servo myServo;

// Define the signal pin const int servoPin = 3;

// Variables for servo position int pos = 0;

void setup() { // Attach the servo to the specified pin myServo.attach(servoPin);

// Optional: Initialize serial for debugging Serial.begin(9600); while (!Serial); // Wait for serial port to connect (for native USB) Serial.println("MKR NB 1500 Servo Test Started"); }

void loop() { Serial.println("Sweeping from 0 to 180 degrees..."); // Sweep from 0 to 180 degrees for (pos = 0; pos <= 180; pos += 1) { myServo.write(pos); // Command the servo to move to 'pos' delay(15); // Wait 15ms for the servo to reach the position }

Serial.println("Sweeping back from 180 to 0 degrees..."); // Sweep back from 180 to 0 degrees for (pos = 180; pos >= 0; pos -= 1) { myServo.write(pos); delay(15); }

delay(1000); // Pause for a second before repeating }

Upload and Test: Connect your MKR NB 1500 to your computer via USB (for programming only, not for powering the servo). Select the correct board and port in the Arduino IDE, and upload this sketch. You should see your micro servo smoothly sweeping back and forth.

Leveling Up: Integrating Cellular Control

Now for the exciting part: moving the servo remotely via the NB-IoT network. This requires setting up your cellular connectivity (with a SIM card and data plan from a supported provider) and creating a simple cloud interface. We'll outline a conceptual example using a webhook.

Setting Up the MKR NB 1500 for NB-IoT

  1. Get a SIM Card: Obtain a NB-IoT/LTE-M compatible SIM from a carrier that supports it in your region.
  2. Install the Board Package: In Arduino IDE, go to Boards Manager and install "Arduino MKR Boards".
  3. Install Necessary Libraries: Install the MKRNB library via the Library Manager.

Example Sketch: Servo Position via SMS/Cloud

This is a simplified structure showing how you could trigger servo movement based on an incoming SMS or a cloud-to-device message.

cpp

include <MKRNB.h>

include <Servo.h>

Servo myServo; const int servoPin = 3;

// Cellular network objects NB nbAccess; NB_SMS sms;

// Your phone number (with country code, e.g., +12345678901) String remoteNumber = "+12345678901";

void setup() { Serial.begin(9600); while (!Serial);

myServo.attach(servoPin); myServo.write(90); // Start at center position

Serial.println("Connecting to cellular network..."); if (nbAccess.begin("", "", true) != NB_READY) { // APN, PIN, restart Serial.println("Failed to connect to cellular network!"); while (1); } Serial.println("NB-IoT Connected!"); Serial.println("Waiting for commands..."); }

void loop() { // Check for incoming SMS int smsCount = sms.available(); if (smsCount > 0) { Serial.print("New SMS received: ");

char senderNumber[20]; char messageText[100];  sms.remoteNumber(senderNumber, 20); Serial.print("From: "); Serial.println(senderNumber);  // Read message sms.read(messageText, 100); Serial.print("Message: "); Serial.println(messageText);  // Simple command parsing String command = String(messageText); command.trim(); // Remove whitespace  if (command == "OPEN") {   myServo.write(180);   sms.beginSMS(senderNumber);   sms.print("Servo moved to OPEN position (180 deg)");   sms.endSMS(); } else if (command == "CLOSE") {   myServo.write(0);   sms.beginSMS(senderNumber);   sms.print("Servo moved to CLOSE position (0 deg)");   sms.endSMS(); } else if (command.toInt() >= 0 && command.toInt() <= 180) {   int angle = command.toInt();   myServo.write(angle);   sms.beginSMS(senderNumber);   sms.print("Servo moved to " + command + " degrees");   sms.endSMS(); }  sms.flush(); // Delete the message from the modem memory 

} delay(1000); }

How It Works: 1. The board connects to the NB-IoT network. 2. It sits in a low-power listening mode, waiting for an SMS. 3. When you send an SMS with "OPEN", "CLOSE", or a number "0"-"180", it parses the command. 4. It moves the servo to the corresponding position and sends back a confirmation SMS.

Real-World Project Ideas

With the fundamentals mastered, here are some projects that truly leverage this combination:

Smart Agricultural Irrigation Valve Controller

Use the micro servo to actuate a small ball valve controlling water flow to a specific plant or sector. The MKR NB 1500 can receive commands based on soil moisture data from a cloud dashboard or a simple SMS schedule, enabling precise, remote irrigation management over a wide area without Wi-Fi.

Remote Security Box Lock

Build a secure enclosure for spare keys or access cards. The servo acts as the latch. Authorized users can send a secure command via a web app (which talks to the board via a cloud API like MQTT) to unlock the box temporarily, with usage logged. Perfect for rental properties or shared facilities.

Cellular-Enabled Camera Pan/Tilt

Mount a lightweight camera or sensor on a two-servo pan-tilt mechanism. Use the MKR NB 1500 to receive movement commands (PAN 90, TILT 45) from a remote dashboard, allowing you to survey a remote location, wildlife site, or construction zone in real-time over the cellular network.

Troubleshooting Common Issues

  • Servo Jitters or Doesn't Move: This is almost always a power issue. Verify your external 5V supply can deliver at least 1A. Ensure all grounds are connected. Add the decoupling capacitor.
  • MKR NB 1500 Resets When Servo Moves: A classic symptom of power backflow/brownout. The external power supply is mandatory. Double-check your wiring against the diagram.
  • "Servo.h: No such file or directory": The Servo library is included with the Arduino IDE. If missing, install it via Sketch > Include Library > Manage Libraries.
  • NB-IoT Connection Fails: Check your SIM card activation, APN settings, and NB-IoT coverage in your area. Ensure the antenna is properly attached to the MKR NB 1500.
  • Servo Gets Hot: It's normal for servos to get warm, but excessively hot indicates it is stalled (mechanically blocked) or under constant load. Ensure the mechanical load is within the servo's specifications and not binding.

Copyright Statement:

Author: Micro Servo Motor

Link: https://microservomotor.com/how-to-connect-a-micro-servo-motor-to-arduino/connect-micro-servo-arduino-mkr-nb-1500.htm

Source: Micro Servo Motor

The copyright of this article belongs to the author. Reproduction is not allowed without permission.

About Us

Lucas Bennett avatar
Lucas Bennett
Welcome to my blog!

Tags