Sensor not running mit app

The pinsensor cannot be read on the mit app

#include <ESP8266WiFi.h>
#include <Wire.h> 

const char WiFiPassword[] = ""; // Tambahkan sandi WiFi Anda di sini
const char AP_NameChar[] = "Counter";

String request = "";
int nilaiAnalog; 
 
int pinSensor = A0; 
int relay = 2;
int counter = 0;
bool run_counter = false;
unsigned long previousMillis = 0;
const long interval = 100; // polling interval dalam milidetik

WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  Serial.print("Setting AP (Access Point)...");
 
  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);
  Serial.println(WiFi.localIP());
    
  pinMode(pinSensor, INPUT);
  pinMode(relay, OUTPUT);

  WiFi.disconnect();
  boolean conn = WiFi.softAP(AP_NameChar, WiFiPassword);
  server.begin();
} 

void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  
  request = client.readStringUntil('\n');

  if (request.indexOf("ON") > 0) {
    digitalWrite(relay, HIGH);
    run_counter = true;
  }
  
  if (request.indexOf("OFF") > 0) {
    digitalWrite(relay, LOW);
    run_counter = false;    
    counter = 0; 
  }
  
  if (run_counter) { 
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      nilaiAnalog = analogRead(pinSensor);
      if (nilaiAnalog > 0) {
        counter++;   
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println("<!DOCTYPE HTML>");
        client.println("<html>");
        client.print("\n");
        client.println(counter);  
      }
    }
  }
}

Is pinsensor equal to zero?

The screenshot of your MIT-App seems to have more things above and below that can not be seen in the screenshot.

The part that of the MIT-App-code that is readable is not about processing this part of your arduino-code

        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println("<!DOCTYPE HTML>");
        client.println("<html>");
        client.print("\n");
        client.println(counter);  

How should anybody help if you give only partial information?

No, it should indicate above the number 0

Your observations indicate it is ZERO. Find why it is zero.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.