Raspberry Pi Node Red

Hi all, I'm a Coderdojo mentor teaching a Raspberry Pi class. We've been successfully using the sensors from the CamJam Edukit2 (https://camjam.me/?page_id=623) with the Pi and I've just started looking at Node Red.
What I'm trying to do is get a sensor reading (e.g. temperature,LDR,PIR) and if the sensor is too high/triggered it would cause an led or buzzer to come on. I can get this to work in python but have no experience in node red.js and am struggling. Has anyone done this before or can anyone advise on where to start?
I can get an led/buzzer to work with node red, but even after searching the internet can't figure out how to do this?
regards,

If I understand your issue correctly...
I've been reading 5 DS18B20 sensors for about a year now, without error but it's on a Raspberry Pi 3, not the RPi Zero that your kit uses. I'm not sure what the difference is.
If you can read the temp in python then the one-wire-interface must be setup so you only need to install the node-red-contrib-sensor-DS18B20 node.
If your node-red install has the palette manager then just search for DS18B20 and if not you can use npm.
Hope this helps

Hi Charles

I’m using a pi 3 andI can read the sensors ok, my problem is how to I use them to make an led turn on. Say I have the temperature working and it reads higher than 28c or lower than 10c I would like a red or blue led to turn on. I think I need a switch node for this but am not sure?

Regards

Are these real LEDs or simulated LEDs on the dashboard?
If real ones, how are they connected?

Have a play with something like this

The 2 nodes on the left are inject nodes to simulate your temp sensors - the switch decides if its hot or not - the two change nodes set the output to 1 for hot, 0 for not hot

Here's part of a NR flow that one of my students created this week.
It controls three LEDs (Red, Green and Blue).
The Blue LED comes on if the temperature is below 10 degrees.
The Green LED if temperature is below 21 dgrees.
And the Red if the temperature is over 20 degrees.

You will need to insert it into your flow and adapt some of the code.

Hoep you find this useful.

[{"id":"30efae4b.aed9fa","type":"function","z":"92b090f3.6833a","name":"","func":"var red = 0;\nvar green = 0;\nvar blue = 0;\n\nif (msg.payload < 10)\n{\n    blue = 1;\n    node.status({fill:\"blue\",shape:\"ring\",text:\"Temp is: \"+ msg.payload});\n}\nelse if (msg.payload < 21)\n{\n    green = 1;\n    node.status({fill:\"green\",shape:\"ring\",text:\"Temp is: \"+ msg.payload});\n}\nelse\n{\n    red = 1;\n    node.status({fill:\"red\",shape:\"ring\",text:\"Temp is: \"+ msg.payload});\n}\n\n return [{payload:red},{payload:green},{payload:blue}];\n","outputs":3,"noerr":0,"x":530,"y":280,"wires":[["793e5214.b4ab7c"],["7c3e608.2731ea"],["4e73663b.bfb67"]]},{"id":"793e5214.b4ab7c","type":"debug","z":"92b090f3.6833a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":220,"wires":[]},{"id":"7c3e608.2731ea","type":"debug","z":"92b090f3.6833a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":280,"wires":[]},{"id":"4e73663b.bfb67","type":"debug","z":"92b090f3.6833a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":320,"wires":[]},{"id":"1604b740.475579","type":"inject","z":"92b090f3.6833a","name":"","topic":"","payload":"6","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":220,"wires":[["30efae4b.aed9fa"]]},{"id":"8b179f84.27907","type":"inject","z":"92b090f3.6833a","name":"","topic":"","payload":"12","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":280,"wires":[["30efae4b.aed9fa"]]},{"id":"6ffdbb56.29a6e4","type":"inject","z":"92b090f3.6833a","name":"","topic":"","payload":"21","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":340,"wires":[["30efae4b.aed9fa"]]},{"id":"a38cfccb.7ab628","type":"comment","z":"92b090f3.6833a","name":"These are test inputs","info":"","x":300,"y":160,"wires":[]},{"id":"4c31d9d0.a5d308","type":"comment","z":"92b090f3.6833a","name":"Connect these outputs to the appropriate GPIO pins to control your LEDs","info":"","x":920,"y":160,"wires":[]}]

Real leds on a breadboard connected to the pins with jumper leads.

So is the problem that you don't know how to drive the LEDs? If they are connected to GPIO pins you can use the GPIO Out node. Or is the problem that of testing the temperature value and sending the right signal to the pin, in which case the flows posted above should help.

It’s testing the temperature value . I’ll take a look at the posts and try it out later . Thanks all for the speedy responses and advice!

If you are driving the LEDs from the Pi's GPIO pins MAKE SURE you include a resistor in series with the LED.

My students usually use resistors that have a value between 220 to 330 ohms.

1 Like