Smart home based on Arduino: step-by-step instruction on assembling

Smart home based on Arduino: step-by-step instruction on assembling

.
..
.

By now, systems such as "smart home" from the amazing exotics, available only to the most affluent, have become a commonplace, to which anyone can join. There is something to choose from: many developers have mastered the release of such hardware-software systems. Among the most famous is Arduino, whose products we will now get acquainted with.

Content

  • 1What is a "smart home"
  • 2Getting to know Arduino
    • 2.1Advantages of the Arduino system
    • 2.2What solutions does Arduino offer?
      • 2.2.1Video: we start working with Arduino - we manage the LED through the web interface
  • 3Drawing up a project on Arduino
    • 3.1The necessary components for the production of the "smart house" system
  • 4Build "smart house step-by-step instruction
    • 4.1Connecting executive and sensor devices
    • 4.2Development of program code
    • 4.3Installing a client application on a smartphone (for Android OS)
    • 4.4Configuring the browser to work with the "smart house"
    • 4.5Working with the router
    • 4.6Setting up an account at noip.com
    • 4.7Video: smart house on Arduino
  • 5Features of some Arduino hardware
..

What is a "smart home"

This term has a more understandable analogue - "home automation". The essence of such solutions is to ensure the automatic execution of various processes occurring in the home, office or specialized facilities. The simplest example is the automatic switching on of lighting at a time when one of the occupants enters the room.

The "smart house" system from Arduino is a set of equipment for controlling the operation of various devices using a mobile phone based on the Android OS

In any "smart house" system, the following components can be distinguished:

  1. Sensory part. This is a set of devices, the main part of which is represented by various sensors, allowing the system to register events of a different nature. Examples are temperature and motion sensors. Other devices of the sensor part serve for transferring the user's commands to the system. These are remote buttons and remote controls with receivers.
    One of the most frequently used elements of the "smart house" is a motion sensor
  2. The executive part. These are the devices that the system can control, reacting in this way to an event in accordance with a user-defined scenario. First of all, it is a relay through which the controller of the "smart house" can supply power to any electrical device, that is, to turn it on and off. For example, on the cotton in the palm of your hand (the system "hears" it with a microphone) you can configure the activation of a relay that supplies power to the fan. Note: in this example, the fan can be any. But you can also use the device, specially released to work as part of a particular system. For example, Arduino manufactures electric motors for its systems, with which it is possible, for example, to close or open the window, and Xiaomi (a Chinese manufacturer of similar systems) - control devices air cleaner. Such a device is completely controlled by the system, that is, it can not only turn it on, but also change the settings.
    Electromotor is an actuator, which is activated by the signal of the system controller and drives the mechanism connected to it
  3. CPU. Can also be called a controller. This is the "brain" of the system, which coordinates and coordinates the work of all its components.
    The processor board (or controller) controls the actuators based on the firmware and the data received from the sensors
  4. Software. This is a set of instructions that guide the processor. In systems of some manufacturers, including Arduino, the user can write a program independently, in others - ready-made solutions are used in which only typical scenarios.

Modern systems "smart house" are divided into several varieties:

  1. Equipped with its own controller.
  2. Using in this capacity the processor of a user's computer (tablet, smartphone).
  3. Processing information using a remote server owned by the developer company (cloud service).
.

The system can not only activate this or that device, but also inform the user about the event that occurred by sending a message to the phone or in some other way. Thus, it can be entrusted with alarm functions, including fire protection.

Scenarios can be much more complex than we described in the examples. For example, it is possible to teach the system to include a boiler and transfer the supply of hot water to it when the central supply is cut off, if it reveals the presence of someone from the tenants in the house (help infrared, ultrasonic sensors, as well as sensors motion).

Getting to know Arduino

Arduino is an Italian company dedicated to the development and production of components and software for simple smart home systems intended for non-specialists. It is noteworthy that this developer made the architecture of the systems he created completely open, which made it possible third-party manufacturers to develop new and copy existing Arduino-compatible devices, as well as produce software for them.

.
The Arduino Uno kit contains the necessary components for implementing the devices described in the attached book

This approach has provided a high popularity for the Italian company's systems, but it also has a disadvantage: because of the fact that for the production components for Arduino-systems are taken, so to speak, all who are not lazy, do not always succeed in the first time to acquire a high-quality product. Often you have to face the problem of compatibility of components from different manufacturers.

A potential user should be aware that since 2008, there are two companies that produce products under the Arduino brand. At the first, which started this direction, the official site is located at www.arduino.cc; the second, newly formed - at www.arduino.org. What was developed before the split, on both sites is represented equally, but the range of new products is already different.

The software for "smart house" systems Arduino has the form of a software shell (called IDE), in which you can write and compile programs. It is distributed free of charge. Programs are written in C ++.

The versions of the Arduino IDE program presented on these sites are also very different, although they have the same not only the name, but also the version numbers.Because of this, they are pretty easy to get confused. The difference is that each software supports its libraries and boards.

The "hardware" of the system consists of a motherboard with a microcontroller (processor board) and expansion cards installed on it, which are commonly called shilds. Connecting the shield to the processor board allows you to add new components to the smart house. The assembled system can be either completely autonomous or working in conjunction with a computer via a standard wired or wireless interface.

On the processor board you can install special extensions (shild), which increase the functionality of the system

Advantages of the Arduino system

This hardware-software package attracts the user with such advantages:

  • the possibility of autonomous work, due to the presence of its own controller;
  • extensive opportunities for setting up the system (the user himself writes a program in which scenarios of any complexity can be provided);
  • Simplicity of process of loading the program into the controller: the programmer is not required for this, it is enough to have a USB cable (in the microcontroller there is a firmware Bootloader);
  • the affordable cost of components due to the lack of monopoly rights for a particular manufacturer (the architecture is open).

If the Bootloader bootloader began to malfunction, or it did not appear in the purchased microcontroller, the user has the option to flash it himself. The IDE software shell provides support for a number of the most popular and popular programmers for this purpose. In addition, almost all Arduino processors have a male connector that allows in-circuit programming.

The Arduino IDE program, presented on the arduino.cc website, user hardware-software platforms, while in the version of the program on arduino.org such function is absent.

What solutions does Arduino offer?

Since the production of Arduino-compatible sensors and devices is handled by many companies, the range of these products is quite wide. Here that is applied most often:

  1. Sensors that monitor climatic parameters:
    • temperature;
    • humidity;
      A special board with temperature and humidity sensors provides an interface for outputting the measured parameters to the LCD display
    • precipitation (rain and snow sensor);
    • illumination;
    • pressure.
  2. Sensors, allowing to determine the spatial position of the object on which they are fixed:
    • 6-axis gyro sensor with accelerometer;
    • compass.
      The built-in compass allows you to determine the sides of the light in relation to the object on which the system is used
  3. Sensors, allowing to register the presence of various objects:
    • Motion Sensor;
    • infrared sensor (fix a motionless sitting person or warm-blooded animal);
      IR sensor allows you to determine the presence of people in the house and go to the appropriate branch of the working scenario
    • ultrasonic sensor (detects objects with any temperature and determines the distance to them).
  4. Emergency sensors:
    • smoke detector;
    • fire sensor;
    • gas leakage sensor;
      Connecting the gas sensor will instantly detect gas leakage in the room and activate the emergency scenario
    • carbon dioxide sensor.
  5. Other devices, for example:
    • microphone;
    • clock;
    • door open sensor;
    • remote controls (radio frequency and infrared) with receivers;
    • remote buttons.

Some of these devices are included in the Arduino Start base kit, which from some manufacturers is called StarterKit.

The starting set of the Arduino system includes a processor board and several most commonly used devices

The executive part contains a huge set of devices, for example:

  • electric motors;
  • relays and various switches;
  • dimmers (allow smoothly changing the intensity of lighting);
  • door closers;
  • Valves and 3-way valves with servo drives.
.

If you plan to connect lighting via Arduino relay, then it's better to use LED lamps as lighting fixtures. Lamps incandescent when connected through such relays quickly burn.

.

Video: we start working with Arduino - we manage the LED through the web interface

Drawing up a project on Arduino

The process of creating and configuring the "smart house" Arduino will be shown on the example of a system in which the following functions will be built:

  • temperature monitoring in the street and indoors;
  • monitoring the state of the window (open / closed);
  • monitoring of weather conditions (clear / rain);
  • generation of an audible signal when the motion sensor is triggered, if the alarm function is activated.

The system will be configured in such a way that the data can be viewed by means of a special application, as well as a web browser, that is, the user will be able to do this from any place where there is access in Internet.

Abbreviations used:

  1. "GND" is the ground.
  2. "VCC" - food.
  3. "PIR" - motion sensor.

The necessary components for the production of the "smart house" system

For Arduino's Smart Home system, you will need the following:

  • microprocessor board Arduino;
  • Ethernet module ENC28J60;
  • two temperature sensors brand DS18B20;
  • microphone;
  • rain and snow sensor;
  • Motion Sensor;
  • switch reed;
  • relay;
  • Resistor resistance, kOhm;
  • twisted pair cable;
  • Ethernet cable.

The cost of all components is approximately $ 90.

To make a system with the necessary functions, we need a set of devices costing about $ 90

Build "smart house step-by-step instruction

.

That's the sequence in which you need to act.

Connecting executive and sensor devices

We connect all components according to the scheme.

The assembly of the system basically reduces to connecting the actuators to the corresponding contacts of the processor board

Development of program code

The user writes the entire program in the Arduino IDE shell, for which the latter is equipped with a text editor, the project manager, the compiler, the preprocessor, and the means to fill the program code into the microprocessor of the board Arduino. Developed versions of IDE for the operating systems of Mac OS X, Windows and Linux. The programming language is C ++ with some simplifications. User programs for Arduino are usually called sketch sketches or sketches, the IDE saves them to files with the extension ".ino".

The main () function, which is mandatory in C ++, is created automatically by the IDE wrapper, prescribing a number of standard actions in it. The user should write the setup () functions (done one time at start time) and loop () (performed in an infinite loop). Both of these functions are mandatory for Arduino.

Header files of standard libraries do not need to be inserted into the program - the IDE does this automatically. It does not apply to user libraries - they must be specified.

.

Adding libraries to the "Project Manager" IDE is carried out in a somewhat unusual way. In the form of source code written in C ++, they are added to a special folder in the working directory of the IDE shell. After that, the names of these libraries appear in the corresponding IDE menu. Those that the user marks will be added to the compilation list.

.

The IDE provides a minimum of settings, and the ability to configure the compiler is missing at all. Thus, a beginner programmer is immune from errors.

Here is an example of the simplest program, which causes the LED connected to the 13th output of the board to flash every 2 seconds:

.

void setup () {pinMode (13, OUTPUT); // Arduino output 13 output}

void loop () {digitalWrite (13, HIGH); // Enable the 13th output, the parameter of the digitalWrite function call HIGH is a high logic level sign

delay (1000); // Delay cycle for 1000 msec - 1 second

digitalWrite (13, LOW); // Output turn off 13, call parameter LOW - low logic level attribute

delay (1000); // Delay cycle for 1 second}

.

However, at the moment, it is not always necessary for a user to personally write a program: there are many ready-made libraries and sketches on the network (look here: http://arduino.ru/Reference). There is a ready-made program for the system considered in this example. It needs to be downloaded, unpacked and imported into the IDE. The text of the program is provided with comments explaining the principle of its operation.

All programs on Arduino operate on the same principle: the user sends a request to the processor, and the user downloads the necessary code to the screen of a computer or smartphone

When the user clicks the "Refresh" button in the browser or on the smartphone application, the Arduino microcontroller sends the data to this client. With each of the pages designated as "/ tempin "/ tempout "/ rain "/ window "/ alarm the program code is sent, which is displayed on the screen.

Installing a client application on a smartphone (for Android OS)

To receive data from the smart home system in the network, you can download the ready-made application.

Here's what the gadget owner needs to do:

  1. Download the file SmartHome.apk.
  2. Send it to your phone.
  3. After opening the "File Manager place this file.
  4. Click on it and select "Install" (a "check mark" must be checked, allowing you to install programs outside the Google Play service).
    You must enable the installation of programs not from PlayMarket, which is located in the "Security" section of the smartphone settings
  5. When the installation is complete, activate the application.
  6. Set it up.

With this application, you can not only receive information from the smart house system, but also manage it - enable and disable alarms. If it is on, the application will receive a notification when the motion sensor triggers. Interrogation of the Arduino system for the trigger of the motion sensor application performs at a frequency of once a minute.

By activating the "Settings" icon, you can edit your IP address.

Configuring the browser to work with the "smart house"

In the address bar of the browser, enter XXX.XXX.XXX.XXX/all, where "XXX.XXX.XXX.XXX" is your IP address. After this, it will be possible to receive data from the system and manage it.

The code presented here allows the browser to turn the light on and off, whereas in the Android smartphone application such a function is not implemented.

Working with the router

Then on the router you need to open the port:

  • open the router settings;
  • prescribe the address Arduino IP;
  • open port 80.
    It is necessary to register the route to Arduino processor for port 80

Setting up an account at noip.com

This step is optional, but it is necessary if you want to assign a domain name to the address. To do this, you need to register on the site https://www.noip.com/, go to the "Add host" section and enter the IP address of the system.

After registering on the site noip.com, you can access the system not only by IP address, but also by the full domain name
.

The creation of the project is completed, you can check the health of the system.

Video: smart house on Arduino

..

Features of some Arduino hardware

In view of the fact that Arduino-compatible components are produced by many third-party companies whose product quality itself the company Arduino does not control, the user is more likely to purchase a component that does not work quite correctly.

.

A similar situation has developed in the development of personal computers. At one time, IBM made the architecture of its computers open, as a result of which IBM-compatible computers and individual components began to produce many companies. As a result, "personalities" of this type are widely spread all over the world, however, the quality of components and the degree of their compatibility in many cases were not at the highest level. Opposite tactics adhered to the company Apple. It limited the circle of developers with access to architecture, and the same policy was carried out in the field of software development. As a result, Apple's computers were less common and more expensive, but they are an order of magnitude superior to IBM-compatible devices running Windows.

.

For some components for Arduino systems, users noticed the following:

  1. The temperature sensor DHT11, supplied with the basic kit (StarterKit), gives a significant error of 2-3 degrees. In the room it is recommended to use a temperature sensor DHT22, giving more accurate indications, and for installation on the street - DHT21, capable of operating at negative temperatures and having protection from mechanical damage.
  2. On some Arduino microprocessor boards, when the relay connected to them closes, the COM port fails. Because of this, the microcontroller can not load the sketch: once the fill starts, the processor reboots. The relay then clicks, the COM port is disabled and the sketch loading process stops.
  3. The window / door closing sensor sometimes presents surprises in the form of false positives. In view of this, the sketch is written so that the system produces the necessary action only after receiving several signals in a row.
  4. To configure process management with the help of claps, some inexperienced users order a sound detector with manual threshold adjustment instead of a microphone. For this purpose, this component is not suitable, since it has a very short range: it is necessary to clap not more than 10 cm from the detector. In addition, this sensor transmits signals with pulses of short duration, so that in the presence of a large The sketch, which takes a relatively long time to process, the microcontroller just does not have time for them to fix.
  5. For the fire alarm system, a smoke detector, rather than a fire sensor, should be used. The latter registers a flame not more than 30 cm from itself.
  6. In the event of a malfunction in the operation of the microcontroller or errors in the code, it is better to use normally closed relays with serially connected manual switches.

To avoid the purchase of low-quality components, seasoned users recommend to pre-examine reviews on them, published on the Web. Inexpensive sensors can be bought in several versions to personally verify which one works better.

Perhaps the "smart house" system from Arduino is not the best, but the broadest choice of components and their affordable cost have made it one of the most popular. Using our tips, you will quickly learn how to create Arduino projects by automating various home processes.

.
..
Interesting:
.
.
How to set up satellite TV MTS

How to set up satellite TV MTSHow To Install

How to set up satellite TV MTS. .. . Satellite TV is an opportunity to receive a variety of television channels in remote corners of our country. One of the most popular providers of satellite TV s...

Read More
Manufacturing and installation of a dimmer with your own hands

Manufacturing and installation of a dimmer with your own handsHow To Install

Manufacturing and installation of a dimmer with your own hands. .. . The use of a dimmer is resorted to to regulate the intensity of light from an incandescent lamp or other device. A special elect...

Read More
Replacement and wiring in the panel house

Replacement and wiring in the panel houseHow To Install

Replacement and wiring in the panel house. .. . The replacement of the wiring starts the overhaul of the premises. Dismantling of the old and laying new wiring in the panel house is considered a di...

Read More