1

I am using DEVKIT V1 DOIT board and 30 pinout board.

When I upload this code for checking analog value from serial monitor:

    // Define the analog input pin for the IR sensor
const int analogPin = 13;

void setup() {
  Serial.begin(115200); 
}

void loop() {
  // Read the analog value from the IR sensor
  int sensorValue = analogRead(analogPin);

  // Display the analog value in the Serial Monitor
  Serial.print("Analog Value: ");
  Serial.println(sensorValue);

  // Add a short delay to avoid rapid readings
  delay(500);
}

it came just normally fine.

But when I upload this code:

#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid = "JANINA";
const char* password = "sayma01720";
const char* websiteURL = "http://192.168.1.105:4747/araf/phploginscript-master/sense_value.php?uid=56"; // Replace with your website URL

const int analogPin = 19;

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  int sensorValue = analogRead(analogPin);
  Serial.print("Analog Value: ");
  Serial.println(sensorValue);

  // Prepare the temperature to be sent
  String temperature = "temperature=" + String(sensorValue);

  WiFiClient client;
  HTTPClient http;

  bool success = http.begin(client, websiteURL);
if (!success) {
  Serial.println("Could not connect to the server");
  return;
}

  
  // Set content type to application/x-www-form-urlencoded
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");

  int httpResponseCode = http.POST(temperature);

  if (httpResponseCode > 0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    String response = http.getString();
    Serial.println(response);
  } else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }

  http.end();

  // Wait for some time before sending the next temperature
  delay(2000);
}

It stop read analog value. This was the result shown in serial monitor,

Analog Value: 0 HTTP Response code: 200

Please help me SIR.

2
  • why are you using a different pin than the first example? ... is pin 19 an analog input pin?
    – jsotola
    Commented Jul 21, 2023 at 4:31
  • No.... I was tried many pins 4, 22, 23, 19, etc. but I can not find the solution. Commented Jul 21, 2023 at 5:01

0

Browse other questions tagged or ask your own question.