Introduction to IoT using Arduino

Posted by Momen 03/06/2017 0 Comment(s) Microcontrollers,

Welcome to Zeroohm Arduino Training series. In this series of Arduino Training, Zeroohm will focus its efforts on helping the community learn more about Arduino fundamentals and basics starting with basic control of LED's, motors, sensors and utilizing of wirless communication. We hope that you find this useful, Please, leave a comment for any questions or comments or reviews!

We provide all our trainings for groups from schools, universities, public sector and private sector in Abu Dhabi, Dubai, Sharjah, Fujirah, RAK or anywhere in UAE. Please,click here to contact us directly for any training inquires.

We are also an authorized Arduino distributor for the UAE, Oman, Qatar, Saudi, Kuwait and Bahrain. We can provide you with any product of your choice. Please, contact us for inquires.

- See more at: https://www.zeroohm.com/blog/arduino-begginer-training/#sthash.kuumgqkT.dpuf

internet-of-things-IoT

 

Welcome to Zeroohm Arduino Training series. In this series of Arduino Training, Zeroohm will focus its efforts on helping the community learn more about Arduino fundamentals and basics starting with basic control of LED's, motors, sensors and utilizing of wirless communication. We hope that you find this useful, Please, leave a comment for any questions or comments or reviews!

We provide all our trainings for groups from schools, universities, public sector and private sector in Abu Dhabi, Dubai, Sharjah, Fujirah, RAK or anywhere in UAE. Please,click here to contact us directly for any training inquires.

We are also an authorized Arduino distributor for the UAE, Oman and Qatar. We can provide you with any product of your choice. Please, contact us for inquires.

Our internet of things (IoT) training series:

1. Introduction to IoT using Arduino

2. IoT: Humidity and Temperature Sensor

3. ESP8266 WiFi Controlled Home Automation

4. IoT: Smart Doorbell

 

Objectives:

We aim to let you get familiar with IoT Applications with Arduino:

  • Understanding Arduino, and how it works.
  • Learning how to use the Android app Blynk to control arduino Inputs and Outputs.
  • Learning how to write a Arduino Blynk Code.

 

Get Started:

First, we start by downloading the Blynk app and install the library, to do so, follow these steps:

  1. Download Blynk app on your mobile from Google play or Apple store.
  2. Create a new account in Blynk App.
  3. Create a New Project. Then choose the board and connection you will use.
  4.  After the project was created, you will received  Auth Token over email.
  5.  Check your email inbox and find the Auth Token.
  6.  copy and paste it on the required field in Arduino IDE.

 

Now install Blynk library:

  • download the library from here:                    

          https://github.com/blynkkk/blynk-library/releases/tag/v0.4.7

  • Download the latest release .zip file.
  • Unzip it. You will notice that archive contains several folders and several libraries.
  • Copy all these libraries to C:\Program Files (x86)\Arduino\libraries.

If you don't have a WiFi shield or Module, you can use Blynk App through your PC/Laptop Internet Connection Using the simple USB cable of the Arduino. To do So:

4.  After writing the code in Arduino IDE (Which you'll do in the expermionts below) and making upload , run “ command prompt “

5.  Run the blynk-ser script, located in scripts folder:

         Windows: My Documents\Arduino\libraries\Blynk\scripts

         Mac: ~/Documents/Arduino/libraries/Blynk/scripts

          Linux: ~/Arduino/libraries/Blynk/scripts

6. Copy the path of it and paste it on the “ command prompt “ after typing “ cd “ then press inter.

7.  Type

blynk-ser.bat -c COM4 

then press Enter , after this step the Blynk app connected to the internet th and ready to use it. 

Note : the number followed “ COM “ depend on the port which the USB connected , it shown in the right bottom in the Arduino IDE .

 

Experiment 1: LED blinking using blynk

A light-emitting diode (LED) is a semiconductor device that produces light from electricity.  LEDs last a long time and do not break easily compared to incandescent light bulbs. They can produce many different colours.

In this task you will control the switching of an LED by the following steps:

  1. Connect the following Circuit using the shown components in Fig1.

connect LED to Arduino

  1. Open Arduino IDE software and start writing the following code:

#define BLYNK_PRINT SwSerial

#include <SoftwareSerial.h>

SoftwareSerial SwSerial(10, 11);    

#include <BlynkSimpleStream.h>

char auth[] = "YourAuthToken";            // You should get Auth Token in the Blynk App.

WidgetLED led1(V1);

BlynkTimer timer;

 

void blinkLedWidget()                             // V1 LED Widget is blinking

{

  if (led1.getValue()) {

    led1.off();

    SwSerial.println("LED on V1: off");

  } else {

    led1.on();

    SwSerial.println("LED on V1: on");

  }

}

void setup()

{

  SwSerial.begin(9600);                         // Blynk will work through Serial

  Serial.begin(9600);

 Blynk.begin(Serial, auth);

  timer.setInterval(1000L, blinkLedWidget);

}

void loop()

{

  Blynk.run();

  timer.run();

}

  1. Check that your code is correct and upload it to the Arduino.
  2. Choose button on blynk App , click on it and choose V1 as pin .
  3. Notice what happens to the LED.

Discussion :

  • In order to notice the blinking of the LED we set a delay period between the two actions of turning the LED ON and OFF, we use the timer.setInterval() function; which pauses the program for the amount of time (in milliseconds) specified as parameter, there are 1000 milliseconds in a second.
  • Serial function is used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port, It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB.

 

Experiment 2: Servomotor using blynk

A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration.  It consists of a suitable motor coupled to a sensor for position feedback.

In this task you will control the servomotor rotation using potentiometer by the following steps:

  • Step 1: Connect the following Circuit using the shown components in Fig2

connect servo to Arduino

  • Step 2 : Open Arduino IDE software and start writing the following code:

#define BLYNK_PRINT SwSerial

#include <SoftwareSerial.h>

SoftwareSerial SwSerial(10, 11); // RX, TX

#include <BlynkSimpleStream.h>

#include <Servo.h>

char auth[] = "2f6a6ef0529e44098192f2dec082e51a";

Servo servo;

BLYNK_WRITE(V3)

{

  servo.write(param.asInt());

}

void setup()

{

  SwSerial.begin(9600);

  Serial.begin(9600);

  Blynk.begin(Serial, auth);

  servo.attach(9);

}

void loop()

{

  Blynk.run();

}

 

  1. Check that your code is correct and upload it to the Arduino.
  2. Choose slider on blynk App , click on it and choose V1 as a pin , rotate it to left and right.
  3. Notice what happens to the servo .

 

Discussion:

  •  servo.write() Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).

 

Experiment 3: LCD using blynk

The LCD can be used to display alphanumeric characters.

 In this task you will control the LCD and write on it any sentence you want using Blynk by the following steps:

  1. Connect the following Circuit using the shown components in Fig3

connect LCD to Arduino

 

  1. Open Arduino IDE software and start writing the following code:

#define BLYNK_PRINT SwSerial

#include <SoftwareSerial.h>

SoftwareSerial SwSerial(10, 11);

#include <BlynkSimpleStream.h>

char auth[] = "YourAuthToken";

BLYNK_READ(V0) {

  Blynk.virtualWrite(V0, millis() / 1000);

}

BLYNK_READ(V1) {

  Blynk.virtualWrite(V1, millis());

}

void setup()

{

  SwSerial.begin(9600);

  Serial.begin(9600);

  Blynk.begin(Serial, auth);

}

void loop()

{

  Blynk.run();

}

 

  1. Check that your code is correct and upload it to the Arduino.
  2. Choose LCD on blynk App.
  3. Read what’s written on the LCD .

 

Experiment 4: RGB LED using blynk

RGB LED : means red, blue and green LEDs. RGB LED products combine these three colors to produce over 16 million hues of light, Some colors are “outside” the triangle formed by the RGB LEDs. Also, pigment colors such as brown or pink are difficult, or impossible, to achieve.

  1. Connect the following Circuit using the shown components in Fig 4

 

connect RGB to Arduino

  1. Open Arduino IDE software and start writing the following code:

#define BLYNK_PRINT SwSerial

 

#include <SoftwareSerial.h>

SoftwareSerial SwSerial(10, 11);

   

#include <BlynkSimpleStream.h>

char auth[] = "YourAuthToken";

WidgetLED led1(V1);

BlynkTimer timer;

bool ledStatus = false;

#define BLYNK_GREEN     "#23C48E"

#define BLYNK_BLUE      "#04C0F8"

#define BLYNK_YELLOW    "#ED9D00"

#define BLYNK_RED       "#D3435C"

#define BLYNK_DARK_BLUE "#5F7CD8"

 

void blinkLedWidget()

{

  if (ledStatus) {

    led1.setColor(BLYNK_RED);

    SwSerial.println("LED on V1: red");

    ledStatus = false;

  } else {

    led1.setColor(BLYNK_GREEN);

    SwSerial.println("LED on V1: green");

    ledStatus = true;

  }

}

 

void setup()

{

  SwSerial.begin(9600);

  Serial.begin(9600);

  Blynk.begin(Serial, auth);

  led1.on();

  timer.setInterval(1000L, blinkLedWidget);

}

void loop()

{

  Blynk.run();

  timer.run();

}

  1. Check that your code is correct and upload it to the Arduino.
  2. Choose zeRGBa on blynk App , and choose D7 for red , D8 for blue and D9 for green .
  3. Notice what happens to the LED .

Leave a Comment