Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Home Forums Arduino Project Discussions Arduino Uno

Tagged: 

This topic contains 3 replies, has 3 voices, and was last updated by  Bitahwa Bindu 3 months ago.

  • Author
    Posts
  • #3906

    severus snape
    Participant

    Hi.I need the solutions of this problem.The microcontroller is arduino uno.

    Attachments:
    You must be logged in to view attached files.
  • #3908

    Bitahwa Bindu
    Keymaster

    We can’t do your home work. That’s not how forums work.

  • #5122

    nadhem
    Participant

    i work with esp8266-01 and arduino uno for send data to a channel in thingspeak.com:

    when i tried with AT commands directly in the monitor series it works but when tried to send the commands via a program it didn’t work .i didn’t understand the problem. help please

    this is the code;

    #include <SoftwareSerial.h>
    SoftwareSerial espSerial = SoftwareSerial(0,1);

    #include <Adafruit_Sensor.h>
    #include <DHT.h>

    #define DHTPIN 5
    #define DHTTYPE DHT11
    DHT dht(DHTPIN, DHTTYPE);

    String apiKey = “xxxxxxxxxxxxxxxx”; // replace with your channel’s thingspeak WRITE API key

    String ssid=”xxxxxxxxxxxxxxx”; // Wifi network SSID
    String password =”xxxxxxxxxxxxxx”; // Wifi network password

    unsigned char check_connection=0;
    unsigned char times_check=0;

    boolean DEBUG=true;

    //======================================================================== showResponce
    void showResponse(int waitTime){
    long t=millis();
    char c;
    while (t+waitTime>millis()){
    if (espSerial.available()){
    c=espSerial.read();
    if (DEBUG) Serial.print(c);
    }
    }

    }

    //========================================================================
    boolean thingSpeakWrite(float value1, float value2){
    String cmd = “AT+CIPSTART=\”TCP\”,\””;
    cmd += “184.106.153.149“;
    cmd += “\”,80″;
    espSerial.println(cmd);
    if (DEBUG) Serial.println(cmd);
    if(espSerial.find(“Error”)){
    if (DEBUG) Serial.println(“AT+CIPSTART error”);
    return false;
    }

    String getStr = “GET /update?key=”;
    getStr += apiKey;

    getStr +=”&field1=”;
    getStr += String(value1);
    getStr +=”&field2=”;
    getStr += String(value2);
    // getStr +=”&field3=”;
    // getStr += String(value3);
    // …
    getStr += “\r\n\r\n”;

    // send data length
    cmd = “AT+CIPSEND=”;
    cmd += String(getStr.length());
    espSerial.println(cmd);
    if (DEBUG) Serial.println(cmd);

    delay(100);
    if(espSerial.find(“>”)){
    espSerial.print(getStr);
    if (DEBUG) Serial.print(getStr);
    }
    else{
    espSerial.println(“AT+CIPCLOSE”);
    // alert user
    if (DEBUG) Serial.println(“AT+CIPCLOSE”);
    return false;
    }
    return true;
    }
    //================================================================================ setup
    void setup() {
    DEBUG=true;
    Serial.begin(115200);

    dht.begin();

    espSerial.begin(115200);

    espSerial.println(“AT+RST”);
    showResponse(1000);

    espSerial.println(“AT+CWMODE=3”);
    showResponse(1000);

    espSerial.println(“AT+CIPMUX=1”);
    showResponse(1000);

    espSerial.println(“AT+CWJAP=\””+ssid+”\”,\””+password+”\””);
    showResponse(5000);

    if (DEBUG) Serial.println(“Setup completed”);
    }

    // ====================================================================== loop
    void loop() {

    // Read sensor values
    float t = dht.readTemperature();
    float h = dht.readHumidity();
    if (isnan(t) || isnan(h)) {
    if (DEBUG) Serial.println(“Failed to read from DHT”);
    }
    else {
    if (DEBUG) Serial.println(“Temp=”+String(t)+” *C”);
    if (DEBUG) Serial.println(“Humidity=”+String(h)+” %”);
    thingSpeakWrite(t,h);
    }

    delay(30000);
    }

  • #5124

    Bitahwa Bindu
    Keymaster

    Where did you get that code from?

You must be logged in to reply to this topic.

Select your currency
EUR Euro
USD United States (US) dollar