ESP8266 Witty Cloud LDR + ArduinoIDE + Thingspeak = IoT Light Sensor

You may also like...

2 Responses

  1. Brennan Westworth says:

    changes commented with //BW

    /* ESP8266 LDR ArduinoIDE Thingspeak IoT Example code
    *
    * This sketch sends data via HTTP GET requests to api.thingspeak.com of the value on
    * LDR sensor on ESP8266 development board – Wittyboard. You need an api_key from Thingspeak.
    *
    * Based on: https://vaasa.hacklab.fi/2016/02/06/esp8266-on-nodemcu-board-ds18b20-arduinoide-thingspeak/
    * ESP8266 Witty: http://www.schatenseite.de/en/2016/04/22/esp8266-witty-cloud-module/
    */

    #include //BW
    #include //BW

    const char* ssid = “my wi fi”;
    const char* pass = “1234567890”;

    // RGB or button pins are not used in LDR example
    #define RED_PIN 7 // RGB Light pin at Arduino pin 3
    #define GREEN_PIN 8 // RGB Light pin at Arduino pin 5
    #define BLUE_PIN 9 // RGB Light pin at Arduino pin 6
    #define BUTTON_PIN 4 // button
    #define LDR_PIN A0

    char host[] = “api.thingspeak.com”;
    String ApiKey = “NASTJG7VWYAN18NZ”;
    String path = “/update?key=” + ApiKey + “&field1=”;

    int ldr_value = 0;

    void setup() {

    Serial.begin(9600); //BW
    Serial.println(“”);
    Serial.print(“Connecting to “);
    Serial.println(ssid);

    WiFi.begin(ssid, pass);
    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(“.”);
    }

    Serial.println(“”);
    Serial.print(“Connected to “);
    Serial.println(ssid);
    Serial.print(“IP address: “);
    Serial.println(WiFi.localIP());

    pinMode(LDR_PIN, INPUT);

    }

    void loop() {
    ldr_value = analogRead(LDR_PIN); // read input value and store it
    Serial.println(ldr_value); //BW
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
    Serial.println(“connection failed”);
    return;
    }
    client.print(String(“GET “) + path + ldr_value + ” HTTP/1.1\r\n” +
    “Host: ” + host + “\r\n” +
    “Connection: keep-alive\r\n\r\n”);
    delay(100); //BW
    }

  2. Brennan Westworth says:

    #include ESP8266WiFi.h //BW Put these inside “<"
    #include ESP8266WebServer.h //BW

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.