My ESP8266-01 recognises the sensor TSL2561, but the readings always output 65535 for some weird reason. But as I said, when I run the I2C scanner and plug in the wire I see the sensor popping up at 0x39.

When I hook up the same sensor to an ESP8266 NodeMCU breakout and flash the same code on there it reads it out just fine. I have the wires connected as shown below without any resistors or anything in between.

| ESP8266-01 | TSL25611   |
| VCC (3.3V) | VCC (3.3V) |
| GND        | GND        |
| GPIO2      | SCL        |
| GPIO0      | SDA        |

I'm not sure what I'm doing wrong though.

My code:

#include <Wire.h>
#include <ESP8266WebServer.h>
#include <TSL2561.h>

const char *ssid = "Wouter's Place";
const char *password = "";

ESP8266WebServer server(80);
TSL2561 tsl2561(TSL2561_ADDR_FLOAT);

void handleRoot() {
  // Read illuminance
  float visible = tsl2561.getLuminosity(TSL2561_VISIBLE);
  float full = tsl2561.getLuminosity(TSL2561_FULLSPECTRUM);
  float ir = tsl2561.getLuminosity(TSL2561_INFRARED);

  String response = "";
  response += "{\"illuminance\":{";
  response += "\"visible\":";
  response += visible;
  response += ",\"full\":";
  response += full;
  response += ",\"ir\":";
  response += ir;
  response += "}";
  response += "}";

  server.send(200, "application/json", response);

void setup(void)
  Wire.begin(0, 2);


  digitalWrite(LED_BUILTIN, HIGH);

  Serial.print("Connecting to: ");

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)

  Serial.print("Connected to wifi, ip: ");

  Serial.println("Setting up TSL2561..");
  if (!tsl2561.begin())
    Serial.println("Could not find TSL2561 sensor, check wiring!");
    while (1);

  Serial.println("Starting server..");
  server.on("/", handleRoot);
  Serial.println("Web server running!");

void loop()

Resulting output:

    "visible": 0,
    "full": 65535
    "ir": 65535
  • \$\begingroup\$ Can you post a schematic? I can't tell what you've hooked up in your video. \$\endgroup\$ – KingDuken Jan 28 '19 at 19:59
  • \$\begingroup\$ please post the code, not a link to the code \$\endgroup\$ – jsotola Jan 28 '19 at 20:06
  • \$\begingroup\$ Just to comment 65536 is 16 bits of all ones. Since the I2C data line idles high, this probably means the slave isn’t responding. \$\endgroup\$ – DoxyLover Jan 29 '19 at 0:16
  • \$\begingroup\$ @DoxyLover thanks, after reading above I started thinking about it and went another time through my code only to find a quite obvious bug. \$\endgroup\$ – wouterds Jan 30 '19 at 15:14

Found the bug after thinking a bit about what @DoxyLover mentioned! Those 2 lines of leftover code shouldn't be here. Apparently the default LED on the ESP-01 is GPIO2 (which is one of the I2C pins I'm using).

digitalWrite(LED_BUILTIN, HIGH);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.