Control Devices using Cloudchip

We live in an exciting time where more and more everyday items “things” are becoming smart! “Things” have sensors and can communicate to other “things” and can provide control to more “things”. The Internet of Things, IoT, is upon us in a huge way and people are rapidly inventing new gadgets that enhance our lives. The price of microcontrollers with the ability to talk over a network keeps dropping and developers can now tinker and build things inexpensively.

Software Tools:

1.Arduino IDE

2.Cloudchip IoT Platform

Hardware Tools:

1. NodeMcu

2. 4 Channel Relay Module

3. Bulbs

Circuit:

 

Step1: Create a  Device in the Cloudchip

Step2: Create a Dashboard and add four control widgets (i.e, Switches) or else you can follow the guide of adding widgets to the Dashboard over here.

After creating four keys you need to change the “setValue Method”  name in widget settings. The procedure is shown below:

Click on the widgets edit option:

 

Click edit widget option:

Change the RPC setValue method  to Switch1 and save it.

Step 3: Give the connections as shown in the circuit and upload the code to the NodeMcu board.

Note: To run the code you need to have the cloudchip libraries integrated to the Arduino. To know the steps of installing Cloudchip Arduino libraries and integrating to arduino you can go over here

Code:

#include

#define SSID             “SSID” //WIFI Username
#define PASSWORD         “PASSOWRD” //WIFi Password
#define TOKEN            “ACCESS TOKEN” //Access Token

Cloudchip cloudchip;

void setup()
{
  Serial.begin(115200);
  cloudchip.WiFiInit(SSID,PASSWORD);
  cloudchip.Credentials(TOKEN); 
  pinMode(D5,OUTPUT);
  pinMode(D6,OUTPUT);
  pinMode(D7,OUTPUT);
  pinMode(D8,OUTPUT);
}
void loop()
{
  cloudchip.run();
  String Switch1 = cloudchip.getWidget(“Switch1”);
  String Switch2 = cloudchip.getWidget(“Switch2”);
  String Switch3 = cloudchip.getWidget(“Switch3”);
  String Switch4 = cloudchip.getWidget(“Switch4”);

  //Switch1
  if(Switch1.equals(“true”)
    digitalWrite(D5,HIGH)
  if(Switch1.equals(“false”)
    digitalWrite(D5,LOW)
   
  //Switch2 
  if(Switch2.equals(“true”)
    digitalWrite(D6,HIGH)
  if(Switch2.equals(“false”)
    digitalWrite(D6,LOW)
   
  //Switch3 
  if(Switch3.equals(“true”)
    digitalWrite(D7,HIGH)
  if(Switch3.equals(“false”)
    digitalWrite(D7,LOW)
   
  //Switch4 
  if(Switch4.equals(“true”)
    digitalWrite(D8,HIGH)
  if(Switch4.equals(“false”)
    digitalWrite(D8,LOW)
   
  delay(750);
}

Leave a Reply

Your email address will not be published. Required fields are marked *