Chuyển tới nội dung
Home » Esp8266 Servo Control Arduino Ide | Step 6: Upload Your Program

Esp8266 Servo Control Arduino Ide | Step 6: Upload Your Program

ESP32 Tutorial - Using Servo Motors ( NEW Arduino IDE )

Conclusion

Servo motors are one of the most vital devices on the planet today, even though most of the world’s population is unaware of its existence and importance. Many companies continue to rely on servos because of their reliability, precision, efficiency, size, and potency. It won’t be much of a surprise if businesses will continue to use these helpful devices in the many years to come.

Hardware components
Software apps and online services

In this project we use ESP8266 in its NodeMCU form factor as a webserver and to create a webform to control the current position of the servo motor.

All the data of the webserver are saved on the SPIFFS memory of ESP8266.

What is SPIFFS?

SPIFFS is the original filesystem and is ideal for space and RAM constrained applications that utilize many small files and care about static and dynamic wear levelling and don’t need true directory support. Filesystem overhead on the flash is minimal as well. On the NodeMCU we have 4MB of flash out of which we can the size of the SPIFFS filesystem. In this project all the webserver files including html, css, and javascript are saved on a folder named data which is the folder name required for uploading to ESP8266 with SPIFFS uploader.

I have a detailed tutorial about it in another project. Check it out.

Hardware Setup

  • Start by placing the NodeMCU on a breadboard.
  • Place the servo motor and make the connections as shown.
  • Connections.

3V3V ➡ VCC

GND ➡ GND

SIGNAL ➡ D2

Software Setup

  • Visit my GitHub page and download the necessary files.
  • Download ESPAsyncWebServer library
  • Download ESPAsyncTCP library
  • Install libraries.
  • Download ESP8266 Filesystem Uploader
  • Install the libraries and Filesystem uploader as shown below.
  • Compile the code and upload.
  • Go to tools and use ESP8266 Sketch Data Upload tool to upload sketch data.

Changetheselinesofcodeasperyours:

GitHub Repository link

const char *ssid = "REPLACE_WITH_YOUR_SSID"; const char *password = "REPLACE_WITH_YOUR_PASSWORD"; const uint8_t servoPin = D4;

https://github.com/rahuladitya303/ESP8266_SERVO_CONTROLLER.git

For more details about how to install libraries and filesystem uploader checkout my other project

https://create.arduino.cc/projecthub/rahuladitya303/esp8266-weather-station-with-spiffs-c01037

nodemcu with servo motor Circuit Diagram

Connection Diagram

Nodemcu esp8266 Servo Motor
VV, Vin VCC
G, GND GND
D3 Pin Signal
  • The servo motor has three wires,
  • two for the power and one for the control signal.
  • You have to connect these three wires with the pins of the Nodemcu.
  • Connect the red wire with the 3.3 volts pin of the nodemcu.
  • Join the brown wire of the servo motor with the GND pin of the nodemcu.
  • Connect the signal wire (orange wire) of the servo motor with the digital-3 pin of the nodemcu.
  • After completing the connections use a USB cable to power the nodemcu so that the servo motor starts moving.

PCBWay PCB Prototyping Services

I have assembled the whole circuit on a breadboard. As you know breadboard assembly is not effective for this type of projects. So, PCBWay offers Rapid PCB Prototyping for Your Research Work. I personally, recommend PCBWay because you can get your first-try boards right in 24 hours!

The prototyping stage is the most critical period of time for engineers, students, and hobbyists. PCBWay not only makes your boards quick but also makes your job right as well as cost-effective. This greatly reduces your cost and shortens the time for developing your electronic products.

PCBWay can provide 2 Layer PCBs to highly advanced HDI and flex boards. Even though the PCBs they produce differ a lot regarding functionality and areas of use. I am impressed with the quality of the boards, the delivery time, and the cost-effectiveness.

ESP32 Tutorial - Using Servo Motors ( NEW Arduino IDE )
ESP32 Tutorial – Using Servo Motors ( NEW Arduino IDE )

Servo Motors Parts and Functions

Dozens of parts make up a servo motor with each and every single part playing a vital role in the device’s functionality. Here are its most important parts and the significant roles they play in the functionality of the servos.

  • Stator – A stator creates a rotating magnetic field to efficiently generate torque.

  • Winding – Current flows in the winding produces a rotating magnetic field.

  • Shaft – The shaft transmits the motor output power. This load is driven through the transfer mechanism.

  • Rotor – A rotor is a permanent magnet that is positioned externally to the shaft.

  • Encoder – An optical encoder always observes and calculates the number of rotations being completed and watches the position of the shaft.

Each part of the servo motor serves a huge purpose in making the servos properly function or work.

Advantages and Disadvantages

Servo motors provide quite a lot of advantages but as with all things, they also pose some problems and difficulties for companies who utilize this device.

Advantages

Servos are known to always be frequent and work at the same pace. So, if a heavy load is placed on the motor, the driver will increase the current to the motor coil as it rotates the motor. This basically means that servo motors are expected to always be mechanically on point. And because of its precision, it allows companies to operate it at a high-speed pace.

Disadvantages

As with anything that provides convenience and efficiency, servo motors also tend to have a high cost when it comes to maintenance and operation. Moreover, when a machine using a servo is stopped, the motor continues to move back and forth one pulse, so it is not good if the machine or area is not suitable with vibrations.

ESP32 Servo Motor Web Server with Arduino IDE
ESP32 Servo Motor Web Server with Arduino IDE

Step 4: Preparing the Arduino IDE

After downloading the Arduino IDE navigate to

  1. File tab and then click on Preferences.
  2. In the additional Boards Manager URLs add the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json)
  3. Click OK and then navigate to
  4. Tools – Boards – Boards Manager

In the search field type esp8266 > click the esp8266 by ESP8266 Community – Click Install

Now you have setup the Arduino IDE to work along with the NodeMCU.

Step 6: Upload Your Program

  1. Goto Tools
  2. Board > NodeMCU 1.0 (ESP – 12E Module)
  3. Port ( Choose the right Port )

**Make sure you have your NodeMCU model selected and the correct serial port ticked (see pics).

Then just click the Upload button**

Ready To GO

Participated in the Makerspace Contest 2017

Fuji Electric Product Column
The Purpose of Servo Motors

NodeMcu (ESP8266) control Servo motor basic usage
NodeMcu (ESP8266) control Servo motor basic usage

Components Required

  • ESP8266 nodemcu board
  • Servo motor
  • Jumper wires
  • USB cable for uploading the code
  • Breadboard

Components Table/buy link

You can buy the whole components from the given link we have to share the amazon link. from where you can get a good discount on the components for this esp8266 tutorial.

ESP8266 with servo motor Code

NOTE: Please upload the code which is given below to the nodemcu. You may need to install

library to the IDE software. Check here how to add a zip library to the Arduino IDE.


//TECHATRONIC.COM #include

// servo library Servo s1; void setup() { s1.attach(0); // servo attach D3 pin of arduino } void loop() { s1.write(0); delay(1000); s1.write(90); delay(1000); s1.write(180); delay(1000); }

We hope that you understand this project and please try to make it on your own. If you have any doubts related to this project then ask them in the comments section below. Also, check out our tutorials on Arduino and Raspberry Pi.

Video sample

Điều khiển Servo thông qua NodeMCU ESP8266 và Blynk hiển thị lên OLED 0.96

Trong nội dung bài viết hôm nay mình sẽ hướng dẫn các bạn cách làm thể nào để điều khiển Servo thông qua NodeMCU ESP8266 và App Blynk hiển thị lên OLED 0.96. Để có thể hiểu rõ hơn về bài viết hôm nay các bạn xem lại bài viết bên dưới nhé.

How to Control Servo Motor with ESP8266 and Arduino IoT Cloud | Arduino IoT Cloud Projects
How to Control Servo Motor with ESP8266 and Arduino IoT Cloud | Arduino IoT Cloud Projects

Components Required

  • ESP8266 nodemcu board
  • Servo motor
  • Jumper wires
  • USB cable for uploading the code
  • Breadboard

Components Table/buy link

You can buy the whole components from the given link we have to share the amazon link. from where you can get a good discount on the components for this esp8266 tutorial.

Step 6: Upload Your Program

  1. Goto Tools
  2. Board > NodeMCU 1.0 (ESP – 12E Module)
  3. Port ( Choose the right Port )

**Make sure you have your NodeMCU model selected and the correct serial port ticked (see pics).

Then just click the Upload button**

Ready To GO

Participated in the Makerspace Contest 2017

In this tutorial, we will learn how to control a small servo-motor. If you want to control the position of a mechanism, just have to use this tutorial. Good for beginners who want to make stuff move without building a motor controller with feedback & gearbox, especially since it will fit in small places

Parts Required

To build the global setup you must have the following parts:

  • ESP8266 NodeMCU v1.0;
  • Micro-USB to USB cable;
  • Servo sg90;
  • Male to male jumper wires;
  • 1 Breadboard;

Note: You do not need to have a NodeMCU board nor an ESP8266 to follow this tutorial. I am using this board because it is very famous and also because, I will post future tutorials using wifi communications. In order to use other boards, you just have to change the pin number.

Servo SG90

This SG90 is a very good quality motor widely used in RC aeromodelling projects, Arduino, Raspberry etc. Is tiny and lightweight, but with high output power. A Servo can rotate approximately 180 degrees (90 in each direction) and works just like another Servo.

Where we have the servo especifications:

  • Vcc voltage: 3,0 – 7,2V;
  • Degree of freedom/rotation: 180 graus;
  • Speed: 0,12 seg/60º without load;
  • Torque: 1,2 kg.cm (4,8V) and 1,6 kg.cm (6,0V);
  • Temperature: -30C ~ +60C;
  • Dimentions: 32 x 30 x 12mm;
  • Weight: 9g.

The servo is very simple to operate, but it is not just plugged and play. In figure 2, we have the servo-motor pinout. The red one is for Vcc, the black/brown is for Gnd and the yellow/orange is for the signal that controls the position.

The signal that we send to the servo is called a PPM signal is one of the radio receiver protocols used in RC Devices to transfer data. It is a signal similar to PWM, but with some differences. In figure 3 we can see an example of a PPM signal used by our servo motor and the times required to build the signal.

To generate this signal, we need to choose a pin in our NodeMcu, that support PWM. Despite the fact, that this signal is not a PWM, the PPM signal uses the same timers that are present in PWM pins, like in figure 4.

Circuit

Connect the signal cable (Yellow) to GPIO pin 2 (D4) because it is a PWM pin, Vcc (Red) to 3.3V and GND (Black), as figure 5. Everything will be powered from your PC using micro-USB to USB cable. In this configuration, the servo will be powered directly from the GPIO 2 pin with 3.3V. It is low voltage level but it works. All the current for the will be drawn from the board, and since each GPIO delivers only no more than a few mA, the torque can be low. Let’s try it.

Coding

Copy the main sketch below to your Arduino IDE project and save it. The Servo.h library is already included in the Arduino IDE. Have fun!!


#include < Servo.h> Servo servo; int val; void setup() { Serial.begin(115200); servo.attach(2); // attaches the servo on pin D4 to the servo object servo.write(0); } void loop() { // main program loop servo.write(90); delay(1000); for(val = 0; val <= 180; val++){ servo.write(180); // sets the servo position according to the scaled value Serial.print("Angle:"); Serial.println(val); delay(1000); // waits for the servo to get there } for(val = 180; val >= 0; val--){ servo.write(0); // sets the servo position according to the scaled value Serial.print("Angle:"); Serial.println(val); delay(1000); // waits for the servo to get there } }

In this tutorial ESP8266 we will see How to control Servo motor using NodeMCU web server? where the position of the Servo Motor can be controlled through a Web Page (within the same WiFi Network).

Introduction

Servo Motors are one of the most commonly used motors in both industries and DIY Projects.

I’ll be creating a simple Web Page (HTML) with a circular knob. When this web page is accessed from a laptop or mobile phone that is connected to the same WiFi Network as the ESP8266, you can control the position of the Servo Motor by adjusting the knob.

Web Controlled Servo using ESP8266

Normally, in order to control a Servo Motor with Arduino (for example), all you need is a Servo Motor, Arduino and a Potentiometer. Depending on the position of the POT, the PWM value of the Servo Motor input changes and consequently the position of the Servo Motor’s shaft changes.

In case of a Web Controlled Servo Motor using ESP8266, ESP8266 drives the Servo Motor but the input isn’t from a POT but a Web Page we created with AJAX.

The slider in the web page sends the angle values and is received by the NodeMCU, which acts as a Web Server. The NodeMCU, upon receiving the value, transmits corresponding PWM to servo, which then changes the position of the Servo Motor according to the value.

One important thing to remember here is that both the Server and client should be on the same network i.e. the ESP8266, which acts as the Server, and the Laptop (or a Mobile Phone), which is the client, must be connected to the same WiFi network.

Circuit Diagram

The circuit diagram for Web Controlled Servo using ESP8266 WiFi Module is given in the image below.

Components Required

  1. ESP8266 based Board (NodeMCU)
  2. Servo Motor
  3. Jumper Wires
  4. Laptop

Working of the Circuit

The main program responsible for everything i.e. connecting ESP8266 to WiFi, getting information from Web and finally controlling the Servo.

Pin D5 of NodeMCU will provide the necessary PWM signal to the Servo (Orange). Its other pins are power supply pins and are connected to 5V and GND (Red and Brown).

ESP8266 Servo Arduino Code

The Arduino IDE Code for the Web Controlled Servo using ESP8266 tutorial is given below.

Program is divided in tow parts Web Page (index.h) and Main Hardware Code ESPservo.ino

ESPservo.ino

before uploading code make changes in SSID and Password as per your wifi

/* * ESP8266 Servo Motor Control With Web Server * https://circuits4you.com */ #include

#include

#include

#include “index.h”; #define LED 2 #define ServoPin 14 //D5 is GPIO14 //WiFi Connection configuration const char *ssid = “your-ssid”; const char *password = “your-password”; Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards ESP8266WebServer server(80); //================================================ void handleServo(){ String POS = server.arg(“servoPOS”); int pos = POS.toInt(); myservo.write(pos); // tell servo to go to position delay(15); Serial.print(“Servo Angle:”); Serial.println(pos); digitalWrite(LED,!(digitalRead(LED))); //Toggle LED server.send(200, “text/plane”,””); } void handleRoot() { String s = MAIN_page; //Read HTML contents server.send(200, “text/html”, s); //Send web page } //================================================ // Setup //================================================ void setup() { delay(1000); Serial.begin(115200); Serial.println(); pinMode(LED,OUTPUT); myservo.attach(ServoPin); // attaches the servo on GIO2 to the servo object //Connect to wifi Network WiFi.begin(ssid, password); //Connect to your WiFi router Serial.println(“”); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(“.”); } //If connection successful show IP address in serial monitor Serial.println(“”); Serial.print(“Connected to “); Serial.println(ssid); Serial.print(“IP address: “); Serial.println(WiFi.localIP()); //IP address assigned to your ESP //Initialize Webserver server.on(“/”,handleRoot); server.on(“/setPOS”,handleServo); //Sets servo position from Web request server.begin(); } //================================================ // LOOP //================================================ void loop() { server.handleClient(); } //================================================


index.h

Press Ctrl+Shift+N give name index.h and copy paste below code.

const char MAIN_page[] PROGMEM = R”=====(

<br /> ESP8266 Servo | Circuits4you.com<br />

Circuits4you.com

ESP8266 Servo Motor Control Demo
Servo Angle




)=====";

Working of Web Controlled Servo using ESP8266

Let us now see the working of the Web Controlled Servo using ESP8266. After making all the connections as per the circuit diagram, upload the NodeMCU code.

After the code is uploaded, if you open the serial monitor, you can see the status of the ESP8266 WiFi Module. After all the initialization steps are done (set mode to Station mode, connect ESP8266 to WiFi and start web server), you can proceed for Web Control.

Now Get IP address of ESP8266 from serial monitor and open it using any web browser. If everything is right, when you change the position of the slider, the position of the servo Motor will be changed.

Applications

The idea behind Web Controlled Servo using ESP8266 is to implement a web-controlled device (in this case, a Servo Motor) i.e. to control a motor through internet.

This application can be further extended to more advanced and complex projects like controlling a Robot from the Internet.

In this tutorial, we will learn how to use a Servo Motor.

A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration.[1] It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors.

Servomotors are not a specific class of motor although the term servomotor is often used to refer to a motor suitable for use in a closed-loop control system.

How to control Servo with ESP 8266 NodeMCU | 4 Servo Control | iot project
How to control Servo with ESP 8266 NodeMCU | 4 Servo Control | iot project

Programming

This is the time to setup Arduino with NodeMCU and Servo Motor.Download the code from this Github link. Once downloaded, open it up in the Arduino IDE. Then Create a new sketch and hit Upload.

Program working#include

// Include the Servo library

Servo servo;

void setup() {

servo.attach(2); // We need to attach the servo to the used pin number

servo.write(0);

delay(2000);

void loop() {

servo.write(0); // Make servo go to 0 degrees

delay(1000);

servo.write(90); // Make servo go to 90 degrees

delay(1000);

servo.write(180); // Make servo go to 180 degrees

delay(1000);

Once the code is uploaded, the motor starts to function as shown in below diagram.

Hardware components
Software apps and online services

In this project we use ESP8266 in its NodeMCU form factor as a webserver and to create a webform to control the current position of the servo motor.

All the data of the webserver are saved on the SPIFFS memory of ESP8266.

What is SPIFFS?

SPIFFS is the original filesystem and is ideal for space and RAM constrained applications that utilize many small files and care about static and dynamic wear levelling and don’t need true directory support. Filesystem overhead on the flash is minimal as well. On the NodeMCU we have 4MB of flash out of which we can the size of the SPIFFS filesystem. In this project all the webserver files including html, css, and javascript are saved on a folder named data which is the folder name required for uploading to ESP8266 with SPIFFS uploader.

I have a detailed tutorial about it in another project. Check it out.

Hardware Setup

  • Start by placing the NodeMCU on a breadboard.
  • Place the servo motor and make the connections as shown.
  • Connections.

3V3V ➡ VCC

GND ➡ GND

SIGNAL ➡ D2

Software Setup

  • Visit my GitHub page and download the necessary files.
  • Download ESPAsyncWebServer library
  • Download ESPAsyncTCP library
  • Install libraries.
  • Download ESP8266 Filesystem Uploader
  • Install the libraries and Filesystem uploader as shown below.
  • Compile the code and upload.
  • Go to tools and use ESP8266 Sketch Data Upload tool to upload sketch data.

Changetheselinesofcodeasperyours:

GitHub Repository link

const char *ssid = "REPLACE_WITH_YOUR_SSID"; const char *password = "REPLACE_WITH_YOUR_PASSWORD"; const uint8_t servoPin = D4;

https://github.com/rahuladitya303/ESP8266_SERVO_CONTROLLER.git

For more details about how to install libraries and filesystem uploader checkout my other project

https://create.arduino.cc/projecthub/rahuladitya303/esp8266-weather-station-with-spiffs-c01037

ESP8266 with servo motor | Control servo motor with esp8266

Table of Contents

Step 5: Coding Time

The next step is to write some code to control the Servo.

Download the "Servo.ino" file and open it up in the Arduino IDE. Then Create a new sketch and paste the code below in the arduino IDE and hit Upload.

#include

Servo servo;

void setup() {

servo.attach(2); //D4

servo.write(0);

delay(2000);

void loop() {

servo.write(90);

delay(1000);

servo.write(0);

delay(1000);

The code will take a few minutes to upload and then you should see the Servo changing angle from 0° to 90° at the interval set in the code.

You can tinker with it if you like, or just use it as it is.

nodemcu servo motor control | esp8266 servo control | servo motor with nodemcu
nodemcu servo motor control | esp8266 servo control | servo motor with nodemcu

ESP8266 with servo motor Working

The main advantage of using a servo motor is that we can rotate it in any desired direction as per our needs.

A servo motor can rotate in very small as well as very large angles that are specified by us in the code.

  • when we make this nodemcu with servo motor We use to attach a function to specify the pin of the nodemcu on which the signal pin of the servo motor is connected.
  • The servo motor first comes to the zero position of the shaft and then after a delay of a second,
  • it will move the shaft to the middle position that is ninety degrees. A
  • gain after a delay of a second, the shaft will move to the position of the one-eighty degree.
  • We use the write function to move the shaft of the servo motor.
  • You can modify the values of the position according to you in the code.

You can also check the Robotic arm using servo motors made by us.

Two Types of Servo Motors

There are two types of servo motors that are available and used in the industrial field.

First is the AC servo motor. This type of servo is currently used today by most companies. AC servo motors are mostly used in industrial fields. AC servo motors are AC motors that rely on encoders. These types of servo motors work through controllers providing feedback and closed-loop control. They are known to function at a high accuracy and are easily controllable.

Second is the DC servo motor. These kind of servo motors were used in the past by Fuji Electric but are rarely used nowadays, as AC servo motors are easier to use, more effective, advanced, and reliable.

SERVO MOTOR NODEMCU Tutorial | Blynk app with SERVO MOTOR NODEMCU Project [Code & Libraries]
SERVO MOTOR NODEMCU Tutorial | Blynk app with SERVO MOTOR NODEMCU Project [Code & Libraries]

Step 3: Download Arduino IDE

To get started we need to download the Arduino IDE (Integrated Development Environment) and some necessary drivers.

  1. To download the software head over to the Arduino site: https://www.arduino.cc
  2. Click on Software Click on either Windows, Mac or Linux based on your Operating System.
  3. You can donate if you want or just download.
  4. When this is done, you will simply need to continue the steps to download it to your computer.
  5. You are done!

ESP8266 with servo motor Working

The main advantage of using a servo motor is that we can rotate it in any desired direction as per our needs.

A servo motor can rotate in very small as well as very large angles that are specified by us in the code.

  • when we make this nodemcu with servo motor We use to attach a function to specify the pin of the nodemcu on which the signal pin of the servo motor is connected.
  • The servo motor first comes to the zero position of the shaft and then after a delay of a second,
  • it will move the shaft to the middle position that is ninety degrees. A
  • gain after a delay of a second, the shaft will move to the position of the one-eighty degree.
  • We use the write function to move the shaft of the servo motor.
  • You can modify the values of the position according to you in the code.

You can also check the Robotic arm using servo motors made by us.

Servo Motors, how do they work?
Servo Motors, how do they work?

Connection to Servo

The next job is to connect your servo motor. There are two common types of servo:

  1. White – Red – Black wired servo
  2. Orange – Red – Brown wired servo

If your servo has White – Red – Black wires, then connect it as follows

  • White wire connects to Digital pin D4
  • Black wire connects to GND pin
  • Red wire connects to 3V3 pin

If your servo has Orange – Red – Brown wires, then connect it as follows

  • Orange wire connects to Digital pin D4.
  • Brown wire connects to GND pin
  • Red wire connects to 3V3 pin

ESP8266 with servo motor Code

NOTE: Please upload the code which is given below to the nodemcu. You may need to install

library to the IDE software. Check here how to add a zip library to the Arduino IDE.


//TECHATRONIC.COM #include

// servo library Servo s1; void setup() { s1.attach(0); // servo attach D3 pin of arduino } void loop() { s1.write(0); delay(1000); s1.write(90); delay(1000); s1.write(180); delay(1000); }

We hope that you understand this project and please try to make it on your own. If you have any doubts related to this project then ask them in the comments section below. Also, check out our tutorials on Arduino and Raspberry Pi.

Video sample

16 channel servo controller with Arduino | PCA9685 16 channel PWM servo motor driver tutorial
16 channel servo controller with Arduino | PCA9685 16 channel PWM servo motor driver tutorial

Mechanism

A servomotor is a closed-loop servomechanism that uses position feedback to control its motion and final position. The input to its control is a signal (either analogue or digital) representing the position commanded for the output shaft.

The motor is paired with some type of encoder to provide position and speed feedback. In the simplest case, only the position is measured. The measured position of the output is compared to the command position, the external input to the controller. If the output position differs from that required, an error signal is generated which then causes the motor to rotate in either direction, as needed to bring the output shaft to the appropriate position. As the positions approach, the error signal reduces to zero and the motor stops.

Purpose

Servo motors or “servos”, as they are known, are electronic devices and rotary or linear actuators that rotate and push parts of a machine with precision. Servos are mainly used on angular or linear position and for specific velocity, and acceleration.

Companies heavily use servo motors because of how compact and potent it is. Despite its size, it generates quite the amount of power and is known to be incredibly energy-efficient.

Most of the companies that use servos are manufacturing companies that need it to position control surfaces and rotate objects at precise angles and distances. Most of the companies that use servo motors are manufacturing companies that use machines with servo motors.

AC servo controlled with Arduino
AC servo controlled with Arduino

Introduction

Hey geeks, hope you are doing fine. Are you familiar with the working of a servo motor?

If not then this article is for you in which we are going to teach you how to Control servo motor with esp8266 using a nodemcu IoT development board.

Servo motor is different from an ordinary DC motor as it does not rotate continuously. You can also read our article on servo motor in which we explain the features and specifications of a servo motor.

It has an extra wire for the signal which is used to rotate the shaft in a specific direction. Also, do check out more such amazing projects on IoT and Arduino.

The detailed circuit diagram and code for the project are given below. The servo motor can also work well with the other microcontroller boards like Arduino and Raspberry pi, we have our articles on them also.

in this ESP8266 with servo motor tutorial we are going to explain how to work.

Step 4: Preparing the Arduino IDE

After downloading the Arduino IDE navigate to

  1. File tab and then click on Preferences.
  2. In the additional Boards Manager URLs add the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json)
  3. Click OK and then navigate to
  4. Tools - Boards - Boards Manager

In the search field type esp8266 > click the esp8266 by ESP8266 Community - Click Install

Now you have setup the Arduino IDE to work along with the NodeMCU.

How to control servo motors using ESP32 DEVKIT V1 board with Blynk app #sritu_hobby @sritu_hobby
How to control servo motors using ESP32 DEVKIT V1 board with Blynk app #sritu_hobby @sritu_hobby

Code

#define SW_VERSION "ServoCtrlBlynk_V.1" /*NodeMCU */ #include

char ssid [] = "Phamson"; char pass [] = "phamtheson"; /* Blynk */ #include

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space char auth [] = "6zCB6XaSV9PflOIBv7h1uOF7pgUV99t9"; // Servo Control Project // Servo Control Project /* OLED */ #include "SSD1306Wire.h" #include "Wire.h" const int I2C_DISPLAY_ADDRESS = 0x3c; const int SDA_PIN = 0; const int SCL_PIN = 2; SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN); /* Servo */ #define servo1Pin D2 #include

Servo servo1; /* Initial pot reading and servo position set the position to neutral */ #define potPin A0 int potReading = 1023/2; int servo1Angle = 90; /* Reads slider in the Blynk app and writes the value to "potReading" variable */ BLYNK_WRITE(V0) { potReading = param.asInt(); } /* Display servo position on Blynk app */ BLYNK_READ(V1) { Blynk.virtualWrite(V1, servo1Angle); } void setup () { Serial.begin(115200); servo1.attach(servo1Pin); displaySetup(); Blynk.begin(auth, ssid, pass); } void loop() { Blynk.run(); //PotReading = analogRead(potPin); // Read Analog data from potenciometer not used here servo1Angle = map(potReading, 0, 1023, 0, 180); // Map the pot reading to an angle from 0 to 180 servo1.write(servo1Angle); // Move the servo to a position displayAngle(); delay (200); } /* Initiate and display setup data on OLED */ void displaySetup() { display.init(); // initialize display display.clear(); // Clear display display.display(); // Put data on display } /* Display Servo position */ void displayAngle() { display.clear(); display.setFont(ArialMT_Plain_16); display.drawString(10, 0, "Servo Control"); display.drawString(0, 45, "POSITION:" ); display.setFont(ArialMT_Plain_24); display.drawString(80, 40, String(servo1Angle)); display.display(); }


Giải thích code

Khai báo Tài khoản và Mật khẩu Wifi.

char ssid [] = "Phamson"; char pass [] = "phamtheson";

Mã Token được cấp khi tạo mới Project trên Blynk.

char auth [] = "6zCB6XaSV9PflOIBv7h1uOF7pgUV99t9";

Đọc giá trị thanh trượt trên App Blynk và ghi giá trị vào biến “potReading”.

BLYNK_WRITE(V0) { potReading = param.asInt(); }

Hiển thị giá trị Servo trên App Blynk.

BLYNK_READ(V1) { Blynk.virtualWrite(V1, servo1Angle); }

Thư viện

Introduction: Interfacing Servo Motor With NodeMCU

HelloEverybody,

This here is my first Instructable project.

So you want to get started with NodeMCU? Well, I'm here to share with you.Today, I'm going to show you how to get started with NodeMCU. Let's GO !

NodeMCU has on board ESP8266-12E makes the board suitable for IoT (Internet Of Things). In this Instructable I will show you how to get started with Servo using NodeMCU.

Dynamixel AX-12A  Servo + NodeMCU ESP8266 + Blynk
Dynamixel AX-12A Servo + NodeMCU ESP8266 + Blynk

Step 3: Download Arduino IDE

To get started we need to download the Arduino IDE (Integrated Development Environment) and some necessary drivers.

  1. To download the software head over to the Arduino site: https://www.arduino.cc
  2. Click on Software Click on either Windows, Mac or Linux based on your Operating System.
  3. You can donate if you want or just download.
  4. When this is done, you will simply need to continue the steps to download it to your computer.
  5. You are done!

Sơ đồ nguyên lý

Các linh kiện cần thiết cho dự án

Tên linh kiện Số lượng Shopee
NodeMCU ESP8266 Mua ngay
Dây cắm (Đực – Đực) Mua ngay
Dây cắm (Đực – Cái) Mua ngay
OLED 0.96 Mua ngay
Servo SG90 Mua ngay
Biến trở 100k Mua ngay
Breadboard Mua ngay
Board nguồn (3.3V – 5V) Mua ngay
Arduino obstacle avoiding + voice control + Bluetooth control Robot | DIY Arduino Robot
Arduino obstacle avoiding + voice control + Bluetooth control Robot | DIY Arduino Robot

Bài viết liên quan

  • Hướng dẫn cài đặt ESP8266 và kết nối với Blynk
  • LED RGB sử dụng NodeMCU ESP8266 thay đổi màu sắc trên App Blynk
  • Giám sát nhiệt độ, độ ẩm bằng App Blynk sử dụng NodeMCU ESP8266
  • Cảnh báo trộm bằng cảm biến PIR (HC-SR501) thông qua App Blynk sử dụng ESP8266
  • Xác định khoảng cách khi đỗ xe bằng cảm biến HC-SRF04 sử dụng ESP8266 và App Blynk
  • Điều khiển động cơ Servo SG90 bằng App Blynk sử dụng NodeMCU ESP8266

The Purpose of Servo Motors

Technology has come a long way since the invention of the wheel in 3,500 B.C. Technological advancements have allowed humans to live and work more conveniently and more efficiently. With hundreds of thousands of technological breakthroughs throughout history, some of the most important everyday technologies have gotten lost in the shuffle and people have become unaware of their importance over time.Unbeknownst to most people, parts such as servo motors play a huge role in making people’s lives easier every day. Small technological pieces such as servo motors are heavily used daily in devices you least expect, as you’ll learn with the continuation of this article. It is also used in the industrial field including various of Fuji Electric’s products.Learn everything you need to know about servo motors - including its purpose, the list of everyday items and machines that operate using it, its advantages and disadvantages, and its parts and their functions.

How to setup & test ESP8266 with an Arduino UNO
How to setup & test ESP8266 with an Arduino UNO

Introduction: Interfacing Servo Motor With NodeMCU

HelloEverybody,

This here is my first Instructable project.

So you want to get started with NodeMCU? Well, I'm here to share with you.Today, I'm going to show you how to get started with NodeMCU. Let's GO !

NodeMCU has on board ESP8266-12E makes the board suitable for IoT (Internet Of Things). In this Instructable I will show you how to get started with Servo using NodeMCU.

nodemcu with servo motor Circuit Diagram

Connection Diagram

Nodemcu esp8266 Servo Motor
VV, Vin VCC
G, GND GND
D3 Pin Signal
  • The servo motor has three wires,
  • two for the power and one for the control signal.
  • You have to connect these three wires with the pins of the Nodemcu.
  • Connect the red wire with the 3.3 volts pin of the nodemcu.
  • Join the brown wire of the servo motor with the GND pin of the nodemcu.
  • Connect the signal wire (orange wire) of the servo motor with the digital-3 pin of the nodemcu.
  • After completing the connections use a USB cable to power the nodemcu so that the servo motor starts moving.

PCBWay PCB Prototyping Services

I have assembled the whole circuit on a breadboard. As you know breadboard assembly is not effective for this type of projects. So, PCBWay offers Rapid PCB Prototyping for Your Research Work. I personally, recommend PCBWay because you can get your first-try boards right in 24 hours!

The prototyping stage is the most critical period of time for engineers, students, and hobbyists. PCBWay not only makes your boards quick but also makes your job right as well as cost-effective. This greatly reduces your cost and shortens the time for developing your electronic products.

PCBWay can provide 2 Layer PCBs to highly advanced HDI and flex boards. Even though the PCBs they produce differ a lot regarding functionality and areas of use. I am impressed with the quality of the boards, the delivery time, and the cost-effectiveness.

Getting your Arduino online - Using the ESP-01 and Blynk
Getting your Arduino online - Using the ESP-01 and Blynk

Items that Use Servo Motors

Servo motors are utilized by items that are used every day. Home electronic devices like DVD and Blu-ray Disc players use servos to extract and retract disc trays.

Automobiles also use servo motors. In modern cars, servo motors are used to control its speed. When stepping on the gas pedal, it sends electrical signals to the car’s computer. The computer then processes that information and sends a signal to the servo attached to the throttle to adjust the engine speed. Even commercial aircrafts also make use of servos to push and pull everything within the plane.

They are also used for novelty items such as remote-controlled and scale-sized toy cars, toy airplanes, toy helicopters, and toy robots. Servos are especially helpful for radio-controlled airplanes to position control surfaces.

But servos are mostly used for industrial purposes. Important industries such as robotics, pharmaceutics, food services and in-line manufacturing also make use of servos.

Servos are also most-suited for electrically operated pieces of machinery such as elevators, rudders, walking robots, and operating grippers.

Step 2: Hardware Description

What is a Breadboard?

Its a prototyping platform, where you can plug components and remove them easily. Please refer to the photo to see how its made inside. There is usually 2 bands on each sides indicating the power rails. Its made to easily connect all of the (-) and (+) together.

What is a Servo?

Servo motors are great devices that can turn to a specified angle or called position.

Usually, they have a servo arm that can turn 180 degrees. Using the NodeMCU, we can control a servo to go to a specified position. As simple as that! Here we will see how to connect a servo motor and then how to turn it to different positions.

Connection to Servo

The next job is to connect your servo motor. There are two common types of servo:

  1. White - Red - Black wired servo
  2. Orange - Red - Brown wired servo

If your servo has White - Red - Black wires, then connect it as follows

  • White wire connects to Digital pin D4
  • Black wire connects to GND pin
  • Red wire connects to 3V3 pin

If your servo has Orange - Red - Brown wires, then connect it as follows

  • Orange wire connects to Digital pin D4.
  • Brown wire connects to GND pin
  • Red wire connects to 3V3 pin
Pan Tilt Control using Servos for ESP32 Cam |  WiFi Security Camera
Pan Tilt Control using Servos for ESP32 Cam | WiFi Security Camera

Step 2: Hardware Description

What is a Breadboard?

Its a prototyping platform, where you can plug components and remove them easily. Please refer to the photo to see how its made inside. There is usually 2 bands on each sides indicating the power rails. Its made to easily connect all of the (-) and (+) together.

What is a Servo?

Servo motors are great devices that can turn to a specified angle or called position.

Usually, they have a servo arm that can turn 180 degrees. Using the NodeMCU, we can control a servo to go to a specified position. As simple as that! Here we will see how to connect a servo motor and then how to turn it to different positions.

Connection to Servo

The next job is to connect your servo motor. There are two common types of servo:

  1. White - Red - Black wired servo
  2. Orange - Red - Brown wired servo

If your servo has White - Red - Black wires, then connect it as follows

  • White wire connects to Digital pin D4
  • Black wire connects to GND pin
  • Red wire connects to 3V3 pin

If your servo has Orange - Red - Brown wires, then connect it as follows

  • Orange wire connects to Digital pin D4.
  • Brown wire connects to GND pin
  • Red wire connects to 3V3 pin

Step 5: Coding Time

The next step is to write some code to control the Servo.

Download the "Servo.ino" file and open it up in the Arduino IDE. Then Create a new sketch and paste the code below in the arduino IDE and hit Upload.

#include

Servo servo;

void setup() {

servo.attach(2); //D4

servo.write(0);

delay(2000);

void loop() {

servo.write(90);

delay(1000);

servo.write(0);

delay(1000);

The code will take a few minutes to upload and then you should see the Servo changing angle from 0° to 90° at the interval set in the code.

You can tinker with it if you like, or just use it as it is.

How to Control Servo Motor Using Blynk IOT and ESP8266 | Servo Motor Control With Blynk
How to Control Servo Motor Using Blynk IOT and ESP8266 | Servo Motor Control With Blynk

Introduction

Hey geeks, hope you are doing fine. Are you familiar with the working of a servo motor?

If not then this article is for you in which we are going to teach you how to Control servo motor with esp8266 using a nodemcu IoT development board.

Servo motor is different from an ordinary DC motor as it does not rotate continuously. You can also read our article on servo motor in which we explain the features and specifications of a servo motor.

It has an extra wire for the signal which is used to rotate the shaft in a specific direction. Also, do check out more such amazing projects on IoT and Arduino.

The detailed circuit diagram and code for the project are given below. The servo motor can also work well with the other microcontroller boards like Arduino and Raspberry pi, we have our articles on them also.

in this ESP8266 with servo motor tutorial we are going to explain how to work.

Keywords searched by users: esp8266 servo control arduino ide

Esp8266 With Servo Motor | Servo Motor With Esp8266 | Esp8266 Tutorial
Esp8266 With Servo Motor | Servo Motor With Esp8266 | Esp8266 Tutorial
Servo Motor Control Using Esp8266 And Blynk App - Step By Step Instructions  - Sritu Hobby
Servo Motor Control Using Esp8266 And Blynk App - Step By Step Instructions - Sritu Hobby
Nodemcu (Esp8266) Control Servo Motor Basic Usage - Youtube
Nodemcu (Esp8266) Control Servo Motor Basic Usage - Youtube
Interfacing Servo Motor With Nodemcu : 6 Steps (With Pictures) -  Instructables
Interfacing Servo Motor With Nodemcu : 6 Steps (With Pictures) - Instructables
Arduino | Nodemcu Esp8266 / Esp12E Control Servo Via Local Web Server -  Youtube
Arduino | Nodemcu Esp8266 / Esp12E Control Servo Via Local Web Server - Youtube
Esp8266 Control Servo Node-Red Mqtt (Mosquitto) Iot : 6 Steps -  Instructables
Esp8266 Control Servo Node-Red Mqtt (Mosquitto) Iot : 6 Steps - Instructables
Servo Motor Control Using Esp8266 And Blynk App - Step By Step Instructions  - Sritu Hobby
Servo Motor Control Using Esp8266 And Blynk App - Step By Step Instructions - Sritu Hobby
Esp8266 Nodemcu Web Server: Stepper Motor (Websocket) | Random Nerd  Tutorials
Esp8266 Nodemcu Web Server: Stepper Motor (Websocket) | Random Nerd Tutorials
Control Servo Using Ldr With Nodemcu : 4 Steps (With Pictures) -  Instructables
Control Servo Using Ldr With Nodemcu : 4 Steps (With Pictures) - Instructables
Nodemcu Web Server Controlled Servo Motor
Nodemcu Web Server Controlled Servo Motor
Esp8266 Servo Controller - Hackster.Io
Esp8266 Servo Controller - Hackster.Io
How To Use Blynk With Nodemcu Esp8266 And Arduino Ide Servo Motor Control  Using Blynk #Iot - Youtube
How To Use Blynk With Nodemcu Esp8266 And Arduino Ide Servo Motor Control Using Blynk #Iot - Youtube
Nodemcu (Esp8266) Control Servo Motor Basic Usage - Youtube
Nodemcu (Esp8266) Control Servo Motor Basic Usage - Youtube
Esp32 Servo Motor Web Server With Arduino Ide | Random Nerd Tutorials
Esp32 Servo Motor Web Server With Arduino Ide | Random Nerd Tutorials

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *