loading
6Comments

Tell us about yourself!

Complete Your Profile
  • Send sensor data (DHT11 & BMP180) to ThingSpeak with an Arduino, using cable or WiFi (ESP8266)

    yesbecause the AP is on another ESP8266 and it's connected to arduino to collect this sensors values.

    View Instructable »
  • Send sensor data (DHT11 & BMP180) to ThingSpeak with an Arduino, using cable or WiFi (ESP8266)

    i change the code for dht22 and mg811 sensors :)now I just need to figure out how to read this data on AP because I don't have wifi or internet in place where i'm using them.` #include <DHT.h>#include <SoftwareSerial.h>#define DHTPIN 0#define DHTTYPE DHT22DHT dht(DHTPIN, DHTTYPE);int ppm;#define MG_PIN (A0) //define which analog input channel you are going to use#define BOOL_PIN (8)#define DC_GAIN (11.5) //define the DC gain of amplifier#define READ_SAMPLE_INTERVAL (200) //define how many samples you are going to take in normal operation#define READ_SAMPLE_TIMES (5) //define the time interval(in milisecond) between each samples in ...see more »i change the code for dht22 and mg811 sensors :)now I just need to figure out how to read this data on AP because I don't have wifi or internet in place where i'm using them.` #include <DHT.h>#include <SoftwareSerial.h>#define DHTPIN 0#define DHTTYPE DHT22DHT dht(DHTPIN, DHTTYPE);int ppm;#define MG_PIN (A0) //define which analog input channel you are going to use#define BOOL_PIN (8)#define DC_GAIN (11.5) //define the DC gain of amplifier#define READ_SAMPLE_INTERVAL (200) //define how many samples you are going to take in normal operation#define READ_SAMPLE_TIMES (5) //define the time interval(in milisecond) between each samples in //normal operation#define ZERO_POINT_VOLTAGE (0.240) //define the output of the sensor in volts when the concentration of CO2 is 400PPM#define REACTION_VOLTGAE (0.050) //define the voltage drop of the sensor when move the sensor from air into 1000ppm CO2float CO2Curve[3] = {2.602,ZERO_POINT_VOLTAGE,(REACTION_VOLTGAE/(2.602-3))}; #define DEBUG FALSE //comment out to remove debug msgs//*-- Hardware Serial#define _baudrate 9600//*-- Software Serial//#define _rxpin 2#define _txpin 3SoftwareSerial debug( _rxpin, _txpin ); // RX, TX//*-- IoT Information#define SSID "ESP"#define PASS "asdfgh"#define IP "192.168.4.1" void setup() { Serial.begin( _baudrate ); debug.begin( _baudrate ); dht.begin(); sendDebug("AT"); delay(5000); if(Serial.find("OK")) { debug.println("RECEIVED: OK\nData ready to sent!"); connectWiFi(); } pinMode(BOOL_PIN, INPUT); //set pin to input digitalWrite(BOOL_PIN, HIGH); }void loop() { int percentage; float volts; volts = MGRead(MG_PIN); percentage = MGGetPercentage(volts,CO2Curve); float h = dht.readHumidity(); float t = dht.readTemperature(); String temp =String(t);// turn integer to string String humid=String(h);// turn integer to string String ppm= String(percentage);// turn integer to string updateTS(temp, humid, ppm); delay(3000); //}//----- update the Thingspeak string with 3 valuesvoid updateTS( String T, String P , String H){ // ESP8266 Client String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection cmd += IP; cmd += "\",80"; sendDebug(cmd); delay(2000); if( Serial.find( "Error" ) ) { debug.print( "RECEIVED: Error\nExit1" ); return; } cmd = "&field1=" + T +"&field2="+ P + "&field3=" + H +"\r\n"; Serial.print( "AT+CIPSEND=" ); Serial.println( cmd.length() ); if(Serial.find( ">" ) ) { debug.print(">"); debug.print(cmd); Serial.print(cmd); } else { sendDebug( "AT+CIPCLOSE" );//close TCP connection } if( Serial.find("OK") ) { debug.println( "RECEIVED: OK" ); } else { debug.println( "RECEIVED: Error\nExit2" ); }}void sendDebug(String cmd){ debug.print("SEND: "); debug.println(cmd); Serial.println(cmd);}boolean connectWiFi(){ Serial.println("AT+CWMODE=1");//WiFi STA mode - if '3' it is both client and AP delay(2000); //Connect to Router with AT+CWJAP="SSID","Password"; // Check if connected with AT+CWJAP? String cmd="AT+CWJAP=\""; // Join accespoint cmd+=SSID; cmd+="\",\""; cmd+=PASS; cmd+="\""; sendDebug(cmd); delay(5000); if(Serial.find("OK")) { debug.println("RECEIVED: OK"); return true; } else { debug.println("RECEIVED: Error"); return false; } cmd = "AT+CIPMUX=0";// Set Single connection sendDebug( cmd ); if( Serial.find( "Error") ) { debug.print( "RECEIVED: Error" ); return false; }}float MGRead(int mg_pin){ int i; float v=0; for (i=0;i<READ_SAMPLE_TIMES;i++) { v += analogRead(mg_pin); delay(READ_SAMPLE_INTERVAL); } v = (v/READ_SAMPLE_TIMES) *5/1024 ; return v; }int MGGetPercentage(float volts, float *pcurve){ if ((volts/DC_GAIN )>=ZERO_POINT_VOLTAGE) { return -1; } else { return pow(10, ((volts/DC_GAIN)-pcurve[1])/pcurve[2]+pcurve[0]); }}`

    now is finally working and hope is gonna stay in that waythanks

    View Instructable »
  • Send sensor data (DHT11 & BMP180) to ThingSpeak with an Arduino, using cable or WiFi (ESP8266)

    yes i just copy and past it in IDE without url's. now somehow it stops making me debug error but it making me error for 'A1' and 'A2' was not declared in this scope...A0 is somehow ok...

    now somehow it stops making me debug error but it making me error for 'A1' and 'A2' was not declared in this scope...A0 is somehow ok...

    View Instructable »