[ Google Voice Kit ] The third lesson of voice programming is playing smart home
Dec 6, 2020 15:00 · 1196 words · 6 minute read
You may ask me why I opened the Voice Kit Well, last time I taught you how to control real appliances through IoT Some friends are interested in this smart box and understand that how to use relay to control 220V electrical appliances So some people think of Voice Kit I also had a video introducing Voice Kit programming before Using Cantonese and English to control the devices Can Voice Kit and Smart Box be used together? Today I will provide two methods Hope you will watch till the end Just a reminder, if everyone likes the channel of Carlos the OrganMan Please click subscribe in the lower right corner If you want to be notified of new videos as soon as possible Please click the bell You are also welcome to add likes and comments Let me tell you, as long as you understand IoT control All electrical and electronic devices can be connected together Electricity is either digital or analog, either low voltage or high voltage Now that you understand programming, Voice Kit can recognize language instructions Of course the smart box can be controlled by wired or wireless methods The first method today is to use wired Open the Voice Kit, you will see the Servos pins on the Voice Hat Originally there are no pins But I told you how to solder three pins on Servos 0 in the enhancement video. Now it comes in handy If necessary, you can also solder other pins Three pins pull out three lines The current setting blue is GND, red is VCC, green is DATA We plan to use these three lines to control real appliances So use the smart box that realizes the control of home appliances But this time I will not use NodeMCU And only use relay modules So first disconnect NodeMCU and relay module Then extend the blue (GND) and green (DATA) from the Voice Kit into the smart box You may ask, we only need to know the status of DATA Why connect to GND? Actually this is basic electronics Let’s use EveryCircuit to explain Assuming this is the DATA output of Voice Kit Switch not closed means no output Start the simulation, the switch is closed, it means that the Voice Kit has output But why is there no action? It’s simple. Electrical current is different from water flow. It must returns through a loop. We find the ground symbol in the menu Connect it to the negative terminal of the power supply, then this symbol represents 0V When designing circuits, we will add “ground” to the negative pole of all circuits The “ground” on the circuit diagram is separated The real situation is all connected by wires This practice is called “Common Ground” What happens if the Voice Kit has output after common ground? The circuit is formed, the relay operates, and the secondary stage operates So in addition to connecting the green DATA line All circuit boards must “common ground” In the future, if multiple circuit boards are operated together, it is also necessary to “common ground” After programming the Voice Kit, the relay will act, and the 220V appliances will also act We use VNC to open the Voice Kit screen according to the method in the second lesson of Voice Kit Enter the Python Editor and take a Script to modify I will point out a few sentences of Python syntax This sentence import RPi.GPIO as GPIO is used to start GPIO We want Voice Kit to respond, so we have to import aiy.voice.tts The difference is that I have added two commands: ‘turn on the fan’ and ‘turn off the fan’ Pay special attention to these three sentences It turns out that now we are leading GPIO 26 We add two elifs into the “if” loop When receive ‘turn on the fan’ instruction, say ‘OK, I will turn fan on’ Then set GPIO 26 to HIGH When receive the ‘turn off the fan’ command, response, and then set GPIO 26 to LOW Finally, check the wiring, and then cover it Start the smart box, try the ‘turn on the light’ command turn off the light Turn on the fan…
(OK, I will turn fan on) Success! 06:54 - Turn off the fan… (OK, I will turn fan off) Seems very good, you can use voice to control electrical appliances now But this is not the best At the beginning of the video, I said I would introduce two methods The first method is wired, the second one must be wireless Imagine putting this box in “Yuen Long” And we are here to order the Voice Kit to activate the fan in Yuen Long, which is called IoT! Unwrap the wire to restore I am going to teach you how to do it First go back to the smart box to restore all Connect the D0 and D4 outputs of NodeMCU back to the two inputs of the relay module This time we want to achieve multi-purpose control of mobile phones, tablets, computers, and Voice Kit So I will use the code of my previous video: “Use NodeMCU to build a Webserver” If the Wi-Fi is unchanged, the program does not need to be modified But pay attention to these four GET instructions “GET /D0/on”, “GET /D0/off”, “GET /D4/on”, “GET /D4/off”, The Python program should be able to output these four commands later Now upload to the NodeMCU of the smart box After completion, open the Serial Monitor and write down the IP Address The IP Address is different each time, this time it is 192.168.2.45 Python program needs to be modified Added ‘room lights on’ and ‘room lights off’ The sentence about GPIO can be deleted The “if loop” is the same In addition to the four elif sentences And x = requests.get It should contain the URL of the IP Address After the URL, there are /D0/on, /D0/off, /D4/on, /D4/off The syntax is simple, that is to listen to the voice command, and then send a URL command to the webserver Smart box will act upon receive Webserver is used this time Those who have watched the video know that it can be controlled by any Internet device You can go to this network by typing IP Address in the browser You can control fans and lights at will after entering the webpage Enter the IP with a mobile phone Voice Kit can also be used Voice Kit is here, assuming the smart box is in Yuen Long Say ‘turn on the room light’ to the Voice Kit OK, I will turn light on Turn on the fan OK, I will turn fan on Turn off the fan OK, I will turn fan off Turn off the room lights OK, I will turn light off This is how I have been developing the integration of Voice Kit and IoT Not only can be controlled by mobile phones, tablets, etc. Also voice controlled I hope you can cultivate the research spirit after watching Continuously improve your DIY plan Work hard as a STEMaker If you like my video, please like, subscribe and share .