Good evening, everyone. I have a big problem and in two days I will present the project that I’ve been developing for some time with thinger.
My project is based on a weather station with dht11 sensor, wind speed sensor and wind direction sensor. I’m using an esp8266, so I can only use one analog sensor, but as I need two I decided to use another way, because I didn’t have time to buy the esp32.
For this solution I had to use the arduino connected with a serial cable, to pass the data that the arduino receives from the sensors to the esp. And there my problem starts. I am using two sketch, in the esp sketch that is the one that receives the data I don’t know how I will replicate the data that it receives to the internet, to the thinger.io platform.
Can someone help me to solve this problem urgently.
Arduino Code:
#include "DHT.h"
#include <SoftwareSerial.h>
#include <Wire.h>
#define DHTPIN 2
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 //--> DHT11
SoftwareSerial espSerial(5, 6);
DHT dht11(DHTPIN, DHTTYPE); //--> DHT11 Sensor Initialization
String str;
void setup(){
Serial.begin(115200);
espSerial.begin(115200);
dht11.begin();
Wire.begin();
delay(2000);
}
void loop()
{
float h = dht11.readHumidity();
// Read temperature as Celsius
float t = dht11.readTemperature();
Serial.print("H: ");
Serial.print(h);
Serial.println("% ");
Serial.print(" T: ");
Serial.print(t);
Serial.print("ºC");
// Read velocidade do vento
int RPM = analogRead(A0);
// print out the value you read:
Serial.print("km/h ");
/*double windspeed = (((4 * 3.1416 * 7 * RPM) / 60) / 1000) * 3.6; //Calcula a velocidade do vento em km/h*/
double windspeed = (((4 * 3.1416 * 70 * RPM) / 60) / 1000)*3.6; //Calcula a velocidade do vento em km/h
Serial.println(windspeed);
// Read direção do vento
int sensorValue = analogRead(A1);
float Tencao = sensorValue*5/1023.0;
int Direcao = map(sensorValue, 0, 1023, 0, 360);
// print out the value you read:
Serial.print("ADC : ");
Serial.println(sensorValue);
Serial.print("Tenção : ");
Serial.println(Tencao);
Serial.print("Direção : ");
Serial.println(Direcao);
String ventoDir = "";
if (Direcao >= 23 && Direcao <= 67) {
ventoDir = "NE";
} else if (Direcao >= 68 && Direcao <= 112) {
ventoDir = "E";
} else if (Direcao >= 113 && Direcao <= 157) {
ventoDir = "SE";
} else if (Direcao >= 158 && Direcao <= 202) {
ventoDir = "S";
} else if (Direcao >= 203 && Direcao <= 247) {
ventoDir = "SW";
} else if (Direcao >= 248 && Direcao <= 292) {
ventoDir = "W";
} else if (Direcao >= 293 && Direcao <= 337) {
ventoDir = "NW";
} else {
ventoDir = "N";
}
Serial.print("Direção : ");
Serial.print(Direcao);
Serial.print("° ");
Serial.print("(");
Serial.print(ventoDir);
Serial.println(")");
str =String("Valores do Arduino: ")+String("H= ")+String(h)+String("%")+String(" T= ")+String(t)+String("ºC")+String(" km/h= ")+String(windspeed)+String(" Direção= ")+String(ventoDir);
espSerial.println(str);
delay(1000);
}
Esp Code:
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop() { // run over and over
if (Serial.available()) {
Serial.write(Serial.read());
}
}