LSL
LSL

Reputation: 109

Conflict between WiFi and lightsensor?

I have a weird problem with my ESP8266 Lolin32. I try to make a project which get value from a lightsensor and establish a WiFi connection. I can properly display values, but when I add Wifi connection, light sensor always display 4095 and never change even when light sensor is hid. Here's some code

#include <WiFiUdp.h>
#include <ETH.h>
#include <WiFiSTA.h>
#include <WiFiMulti.h>
#include <WiFiType.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <WiFiScan.h>
#include <WiFiAP.h>
#include <WiFiGeneric.h>
#include <WiFi.h>

int photocellPin = 14; 
int photocellReading; 


const char* ssid = "ssid";
const char* password = "pass";

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

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting\n");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("Waiting for connection...\n");
  }

  Serial.println();

  //configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");


  Serial.print("Connected, IP address: \n");
  Serial.println(WiFi.localIP()); 

}

void loop() {

  photocellReading = analogRead(photocellPin);
  Serial.print("Analog reading = ");
  Serial.print(photocellReading); // the raw analog reading
  // We'll have a few threshholds, qualitatively determined
  if (photocellReading < 10) {
    Serial.println(" - Black");
  } else if (photocellReading < 200) {
    Serial.println(" - Dark");
  } else if (photocellReading < 500) {
    Serial.println(" - Light");
  } else if (photocellReading < 800) {
    Serial.println(" - Light +");
  } else {
    Serial.println(" - Light ++");
  }
  delay(50);
}

always display 4095 - Light ++

Upvotes: 0

Views: 71

Answers (1)

mariotorrone
mariotorrone

Reputation: 56

I've never actually used that Wi-Fi module, but it might be that pin 14 is already used by the libraries of the module for something else. I would try connecting the light sensor to another pin or maybe even check through the libraries for signs of using pin 14 for something else.

Upvotes: 0

Related Questions