Posted on

DHT11 Sensor Data to New blynk2.0 IoT using Raspberry Pi

This tutorial will guide you how you can connect Raspberry Pi with New Blynk2.0 IoT App and Web Dashboard..

So connect the DHT11/DHT22 Sensor with Raspberry pi as  per this circuit diagram.

Now, install the DHT sensor poython library in the Raspberry Pi through the below commands.

sudo pip3 install Adafruit_DHT

If you are getting any problem to install the DHT sensor library, Watch the complete video tutorials on “How to get Humidity and Temperature data to raspberry pi using DHT11 sensor”.

Once installed, then you need to install the New Blynk library through below command.

git clone https://github.com/vshymanskyy/blynk-library-python.git

After the installation of blynk library, you need to create the text file uisng TextEditor. So go to the Accessories and open the TextEditor. Copy the below code and paste in to the file.

git clone https://github.com/vshymanskyy/blynk-library-python.git

Now, go to the Accessories and open the TextEditor. Copy the below code and paste in to the file.

After that, save this file in the inside the Blynk Library folder with name as DHT11_NewBlynk2.py

"""
This Code is belong to SME Dehraun. for any query write to schematicslab@gmail.com

"""

import BlynkLib
import RPi.GPIO as GPIO
from BlynkTimer import BlynkTimer

import Adafruit_DHT
import time

DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4
#BLYNK_AUTH_TOKEN = 'kt85ldXRL362juNQiymMClUUxdsuygTN'
BLYNK_AUTH_TOKEN = 'jsfpl_ACPJIVDdkFJ9THE5PkCVvYR8FS'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH_TOKEN)

# Create BlynkTimer Instance
timer = BlynkTimer()


# function to sync the data from virtual pins
@blynk.on("connected")
def blynk_connected():
print("Hi, You have Connected to New Blynk2.0")
print(".......................................................")
print("................... By SME Dehradun ...................")
time.sleep(2);

# Functon for collect data from sensor & send it to Server
def myData():
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity))
else:
print("Sensor failure. Check wiring.");

blynk.virtual_write(0, humidity,)
blynk.virtual_write(1, temperature)
print("Values sent to New Blynk Server!")

timer.set_interval(2, myData)


while True:
blynk.run()
timer.run()

 

So we have successfully save our program. Now time to run the program in the Terminal and send the Humidity & Temperature values to New Blynk2.0 IoT app and Web Dashboard.

So run the following command to run the program.

 

cd blynk-library-python
sudo python DHT11_NewBlynk2.py

After running the command, You will get the output in the serial like this.

 

Now you can see the humidity and Temperature Values in the New Blynk Web Dashboard like this.

You can also see the data in New Blynk Mobile App.

Watch the Video Tutorial- How to connect the Raspberry with New Blynk2.0.

Posted on

DHT11 Sensor interfacing with Raspberry Pi- Humidity & Temperature Monitoring

Watch the complete video tutorials on “How to get Humidity and Temperature data to raspberry pi using DHT11 sensor” at our YouTube channel.

This tutorial will guide you how you can interface the DHT11/ DHT22 Sensor with Raspberry Pi Board.

As we all of know that the DHT-11 Digital Temperature And Humidity Sensor is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed).

  • Humidity measuring range: 20%~90%RH(0~50 degree (temperature compensation).
  • Temperature measuring range: 0~+50degree.
  • Humidity measurement accuracy: ±5.0%RH.
  • Temperature measurement accuracy: ±2.0degree.
  • Low power consumption.
  • Relative humidity and temperature measurement
  • All calibration, digital output
  • Excellent long-term stability

As we know that Raspberry Pi is independent Operation system, based on Linux. Raspberry Pi is a series of small single-board computers (SBCs) developed in the United Kingdom by the Raspberry Pi Foundation in association with Broadcom.

For more details, visit to Raspberry Pi Wikipedia Page.

Let's interface the DHT11/DHT22 Sensor With Raspberry Pi Now.

So connect the DHT11/DHT22 Sensor with Raspberry Pi as shown in the Circuit Diagram.

DHT11/DHT22 pin connection with Raspberry Pi like shown in the Circuit Diagram:

  • DHT11/22 Sensor Vcc+ to 5V  pin of Raspberry Pi 
  • DHT11/22 Sensor GND to GND pin of Raspberry Pi
  • DHT11/22 Sensor Signal to GPIO4 no pin of Raspberry Pi
You will get the video tutorial for it soon. stay tuned at YouTube Channel

Now we need to install the DHT sensor poython library in the Raspberry Pi. 

but before that Python must be installed in your Raspberry Pi OS. If not installed, then you need to installed by the following commands in the LX Teminal: 

sudo apt update
sudo apt install python3-pip
sudo pip3 install --upgrade setuptools

Now install the DHT Sensor Pyhton Library:

sudo pip3 install Adafruit_DHT

Now, go to the Accessories and open the TextEditor. Copy the below code and paste in to the file.

Now save this file in the root folder with name as DHTsensor.py

Now, go to the Accessories and open the TextEditor. Copy the below code and paste in to the file.


import Adafruit_DHT
import time

DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4

while True:
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity))
else:
print("Sensor failure. Check wiring.");
time.sleep(2);

Now save this file in the root folder with name as DHTsensor.py

Once Saved, open the LX Terminal and Write this command:

Sudo python DHTsensor.py

Watch the complete video tutorials on “How to get Humidity and Temperature data to raspberry pi using DHT11 sensor” at our YouTube channel.

Posted on

How to install VNC Server in Raspberry Pi

As we know that Raspberry pi is independent Operation system, based on Linux. Raspberry pi is taking too much attachments like TFT/ Monitor Display, Keyboard, mouse to run.

So isn’t very easy that we just connect the Power Adaptor to the raspberry pi and we can directly access it to PC or Laptop without physically connectivity. Yes this is possible. We can possible it with the help of VNC.

So first of all you install the Raspbian OS in to your Raspberry Pi.

If you don’t know how to install Raspbian OS in Raspberry Pi, then you can see below video tutorial for help.

 

By default, VNC server preinstalled to the Raspbian OS (Dabian). But if not, then we need to install it manually. First verify, VNC Server has installed to your Raspberry Pi or not?

 

Go to the Menu > Preferences > Raspberry Pi Configuration > Interfaces in your Raspberry Pi.

If you found the VNC here, that means you have preinstalled VNC server in your Raspberry Pi OS. Otherwise follow the commands below to install the VNC Server.

To install the VNC server to the Raspberry pi, Open the LX terminal in raspberry pi.

Write this command to update first:

sudo apt-get update

Once updated, then install the VNC server using this command-

sudo apt-get install realvnc-vnc-server

Once installed, go to the Menu > Preferences > Raspberry Pi Configuration > Interfaces in your Raspberry Pi.

Enable the VNC by toggle button and click on the ok.

Once you enable the VNC, you will get the VNC logo in your Raspberry Pi Desktop. Now you can access your Raspberry pi using VNC Server.

Now install the VNC viewer in your pc and access the raspberry pi through its ip address.

 

We will update the complete video Guide that will help you to access the Raspberry pi wirelessly using VNC Server soon.

Posted on

How to install Raspberry Pi Desktop OS in Raspberry Pi- Getting Started

Hello Guys, there are lots of the tutorials are available to install the Raspberry Pi OS. But believe me, I will show you the shortest way to install it.

So first of all, download the Raspbian OS Boot Image file.

You need minimum 16GB MicroSD card and USB SD Card Reader.

Download the SD Card Formatter and install it.  Insert the 16/32GB Micro SD Card to your computer using Micro SD Card reader and Open the SD Card Formatter.

Now Download and install the Win32 Disk Imager software and open it.

Now select the Raspbian OS image file that you have just downloaded. And click on the write button to write it to the Micro SD Card.

It will take 2-3 minute to write the Raspbian OS to the Micro SD Card.

Once it’s done. then disconnect the Micro Sd Card from the laptop and insert it to the Raspberry pi.

Now connect the Raspberry pi to the TFT Display using HDMI to VGA Converter. Connect the USB Keyboard and Mouse to the Rspberry pi.

Once power up the raspberry pi, it’s display the screen like this.

Your Raspberry Pi Desktop is ready to use.

Now configure the Raspberry Pi as per your requirements.  You can check the Raspberry Pi version as well as other information using Lx terminal through these commands.

  • to install the rpi-update utility- sudo apt install rpi-update
  • command to know the RPI Version? cat /etc/os-release

For any query, write to us.

Posted on

How to Install New Blynk Library in Arduino IDE

To install a new library into your Arduino IDE, you can use the Library Manager.

First, connect your computer o the Internet. Open the IDE and click to the “Sketch” menu and then Include Library > Manage Libraries.

Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. Search for Blynk library and in the version selection choose the latest version to date.

Finally click on Install and wait for the IDE to install the new library. Downloading may take time depending on your connection speed. Once it has finished, an Installed tag should appear next to the Bridge library. You can close the library manager.
 
Follow the video tutorial And don’t forget to subscribe.
Posted on 1 Comment

How to Install the ESP32 Board in Arduino IDE

ESP32 is another addon board for arduino like NodeMCU, that have more sound feature than NodeMCU.

So how we can install ESP32 board to Arduino IDE? Let’s start. Follow the below instruction.

So open your Arduino IDE software. If you don’t have Arduino IDE installed in your computer, then you can download it from this link (https://www.arduino.cc/en/Main/Software).

Step1- In your Arduino IDE, go to the file tab and then click on the preferences. 

Step2- Copy & paste this link https://dl.espressif.com/dl/package_esp32_index.json in to the Additional board Manager URLs:  and then click on ok.

Note: if you already installed NodeMCU ESP8266 board in your Arduino IDE, then you copy & paste this link to the Additional board Manager URLs-

https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

Step3- Now, go to the Tools tab, then board and click on Board Manager as shown below: (you need internet to be connected in your computer)

Step4- Now, search for ESP32, you will get the board ESP32 by Espressif Systems. Click on the install button.

Step5- It will take little time to complete. Once finished, you will see like it. Click on the close button.

How to select ESP32 Board to upload the program

Go to the tools tab, click on the Boards and Scroll below, you will get the get the ESP32 Wrover Board. Select it and it’s done.

Now you can upload your program to ESP32 Board.

Now, you can upload your program to ESP32 Board. 

So this is how you can select & upload the program to ESP32 board. 

Posted on Leave a comment

How to Install and Program any Customized board with Arduino IDE- Arduino Compatible boards only

This tutorial will teach you how to install download, install, and testing the Arduino software( Arduino IDE) & then how to install Nutty ATmel ATmega328 Board to Arduino Software.

Now, talk about primary requirements. You need

Step1. 

Download the Arduino Software from arduino official site & scroll down. you will see the arduino downloading option. click on “Window Installer, for window XP and up” as shown in image below.  Now arduino software will start download.

 

Step2. 

After download, install the arduino software.

Step3. 

Open the Arduino IDE, & go to tools->board, Now you will see the many option for Arduino Boards. like we our Nutty ATmel Atmega328 Board, it is recommended to select “Arduino/Genuino Uno” as shows in image.

After it, this is programmer for arduino.

Connect FTDI/ CH340 programmer to your Customized board.

But be careful, you need to connect it properly as per shown below. if you connect it wrongly, then it can harm your customized board as well as your computer.

Now, go to the Tools->Port-> and select the com port as COM3.

Note: If you don’t know how to install FTDI programmer to Arduino IDE, then visit to to our another post that will show you how to install it .

Write your first program:

Copy & paste below program to your Arduino IDE.

/*

Builtin led has connected to 13no pin of Arduino. but we need to connect external led on Customized board

*/

 

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println(“Welcome to Nutty’s ATmel ATmega328 Firmware”);
delay(1000);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println(“Led High”);
delay(500); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.println(“Led Low”);
delay(500); // wait for a second
}

and click on the upload button to upload the program .

Now, you connect led to 13 no pin (as per the Arduino pins ) of your customized board and it will start blinking.

This is how you can test your customized board.

Posted on 7 Comments

How to install NUTTYFI NodeMCU wifi IoT Board in Arduino IDE

In this tutorial, you will know, how you can install the NodeMCU ESP8266 Nuttyfi Board to your Arduino IDE. 

NodeMCU is an addon board for arduino like ESP32. IF you are using ESP32 board, then you can install ESP32 board to your arduino from our another post- How to Install the ESP32 Board in Arduino IDE

So Let’s start. Follow the below instruction.

Open your Arduino IDE software. If you don’t have Arduino IDE installed in your computer, then you can download it from this link (https://www.arduino.cc/en/Main/Software).

 

Fundamental Requirements:

  • Arduino IDE
  • Internet connection

 

Now Start with Arduino IDE:

 

Instructions

  1. Open Arduino and go to file open Preferences window.
  2. Copy & paste this link to  into Additional Board Manager URLs field as shown in image below  “http://arduino.esp8266.com/stable/package_esp8266com_index.json”  then press OK button.
  3. Now, go to Tools on arduino Ide, click on board & then click on Board Manager that is on top of the list as shown in image below. Note it is essential that your computer/laptop must connect to internet before process these steps.
  4. As you click on board manager, a window will appear like shown in image below.
  5. Once this board manager download all the packages index from internet, a window will look like image given below.
  6. Now scroll the cursor at the end, you will find the Nuttyfi board package named “esp8266 by ESP8266 Community version 2.4.2”. Version may be differing as it will update on regular basis. Now click on this package, Select the version you need from a drop-down box & click on install button. It will take 10 minute to 20 minute to install the board package, depend on speed of your internet connection.
  7. Once installation completed, close and re -open Arduino IDE for ESP8266 library to take effect.
  8. Now, go to Tools > Board > ESP8266 Modules and you can see many option for ESP8266. For NuttyFi, it is recommended to select “NodeMCU 1.0 (ESP-12E Module).

 

Now, your NUTTYFI IoT, NodeMCU, ESP8266 Board is installed on Arduino IDE. Enjoy your Board now.

 

Posted on 1 Comment

How to Install FTDI USB to UART Bridge Drivers

We have Customized boards that are Compatible with Arduino IDE that use the FT232RL. If you have one of these older versions, you’ll want to use the FDTI drivers as well. if you are using CH340 based programmer then you can buy it from here

Now that you know why the FTDI Basic is important and what products it is used for, let’s learn how to install the drivers.

Windows – Quick and Easy

Note: The tutorial is compiled with windows 7. The process should be very similar for other versions of Windows. For most late versions of windows, such as 8.1 through Windows 10, the hardware may work fine without any driver install. If you can’t locate a COM port for your hardware, then the set of instructions below is the possible fix.

Note for Educators: You will most likely need to obtain administrative privileges from your network or IT administrator in order to install these drivers.

  • By default, windows does not have FTDI drivers installed. If you plug in your FTDI, open the Arduino IDE, go to ‘Tools -> Serial Ports’, and see nothing, you need the drivers! Let’s go get them!
  • Download a copy of the v2.12.28 FTDI VCP Driver Executable here:

WINDOWS FTDI VCP DRIVER EXECUTABLE – V2.12.28 (CDM21228_SETUP.EXE)

Otherwise, visit FTDI’s VCP official Drivers page for the latest download of the Windows. if you are using CH340 ic based programmer, then download it from here at CH340 Driver’s official page.  FTDI Driver executable and clicking on the Window’s “Available as a setup executable” link. Make sure to unzip the executable before proceeding to the next step.

  • Choose ‘Run’ once it is has finished downloading, or find the file you just downloaded “CDM21228_Setup.exe” and double-click it to run it.

Note: At the time of this tutorial, the images were referencing the old “v2.12.00” FTDI VCP driver executable. The installation process will be the same regardless of the version number.

  • Choose ‘Extract’ and continue through the installation until it finishes.
  • If everything was successful, you should see some nice green check marks, indicating success!

Note: You may need administrator privileges on your machine in order for this to run properly. If things didn’t work out, try the next section of this tutorial: Windows – In Depth.

  • Open up the Arduino IDE, and go to ‘Tools -> Serial Port’. If you now have a COM port, congratulations! Again, if something went wrong, either retry this tutorial or give Windows – In Depth a try!

Windows – In Depth

Note: The screen shots in this tutorial are from Windows 7. The process should be very similar for other versions of Windows. The exception to this is Windows 8. For instructions on how to disable device driver signatures, please visit this tutorial.

Note for Educators: You will most likely need to obtain administrative privileges from your network or IT administrator in order to install these drivers.

  • Plug in your FTDI using a USB cable. Windows doesn’t have the correct drivers, so let’s find them!
  • Navigate to the FTDI website, and choose the ‘VCP’ (Virtual Com Port) option near the bottom.
  • Now choose either the 32 bit version or the 64 bit version. Not sure which you have? The next steps will go over how to find that information. If you already know which version you are running, you may skip the next two steps.
  • Open the start menu, right-click on ‘Computer,’ and left-click on ‘Properties’.
  • Look under ‘System type,’ to see which version you have.
  • Now go back to the FTDI site, right-click on the correct version, and save it to your computer. Remember where the files are saved. We’ll need them in the next step.
  • Navigate to the folder containing the files. They will be inside of a .zip file, so you’ll need to extract them. Right-Click on the .zip file, and choose ‘Extract All…’ When the next window appears, as shown above, pay attention to where it is extracting the files. Make sure that ‘Show extracted files when complete’ is checked, and click ‘Extract’.
  • When the extraction is complete, the folder is opened. Again, take note of this folder location. This is the one containing the drivers.
  • We’re almost there! Open the start menu, right-click on ‘Computer’, and left-click on ‘Manage’. You will need administrator rights to do this. If you aren’t an administrator on your computer, talk to the person who is and have them enter their credentials.
  • Left-click on ‘Device Manager’ in the leftmost column. Here is where we see the offending hardware. It has an exclamation mark next to it.
  • Right-click on ‘FT232R USB UART,’ and left-click ‘Update Driver Software…’
  • Now choose ‘Browse my computer for driver software’.
  • Left-click ‘Browse,’ and navigate to the location of the extracted files. Choose the extracted folder. There is no need to search any further in the folder. Then left-click ‘OK’.
  • Make sure ‘Include subfolders’ is checked (very important!), and left-click ‘Next’.
  • After a moment, you will see a success message! Left-click ‘Close’.
  • The Device Manager page will refresh and you will see a new item with an exclamation mark named ‘USB Serial Port’. You will need to install a second driver for the same device. Follow the steps 1-15, as before, and use the same driver folder too!
  • Once those steps are complete, you will see another success message! Left-click ‘Close’.
  • The Device Manager Page will refresh again and show ‘USB Serial Port (COMxx),’ where xx = some number. Congratulations, you now have the proper FTDI drivers and can begin to use your device!
  • Open up the Arduino IDE, and go to ‘Tools -> Serial Port’. If you now have a COM port, congratulations! Again, if something went wrong, either retry this tutorial or give Windows – In Depth a try!

Note: You should only need to go through this process once. Every subsequent FTDI device you plug in should now have these drivers associated with it. However, if this is not the case, you can follow these instructions again for other devices.

Note: If you have more than one FTDI device plugged in to your computer at the same time, all of the devices will show up in the Arduino IDE’s Serial Port menu and device manager. To figure out which device is which, look under the Arduino IDE’s ‘Serial Port’ menu. Take note of the names of each device. Then unplug the device you want to use. Go back to the ‘Serial Port’ menu. The device you unplugged should no longer be listed. That is the device you want. Plug it back in, and select the device that has now reappeared.

You can determine what COM port an FTDI device enumerated to by opening the device manager and browsing the “Ports (COM & LPT)” tree.

Posted on Leave a comment

Getting Start with NUTTYFI- An IoT Device Examples

Fundamental Requirements:

To Start with NUTTYFI, You have to NUTTYFI IOT Device & FTDI USB to UART Bridge.

After that Connect NUTTYFI to your Computer using FTDI USB to UART Bridge & got to tools -> boards-> NodeMCU 1.0(ESP-12E Module & Select the Port like COM3.

after that copy these code (codes given below) to your arduino IDE & compile & upload to NUTTYFI & all done.

Download: 

Examples- 

  • How to Blink LED using NUTTYFI?
/**************************************NUTTYFI****************************/
// connect LED Positive pin at D6 of NUTTYFI. Connect Negative pin of LED to GND at NUTTYFI.
const int led = D6;
void setup() {
pinMode(led, OUTPUT); // initialize digital pin 'led' as an output.
} 
// the loop function runs over and over again forever 
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
/*********************************************************/
/**************************************NUTTYFI****************************/
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(D2, D3, D4, D5, D6, D7);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Set the cursor
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Hi! Welcome");
}

void loop() {

lcd.setCursor(0, 1);
lcd.print("to NUTTYFI");
lcd.setCursor(12, 1);
lcd.print(millis() / 1000);
}
/*********************************************************/
/*********************************NUTTYFI*********************************/

#include <ESP8266WiFi.h>
String apiKey = "Z55PHKYMUB0QTTE5"; //Change your 'Write API Key' of your thingspeak channel
const char* ssid = "NUTTYFI"; // Change your hotspot/ wifi name here
const char* password = "NUTTYFI@123"; // Change your wifi/ hotspot password
const char* server = "api.thingspeak.com";
WiFiClient client;

const int temp=A0; // Connect your LM35 temperature sensor AOUT pin TO A0 Pin of NUTTYFI.
int LM35_data=0;
String inputString_NODEMCU = "";

void setup()
{
Serial.begin(9600); // Serial Begin at 9600 Baud Rate
delay(3000);
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}

void loop()
{
// as LM35 sensor gives 10mV Scale Factor to change in one Degree Centegrade,double as compare to Arduino
LM35_data=analogRead(temp)/2;
if (client.connect(server,80))
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(LM35_data);
postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);

Serial.print("Field-1: ");
Serial.print(LM35_data);
Serial.println(" data send");


}
client.stop();
Serial.println("Waiting");
delay(400);// thingspeak needs minimum 15 sec delay between updates

}
/*********************************************************/
/***************************NUTTYFI***************************************/
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>

String apiKey = "Z55PHKYMUB0QTTE5"; //Change your 'Write API Key' of your thingspeak channel
const char* ssid = "NUTTYFI"; // Change your hotspot/ wifi name here
const char* password = "NUTTYFI@123"; // Change your wifi/ hotspot password
const char* server = "api.thingspeak.com";
WiFiClient client;

const int trigPin = D6;
const int echoPin = D7;
// defines variables
long duration;
int distance;

void setup()
{
Serial.begin(9600);
delay(10);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}

void loop()
{
void Ultra_NUTTYFI();
if (client.connect(server,80))
{
NUTTYFI_Ultrasonic_POST();
}
client.stop();
Serial.println("Waiting");
delay(1000);// thingspeak needs minimum 15 sec delay between updates

}

void Ultra_NUTTYFI()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);// Sets the trigPin on HIGH state for 10 micro seconds
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance= duration*0.034/2; // Calculating the distance
Serial.print("Distance: ");// Prints the distance on the Serial Monitor
Serial.println(distance);
}
void NUTTYFI_Ultrasonic_POST()
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(distance);
postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);

Serial.print("Send data to channel-1 ");
Serial.print("Content-Length: ");
Serial.print(postStr.length());
Serial.print("Field-1: ");
Serial.print(distance);
Serial.println(" data send");

}
class="brush: cpp">
/*********************************************************/