Once the headless Raspberry Pi had been set-up we got started with Node-Red, sensors, LEDs and Servos.
For the sensors I selected 3 different kinds, light, touch and motion.
The light sensor is based around a simple LM393 comparator with a preset to do the comparison. This is powered from 3.3v and the output is a digital signal. There is a power and output LED so that it can be tested independently.
The touch sensor is based around a TTP223B chip, this is also powered from 3.3v and the output should be digital.
The motion sensor is a passive infra-red detector based on the HC-SR501C, this is powered from 5v but has a 3.3v output. There are two adjustments, one for sensitivity and the other controls how long the output stays high once an event is triggered.
I did not have a chance to try out the LDR and my intial experiments with the touch sensor were unsuccessful too. However the PIR was what was needed for the first project and that worked well so we stuck with that.
The LEDs were pre-wired with a series resistor and sockets to connect to the GPIO on the Pi, this worked really well.
The Servos were cheap micro-servos, I also brought along a few servo testers which we used to make sure the servos were working correctly.
Cat Scarer
Charlie's project was to stop the neighbour's cats from spending time on his lawn. One of our main challenges was getting the voice recording off an IPad and onto the Pi. We eventually got help from the sound guy and re-recorded it onto an SDCard and used WinSCP to copy the file onto the Pi.
This project used a PIR sensor and a powered headphone speaker connected to the 3.5mm audio jack on the Pi.
The flow works as follows:
The sensor goes high when motion is detected.
To avoid multiple triggers we limit the flow to one message every 2s.
This is then wired to the LED so we can see that the sensor has triggered an event.
A random node creates values 1 or 2 and this passes to the switch to select one of the two outputs.
Finally the EXEC nodes run the command line "aplay" with one of two values for a police siren or a recorded message.
Trouble with servos
We tried to get the servos to work but they simply refused to co-operate. I've since followed up on this and we should have used the GPIO 2 pin as that has hardware PWM, there's also a limited range of values that can be used. If we'd have had time I also had a Picon Zero which we could have used to control lots of servos.
Mouse Toggle
David used a blue tooth mouse to remote control his Pi's LED. This was one area where we could not work out how to complete the flow without code. Each mouse click turned the LED on or off.
Toggle Code
var state = context.get('state')||0; if (state == 0) { state = 1; } else { state = 0; } context.set('state',state) msg.payload = state; return msg;