Search code examples
pythonbeagleboneblackxbee

Convert reading from Temperature Sensor connected to XBee


I suppose to calculate actual temperature of remote location using lm35 temperature sensor and xbee sensor. I am getting analog input from sensor, but I am unable to calculate temperature. complete scenario is given below.

Scenario:

I have Connected LM35 Temperature sensor to XBee (Consider sensing node) pin0 which Analog (ADC) and sampling rate is 4 Seconds. Same I have another XBee as Coordinator which is accepting values from xbee sensing node. The coordinator is connected to UART-4 of BeagleBone via it's TX and RX pins. I have used python-xbee python library to read from serial port i.e. UART-4. I am successfully getting analog values from remote xbee. But I am not able to calculate temperature from received analog values.

Sample Frames Which I am Receiving

{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 182, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 182, 'adc-1': 469, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 182, 'adc-1': 468, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 182, 'adc-1': 470, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 182, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 183, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 178, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 180, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 177, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 182, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 183, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 182, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 183, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 166, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 166, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}
{'source_addr_long': '\x00\x13\xa2\x00@\xd6\xa58', 'source_addr': '\xaa\xf9', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-0': 166, 'adc-1': 466, 'adc-2': 1023}], 'options': '\x01'}

Note:

adc-0 is pin of remote xbee where I have connected tempreture sensor.

adc-1 is pin of remote xbee where I have connected Humidity sensor.

adc-2 is pin of remote xbee where I have connected CO2 sensor.

How do I calculate actual temperature? (Current temperature is ~16 to ~18)


Solution

  • The sensor documentation should provide a formula for converting voltage to temperature and humidity.

    You can convert the ADC readings to voltage by multiplying the reading by the reference voltage, and then dividing by 1023. You don't indicate which XBee module you're using, so you'll have to check the datasheet for the reference voltage -- it might be on one of the pins, or might be some fixed value.

    From a Google search, I see that the LM35 produces a voltage of 10 mV per degree Celcius. 182 / 1023 = 0.178 If your reference voltage is 1V, then that's 17.8C.

    The humidity calculation will be similar. The key is to convert the ADC reading to voltage, and then plug that into the formula provided on the datasheet.