Question

In: Physics

this is code to Temperature and Humidity Monitoring over ThingSpeak using Arduino UNO and ESP8266 i...

this is code to Temperature and Humidity Monitoring over ThingSpeak using Arduino UNO and ESP8266 i need someone explain the steps for me

#include <stdlib.h>

#include <DHT.h>

#define DHTPIN 5         // DHT data pin connected to Arduino pin 5

#define DHTTYPE DHT11     // DHT11 (DHT Sensor Type )

DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor

#define SSID "WiFi Name"     // "WiFi Name"

#define PASS "WiFi Password"       // "Password"

#define IP "184.106.153.149"// thingspeak.com ip

String msg = "GET /update?key=Your API Key"; //change it with your key...

float temp;

int hum;

String tempC;

int error;

void setup()

{

Serial.begin(115200); // use default 115200.

  Serial.println("AT");

delay(5000);

if(Serial.find("OK")){

    connectWiFi();

}

}

void loop(){

   start:

error=0;

temp = dht.readTemperature();

hum = dht.readHumidity();

char buffer[10];

tempC = dtostrf(temp, 4, 1, buffer);

updateTemp();

if (error==1){

    goto start;

}

delay(5000);

}

void updateTemp(){

String cmd = "AT+CIPSTART=\"TCP\",\"";

cmd += IP;

cmd += "\",80";

Serial.println(cmd);

delay(2000);

if(Serial.find("Error")){

    return;

}

cmd = msg ;

cmd += "&field1=";  

cmd += tempC;

cmd += "&field2=";

cmd += String(hum);

cmd += "\r\n";

Serial.print("AT+CIPSEND=");

Serial.println(cmd.length());

if(Serial.find(">")){

    Serial.print(cmd);

}

else{

    Serial.println("AT+CIPCLOSE");

    //Resend...

    error=1;

}

}

boolean connectWiFi(){

Serial.println("AT+CWMODE=1");

delay(2000);

String cmd="AT+CWJAP=\"";

cmd+=SSID;

cmd+="\",\"";

cmd+=PASS;

cmd+="\"";

Serial.println(cmd);

delay(5000);

if(Serial.find("OK")){

    return true;

}else{

    return false;

}

}

Solutions

Expert Solution

The explanation is given with comment (//) mark in the right side: (in bold)

#include <stdlib.h> //header file containing the library definitions, inside variables, commands etc.

#include <DHT.h> //same (.h file)

#define DHTPIN 5         // DHT data pin connected to Arduino pin 5

#define DHTTYPE DHT11     // DHT11 (DHT Sensor Type )

DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor

#define SSID "WiFi Name"     // "WiFi Name"

#define PASS "WiFi Password"       // "Password"

#define IP "184.106.153.149" // thingspeak.com ip

String msg = "GET /update?key=Your API Key"; //change it with your key...

float temp; \\setting up the temperature sensing via WiFi channeling

int hum;

String tempC;

int error; //error measurement, accuracy of the sensor

void setup()

{

Serial.begin(115200); // use default 115200.

  Serial.println("AT");

delay(5000); \\delay time

if(Serial.find("OK")){

    connectWiFi(); //connection to the wifi

}

}

void loop(){

   start: \\starting the system after connecting with wifi

error=0;

temp = dht.readTemperature(); //sensor reading the temperature

hum = dht.readHumidity();

char buffer[10]; //strings for temperature mesaurement

tempC = dtostrf(temp, 4, 1, buffer);

updateTemp();

if (error==1){ //if sensor doesn't read any input, start it again

    goto start;

}

delay(5000); //reading delay of 5 sec

}

void updateTemp(){

String cmd = "AT+CIPSTART=\"TCP\",\""; //procedure to give input commands to temp sensor

cmd += IP;

cmd += "\",80";

Serial.println(cmd);

delay(2000);

if(Serial.find("Error")){

    return;

}

cmd = msg ;

cmd += "&field1=";  

cmd += tempC;

cmd += "&field2=";

cmd += String(hum);

cmd += "\r\n";

Serial.print("AT+CIPSEND=");

Serial.println(cmd.length());

if(Serial.find(">")){ \\after successful measurement print/output the temp. value to the display or screen

    Serial.print(cmd);

}

else{

    Serial.println("AT+CIPCLOSE");

    //Resend...

    error=1;

}

}

boolean connectWiFi(){

Serial.println("AT+CWMODE=1");

delay(2000);

String cmd="AT+CWJAP=\"";

cmd+=SSID;

cmd+="\",\"";

cmd+=PASS;

cmd+="\"";

Serial.println(cmd);

delay(5000);

if(Serial.find("OK")){

    return true;

}else{

    return false;

}

}


Related Solutions

We need to code an LCD with a temperature and humidity sensor for the arduino UNO...
We need to code an LCD with a temperature and humidity sensor for the arduino UNO board. The LCD should simply display the temperature and humidity reading from the DHT11 sensor. We must do this without the use of arduino or lcd libraries, and only use raw c code. For example we need to use PORTD |= (1<<5); to set the pin to 5. The LCD is connected to pins A0 and A1, and it is using I2C. The temperature...
I need an Arduino uno code to measure high low levels with hcsr04 of a tank...
I need an Arduino uno code to measure high low levels with hcsr04 of a tank and display it on i2c 20x4 lcd.
write the code of 4 digit 7-segment display using arduino uno in assembly language by using...
write the code of 4 digit 7-segment display using arduino uno in assembly language by using software AVR STUDIO 5.1?
I need simulation on protues of speed control of unipolar stepper motor using uno arduino. Must...
I need simulation on protues of speed control of unipolar stepper motor using uno arduino. Must using protues..
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Arduino Uno code, Please explain what does this code do? unsigned long ms_runtime; int one_ms_timer; //define...
Arduino Uno code, Please explain what does this code do? unsigned long ms_runtime; int one_ms_timer; //define all timers as unsigned variables unsigned long timer1 = 0; // timer1 increments every 100ms = 0.1s const int USER_LED_OUTPUT = 13; const int USER_BUTTON_INPUT = 2; void setup() { // initialize the digital pin as an output. pinMode(USER_LED_OUTPUT, OUTPUT); pinMode(USER_BUTTON_INPUT, INPUT); Serial.begin(9600); } void loop() { // run loop forever static int state, old_state,counter; timers(); // logic for state change if(state == 0)...
With an Arduino Uno: Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’,...
With an Arduino Uno: Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’, design a sequence detector to detect a pattern “1101”. An LED lights up once, when the sequence “1101” occurs.
Pharaphrase and rewrite the following paragraph: Arduino Arduino Uno is a microcontroller board b... pharaphrase and...
Pharaphrase and rewrite the following paragraph: Arduino Arduino Uno is a microcontroller board b... pharaphrase and rewrite the following paragraph: Arduino Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. It contains everything needed to support the microcontroller; simply connect it to...
Design and program an Arduino-based circuit that contains the following items - 1 Arduino Uno microcontroller....
Design and program an Arduino-based circuit that contains the following items - 1 Arduino Uno microcontroller. - 1 IR remote control, - 1 IR sensor - 1 LCD 16x2 Display - Any other components you find necessary. The circuit will do the following: - The circuit represents a 2-digit calculator. - At start of operation, the LCD display should display “0” in line 2 of the LCD display. - Pressing the On/Off button on the IR remote represents the “Clear”...
Using Arduino to blink an LED in morse code. Morse code is used as one of...
Using Arduino to blink an LED in morse code. Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT