-2

I am trying to gather inputs from five sensors and simply print the same but the return values always seem to return 1 or 0 regardless to change in the inputs to the sensors.

The code used by me is as follows

from machine import pin
p0 = Pin(0,Pin.IN)
p2 = Pin(2,Pin.IN)
print(p0.value())
print(p0.value())

Outputs:
1
1
or  0 0 or 1 0

etc depending if sensor is active or not but I am unable to get the exact value read by the sensor ie if I have pulse rate sensor connected it just shows 1 if its in use rather than providing the pulse rate.

OshoParth
  • 1,492
  • 2
  • 20
  • 44
  • You are reading digital pins. Of course they are only 0 or 1. It's also unclear what kind of sensors are you using. – gre_gor Dec 22 '18 at 14:58
  • As I have mentioned in the example that I am using the pulse rate sensor and along with that I am using the motion ( PIR ) Sensor. – OshoParth Dec 24 '18 at 07:10
  • You didn't tell us what kind of pulse sensor do you use. So we don't know how it's supposed to be interfaced. Could be SPI, I2C, just pulses, ... And PIR sensor is just on or off, so there is nothing analog. – gre_gor Dec 25 '18 at 11:01

1 Answers1

1

A NodeMCU like all ESP8266 based systems has only one (rather limited) analog input. All other GPIO ports are digital. They deliver 0 or 1 only.

To read analog values you will need additional hardware like an ADS1115.

Klaus D.
  • 13,874
  • 5
  • 41
  • 48