Node-Red Sensors

Hello

I have a question about reading Sensor datas with Node-Red and the Raspberry Pi.
I watched some Youtube Videos, and the most of them have the Grove Pi addition to connect there Sensors.

Now i want to ask if i need this Grove Pi or can i connect the Sensors directly with the Raspberry Pi and Analyse the Sensor Datas with a Node-Red flow.

Some of the sensors only have an analog output so i would connect a ADC MCP3008 to the Pi. Do this also work with Node-Red?

Would be nice if you can share a tutorial i can read/watch, how i connect the sensors / ADC with the Pi and how i can read the datas from it. (If something like this exists.)

Thanks

Have a look here:

https://nodered.org/docs/hardware/raspberrypi

Interacting with the Pi hardware

Thanks exactly what im looking for.

This contrib-node may also be useful.

node-red-contrib-ds18b20-sensor

1 Like

and - https://flows.nodered.org/node/node-red-node-pi-mcp3008

Thanks ill try this at the weekend.

Will this work for every type of sensor?

This one ill try for the sensors with the analog output.

I believe that the ds18b20 node is only for ds18b20. If you are using 1-Wire devices then also look at using owserver along with node-red-contrib-owfs. That will talk to all 1-wire devices I think.

You can, as you've seen, attach sensors direct to Pi GPIO though direct driver support can be lacking. Much sensor-type work on the Pi focuses on the use of Python rather than JavaScript.

You do need to be quite careful how you connect your sensors. The Pi's GPIO is unbuffered and many people have "blown" their Pi due to incautious wiring and misuse of power.

Many of us find it easier & safer to use an ESP8266 (for wireless) or Arduino Nano (connected direct to the Pi) as sensor platforms. This can also get round timing issues - as you probably know, the Pi is a general purpose computer and therefore not optimised for the kind of real-time use you may want when dealing with sensors. Using an ESP based microprocessor also means that you can put the sensor and the Pi in more convenient locations.

Before the advent of the Pi Zero, this arrangement was also often a lot cheaper. The Pi Zero has evened that out a little though as you can get an ESP8266 on a development board with USB & headers for a couple of dollars US, it will still be cheaper.

3 Likes

Thanks for your answers.
But there is one more thing im not sure about.
How do i need to connect the ADC MCP3008 to the Raspberry Pi.
In every tutorial they do it different.

What is the rule for the connection?

Thanks

The one I wrote the mcp3008 node for was this one

Okay.
But i have only the MCP3008 without any additional stuff.
Do i need some transistors for safety or will the ADC Module itself be okay?

I am interested in this method. I would like to house NR on a Pi and use an Arduino Nano to remotely handle the heavy lifting.

It's purpose would be analog (and digital) sensors and turning external relays on/off with the digital pins.

What is the best way to control all of this logic via Node-Red? I would really appreciate some examples or tutorials that could help with this specific use case.

I believe you can use MQTT in an Arduino. If so then that may well be the easiest way to communicate with node red.

Depends on the arduino. A simple nano would probably be easiest to talk serial to the Pi.

1 Like

Correct Colin, the library was written by Nick O'Leary (whoever he is :slight_smile: )

As stated, requires an ethernet shield or WiFi in order to work.

In fact, ESP8266 devices are easier to work with partly for this reason. You can also get Arduino's with ethernet but they may be more expensive - thanks to Expressif and their excellent, low-cost WiFi chipset which can still be programmed using the Arduino IDE.

ESP8266 devices cost a few dollars typically. Often cheaper even than Arduino's I think.

They need separate power though you could probably power one using a 5v feed from a Pi if you really wanted to - make sure you have at least a 2-3 amp capable Pi power supply if doing this. Better to provide separate power though and then you can position the ESP device separate to the Pi.

1 Like

Also note that Peter Scargill has a solution to this where he has a total home control system written around NR and RPis. He provides a firmware download for the Nano that turns it into a glorified peripheral expansion for the Pi - very easy to use and come to grips with and gives you thes best of both worlds.

The beauty of MQTT and NR is that you can mix and match peripherals as needed to meet function and/or specific price points.

Craig

1 Like

@scargill's blog is definitely a good source of some fun ideas.

2 Likes

My plan is to have the "arduino" out by my pool and the RP inside. I'm hesitant to have a wifi device out there for a few reasons, and was hoping to use serial, but I will look at other options. Right now, I'm able to control it via serial connection and getting accurate values from the arduino into NR, but I' struggling getting those into Home Assistant, but I'm working through that, as I believe NR should be able to act as the intermediary to get the data into Home Assistant. Thanks for all the great suggestions. I'll keep plugging away and most likely be back with more questions!

Serial over any distance brings issues of its own though depending on your location, WiFi with an ESP8266 might be a little exposed, mostly it should be ok. If you want more security, you should move to an ESP32 which has an onboard security processor and so can cope with TLS encryption without issue. The ESP8266 really struggles to do TLS.

For serial over any distance, you'll need to think about wire resistance, voltage losses, external interference (the wire acts as an Arial and can generate an appreciable voltage due to radio interference), lightning strikes and lawnmowers/spades/dogs :slight_smile: Well maybe you do, I'm no expert on that front.

Also don't assume that every transmission over serial will be complete, I've had problems there in the past where the transmission fails part way through what should be a single record. So you will need good validation and error check/correction on the Node-RED end.

1 Like