Continuous Rotation Servo (CRS) Motor With Telegram Control

In this instructable I will teach you how to control a CRS via telegram. For this instructable you will need a couple of things. I will be working on a NodeMCU 1.0 (ESP-12E Module). This can work on other Arduino bords, you just need to find the proper drives for it.

The following was the setup enviroment for ESP-12E Module:

  • Windows 10
  • Arduino IE 1.8.7 (Windows Store 1.8.15.0)

A guide on how to install the drivers and core files for the ESP-12E Module can be found here:

Once you've done this. We're ready to go!

Step 1: Step 1: Components

For this tutorial you will need some components:

  • ESP12-E Module (ESP8266)
  • Continuous Rotation Servo Motor (this is the one I used)
  • Micro USB Cable
  • A Wifi Network
  • Telegram App
  • A Botfather Bot (don't worry, we'll get there)

Step 2: Step 2: Connect the Servo Motor

Follow this schematics to wire up the servo motor.

  • Black: GND (Ground)
  • Red: 3.3V or 5V (Power)
  • Yellow or White: Digital output (Signal)

So, if you are using the same servo motor I used and have a arduino board with a higher voltage (5V max) output, you can stick the powercable there. It will just mean the servo motor will produce more torque. Either way, 3.3V or 5V are both fine.

Step 3: Step 3: a Little Understanding

Before we start testing code and see if it works, there's something you need to understand about this servo motor. Since it isn't a conventional servo motor, which turns to specific angles, the code you need to use is a little different.

I do not recommend using the servo at full torque, since it creates a lot of heat and might consume a lot of the life that the product has. Try staying around the area of [60, 120].

void loop {
	myservo.write(90); // this means no movement, the servo motor is standing still
	delay(1000);
	
	myservo.write(0); //this means full speed counterclockwise movement  
	delay(1000);

	myservo.write(180); //this means full speed clockwise movement 
	delay(1000);
}

Step 4: Step 4: Add Code to Test the Servo Motor.

#include <Servo.h>
Servo myservo;


void setup() {
	myservo.attach(D5); //attach the servo on pin D5)
}

void loop() {
	myservo.write(85); //rotates the motor counterclockwise at slow speed
	delay(1000);

	myservo.write(120);
	delay(1000);

	myservo.write(90);
	delay(5000);
}

Step 5: Step 5: Preparing for Communication

To be able to communicate with you Arduino you'll need to fix a couple of things. They are pretty easy. We will divide this tasks in two small sections.

The bot

  1. Install Telegram on your mobile phone.
  2. Make an account on Telegram.
  3. Search the user 'Botfather'.
  4. Make a new bot using the commands he shows (save the key he gives you).

The Arduino tasks

  1. Open Arduino IE.
  2. Go to the 'Library Manager'.
  3. Add the library 'Universal Telegrambot'.
  4. Add the library 'ArduinoJson'.
    • Dont add the beta
    • Add the latest 5.x build there is.

Step 6: Step 6: Testing the Communication

We're almost there.

  1. Open 'echobot' out of the universaltelegrambot > esp8266 library.
  2. Change the wifi credentials to match your network at the place you are.
  3. Change the BOTtoken that the Botfather gave you.
  4. Add this line of code in the for loop that is in the `void loop();`

Serial.println(bot.messages[i].text);

Now we're ready to test.

Upload this code to your Arduino. Check in the serial monitor if you're NodeMCU is connecting to your wifi network. Once you see that it is connected, send a message to your bot. It should send you the exact same message back.

Step 7: Step 7: Adding the Commands

So, it worked! We got a connection in between devices. The next step is adding things together. So we're going to add commands to the existing echobot code. It might be a good idea to put the next code instead of the last code I gave you. So we'll prevent us from having a bot that behaves like a parrot.

This next piece of code needs to be in the for loop that loops through new messages. Depening on how you place the servo motor you might want to swap the 'Open' and 'Close' commands. Upload this to your esp8266 and check if it works.

//the command you want

if(bot.messages[i].text == "Open") {

// The answer your bot will give you
bot.sendMessage(bot.messages[i].chat_id, "I'm opening the curtains for you.");

// what the arduino board will do

myservo.write(80); // servo motor turns counterclockwise to open the curtains

}

if(bot.messages[i].text == "Stop") {
// The answer your bot will give you bot.sendMessage(bot.messages[i].chat_id, "Stopping the curtains."); // what the arduino board will do myservo.write(90); // servo motor stops turning }

if(bot.messages[i].text == "Close") {
// The answer your bot will give you bot.sendMessage(bot.messages[i].chat_id, "I'm closing the curtains for you."); // what the arduino board will do myservo.write(80); // servo motor turns clockwise to close the curtains }

Step 8: Step 8: Connect the Device to Your Curtains (not Necessary)

Yeeeey, you're done!

The instructions were on how to connect a Telegrambot to your Arduino so you could control it from a distance. But I made this special set-up to have a way of opening my curtains in my studio without having to physically open them. So if you would like to do the same as me, the last stap is to connect our little device to your curtains and voila.

Share

    Recommendations

    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Toys Contest

      Toys Contest
    • First Time Author

      First Time Author

    Discussions

    0
    None
    seamster

    4 weeks ago

    Welcome and thanks for sharing your first instructable! : )