Servo Motor Control with Bolt IoT

Ever had to work with a project where you had moving parts?

No, I mean quite literally moving parts which you had to control, using some form of a servo motor?

moving parts

 

If you have worked with motors and especially servo motors in the past, then you know the pain which in involved in designing the circuit that can control these motors. For the newbie, servo motors are a class of motors where you can tell the motor, what position it should move to or what speed it should move, and it's internal mechanism uses some form of feedback to ensure that the required position or velocity is achieved. This help in reducing your efforts in ensuring that that work you have given the motor is done.

servo control

There are quite a few type of servo motors available in the market, but some of the most popular servo motors allow you to control their position or velocity by having to pass to them pulse width modulated (PWM for short) signal. Checkout the photo below for an example of such a motor.

how-servo-motors-work-fig3

The way you tell these motors what angle (position) it should try to maintain, you have to send it a PWM signal every 20 ms, where the width of the pulse is proportional to the angle which you want the motor to stop at. To set an angle of 0 degrees, you will send a high signal for 1 ms, and a low signal for 19 ms, and to set an angle of 180 degrees, you will send a high signal for 2 ms and a low signal for 18 ms.

giphy

If these calculations are too confusing for you, then don't bother about it, as the Bolt IoT platform, has simplified this by giving a new API for it's latest firmware update '1.4.1', and you can use the steps in this blog to quickly control your servo motor.

giphy

NOTE: To be able to use this feature, you have to subscribe to the Bolt Cloud Pro plan. Click here to upgrade your account now.

Hardware setup:

The servo motor should have three wires coming out of it which may be Black(GND), Red(5V) and White(PWM input) in colour.

Connect the jumper cables from the Servo motor to the Bolt device in the fashion given below:

  • Bolt  device<-- --> Servo motor
  • 5V <-- -- Red Wire
  • GND <-- -- Black Wire
  • Digital Pin 0 -- --> White Wire

For further clarity, refer to the Fritzing diagram.

Power up the system, by connecting the micro USB to the device.

Building the API link:

To be able to control the servo motor, you need to build a link which you should call to run the API.

In the case of the servo motor control, the link is of the form

https://cloud.boltiot.com/remote/<API key>/servoWrite?pin=<pin>&value=<angle>&deviceName=<device name>

To create a proper link, replace the following tags in the above link with the respective elements.

  • <API key> : Click here to get your API key.
  • <pin> : This is the pin of the Bolt WiFi module to which you connect the signal pin of the servo motor. In our case this is 0. ( Servo motor control is available on digital IO pins of the Bolt WiFi module).
  • <angle>: This is the angle which the Bolt WiFi module will relay to the servo motor. This angle can be between 0 and 180.
  • <device name>: This is the device id of the the Bolt and is of the form BOLTxxxxx.

Once the you finish building the link, it should look something like the following:

https://cloud.boltiot.com/remote/44b2de6b-7e68-40e7-a27f-814b58afe008/servoWrite?pin=0&value=0&deviceName=BOLT1257632

The above link will set the motor position to 0 degrees.


https://cloud.boltiot.com/remote/44b2de6b-7e68-40e7-a27f-814b58afe008/servoWrite?pin=0&value=90&deviceName=BOLT1257632

The above link will set the motor position to 90 degrees.


https://cloud.boltiot.com/remote/44b2de6b-7e68-40e7-a27f-814b58afe008/servoWrite?pin=0&value=180&deviceName=BOLT1257632

The above link will set the motor position to 180 degrees.

 

Running the API call:

To run the API call, simply run the paste the API link that we made earlier into the address bar of a browser, and click on go, and watch the servo motor move.

 

giphy

 

Gotchyas:

These are the things you have to remember while having to control a servo motor with the Bolt WiFi module.

  • This feature is only available for Bolt Cloud Pro users. Click here to upgrade to Bolt Cloud Pro.
  • The feature only works with for Bolt WiFi module which have a firmware version 1.4.1 and above. Click here to find out how to update your device firmware.
  • Servo motors generally require a bit of a kick when it comes to power supplies, so if your motor is not moving the way you want it, try using a power supply with a higher current rating. (Voltage rating should be 5v).

servo motor