vishnu_dadiAjay Kumar
Published

IoT Based Anemometer

Measurement of wind speed using a anemometer (DC motor with blades) with the help of NodeMCU and interfacing it with the cloud (ThingSpeak).

BeginnerShowcase (no instructions)3,298
IoT Based Anemometer

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Dc motor 5v
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

circuit

One terminal of Dc motor to analog pin (A0) and other terminal to the Ground of the NodeMCU

Block Diagram

ThingSpeak results

The Final Results in the ThingSpeak are shown below

Code

NodeMCU - Arduino IDE Code

C/C++
Install the NodeMCU library in the Arduino IDE before Executing the code
#include <ESP8266WiFi.h>
String apiKey = "Your apikey";     //  Enter your Write API key from ThingSpeak

const char *ssid =  "Your ssid";     // replace with your wifi ssid and wpa2 key
const char *pass =  "your password";
const char* server = "api.thingspeak.com";
int ledPin = 9;
WiFiClient client;
void setup() {
 Serial.begin(9600);
 
       Serial.println("Connecting to ");
       Serial.println(ssid);
 WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED) 
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
      }

void loop() {
 float sensorvalue = analogRead(A0);
 float k= (sensorvalue*(51.0/1023.0)*50);
  if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {  
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(sensorvalue);
                             postStr +="&field2=";
                             postStr += String(k);
                             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("voltage: ");
                             Serial.print(sensorvalue);
                             Serial.print(" wind speed ");
                             Serial.print(k);
                             Serial.println("%. Send to Thingspeak.");
                        }
          client.stop();
 
          Serial.println("Waiting...");
  
  // thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(10000);
}

Credits

vishnu_dadi

vishnu_dadi

1 project • 0 followers
Ajay Kumar

Ajay Kumar

1 project • 0 followers

Comments