Things used in this project

Code

blynk_servo.inoC/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

As4lz5rp
Daniel Oglvie
5 projects • 28 followers
Launchpad Engineer at Texas Instruments
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login