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
Each linked text will lead you to well tutorials to understand how to use each component from practical perspective.
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
Use any virtual com port emulators to commit this step. I used fabulatech virtual serial port kit
If you look at the Arduino code, you can easily distill it into portions:
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 pinMode(pinMotor,OUTPUT); //Set Encoder pin as input pinMode(pinEncoder,INPUT); // Blynk will work through Serial Serial.begin(9600); 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 BLYNK_WRITE(V1) { 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 Blynk.run(); timer.run(); // Initiates SimpleTimer }</p><p>// Interrupt Service Routine (ISR) void encoderCounter() { counter+=1; //a pulse received }</p>
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!