Have you ever wanted to make or experiment with an IoT device but don't have a microcontroller or shield that can connect to the internet? Well there's a solution for you; that is, connecting your microcontroller to the internet via a USB connection to your computer. This is quite a simple process, and I will try my best to explain this! We will be using Blynk, so no HTML, and will be going over set up, and using digital pins (With the LED) and virtual pins (With the servo).
However, if you do not understand this by the end of this project, don't give up! Keep looking for resources until you find something that you can grasp!
Part 1: Setting up the softwareFirst things first, and that is installing the Blynk app to your mobile device! This can be found on the iOS App Store or Google Play Store.
Next, install the Blynk Library to your Arduino IDE. This can be found here: http://www.blynk.cc/getting-started/. Also feel free to read some of the helpful advice on that page, or explore the Docs on the site.
Now, open the l example sketch, as shown in the picture:
There may be a change in positioning after this is posted; if so please say so in the comments.
In the example sketch, there should be full directions and instructions explaining what to do and what the important things do, please feel free to read through this as this is the setup process. I will also have a video explaining the set up process found here:
Part 2: Building the circuitFor this project, we will be building a very simple servo and LED circuit which can be found in the resources section of this project. These will be used to explain Digital and Virtual Pins in Blynk. If you do not have an LED and resistor, you can use pin 13 instead.
Part 3: The Fun Stuff! Writing Code and Playing with Blynk!Digital and Analog Pins
Making the LED blink is actually extremely simple with Blynk. For our purposes, simply create a button in the app and in it, set the pin to Digital D2 (or whatever pin you connected your LED to). This will directly turn on pin 2 on the Arduino whenever you press it without writing any additional code! Analog Pins use the same concept. Additional info here: http://docs.blynk.cc/#blynk-firmware-digital-analog-pins-control
If you do not have the supplies, you can use Digital D13 instead which will turn on the on-board LED.
Virtual Pins
Now, knowing this, we can do the same with servos right? Well, not exactly. As you might recall, servos are moved using the function Servo.write();
, and will move very erratically without it. So for this, we will be using Blynk's virtual pins which sends values from the app to the Arduino, we will then store and put that value into the Servo.write()
function.
In the app, create a slider and in it, set the pin to Virtual V1. Then add this into the example sketch (assuming you already created and attached the servo object):
BLYNK_WRITE(V1){
int value = param.asInt();
servoName.write(value);
}
What this is doing is basically, if V1 is called, then run whatever is in the code block. The param.asInt()
returns whatever integer value you gave it from the Blynk app, it's as simple as that! And one thing to remember is that this goes OUTSIDE the loop function as it is itself a function. Additional info here: http://docs.blynk.cc/#blynk-firmware-virtual-pins-control (I really recommend reading it). If you are confused, please read through the link above or look at the code provided.
We will store the value in the "value" variable and will be putting that into the Servo.write()
function to make the servo move.
Virtual Pins are designed to send any data from your microcontroller to the Blynk App and back and can be used to interface with libraries. (From Docs)
You can also use virtual pins to make the LED blink!
And that's it! Again, the code used is in the resources section. Once you are done with all this, upload the sketch to the Arduino, and connect the Arduino to the Blynk using the instructions provided in the example, or in the video above. Also, please read the important notes section of the project.
Important NotesWhenever you connect the Arduino to Blynk, I highly recommend pressing the reset button before making the connection, I find that this clears up any connection/lag issues. Also, give it at least 10 seconds to connect. If it does not connect, then restart the entire process again or make sure the app is set to whatever board you are using.
You'll need to redo the connection process every time you upload a new sketch to the Arduino or turn the Arduino off.
Comments