# Esp 8266 avec une LDR

**URL:** <https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630>\
**Category:** Français\
**Created:** [August 21, 2025, 1:18pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630 "2025-08-21T13:18:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 21, 2025, 1:18pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/1 "2025-08-21T13:18:29Z")

</div>

bonjour, je suis en train d essayer de faire une petite station meteo, avec un ESP8266 et comme capteur un BME280 et une LDR j ai reussi grace a sdes tuto pour le capteur BME280 mais lorsque je rajoute la LDR sa ne fonctionne plus, alors que si j essai avec juste la LDR j ai aucun souci mon erreur apparait sur la derniere ligne du SERIAL.PRINT sensorValue  
je vous es mis le code je sais pas si je les mis au bon endroit merci pour votre aide

`// Load Wi-Fi library  
#include \<ESP8266WiFi.h\>  
#include \<Wire.h\>  
#include \<Adafruit\_BME280.h\>  
#include \<Adafruit\_Sensor.h\>

//uncomment the following lines if you're using SPI  
/#include _\<SPI.h\>_  
#define _BME\_SCK 14_  
#define _BME\_MISO 12_  
#define _BME\_MOSI 13_  
#define _BME\_CS 15_/

#define SEALEVELPRESSURE\_HPA (1013.25)

Adafruit\_BME280 bme; // I2C  
//Adafruit\_BME280 bme(BME\_CS); // hardware SPI  
//Adafruit\_BME280 bme(BME\_CS, BME\_MOSI, BME\_MISO, BME\_SCK); // software SPI

// Replace with your network credentials  
const char\* ssid = "Freebox-1621E7";  
const char\* password = "";

// Set web server port number to 80  
WiFiServer server(80);

// Variable to store the HTTP request  
String header;

void setup() {  
Serial.begin(115200);  
pinMode(LDRSensor, INPUT);

Serial.println();  
Serial.print("connecter");  
Serial.println("Serveur demarrer !");  
Serial.println("WiFi Connecté Succès !");  
Serial.print("NodeMCU IP Adresse : ");  
Serial.println(WiFi.localIP() );

bool status;

// default settings  
// (you can also pass in a Wire library object like &Wire2)  
//status = bme.begin();  
if (!bme.begin(0x76)) {  
Serial.println("Could not find a valid BME280 sensor, check wiring!");  
while (1);  
}

// Connect to Wi-Fi network with SSID and password  
Serial.print("Connecting to ");  
Serial.println(ssid);  
WiFi.begin(ssid, password);  
while (WiFi.status() != WL\_CONNECTED) {  
delay(500);  
Serial.print(".");  
}  
// Print local IP address and start web server  
Serial.println("");  
Serial.println("WiFi connected.");  
Serial.println("IP address: ");  
Serial.println(WiFi.localIP());  
server.begin();  
}

void loop(){  
int sensorValue = analogRead(A0);  
printValues();

WiFiClient client = server.available(); // Listen for incoming clients

if (client) { // If a new client connects,  
Serial.println("New Client."); // print a message out in the serial port  
String currentLine = ""; // make a String to hold incoming data from the client  
while (client.connected()) { // loop while the client's connected  
if (client.available()) { // if there's bytes to read from the client,  
char c = client.read(); // read a byte, then  
Serial.write(c); // print it out the serial monitor  
header += c;  
if (c == '\n') { // if the byte is a newline character  
// if the current line is blank, you got two newline characters in a row.  
// that's the end of the client HTTP request, so send a response:  
if (currentLine.length() == 0) {  
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)  
// and a content-type so the client knows what's coming, then a blank line:  
client.println("HTTP/1.1 200 OK");  
client.println("Content-type:text/html");  
client.println("Connection: close");  
client.println();

```arduino
        // Display the HTML web page
        client.println("<!DOCTYPE html><html>");
        client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
        client.println("<link rel=\"icon\" href=\"data:,\">");
        // CSS to style the table 
        client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial;}");
        client.println("table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }");
        client.println("th { padding: 12px; background-color: #0043af; color: white; }");
        client.println("tr { border: 1px solid #ddd; padding: 12px; }");
        client.println("tr:hover { background-color: #bcbcbc; }");
        client.println("td { border: none; padding: 12px; }");
        client.println(".sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");
        
        // Web Page Heading
        client.println("</style></head><body><h1>ESP8266 with BME280</h1>");
        client.println("<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>");
        client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
        client.println(bme.readTemperature());
        client.println(" *C</span></td></tr>");  
        client.println("<tr><td>Temp. Fahrenheit</td><td><span class=\"sensor\">");
        client.println(1.8 * bme.readTemperature() + 32);
        client.println(" *F</span></td></tr>");       
        client.println("<tr><td>Pressure</td><td><span class=\"sensor\">");
        client.println(bme.readPressure() / 100.0F);
        client.println(" hPa</span></td></tr>");
        client.println("<tr><td>Approx. Altitude</td><td><span class=\"sensor\">");
        client.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
        client.println(" m</span></td></tr>"); 
        client.println("<tr><td>Humidity</td><td><span class=\"sensor\">");
        client.println(bme.readHumidity());
        client.println(" %</span></td></tr>"); 
        client.println("</body></html>");
        

        
        // The HTTP response ends with another blank line
        client.println();
        // Break out of the while loop
        break;
      } else { // if you got a newline, then clear currentLine
        currentLine = "";
      }
    } else if (c != '\r') { // if you got anything else but a carriage return character,
      currentLine += c; // add it to the end of the currentLine
    }
  }
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");

```

}  
}  
void printValues() {  
Serial.print("Temperature = ");  
Serial.print(bme.readTemperature());  
Serial.println(" \*C");

// Convert temperature to Fahrenheit  
/\*Serial.print("Temperature = ");  
Serial.print(1.8 \* bme.readTemperature() + 32);  
Serial.println(" _F");_/

Serial.print("Pressure = ");  
Serial.print(bme.readPressure() / 100.0F);  
Serial.println(" hPa");

Serial.print("Approx. Altitude = ");  
Serial.print(bme.readAltitude(SEALEVELPRESSURE\_HPA));  
Serial.println(" m");

Serial.print("Humidity = ");  
Serial.print(bme.readHumidity());  
Serial.println(" %");

Serial.print(sensorValue);

Serial.println();  
delay(3000);

}`

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 21, 2025, 1:27pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/2 "2025-08-21T13:27:19Z")

</div>

Malheureusement ton code illisible car tu n’a pas suivi les bonnes pratiques indiqué dans ce [sujet](https://forum.arduino.cc/t/les-bonnes-pratiques-du-forum-francophone/861014) épinglé au début du forum Français. ☹

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 21, 2025, 2:00pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/3 "2025-08-21T14:00:48Z")

</div>

```arduino
// Load Wi-Fi library
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>

//uncomment the following lines if you're using SPI
/*#include <SPI.h>
#define BME_SCK 14
#define BME_MISO 12
#define BME_MOSI 13
#define BME_CS 15*/

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

// Replace with your network credentials
const char* ssid = "Freebox-1621E7";
const char* password = "";

  
 

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

void setup() {
  Serial.begin(115200);
  pinMode(LDRSensor, INPUT);

   Serial.println();
  Serial.print("connecter");
  Serial.println("Serveur demarrer !");
  Serial.println("WiFi Connecté Succès !");
  Serial.print("NodeMCU IP Adresse : ");
  Serial.println(WiFi.localIP() );
  
  bool status;

  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  //status = bme.begin();  
  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();
}

void loop(){
  int sensorValue = analogRead(A0);
  printValues();
  
  WiFiClient client = server.available(); // Listen for incoming clients

  if (client) { // If a new client connects,
    Serial.println("New Client."); // print a message out in the serial port
    String currentLine = ""; // make a String to hold incoming data from the client
    while (client.connected()) { // loop while the client's connected
      if (client.available()) { // if there's bytes to read from the client,
        char c = client.read(); // read a byte, then
        Serial.write(c); // print it out the serial monitor
        header += c;
        if (c == '\n') { // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
            
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the table 
            client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial;}");
            client.println("table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }");
            client.println("th { padding: 12px; background-color: #0043af; color: white; }");
            client.println("tr { border: 1px solid #ddd; padding: 12px; }");
            client.println("tr:hover { background-color: #bcbcbc; }");
            client.println("td { border: none; padding: 12px; }");
            client.println(".sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");
            
            // Web Page Heading
            client.println("</style></head><body><h1>ESP8266 with BME280</h1>");
            client.println("<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>");
            client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
            client.println(bme.readTemperature());
            client.println(" *C</span></td></tr>");  
            client.println("<tr><td>Temp. Fahrenheit</td><td><span class=\"sensor\">");
            client.println(1.8 * bme.readTemperature() + 32);
            client.println(" *F</span></td></tr>");       
            client.println("<tr><td>Pressure</td><td><span class=\"sensor\">");
            client.println(bme.readPressure() / 100.0F);
            client.println(" hPa</span></td></tr>");
            client.println("<tr><td>Approx. Altitude</td><td><span class=\"sensor\">");
            client.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
            client.println(" m</span></td></tr>"); 
            client.println("<tr><td>Humidity</td><td><span class=\"sensor\">");
            client.println(bme.readHumidity());
            client.println(" %</span></td></tr>"); 
            client.println("</body></html>");
            

            
            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') { // if you got anything else but a carriage return character,
          currentLine += c; // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
  }
  void printValues() {
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature());
  Serial.println(" *C");
  
  // Convert temperature to Fahrenheit
  /*Serial.print("Temperature = ");
  Serial.print(1.8 * bme.readTemperature() + 32);
  Serial.println(" *F");*/
  
  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100.0F);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.print("Humidity = ");
  Serial.print(bme.readHumidity());
  Serial.println(" %");

  Serial.print(sensorValue);

  Serial.println();
  delay(3000);

}

```

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 21, 2025, 2:01pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/4 "2025-08-21T14:01:22Z")

</div>

desoler pour la mauvaise manipulation je crois que la c est mieux

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 21, 2025, 2:23pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/5 "2025-08-21T14:23:53Z")

</div>

Oui nettement mieux.

je suppose que quand tu dis que cela ne fonctionne plus ou que ton erreur est sur sensorValue, tu veux dire que cela ne compile pas ?

et que tu as le message error: 'sensorValue' was not declared in this scope?

En règle général, moins tu indiques d’information, moins tu aura de réponse rapide.  
Car moins tu fais d’effort pour nous aider, moins on a envi de faire d’effort pour deviner ce qu'i ne va pas dans ton programme ☹

Là tu déclare une variable dans une fonction et l’utilise dans une autre.  
Hors lorsque tu déclare une variable dans une fonction, elle ne peut être vue dans une autre fonction.  
La bonne chose à faire à mon avis est de passer la variable en paramètre de ta fonction

```arduino
void printValues(int sensorValue) {
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature());
  Serial.println(" *C");
  
  // Convert temperature to Fahrenheit
  /*Serial.print("Temperature = ");
  Serial.print(1.8 * bme.readTemperature() + 32);
  Serial.println(" *F");*/
  
  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100.0F);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.print("Humidity = ");
  Serial.print(bme.readHumidity());
  Serial.println(" %");

  Serial.print(sensorValue);

  Serial.println();
  delay(3000);

}

```

et tu l’appel ainsi

```arduino
printValues(sensorValue);

```

Tu peux aussi mettre la variable global, comme pas **password**  
mais cela ne se justifie pas trop.

Je te conseillerais aussi de passer un peu de temps sur des [formations de C++](https://openclassrooms.com/fr/courses?categories=Cybers%25C3%25A9curit%25C3%25A9%252CData%252CD%25C3%25A9veloppement%252CSyst%25C3%25A8mes%2520%2526%2520R%25C3%25A9seaux)  
@pandaroux007 à commit une liste impressionnante de [ressources](https://forum.arduino.cc/t/liste-de-sites-et-tutos-arduino-externes-au-forum/1124198) qui pourrait t’intéresser.

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 21, 2025, 2:55pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/6 "2025-08-21T14:55:16Z")

</div>

desole je pensais que j avais ete asser claire sur mon defaut, en faite j ai fait un copier coller du programme ou la LDR fonctionne seul et j ai rajouter les lignes dans les memes fonctions du programme en ayant rajouter tout l ensemble du programme faut dire aussi que je debute c est mon premier programme aussi compliquer pour moi  
je vais regarder pour ta formation en C++  
merci de ton aide

---

<div class="post-metadata">

**Author:** ![al1fch](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/al1fch/32/979602_2.png) [@al1fch](https://forum.arduino.cc/u/al1fch)\
**Post date:** [August 21, 2025, 3:40pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/7 "2025-08-21T15:40:51Z")

</div>

Bonjour

j’ai retiré le mot de passe de la Freebox dans les codes donnés ci-dessus

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 21, 2025, 7:04pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/8 "2025-08-21T19:04:10Z")

</div>

```arduino
// Load Wi-Fi library
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>

//uncomment the following lines if you're using SPI
/*#include <SPI.h>
#define BME_SCK 14
#define BME_MISO 12
#define BME_MOSI 13
#define BME_CS 15*/
int sensorValue = A0;
#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

// Replace with your network credentials
const char* ssid = "Fre";
const char* password = "";

  
 

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

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

   Serial.println();
  Serial.print("connecter");
  Serial.println("Serveur demarrer !");
  Serial.println("WiFi Connecté Succès !");
  Serial.print("NodeMCU IP Adresse : ");
  Serial.println(WiFi.localIP() );
  
  bool status;

  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  //status = bme.begin();  
  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();
}

void loop(){
  int sensorValue = analogRead(A0);
  Serial.print("Luminosite = ");
  Serial.print(sensorValue);
  Serial.println(" Lux");
  
  printValues();
  
  WiFiClient client = server.available(); // Listen for incoming clients

  if (client) { // If a new client connects,
    Serial.println("New Client."); // print a message out in the serial port
    String currentLine = ""; // make a String to hold incoming data from the client
    while (client.connected()) { // loop while the client's connected
      if (client.available()) { // if there's bytes to read from the client,
        char c = client.read(); // read a byte, then
        Serial.write(c); // print it out the serial monitor
        header += c;
        if (c == '\n') { // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
            
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the table 
            client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial;}");
            client.println("table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }");
            client.println("th { padding: 12px; background-color: #0043af; color: white; }");
            client.println("tr { border: 1px solid #ddd; padding: 12px; }");
            client.println("tr:hover { background-color: #bcbcbc; }");
            client.println("td { border: none; padding: 12px; }");
            client.println(".sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");
            
            // Web Page Heading
            client.println("</style></head><body><h1>ESP8266 with BME280</h1>");
            client.println("<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>");
            client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
            client.println(bme.readTemperature());
            client.println(" *C</span></td></tr>");  
            client.println("<tr><td>Temp. Fahrenheit</td><td><span class=\"sensor\">");
            client.println(1.8 * bme.readTemperature() + 32);
            client.println(" *F</span></td></tr>");       
            client.println("<tr><td>Pressure</td><td><span class=\"sensor\">");
            client.println(bme.readPressure() / 100.0F);
            client.println(" hPa</span></td></tr>");
            client.println("<tr><td>Approx. Altitude</td><td><span class=\"sensor\">");
            client.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
            client.println(" m</span></td></tr>"); 
            client.println("<tr><td>Humidity</td><td><span class=\"sensor\">");
            client.println(bme.readHumidity());
            client.println(" %</span></td></tr>"); 
            client.println("</body></html>");
             client.println("<tr><td>Luminosite</td><td><span class=\"sensor\">");
            client.println(sensorValue);
            client.println(" Lux</span></td></tr>"); 
            client.println("</body></html>");

            
            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') { // if you got anything else but a carriage return character,
          currentLine += c; // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
  }
  void printValues() {
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature());
  Serial.println(" *C");
  
  // Convert temperature to Fahrenheit
  /*Serial.print("Temperature = ");
  Serial.print(1.8 * bme.readTemperature() + 32);
  Serial.println(" *F");*/
  
  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100.0F);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.print("Humidity = ");
  Serial.print(bme.readHumidity());
  Serial.println(" %");

  

  Serial.println();
  delay(3000);

}

```

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 21, 2025, 7:09pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/10 "2025-08-21T19:09:16Z")

</div>

merci pour votre aide, j ai modifier un peu le programme, et sa fonctionne je vous les mis si jamais sa peut aider quelqu un ou donne des idees pour un projet  
encore merci a vous

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 21, 2025, 9:28pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/11 "2025-08-21T21:28:44Z")

</div>

Pour garder la logique de ton programme qui est de faire l’acquisition et l’affichage de la valeur.  
Tu aurais pu plutot déplacer analogRead(A0) dans ta fonction.

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 22, 2025, 1:32pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/12 "2025-08-22T13:32:02Z")

</div>

bonjour, comment ca dans la fonction

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 22, 2025, 2:19pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/13 "2025-08-22T14:19:57Z")

</div>

comment ca, comment ca 🙂

tu a déplacer “Serial.print(sensorValue);” dans la fonction “void printValues()”  
pourquoi ne pas avoir déplacer analogRead(A0) dans cette fonction?

dans ta fonction “printValues” tu fais l’acquisition des données et son affichage.  
La logique aurait voulu que tu en fasse de même pour sensorValue ?

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 23, 2025, 9:06am UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/14 "2025-08-23T09:06:07Z")

</div>

j ai tout mis dans void loop  
serial.print et et le sensordValue

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 24, 2025, 6:53am UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/15 "2025-08-24T06:53:41Z")

</div>

> [@calimero1](#):
>
> ai tout mis dans void loop  
> serial.print et et le sensordValue

Oui, je me suis mal exprimé, pourquoi avoir déplacer le Serial.print dans la loop, plutot que le analogRead dans printValues.  
puisque ta fonction, fait les affichages de valeur (printValues).  
Cela aurais permis que tout les afffichages de valeur soit au même endroit, plutot de disiminé dans ton code.

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 24, 2025, 7:28am UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/16 "2025-08-24T07:28:04Z")

</div>

juste parce que ca n avait pas l aire de fonctionne correctement sinon, j avais de memoire un souci soit de le monitor ou je n avais pas tout d afficher soit lorsque je me connectais a l adresse IP j avais une erreur, et vu que je maitrise pas trop la programmation j ai laisser comme ca

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 24, 2025, 7:32am UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/17 "2025-08-24T07:32:23Z")

</div>

Tu peux déplacer le code suivant dans ta fonction printValues

`int sensorValue = analogRead(A0);`  
`Serial.print("Luminosite = ");`  
`Serial.print(sensorValue);`  
`Serial.println(" Lux");`

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 24, 2025, 4:16pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/18 "2025-08-24T16:16:17Z")

</div>

si je fais cela la valeur lumiere ne fonctionne pas lorsque je vais voir les donnees en passant par l adresse IP sa fonctionne que sur moniteur serie de l arduino ide

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 24, 2025, 4:25pm UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/19 "2025-08-24T16:25:18Z")

</div>

Oui, mais tu peux faire la même chose que pour les valeurs du BME, lire la donné que tu veux renvoyer dans la requête HTTP.  
C’est à dire ne pas utiliser sensorValues, mais analogRead(A0)

Tu as aussi une variable global **sensorValue** que je crois tu n’utilises plus et qui est assigné avec un valeur qui ne correspond pas a son nom.

Tout ceci n’est pas spécialement problèmatique, mais c’est très fouillis, donc au fils de l’évolution de ton code, tu risques de passer un certain temps à dénouer les fils

---

<div class="post-metadata">

**Author:** ![calimero1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/calimero1/32/1126465_2.png) [@calimero1](https://forum.arduino.cc/u/calimero1)\
**Post date:** [August 25, 2025, 7:41am UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/20 "2025-08-25T07:41:53Z")

</div>

j ai essayer de faire ca mais j ai pas reussi, en essayant de faire comme pour le BME, j ai surement loupe un truc ou un truc que j ai pas compris et c est pour ca que j y arrive pas

---

<div class="post-metadata">

**Author:** ![terwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terwal/32/1098571_2.png) [@terwal](https://forum.arduino.cc/u/terwal)\
**Post date:** [August 26, 2025, 10:21am UTC](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630/21 "2025-08-26T10:21:29Z")

</div>

Oui, mais justement le Forum est là pour ça.  
montre nous ce que tu as essayé de faire et on te guidera pour que tu comprennes et que cela fonctionne 🙂

Si tu suit les tutoriaux indiqué par @pandaroux007 et nous poses des questions sur les parties que tu n’a pas compris et qui ne marche pas lors de tes mises en applications, tu devrais pouvoir réaliser assez facilement ton projet.

[Next page](https://forum.arduino.cc/t/esp-8266-avec-une-ldr/1403630.md?page=2)
