NeitoFR
Posts: 1
Joined: Mon Jan 22, 2018 10:38 pm

Precision of luminosity sensor. Get data from nodejs

Mon Jan 22, 2018 10:53 pm

Hello, this is my first post here.

My material:
Raspberry Pi 2 Model B
A Digital Luminosity sensor it is this one : http://osoyoo.com/wp-content/uploads/2017/03/14.jpg

How I wired it :
There is three pin to wire
I plugged the VCC one to the 3.3V GPIO pin,
the GND one to one of the ground GPIO pin,
and the last one called "DO" (I guess it is for Digital Output) i plugged it in the GPIO pin 4.

Here is my issue : I wrote a piece of code to get data from the sensor, it works ! But I only get to read 1 and 0 !
I would like to get more precise value (like a value between 0.000 and 1 you know ?)

Here is the code :

Code: Select all

"use strict";

var Gpio = require('onoff').Gpio,
    pr = new Gpio(4, 'in'),
    readInterval = setInterval(getPrValue, 25);

function getPrValue(){
    console.log("Value of photo resistance : "+pr.readSync());
}
    
process.on('SIGINT', function(){
    clearInterval(readInterval);
    pr.unexport();
}); 
My question is, Is my light sensor able to send more precise value than 0 and 1 (would be a huuuuge disappointement if it wasn't) ? And the second one would be to know what variation to the code would make the difference ?

Have a nice day everyone, thanks for your time.

NeitoFR

asandford
Posts: 1996
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Precision of luminosity sensor. Get data from nodejs

Tue Jan 23, 2018 1:23 am

NeitoFR wrote:
Mon Jan 22, 2018 10:53 pm
the last one called "DO" (I guess it is for Digital Output) i plugged it in the GPIO pin 4.

Here is my issue : I wrote a piece of code to get data from the sensor, it works ! But I only get to read 1 and 0 !
That's all digital pins give - 1 or 0 - on or off, in the case of your sensor it means that a light threshold has been met (or not).
NeitoFR wrote:
Mon Jan 22, 2018 10:53 pm
I would like to get more precise value (like a value between 0.000 and 1 you know ?)
If you want more granularity then use the analog output (A0), but the Pi can't directly read; you'll need an ADC to do that.

Return to “Other programming languages”