Analog Ambient Light Sensor

I am having trouble getting this sensor to work.

The sensor has 3 connections.

  1. I’ve connected GND to the ground pin on the Imp001.
  2. I’ve connected VCC to the 3.3V pin on the Imp001.
  3. I’ve connected SIG to pin 8 on the Imp001.

I use the following bit of code to poll it:

`
const lightCheckFreq = 0.1;

lightSensor <- hardware.pin8;
lightSensor.configure(ANALOG_IN);

refVoltage <- hardware.voltage();
server.log("Reference Voltage: " + refVoltage + “V”);

function checkAmbientLight()
{
server.log("Light Sensor Output: " + lightSensor.read() + “/65535”);
imp.wakeup((lightCheckFreq*60), checkAmbientLight);
}

checkAmbientLight();
`

I can get values but they aren’t very high. I shined a flashlight onto the sensor and It only read around 300 when I would have expected a value around 60000. Here is what the log looked like when I flashed it:

2016-09-08 12:35:16 UTC-4 [Device] Reference Voltage: 3.27400V 2016-09-08 12:35:35 UTC-4 [Device] Light Sensor Output: 0/65535 2016-09-08 12:35:41 UTC-4 [Device] Light Sensor Output: 0/65535 2016-09-08 12:35:47 UTC-4 [Device] Light Sensor Output: 288/65535 2016-09-08 12:35:53 UTC-4 [Device] Light Sensor Output: 304/65535 2016-09-08 12:35:59 UTC-4 [Device] Light Sensor Output: 0/65535 2016-09-08 12:36:05 UTC-4 [Device] Light Sensor Output: 0/65535

I assumed that this sensor would output a voltage in the range of GND to VCC depending on the light striking it which is why I powered it with 3.3V so that it wouldn’t return a voltage higher than that to the ADC.

In order to troubleshoot, I replaced the sensor with a jumper wire from the 3.3V pin directly to pin 8 to see what the ADC returns. It returns values around 400:

2016-09-08 13:37:26 UTC-4 [Device] Light Sensor Output: 416/65535 2016-09-08 13:37:32 UTC-4 [Device] Light Sensor Output: 416/65535 2016-09-08 13:37:38 UTC-4 [Device] Light Sensor Output: 400/65535 2016-09-08 13:37:44 UTC-4 [Device] Light Sensor Output: 384/65535 2016-09-08 13:37:50 UTC-4 [Device] Light Sensor Output: 400/65535 2016-09-08 13:37:56 UTC-4 [Device] Light Sensor Output: 400/65535 2016-09-08 13:38:02 UTC-4 [Device] Light Sensor Output: 416/65535 2016-09-08 13:38:08 UTC-4 [Device] Light Sensor Output: 416/65535 2016-09-08 13:38:14 UTC-4 [Device] Light Sensor Output: 400/65535 2016-09-08 13:38:20 UTC-4 [Device] Light Sensor Output: 400/65535 2016-09-08 14:17:54 UTC-4 [Device] Light Sensor Output: 544/65535

I must be missing something?!

I’ve left it running for about an hour and the highest value I found was 544.

Could it be that the light sensor requires 5V. Which leads to 2 questions:

  1. What happens when 5V is fed into an analog pin?

  2. Can I feed the 5V sensor signal through a logic level converter?

I have this one on the board for another purpose, but It has some free pins.

I’m pretty sure that the logic level converter is just for digital signals (based on the name of the component).

Edit: I answered #2 already - No

“Keep in mind that these level shifters are purely digital. They can’t map an analog voltage from one max voltage to another.”

https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide

Just some additional info (still not solved):

I connected the ADC to ground and do get 0.
I unconnected it to let it float and it registers random values in the 30000 range.
I changed the program to use pin 9 and got the same result.

So I know it isn’t a hardware fault, etc.

I am also using the 3.3v pin to power the low voltage side of the logic level converter. And the Imp is powered from a 1.5A USB charger.

I’m out of ideas. Hopefully someone can give me some new things to try to diagnose the possible issue.

SOLVED - I made a wiring mistake. Everything is working fine. Carry on.

Note to self - double check your circuits!!