📜 ⬆️ ⬇️

Lighting control and voice weather alerts on the Raspbery Pi

Lighting control and voice weather alerts. Sample code and electrical connection diagram of the relay to the Raspberry Pi.

Pre-install mplayer and alsa :
sudo apt-get install alsa-utils sudo apt-get install mplayer 

Also install pip for Python for easy installation of packages. And then install it with feedparser . I will not tell, it is easier to find information on the query “install pip python” in a search engine.

The code for the WebIOPi script itself:
 #     utf8,     # -*- coding: utf-8 -*- #   import webiopi import subprocess import feedparser #  GPIO GPIO = webiopi.GPIO #     GPIO LIGHT = 23 BUTTON1 = 17 BUTTON2 = 22 def setup(): #   GPIO GPIO.setFunction(LIGHT, GPIO.OUT) GPIO.setFunction(BUTTON1, GPIO.IN) GPIO.setFunction(BUTTON2, GPIO.IN) def loop(): #    1 if (GPIO.digitalRead(BUTTON1) == GPIO.HIGH): #     ( ) GPIO.digitalWrite(LIGHT, not GPIO.digitalRead(LIGHT)) #    2 if (GPIO.digitalRead(BUTTON2) == GPIO.HIGH): #    subprocess.call(["mplayer", "http://translate.google.com/translate_tts?tl=ru&ie=UTF-8&q=, ,  ."]) #   d = feedparser.parse('http://rp5.kz/rss/76334/ru') #   subprocess.call(["mplayer", "http://translate.google.com/translate_tts?tl=ru&ie=UTF-8&q="+d.entries[0].title]) def destroy(): #  ,   ) GPIO.digitalWrite(LIGHT, GPIO.LOW) 


Scheme:

')
Transistor of any NPN structure, I used the Soviet KT961B , any one will work for switching mode operation. Pick resistance for the required opening current of the transistor. I took the SRI-05VDC-SD-C relay with a voltage of 5 volts and a maximum current for contacts 10A. Diode 1N4001 seems to be necessary to remove the self-induction effect of the relay coil, otherwise we hit the transistor and the raspberry leg. The earth on the transistor is common with the power relay and raspberry.
Do not power the relay from GPIO! Burn "raspberries". Before powering, you can turn on the relay. And so preferably a separate power source for such pieces. The relay can be at 12 volts. Please do not blame me for burnt raspberries, do everything at your own peril and risk. You must be able to hold a soldering iron and know the basics of working with electrical circuits. Be careful about 220 volts! This is deadly.

Source: https://habr.com/ru/post/362075/


All Articles