Voice and Touchscreen GUI Relay Activation - How To Use A PiRelay V2 HAT with Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey gang Tim here at car electronics and today we're going to set up the pi relay version 2 hat with a Raspberry Pi single ball computer at the end of this guide you're going to know exactly how to control these four relays through scripts through voice activation or through a touch screen GUI simply a relay is a electronically operated switch before on this hat are strong enough to switch loads up to 30 volts DC at 10 amps relays like this and home automation go hand in hand all these relays are controlled through I squared C communication and these hats can be stacked but even more relay control in this big world there is a whole bunch of high current high voltage devices now a Raspberry Pi single ball computer operates at 5 volts if 30 volts were driven through it our computer would break so does that mean we cannot control high current or high voltage devices with our five volt computer absolutely not we can use relays we can send our relay a signal at 5 volts from our Raspberry Pi that signal will then open or close the electrical flow to our external high voltage system performing on the table is everything you're going Anthony use any Raspberry Pi single ball computer here I'm using a Raspberry Pi 4 model B you're going to need a pi relay version 2 hat along with the standoffs that come with it from here on out you're just going to need everything to run this Raspberry Pi as a desktop computer we will also need a little Phillips head screwdriver too we also want an externally powered system for these relays to turn on and off here I have a little DC motor connected up to a battery whenever I complete the circuit the motor will spin for voice control we will need a USB microphone like this for touch screen control we will want a Mini gpio screen like this wave share 3.5 inch LCD begin assembly by attaching those nylon standoffs to the Hat then attach the hat to the top of the Raspberry Pi when doing this line up the headers of the Hat with the gpio pins of the Raspberry Pi carefully then push both boards firmly together make sure the head is fully seated and screw in those two nylon screws this is a good opportunity to note the yellow jumpers on the top right of the board if you pull any of these off then the corresponding relay is no longer going to be powered now let's attach our external system to the relay one outputs on the Hat let me State here if you have no experience working with Mains powers do not hook up Mains powers to a relay particularly in Australia out 240 volts at 50 hertz AC is life-threatening it's proper necessary to have credentials experience knowledge and certificates if you're going to try and do that so for today I will attach devices that are all safely driven through battery power the demonstration purposes it's going to be this brushed DC motor that I've connected directly to a 9-volt battery the two ends of my system are right here now to complete this circuit all we need to do is push these two wires together these two wires are what we're going to connect to the relay the PCB hat has four groups of three screw down terminal connectors with a label next to them for which relay it corresponds to each relay has the outputs no but normally open com the common ground and NC are normally closed we want our system to be unpowered unless the relay is activated therefore I will connect the black wire to the com and the red wire to the normally open of relay one [Music] [Applause] foreign system is connected to the no and the com screw down terminals If instead you wanted to stop the power going to the external system whenever the relay is activated you're going to attach your positive red wire to the NC port in scripts we will refer to and identify the relays via the numbers written on the PCB board with that complete insert a Micro SD card flashed with Raspberry Pi OS and hook it up as a desktop computer add a mouse keyboard and HDMI to a monitor then power up the Raspberry Pi system by plugging in a USBC connector with power into the system and the boot up wizard complete you will be welcomed by that Raspberry Pi desktop the pi relay version 2 hat requires I squared C communication to work by default on Raspberry Pi OS this communication method is turned off so the very first software step is to turn that on open up the Raspberry Pi configuration menu found using the top left menu and scrolling over preferences then enable I squared C connection found under the interfaces tab while here double check that one wire is disabled if enabled relay 4 will not operate correctly also check the serial Port is enabled reboot to lock in these changes now with your system rebooted and connected to the internet open up a new terminal window by pressing the black button on the top left of the screen this terminal window will enable us to download from the internet the exact packages we require type and enter the following lines into the terminal to get the packages that you will need you can also copy and paste these terminal lines one by one from the full written up article link down in the description if prompted type an N to Y to continue the installations [Music] once completed we have fully set up our Raspberry Pi single ball computer to work with our PI relay version 2 hack the first python script we are interested in is called test.py we can find it by jumping through the directory structure like so as you've completed the above terminal commands you will have these example scripts in the exact same location too from here let's open up a python interface like funny IDE click on the applications menu this is the Raspberry Pi symbol on the top left of the screen hover over the programming tab to find funny ideony IDE is just a python interpreter software and you can use whichever is your preference copy and paste the following from the section in the written up article straight into your coding area then Simply Save the script in the same directory location and run it by pressing the Big Green Run Button as soon as we do our connected external system will activate for a second before switching off you would have also been able to hear the noise as each electromechanical relay clicks on and off you also get this really nice LED light that shows up each time one of them is activated allow me a second to die through the script so we can see exactly what is going on the first two lines import all the necessary packages here we need time and out downloaded Pi relay package then we create variable names to quickly identify and Target each relay that we want to have activated very next line is a command to toggle on relay 1 as labeled on the pi relay version 2. R1 Dot on this activates the relay then the next line is a small time delay relay 1 will remain energized during this delay the next line is the command to toggle off relay one as labeled on the pi relay version 2. and that is R1 off the pattern is then repeated for all relays note that all relays upon the end of the Python script are de-energized a relay left on for a long time will get warm if your relay is getting hot the service life of your relay is likely coming to an end let's Now activate these relays using only our voice any word or phrase could be spoken to get our external system started we just need to code it in your system is going to need internet connection or voice control to work and also a connected USB microphone there is a default example script that you can locate by jumping through these folders it is named High relayvoicecontrol.py to correctly run this script we will need to adjust this line so that way the script can focus on our specific microphone fastest way to figure out exactly what to write here is to run a two-line python script I created called mikelist.py open it and run it in funny IDE as you would normally as soon as you do it it will print out a list of all the connected audio inputs you can see it over here with my connected USB microphone the text string that we want starts with USB and it's right here if you're using a different microphone this is going to be different copy and paste this string into our voice control script like so you can now save and run the python script by pressing the Big Green Run Button as soon as you do it it's going to spit out to the Shell the output say something with clear dictation speak out loud and directly to your Raspberry Pi the following phrase turn on relay one let's give it another go turn on relay one and as soon as you can do it and that the Google speech recognition has figured out exactly what you said our relay one is going to turn on turn off relay one so as you can see the words that I speak is picked up by the Google speech recognition software and it outputs to the Shell what I believe you said if what you said is registered correctly relay one will energize now this is really cool to stop all the relays from being energized say clearly turn off all relays let's now look at the script and create a custom phrase that will activate our relay the first section of the script is very similar to before except we are also importing speech recognition functionality variables are created for the relays along with the connected microphone sampling rates are decided for the voice recognition then an infinite Loop is created to constantly listen to our voices looking here we can see that the relays are activated only when the correct phrase is said understood accurately and the phrase contains enough trigger words to get deep enough into the if statement trees once it does this it will hit a relay one dot on or a similar statement once we reach that statement the Raspberry Pi is going to activate relay one the end of the script has some exceptions that will print out information to the Shell to Aid in troubleshooting now to add our custom keyword the let's jump into the script and locate that try section found within the while true infinite Loop this section breaks down the words it has identified from our speech and searches for trigger words these words are organized in layers of if statements this format is what I will mimic or our unique keyword nosy down to the bottom of these if trees and add a custom one to it I also will pay close attention to get the correct indentation so now our search will also look for the words let also search for the words it and if it finds those two words then it will turn a relay one on select save the script and run ah indentation error right tab in this like so I should have fixed the problem having fixed some of those indentations we'll give it another go let it rip now whenever I say let it rip the Raspberry Pi will recognize the two trigger words let and it spit out a message to the Shell output energize the relay and most importantly start out DC motor now if you just want a touch screen that you can click on to easily turn on or off your relays this is how you're going to do it start by attaching a gpio connected mini touchscreen like this wave share 3.5 inch LCD to your system I've created a guide on setting the screen up so check the description for that if you need simply the gpio screen can mount directly on top of the SB components relay V2 hat which is mounted onto the Raspberry Pi single port computer we got a double stack on our hands now the GUI script can be found from the full written up article and is named High relay GUI Tim Dot py open it up and run it in funny IDE just like before the GUI will open up as a full screen window and display on your little screen like so we can now simply tap on the screen to activate relays in the system foreign I also included a shutdown and reboot button where the connected keyboard use the keystroke combination alt f4 to close the GUI window the final step is to run this GUI script automatically on boot we can do this with cron tab we have a guide on contab linked to it down in the description with that completed whenever you reboot the Raspberry Pi it's going to provide this full screen interface check the full written up guide if you want to know exactly how to do this you now have the ability to turn on and off these relays through scripts voice and a touchscreen GUI so feel free to plug in a smorgasbord of devices that will all have their power toggled by your Raspberry Pi another worthwhile Pursuit for Relay control would be a Raspberry Pi locally hosted GUI website this web server would have toggle buttons just like our GUI which we could turn on and off on any locally connected device the realm of home automation opens up to us when we venture down the path of relay controls and with Raspberry Pi it has never been easier and that's all for today we are full-time makers and always Keen to help so until next time Steakhouse [Music]
Info
Channel: Core Electronics
Views: 12,932
Rating: undefined out of 5
Keywords: Voice activated relay system, touch interface to control relays, can a rasperrry pi control relays high power, what is the best way to control relays with a Rasp Pi Comp, How to set up a button to turn relay on and off, how to make relay turn on, why would i want a relay, how to control high voltage/high current situations with a low power device, micro-processor relay control, pi- relay v2 how to set up, keyword activated, sound activated relay, custom phrase to turn on relay
Id: EJ3jFwG2rNk
Channel Id: undefined
Length: 16min 35sec (995 seconds)
Published: Mon Sep 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.