0

I'm using a -12E with three light sensors and a sketch I've successfully used with an Uno. I cannot get the -12E to print anything but 0 or 1023 for a light level (0 when I connect the grounds, 1023 without grounds).

I've successfully printed from a single light sensor but now I'd like to try three.

I'm curious to know what I'm missing. Any guidance would be appreciated.

Code is as follows:

const int photocellPin_0 = 16; // D0
const int photocellPin_1 = 5; // D1
const int photocellPin_2 = 4; // D2
int photocellReading_0;
int photocellReading_1;
int photocellReading_2;
void setup() {
 delay(4900);
 Serial.begin(115200);
 Serial.println("Startup");
 delay(100);
 pinMode(photocellPin_0, INPUT);
 pinMode(photocellPin_1, INPUT);
 pinMode(photocellPin_2, INPUT);
}
void loop() {
 delay(1000);
 photocellReading_0 = analogRead(photocellPin_0);
 photocellReading_1 = analogRead(photocellPin_1);
 photocellReading_2 = analogRead(photocellPin_2);
 Serial.println("-----NEW ON READING-----");
 Serial.print("Photo Sensor #1 = ");
 Serial.println(photocellReading_0); // the raw analog reading
 Serial.print("Photo Sensor #2 = ");
 Serial.println(photocellReading_1);
 Serial.print("Photo Sensor #3 = ");
 Serial.println(photocellReading_2);
 delay(5000);
}

This is based on an adafruit sketch I pulled off of some website (modified for three photo sensors) and I'd credit it if I could recall exactly where I got it from.

asked Feb 17, 2017 at 0:57
1
  • 1
    you can only use analogRead on pin A0 on the ESP8266. you can multiplex or even use a relay to switch out sensors, or use a cheap and precise I2C ADC, like the 16-bit ads1115 (2ドル.5), which gives you four hi-res analog inputs. you could also use a cheap pro mini or nano to expand IO, but they don't have the best ADCs... Commented Feb 17, 2017 at 10:04

1 Answer 1

3

The ESP8266 ESP-12E has only one analog input, that is A0 (which tolerates a range 0-1 volt).

digitalRead() statements are not appropriate for a photocell within a potential divider since you will simply get a boolean result 0 or 1 from the connected pin.

You can read one photocell connected on A0 by analogRead( A0 ) assuming it is so connected within a potential divider that a maximum of 1 volt is presented to pin A0.

The Arduino Uno by contrast has 6 Analog inputs which tolerate up to 5 volts

answered Feb 17, 2017 at 11:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.