Arduino esp32/Photoresistor sensor not working

I am trying to post sensor data to google sheet ,but my sensor seems to... not wanna turn on

I appreciate any help in advance.

Sorry it is my first time post

here is code:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "WiFi.h"
#include <HTTPClient.h>
#include "time.h"
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 19800;
const int daylightOffset_sec = 0;
//WiFi credentials//
const char* ssid = "Jiawifi"; // change SSID
const char* password = "11223344"; // change password
// Google script ID and required credentials//
String GOOGLE_SCRIPT_ID = "AKfycbxtVXqjb9L2qIwc4BLZxkSvkVvWdw8pR2S5jinyXG8HWswZcfp_6CZjcSNyMD50vttb"; // change Gscript ID
int count = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
//photoresistor setup//
delay(1000);
Serial.begin(115200);
delay(1000);
pinMode(13, INPUT);//選告GPIO 13作為輸入(光敏電阻)
//Wifi setup//
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to wifi: ");
Serial.println(ssid);
Serial.flush();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Init and get the time
// configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);

}
/******************************************************************************/
void loop() {
// wifi connected
if (WiFi.status() == WL_CONNECTED) {
static bool flag = false;
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
// read in photoresistor value
int LightValue;
LightValue = analogRead(13);
Serial.println(LightValue);
// data post to goolge sheet
String urlFinal = "https://script.google.com/macros/s/"+GOOGLE_SCRIPT_ID+"/exec?"+"point=" + LightValue + "&holenumber=" + "1"+"&oneinhole="+"yes";
Serial.print("POST data to spreadsheet:");
Serial.println(urlFinal);
HTTPClient http;
http.begin(urlFinal.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int httpCode = http.GET();
Serial.print("HTTP Status Code: ");
Serial.println(httpCode);

http.end();

}
//count++;
delay(1000);
}

…and not a very good attempt.

Please read the sticky posts about HOW TO USE THIS FORUM.

sorry i will read

What, exact sensor do you have?

Please post a diagram showing how the sensor is wired.

I suggest that you write a small sketch to only get the sensor to work and display the output values. Leave the complication of the Wifi stuff till after you understand the sensor.

Help us help you.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Please post a schematic.

Please post an image of your project.

Please describe the problem better then you just did.

  1. I can readings from the sensor whenever wifi setup is not instantiated.

You cannot analogRead from ADC2 with WiFi enabled.
Use those associated with ADC1.

PE -- 32-36, 39 (stick with 32-35)

thank for answer!!!!!!!!!! i will try it later
:laughing:

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