# Aosong AM2315 temp/rh

**URL:** <https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589>\
**Category:** Hardware\
**Created:** [5 November 2018 17:17 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589 "2018-11-05T17:17:50Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [5 November 2018 17:17 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/1 "2018-11-05T17:17:50Z")

</div>

Has anyone tried to collect Temp/RH data from a AM2315 sensor?

I've tried the i2C in/out nodes with little success (I get a return from the sensor but it doesn't make sense).

I can get data through python scripts so I know the sensor is wired correctly.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [5 November 2018 17:30 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/2 "2018-11-05T17:30:38Z")

</div>

Which hardware? Show us your flow please!

---

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [5 November 2018 19:03 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/3 "2018-11-05T19:03:21Z")

</div>

```auto
[{"id":"1477d41f.ef3274","type":"inject","z":"414b12bb.d470bc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":360,"wires":[["9809ef2.46f0c1","4374245d.98630c"]]},{"id":"ea35a8fa.c6eb","type":"debug","z":"414b12bb.d470bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750,"y":420,"wires":[]},{"id":"9809ef2.46f0c1","type":"delay","z":"414b12bb.d470bc","name":"","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":430,"y":360,"wires":[["cb6377b9.a717a8","df8343ed.6fba58"]]},{"id":"cb6377b9.a717a8","type":"i2c out","z":"414b12bb.d470bc","name":"","address":"92","command":"3","payload":"[0x00,0x04]","payloadType":"str","count":"3","x":620,"y":360,"wires":[]},{"id":"df8343ed.6fba58","type":"i2c in","z":"414b12bb.d470bc","name":"","address":"92","command":"3","count":"5","x":610,"y":420,"wires":[["ea35a8fa.c6eb"]]},{"id":"4374245d.98630c","type":"i2c out","z":"414b12bb.d470bc","name":"","address":"92","command":"0","payload":"0","payloadType":"str","count":"2","x":440,"y":300,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [5 November 2018 21:14 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/4 "2018-11-05T21:14:02Z")

</div>

Please redo pasting the flow between back-ticks or triple back-ticks.

You may need to decode the Python library you are using in order to work out how to read the raw sensor data. Personally, I always put sensors on an Arduino (direct connect) or ESP (output to MQTT) microprocessor so I don't have to think about sensor complexity - there is nearly always a suitable Arduino IDE library available.

---

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [8 November 2018 16:43 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/5 "2018-11-08T16:43:41Z")

</div>

Re-pasted a simpler flow inside backticks.....

I am using a Raspberry Pi 3b with a Aosong AM2315.

The sensor needs to be sent a couple of bytes to wake it up then the commands to read (0x03), from register 0 (0x00), and the number of bytes (4). So all together is: [0x03,0x00,0x04]

The I2C input node seems to only allow a single byte in its command.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [8 November 2018 16:46 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/6 "2018-11-08T16:46:18Z")

</div>

> [@JaSiev](#):
>
> Re-pasted a simpler flow inside backticks.....

The backticks should be on separate lines, before and after the code:  
```  
code  
```

---

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [8 November 2018 16:47 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/7 "2018-11-08T16:47:20Z")

</div>

sorry - new to this whole forum thing

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [8 November 2018 16:49 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/8 "2018-11-08T16:49:24Z")

</div>

Still wrong way.  
Please read this to get flow sharing done in proper way  
[https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [8 November 2018 16:59 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/9 "2018-11-08T16:59:52Z")

</div>

thank you - fixed (really this time)

---

<div class="post-metadata">

**Author:** ![Elvincth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/elvincth/32/3850_2.png) [@Elvincth](https://discourse.nodered.org/u/Elvincth)\
**Post date:** [11 November 2018 04:06 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/10 "2018-11-11T04:06:16Z")

</div>

I am currently working on am2315 temperature sensor on raspberry pi, it will be kind if you can share the flow and how do you connect the sensor, get everything works together, I tried about an hour now but no luck thanks in advance, Elvin.

---

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [14 November 2018 19:05 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/11 "2018-11-14T19:05:07Z")

</div>

Elvincth - my flow is pasted further up on the thread - as I stated, I get numbers from the sensor but they don't seem to coincide with my expected HEX Temp/RH.

The sensor needs to be wired to the PI: Red wire to 3.3V, Black wire to Ground, Yellow to SDA, White to SCL. Both Yellow and white wires require a pull-up resistor (I used 10K) from 3.3V.

---

<div class="post-metadata">

**Author:** ![Elvincth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/elvincth/32/3850_2.png) [@Elvincth](https://discourse.nodered.org/u/Elvincth)\
**Post date:** [15 November 2018 14:52 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/12 "2018-11-15T14:52:06Z")

</div>

Thanks mate!

---

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [21 November 2018 21:44 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/13 "2018-11-21T21:44:07Z")

</div>

no problem - let me know how it turns out or if you figure out what I've done wrong.

---

<div class="post-metadata">

**Author:** ![JaSiev](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JaSiev](https://discourse.nodered.org/u/JaSiev)\
**Post date:** [12 December 2018 22:51 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/14 "2018-12-12T22:51:43Z")

</div>

In case anyone is interested I managed to get the AM2315 Temp/RH to work using the NPM i2c-sensor-am2315 driver:

```auto
[{"id":"b969dd56.ca08c","type":"debug","z":"414b12bb.d470bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1070,"y":100,"wires":[]},{"id":"d5647717.af045","type":"debug","z":"414b12bb.d470bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":220,"wires":[]},{"id":"6a8e5018.4d76d","type":"function","z":"414b12bb.d470bc","name":"AM2315","func":"var Driver = global.get('am2315');\n\n// create device\nvar device = new Driver();\n\n// read the sensor\ndevice.read(function(err, data) {\n\tif (err) {\n\t\tconsole.error(err);\n\t} else {\n\t\tconsole.log('Original in K');\n\t\tconsole.log(data);\n\t\tnode.send([{payload: data}]);\n\t \n\t}\n});\n\n\n\n","outputs":1,"noerr":0,"x":360,"y":160,"wires":[["54fd5c06.5177fc","ca3e1500.27111"]]},{"id":"9a2fe3db.285a3","type":"inject","z":"414b12bb.d470bc","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":160,"wires":[["6a8e5018.4d76d"]]},{"id":"54fd5c06.5177fc","type":"debug","z":"414b12bb.d470bc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":100,"wires":[]},{"id":"ca3e1500.27111","type":"split","z":"414b12bb.d470bc","name":"Split Environment","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":590,"y":160,"wires":[["76fd5ab5.7c7c04","8d65cce5.b8e4b"]]},{"id":"76fd5ab5.7c7c04","type":"function","z":"414b12bb.d470bc","name":"Environment Type","func":"var topic = msg.topic;\n\nif(topic == 'temperature') {\n var T = parseFloat(msg.payload - 273.15).toFixed(1);\n global.set(\"TEMP\",T);\n msg.payload = T\n return [msg, null];}\nelse if (topic == 'humidity'){\n var R = parseFloat(msg.payload).toFixed(1);\n global.set(\"RH\",R);\n msg.payload = R;\n return [null, msg];}\n\n","outputs":2,"noerr":0,"x":790,"y":160,"wires":[["b969dd56.ca08c","d8251f9d.8fa6f"],["d5647717.af045","a69c2bd0.c15b08"]]},{"id":"d8251f9d.8fa6f","type":"ui_gauge","z":"414b12bb.d470bc","name":"Temp","group":"7c438e24.69789","order":0,"width":0,"height":0,"gtype":"gage","title":"Temp","label":"Deg C","format":"{{value}}","min":"-50","max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"0","seg2":"25","x":1050,"y":140,"wires":[]},{"id":"a69c2bd0.c15b08","type":"ui_gauge","z":"414b12bb.d470bc","name":"RH","group":"7c438e24.69789","order":0,"width":0,"height":0,"gtype":"gage","title":"RH","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"40","seg2":"60","x":1050,"y":180,"wires":[]},{"id":"8d65cce5.b8e4b","type":"debug","z":"414b12bb.d470bc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":770,"y":100,"wires":[]},{"id":"7c438e24.69789","type":"ui_group","z":"","name":"TEMPERATURE","tab":"6fde6a42.ec3284","order":1,"disp":true,"width":"6","collapse":true},{"id":"6fde6a42.ec3284","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

```

---

<div class="post-metadata">

**Author:** ![mefloump](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mefloump](https://discourse.nodered.org/u/mefloump)\
**Post date:** [6 September 2019 18:41 UTC](https://discourse.nodered.org/t/aosong-am2315-temp-rh/4589/15 "2019-09-06T18:41:14Z")

</div>

I don't fully understand how you got this to work. I can get the sensor to work outside of Node Red but i cannot get your flow to work. I'm most likely over looking something simple but could use some guidance. The error I am getting is [function:am2315] TypeError: Driver is not a constructor. I don't know what that means.
