WiFi Enabled Arduino Over USB

by millerman4487 in Circuits > Arduino

7717 Views, 31 Favorites, 0 Comments

WiFi Enabled Arduino Over USB

IMG_20171228_124918611-01.jpeg

This project uses Blynk, which is a service you can use to connect WiFi enabled things to a server. You can control devices like the Raspberry Pi or a specialized SparkFun Blynk Board from an app on your phone. The boards mentioned already have built in wireless capabilities, but the Arduino is not meant to do that - at least not without some help.

If you have never used Blynk before, this will be helpful: http://www.blynk.cc/getting-started/

Install Necessary Software

Set Up the App

Screenshot_20171228-120729-01.jpeg
Screenshot_20171228-120718-01.jpeg

  1. Open the Blynk app
  2. Create a new project
  3. Give it a cool name
  4. Select the board "Arduino UNO"
  5. Set the connection type to USB
  6. Tap "Create" - It should send you an email with your Auth token (you'll need this later)
  7. Click run

At the top it will probably say that your board is offline, we'll fix that in the next step.

Upload and Run the Code

  1. Connect the Arduino board to your computer
  2. Navigate through the newly installed Blynk Library to find the Arduino code: Arduino > libraries > Blynk > examples > Boards_USB_Serial > Arduino_Serial_USB
  3. Change the "YourAuthToken" to the Auth token provided in the app:

char auth[] = "YourAuthToken"; 

- Once you change it, it might look like

char auth[] = "c3e7d746a05b4cah18723cbcb3631a97"; 

(I just made up some random stuff there - don't try using it for real)

Run the Blynk Script

  • With the Arduino code still going, run the .bat file located in: Arduino > libraries > Blynk > scripts. Type your serial port when it prompts you and press enter (Mine is COM3).

Open the app again and wait a little while. If it still doesn't come online, close the running .bat file and continue with the step below.

  1. Close the .bat file
  2. Edit blynk-ser.sh with wordpad (or something similar) located in: Arduino > libraries > Blynk > scripts - (you might need to change baud rate):
# === Edit default options to match your need === 
FROM_TYPE="SER" # SER, TCP 
TO_TYPE="SSL"   # TCP, SSL 
COMM_BAUD=9600
SERV_ADDR=blynk-cloud.com 
...
  1. Save the document and close it
  2. Run the .bat file again

If the app says everything is online, you can move on.

Add a Button

Screenshot_20171228-120849-01.jpeg
Screenshot_20171228-120859-01.jpeg
Screenshot_20171228-125050-02.jpeg
Untitled Sketch_bb.png

We will use a virtual button on your phone to control what we just made:

  1. Press the (+) button at the top and select a button widget
  2. Set the output to V0
  3. Press Run

Now we have to tell the Arduino to do something when you press the button:

  1. Close the .bat file
  2. In the void setup() section, add:
 pinMode(13, OUTPUT); 

Now scroll down to the bottom of the code and add this below the void loop() section:

BLYNK_WRITE(V0) {
 int pinData = param.asInt(); 
 digitalWrite(13,pinData); 
} 

Upload the code again and run the .bat file. Now when you press the button it should turn on the onboard led.

Going Further

If you want to do more than turn on an led, you can add these sections to your code to both send and receive data to your board:

How to send data (this is what you did before):

BLYNK_WRITE(V0) {
 int pinData = param.asInt(); 
 } 

How to recieve data:

  • Make a value display in the app and set the input to V5.
  • You can attach a button to the Arduino for example, and have the display tell you when the button is pressed by typing:

 pinMode(2, INPUT);

in void setup(). Use the code below in void loop():

BLYNK_READ(V5) { 
 int val = digitalRead(2); 
 Blynk.virtualWrite(5, val); 
}