mkganesan1975
Published © GPL3+

Sending Data to Cloud

This project will guide to send an analogue data (potentiometer reading at analogue A0) to the cloud using thingspeak.

IntermediateFull instructions provided111
Sending Data to Cloud

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Arduino UNO
Arduino UNO
×1
USB-A to B Cable
USB-A to B Cable
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1

Hand tools and fabrication machines

Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Optional / Can use any other screw drivers to turn the potentiometer

Story

Read more

Schematics

Figure 1: Analogue Input

Figure 2: Full Circuit Diagram

Code

Code 1: display potentiometer reading

Arduino
#include<Arduino.h>

int analogpin = A0;
int pause = 1000;


void setup() {
  Serial.begin(9600);
  pinMode(analogpin,INPUT);
}

void loop() {
Serial.println(analogRead(analogpin));
delay(pause);
}

Code 2: Send Data to Cloud

Arduino
#include <ThingSpeak.h>
#include <SoftwareSerial.h>
#include "arduino_secrets.h"

#define RX 11
#define TX 10

String AP = SECRET_AP;
String PASS = SECRET_PASS;
String API = SECRET_API;
String HOST = SECRET_HOST;
String PORT = SECRET_PORT;

String field = "phvalue";

int countTrueCommand;
int countTimeCommand; 
boolean found = false; 
int valSensor = A0;

SoftwareSerial esp8266(RX,TX); 
  
void setup() {
  Serial.begin(9600);
  esp8266.begin(115200);
  sendCommand("AT",5,"OK");
  sendCommand("AT+CWMODE=1",5,"OK");
  sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}

void loop() {
 
 valSensor = getSensorData();
  String getData = "GET https://api.thingspeak.com/update?api_key=NKPNJFC389G2XEIL&field1=0" + String(valSensor);
 sendCommand("AT+CIPMUX=1",5,"OK");
 sendCommand("AT+CIPSTART=0,\"TCP\",\"" + HOST + "\"," + PORT,3,"OK");
 sendCommand("AT+CIPSEND=0," + String(getData.length()+4),3,">");
 esp8266.println(getData);
 delay(100);
 countTrueCommand++;
 sendCommand("AT+CIPCLOSE=0",3,"OK");
}

int getSensorData(){
  return analogRead(A0);
}

void sendCommand(String command, int maxTime, char readReplay[]) {
  Serial.print(countTrueCommand);
  Serial.print(". at command => ");
  Serial.print(command);
  Serial.print(" ");
  while (countTimeCommand < (maxTime*1)) {
    esp8266.println(command);
    if (esp8266.find(readReplay)) {
      found = true;
      break;
    }
    countTimeCommand++;
  }

  if (found == true) {
    Serial.println("Pass");
    countTrueCommand++;
    countTimeCommand = 0;
  }
  
  if (found == false) {
    Serial.println("Fail");
    countTrueCommand = 0;
    countTimeCommand = 0;
  }
  found = false;
}

Credits

mkganesan1975
2 projects • 1 follower

Comments