Raspberry Pi, alarm and smart home


    It all started 4 years ago when during the working day my apartment was cleaned. It was no longer possible to get home through the door because of a damaged lock. An unpleasant event made us think about the safety of the home. And this is just one of the reasons for monitoring and automating the apartment. How often when you came to work (or even when leaving or flying away somewhere) you doubted whether you turned off the iron before leaving, closed the gas, water ;-) Let's add oil to the fire to admins - are you calm that your old PSU in a working system unit at home is not child and does not blaze !?) And what to do remotely with a device that "hangs tightly."

    In this post, I will discuss some of the solutions available on the market, the retail cost of affordable hardware and how to create an apartment alarm and some of the functions of a “smart home” using a Raspberry Pi single-board computer.


    Of course, you can connect to private security, pay three times for equipment, installation and pay monthly subscription. This is not an option for geeks) Security will not cost a cheap computer that is hanging at home, and besides, not all objects will be able to be secured. Do you all have a telephone line? ;-)

    A university friend suggested how to connect a motion and smoke sensor to a computer via an LPT port. This port is an option now not fashionable in motherboards and it is not very convenient to program it in the OS operating in protected mode in a high-level language, and not in single-tasking DOS real mode. Oldfags will curse me and sadden with nostalgia about the sound of Covox on LPT, which they once soldered and programmed themselves)))

    Meanwhile, the sensors were gathering dust in the closet ... With a classmate, they successfully remembered the USB ports and HID drivers that are present “out of the box” "In all modern OSes. Another friend, well versed in electronics, again helped with the device. This time the device was on the STM32 Cortex M3 controller. In order not to solder “from scratch” I bought a ready-made STM32-H103 boardwww.olimex.com/dev/stm32-h103.htmland ST-Link programmer. The prospect of programming for this controller without experience and without the help of a friend did not smile at me. As a result, I now dust the microcontroller board with the firmware and the optocoupler circuits soldered onto the breadboard for connecting the sensors to the controller's programmed GPIO legs. I never learned to program STM32 microcontrollers on my own, but I really liked the implemented idea from this solution - access to the sensor states via MK via USB Virtual COM Port. On Linux, USB serial drivers are included in the kernel and access from a java application is just reading and writing text data to a file. An elegant solution, you can come up with and implement your text protocol on the controller. In general, the solution for entering discrete signals into a computer is not the most affordable. The price of such a board was about 1500r, the programmer cost almost the same money. To add new functions to such a device, knowledge of development environments for the controller, libraries of controller functions, and deeper knowledge of circuit design are required. A great solution for those who are friends with STM32, Keil and a soldering iron ;-) But again, too confused for application programmers.

    It seems obvious to look for ready-made solutions. But it wasn’t here! Prices just for terminal blocks with optocouplers start at 2500r. Blocks with which you can switch the external load from the computer start from 900p www.chipdip.ru/product/mp709.aspx . Although it is clear to any red-eyed person that it cannot be so expensive a cheap Chinese electromagnetic relay with drivers for windows. Once upon a time, the same master whale on sale had a more human solution for switching network load, namely a solid-state relay www.masterkit.ru/info/magshow.php?num=199 (People are actively using a similar circuit in their home arduino- devices en.blogspot.com/2009/02/220.html) Retail prices for solid state relays in the case start at 600 rubles. There are no available adapters for inputting discrete signals via USB, there are only expensive ones for industrial electronics. I still could not connect more than one webcam broadcasting to the network to the USB 2.0 controller of the computer. IP cameras are still quite expensive. You should also look for sales DVR cards with many video inputs running under linux (there is information on such boards on the zone minder project page) and they require a PCI port. Those that work via USB usually contain only 1 video input.

    Of the available universal solutions, I can mention NetPing / PWR-220 v2 at a fairly affordable cost of 112 cu A more expensive and specialized USB input / output device availableGeovision GV-IO USB Box 16 Inputs 16 Relay Outputs for $ 150. The price of finished 3G alarms starts at 3500r for the remote control unit. There are many security system remotes designed for the equipment of any one company, using a radio channel for communication with sensors controlled by proprietary software and sending SMS only in case of an alarm. But what about “GSM silencers” and radio frequency sensors !?

    What stops us from implementing a massively affordable solution based on open source code for apartment security and remote control of electrical load?
    1. The lack of multiple GPIO contacts in computers for inputting signals from sensors / output control signals
    2. High purchase price and power consumption for a constantly running computer.
    3. Lack of available mass cards of discrete input / output signals with opto-isolation and the ability to switch the load in the AC network.
    4. The lack of available USB web cameras with hardware compression of the video stream. Or an affordable DVR card with many video inputs for security cameras with hardware compression of the video stream.

    The introduction of the Raspberry Pi single-board computer should solve the first two problems.

    The board judging by the documentation has 8 GPIO. The $ 35 modification has an Ethernet port. In retail, there are usb wifi adapters running under Debian linux from 400r. A 3G modem without reference to a telecom operator is in Svyaznoy from 990 rubles. Power can be obtained from the USB hub of the Defender Septima Light with an external power supply and use it for its intended purpose, while its cost in the retail network is from 440 rubles. If we need a microphone input, then we can go broke on a Chinese USB audio card for 220p, which people successfully use under linux everybuying.ru/product_info.php?products_id=1469. An 8Gb SD card can be bought at retail for 300 rubles. The case is just like a box with leads for wires for CEA will cost from 160r. Prices for external HDDs for 500GB begin in the region of 2600r (this is optional for work and is needed only in the case of a file download, media player). Yes, if suddenly one ethernet adapter is not enough for us, then you can buy a USB ethernet adapter. For example, TrendNet TU-ET100C for 460 rubles. In any case, such a solution will be at least 3-4 times cheaper than a nettop, more energy-efficient and more compact.

    Programming GPIO in linux is quite simple - either using the C API, or more conveniently, access through the file system

    If we use only for security purposes, the home web, file server and torrent rocking chair, then we can not buy a separate monitor and connect remotely from a phone or laptop via wifi or from a desktop via ethernet. If we need a home media player, we can connect it to the TV via HDMI. And if we decide to use it in a car or as a video intercom, we can purchase a portable 7 "monitor with a composite video input, for example Velas VTV-720 (from 1900r). As a power supply, you can use a cigarette lighter charger for USB 300-500r.
    To provide uninterrupted power to the sensor and Raspberry Pi power supplies, you can use a computer uninterruptible power supply, such as the APC Back-UPS ES 525VA. At a cost of about 3000r, this UPS has support for signaling that there is no external power and the remaining battery level via USB output in linux (everything works fine for me in ubuntu).

    There will remain a problem with the discrete I / O signal board, but even with my knowledge of circuitry and soldering iron skills, I can quite assemble a prototype board for 4 discrete inputs with opto-coupler, 4 discrete outputs. A pair of conclusions can be used to switch the network load using the opto-relay and remotely turn on / off electrical appliances at home. The remaining conclusions with opto-isolation can be used, for example, to remotely press the reset server, turn on the solenoid valve to shut off water / gas in the event of a leak, etc. I am sure that China is not asleep and soon such ready-made devices will be massively distributed on the market. There is a need for such devices.

    At a first approximation, the cost of parts in the retail network does not exceed 1000 rubles for the development of a prototype of a discrete I / O board, with opto-isolation of external signals, contact panels for sensors, with 2 switched 220V power sockets, a ready-made case.

    A little about the sensors for alarm systems and their cost at retail. A motion sensor costs about 400r, a smoke sensor 400-500r, a water leakage sensor 400-800r, a natural gas leakage sensor 1300r, a sensor reacting to breaking window glass 400r, a reed switch (tight contact) that works when the door and window frames open / close are around 30p))))

    Also, such a solution is suitable not only for a standard apartment, but also in the case of the protection of a large territory. Because these computers are quite cheap and equipped with all the necessary network interfaces, it is easy to collect data and transmit control signals. The interference can be the temperature range in which the Raspberry Pi operates (a possible solution is a case with a temperature sensor and heating), moisture and dust protection (this problem can be overcome by a sealed case).

    Interfere with wires from sensors and optorelays / actuators !? We can make the connection less secure and noiseproof. For example, using a microcontroller with an integrated Zegbee transceiver. Many devices can be powered by batteries of small capacity for a long time and be available over the air. Controlled mains sockets and electrical switches provide AC voltage, which can be used to power a low-power controller through a compact transformerless power supply. There are already a sufficient number of devices controlled by the Zigbee protocol in the Chinese market. Our electronic device market has a lot to strive for ;-)

    For software compression of video from several web cameras, the device’s performance is unlikely to be enough. If something changes in the market of IP cameras and they become more accessible for the mass market, then the performance of the device should be quite enough for recording and broadcasting compressed video.

    From the point of view of the programmer, such hardware allows you to send a signal about the triggering of sensors via SMS, 3G, WiFi, wired Internet. It’s easy enough to create a web service that will allow you to access home security, web cameras, manage outlets. Failure to connect to the system is also a signal that not everything is in order. It is possible to receive sms, email, jabber, skype, etc. Alerts For paranoid, distrusting web services, you can organize your own space park ...

    How do you like the idea of ​​using an affordable universal computer with linux for the security system of an apartment, managing smart home systems and adding other useful functions to it? How to develop a USB-> GPIO board on a microcontroller as a second option for using older computers?

    I repeat that I am a programmer and do not know the details of designing devices for mass production. You can wait for the development of Chinese industry, but it is better to create a mass solution earlier and focus on creating software for it. How difficult is it to launch a small series of I / O boards into production (up to 1000pcs). Where is it better to produce printed circuit boards, where is it better to carry out the installation of elements? What is the cost price for such a batch of devices?

    Also popular now: