Daniel Oglvie
Published

Spin a Servo from the Cloud! UIUC + TI

A collection of labs for the Texas Instruments + UIUC workshop. Spin a servo from the cloud with an MSP432 and Blynk!

BeginnerFull instructions provided2 hours2,436

Things used in this project

Story

Read more

Code

blynk_servo.ino

C/C++
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEnergiaWiFi.h>
#include <SimpleTimer.h>
#include <Servo.h>
Servo myservo;
int potpin = 2;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXXXXXX"; //Use your auth token from the app
SimpleTimer timer;
// Your WiFi credentials
char ssid[] = "WiFi SSID HERE";
char pass[] = "WiFi PASSWORD HERE";        // Set to "" for open networks

void setup()
{
  //Open a serial terminal with the PC
  Serial.begin(9600);   
  Serial.println("Begining...");
  //Set up a blynk connection with your WiFi credentials
  Blynk.begin(auth, ssid, pass);  
  Serial.println("Connected to Blynk...");
  while (Blynk.connect() == false) {
    // Wait until connected
  }
  myservo.attach(19);  
}

// Virtual Pin 1 - Toggles the LED high or low depending on the mobile app input
BLYNK_WRITE(V0)
{  
  int i = param.asInt();         //Read the X-Axis value and save it to the variable i
  BLYNK_LOG("Got a value: %s!", param.asStr()); 
  val = map(i, 0, 255, 0, 180);  // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);            // sets the servo position according to the scaled value 
}

// The main loop listens for commands from the mobile app
void loop()
{
  Blynk.run();
  timer.run();
}

Credits

Daniel Oglvie

Daniel Oglvie

6 projects • 35 followers
Launchpad Engineer at Texas Instruments

Comments