Virtual IoT With Proteus and Blynk : Servo Motor Speed Monitor

Introduction: Virtual IoT With Proteus and Blynk : Servo Motor Speed Monitor

About: An Assistant Lecturer in Faculty of Engineering. An MSc. holder in #Mechatronics, Ain Shams University. #MCPD, #CLAD and ISTQB CT. #Kinect #WPF #LabVIEW #wpdev


This is my second tutorial showing how to make use of Blynk app with the state of the art Proteus ISIS to build virtually any IoT mobile connected app without even buying an Arduino board. Not only this, but also testing all available sensors on Proteus.

To show how amazing to blend Blynk with Proteus, you will learn how to change the speed of a simulated servomotor while reading the feedback Revolutions Per Minute (RPM) speed of the mounted quadrature encoder.

Before you begin, I recommend you take a glimpse at my instructable for using Blynk with simulated LEDs

Components list with references

  • Arduino Uno (project clip).
  • L293 : which is used to drive DC motor. In summary, you can not connect any motor directly to Arduino since the sourcing current /voltage won't be enough to drive it. Hence L293 allows you to do that easily.
  • DC motor with quadrature encoder: You will learn how to control moor speed by means of Pulse Width Modulation (PWM) and read the current speed of motor with double resolution by XORing the ouptut from both encoder channels.
  • Frequency counter : to display the number of feedback pulses per second. It should return double the resolution set on servo properties on Proteus.
  • COMPIM : for connecting Proteus to Blynk server
  • Virtual Serial Port Software : for creating two virtual com ports, one to be set on COMPIM in Proteus, the other will be used when running blynk USB-ser.bat script

Each linked text will lead you to well tutorials to understand how to use each component from practical perspective.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Build Proteus Model

One of the worthy powers of the new version of Proteus is the ability to save portion of your circuit to be reused in other projects. This is know as project clips

  1. Import Arduino 328 (UNO) from project clip.
  2. I have already spared your effort and created a project clip of DC motor , frequency counter, XOR circuit and terminal connection with Arduino. You can find it under the name "Servo Motor.pdsclip". Use import project clip to bring it to your schematic.
  3. Another time saving clip snippet is "Arduino COMPIM.pdsclip" for direct connection of COMPIM with Arduino.

Step 2: Create Connected Pair of Virtual COM Ports

Use any virtual com port emulators to commit this step. I used fabulatech virtual serial port kit

  • COM1 : will be selected in COMPIM component.
  • COM2 : will be used later when running blynk USB-Serial script.

Step 3: Configure Servo Motor Properties

You can set the number of pulses/rev generated from each encoder pin. I chose the default of 24 PPR. Since xor is used, the actual encoder output will be 48 pulses per revolution.

Step 4: Arduino Code

If you look at the Arduino code, you can easily distill it into portions:

  1. Reading Motor Speed from Blynk App: This is done via using Virtual Pin. V1 is used to get the PWM value (0-100), and then map it to PWM Arduino range (0-255).
  2. Fetching encoder pulses via two interrupt pins. storing value in counter.
  3. Using timer to calculate the actual speed (count/time)
  4. Calculate actual RPM and send it to V2 vierual pin which is assigned to Blynk gauge.

Note : Gauge is heavily commented and if you can't grasp any part of it, just leave a comment and I'll happily respond on weekends.

<p>/****************************************************************************************<br> *  Code is based on Blynk USB-Serial Example
 *  Make sure you go to C:\Users\Your Username\Documents\Arduino\libraries\Blynk\scripts
 *  Press CTRL + LMouse Button and select Open Command Windows Here
 *  Then type in command windws >> blynk-ser.bat -c COM2 and click enter
 *  Enjoy the Virtual IoT !!!
#include <BlynkSimpleStream.h></p><p><blynksimplestream.h>#include <simpletimer.h> <</simpletimer.h></blynksimplestream.h>SimpleTimer.h>        //Timer to update encoder count</p><p>// Pin Assignments
int  pinMotor=10;                                   // PWM Pin for Motor Speed.
int  pinEncoder=2;                                 //  Pin to receive XORed (double resolution) encoder pulses.
volatile unsigned int counter=0;                  //   Counter to hold counted pulses.
unsigned int motorSpeedRPM=0;                    //    Calculated motor speed from encoder value.
SimpleTimer timer;                              //     Timer object for polling counter value every 1 sec.
const long udpateInterval=1000L;               //      Timer update value (1000 ms)
const float pulsesPerRevolution=24*2.0;  //       Pulses per revolution (Servo Motor-Proteus)</p><p>//Your app authentication token (can be fetched from your blynk app
char auth[] = "2273348720d2405c92584041e6914e5b";</p><p>// This function sends Arduino's up time every 1 second to Virtual Pin (2).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void updateSpeedEvent()
  motorSpeedRPM=((counter/(udpateInterval/1000.0))*60.0)/pulsesPerRevolution; //RPM speed
  Blynk.virtualWrite(V2, motorSpeedRPM); //send RPM value to gauge
  counter=0; //reset counter;
}</p><p>void setup()
  //Set the Motor pin as output
  //Set Encoder pin as input
  // Blynk will work through Serial
  Blynk.begin(auth, Serial);</p><p>  // Setup a function to be called every 1 sec.
  timer.setInterval(udpateInterval, updateSpeedEvent);</p><p>  // Interrupt for accurate counting of encoder pulses
  attachInterrupt(digitalPinToInterrupt(pinEncoder), encoderCounter, RISING);
}</p><p>// This function corresponds to changes in slider 
// Which will change motor speed via PWM
  int motorSpeed = param.asInt(); // assigning incoming value from pin V1 to a variable
  analogWrite(pinMotor,map(motorSpeed,0,100,0,255)); //Map motor slider (0-100)==>(0-255)
}</p><p>void loop()
  // All the magic is here;; // Initiates SimpleTimer
}</p><p>// Interrupt Service Routine (ISR)
void encoderCounter()
    counter+=1; //a pulse received

Step 5: Ready, Set, Go !

Now you are ready to carry the normal Blynk connection like any peroject. I used local server on my PC but you can do the same using Blynk cloud server. Project files are included.

How about building a PID position controller for that servo motor? this is my upcoming video. So, stay tuned!

Maker Olympics Contest 2016

Participated in the
Maker Olympics Contest 2016

Be the First to Share


    • Magnets Challenge

      Magnets Challenge
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest