Homemade sensors for Arduino. Homemade motion sensors (temperature, humidity, lighting) for the Smart Home based on the MySensors system

I was passing by, I looked, and here they write interesting things about various homemade products. I also recently made something, let me write, I think, maybe it will be useful to someone, or it will just be interesting. It's about about the hardware of a budget DIY sensor for embedding in switch and socket panels.

But let's take things in order.

I have been interested in automation systems for Smart Homes for a relatively long time. Now I have several different systems here connected into one whole. There are both industrial and homemade components. I want to tell you about the last homemade product.

Some time ago, on the Internet, I came across the MySensors home automation system. Quite a developed (and constantly being further developed) wireless system based on Arduino and nRF24L01+. However, it’s not about who is interested - look at the source.

The main advantages of the system for me were good software support, bidirectional communication, availability of components and their low cost.

Having played enough with development boards, I decided to develop a device that can be adequately integrated into a home interior (WAF cannot be ignored). The result is a device that, along with others, can be recessed into the wall in a standard 63mm box.

This is the first assembly, I will try to make the subsequent ones more carefully. The large hole (for the light sensor) will be covered with a plexiglass rod.

In semi-assembled form it looks like this:

View from the other side:

It all consists of a (Chinese) 8MHz/3.3V Arduino Pro Mini, nRF24L01+ radio module, HC-SR510 motion sensor, DHT22 sensor (temperature and humidity), BH1750 light sensor and a standard JUNG plug (you can probably use others, like Gira , Berker, etc. I just used what was at hand). Total cost about 15$.

The PCB is designed by Eagle. Sources. Ordered from ITEADStudio, it was done well (except for the silk, the inscriptions turned out so-so).



Probably the font is too small and thin. It looked good on the gerbera.



During the assembly process, some minor inconveniences were discovered; some things could be improved, but overall the board is quite usable.

Good afternoon, today I will share instructions for making a clock with a room thermometer( DIY Arduino clock). The clock runs on Arduino UNO; the WG12864B graphic screen is used to display time and temperature. As a temperature sensor - ds18b20. Unlike most other clocks, I will not use RTS (Real Time Clock), but will try to do without this additional module.

Arduino circuits are distinguished by their simplicity, and anyone can start learning Arduino. You can read about how to connect libraries and flash Arduino in our article.

Let's get started.

To create this clock we will need:

Arduino UNO (Or any other Arduino compatible board)
- Graphic screen WG12864B
- Temperature sensor ds18b20
- Resistor 4.7 Kom 0.25 W
- Resistor 100 ohm 0.25 W
- Battery compartment for 4 AA batteries
- Matching box
- Fine file
- Nail polish (black or body color)
- Some thin plastic or cardboard
- Electrical tape
- Connecting wires
- Circuit board
- Buttons
- Soldering iron
- Solder, rosin
- Double-sided tape

Preparing the graphic screen.
At first glance, connecting the screen poses many problems and difficulties. But if you first understand their types, it will become much easier and clearer. There are many varieties and types of screens on the ks0107/ks0108 controller. All screens are usually divided into 4 types:
Option A: HDM64GS12L-4, Crystalfontz CFAG12864B, Sparkfun LCD-00710CM, NKC Electronics LCD-0022, WinStar WG12864B-TML-T
Option B: HDM64GS12L-5, Lumex LCM-S12864GSF, Futurlec BLUE128X64LCD, AZ Displays AGM1264F, Displaytech 64128A BC, Adafruit GLCD, DataVision DG12864-88, Topway LM12864LDW, Digitron SG12864J4, 4F, TM12864L-2, 12864J-1
Option C: Shenzhen Jinghua Displays Co Ltd. JM12864
Option D: Wintek-Cascades WD-G1906G, Wintek - GEN/WD-G1906G/KS0108B, Wintek/WD-G1906G/S6B0108A, TECDIS/Y19061/HD61202, Varitronix/MGLS19264/HD61202

The list is not complete, there are a lot of them. The most common and, in my opinion, convenient is WG12864B3 V2.0. The display can be connected to Arduino via serial or parallel port. When using with Arduino UNO, it is better to choose a connection via a serial port - then we will need only 3 outputs of the microcontroller, instead of at least 13 lines when connecting via a parallel port. Everything connects quite simply. There is one more nuance: you can find two display options on sale, with a built-in potentiometer (to adjust the contrast) and without it. I chose, and I advise you to do the same, with the built-in one.


This reduces the number of parts and soldering time. It is also worth installing a 100 Ohm current limiting resistor for the backlight. By connecting 5 volts directly, there is a risk of burning out the backlight.
WG12864B – Arduino UNO
1 (GND) - GND
2 (VCC) - +5V
4 (RS) – 10
5 (R/W) – 11
6 (E) – 13
15 (PSB) – GND
19 (BLA) – through a resistor - +5V
20 (BLK) – GND

The most convenient way is to assemble everything behind the screen and bring out 5 wires from it connecting to the Arduino UNO. The end result should look something like this:


For those who still choose a parallel connection, I will provide a connection table.

And the diagram for screens of option B:



Several sensors can be connected to one communication line. One is enough for our watches. We connect the wire from the “DQ” pin of the ds18b20 to “pin 5” of the Arduino UNO.

Preparing the board with buttons.
To set the time and date on the watch we will use three buttons. For convenience, we solder three buttons on the circuit board and remove the wires.


We connect as follows: we connect the wire common to all three buttons to the “GND” of the Arduino. The first button, which is used to enter the time setting mode and switch by time and date, is connected to “Pin 2”. The second, the button to increase the value, is to “Pin 3”, and the third, the button to decrease the value, is to “Pin 4”.

Putting it all together.
To avoid short circuits, the screen should be insulated. We wrap it in a circle with insulating tape, and on the back we attach a strip of insulating material with double-sided tape, cut to size. Thick cardboard or thin plastic will do. I used plastic from a tablet for paper. The result is the following:


In front of the screen, along the edge, we glue double-sided foam tape, preferably black.


Connect the screen to Arduino:


We connect the plus from the battery compartment to the “VIN” of the Arduino, the minus to the “GND”. We place it behind the Arduino. Before installing it in the case, do not forget to connect the temperature sensor and the board with buttons.


Preparing and filling the sketch.
The temperature sensor requires the OneWire library.

Output to the screen is carried out through the U8glib library:

To edit and fill a sketch, you need to install these two libraries. There are two ways to do this. Simply unzip these archives and place the unzipped files in the “libraries” folder located in the Arduino IDE installation folder. Or the second option is to install the libraries directly in the programming environment. Without unpacking the downloaded archives, in the Arduino IDE, select the menu Sketch - Connect Library. At the very top of the drop-down list, select “Add.Zip library”. In the dialog box that appears, select the library you want to add. Open the Sketch menu again – Connect Library. At the very bottom of the drop-down list you should see the new library. Now the library can be used in programs. Don't forget to restart the Arduino IDE after all this.

The temperature sensor operates using the One Wire protocol and has a unique address for each device - a 64-bit code. It is not practical to search for this code every time. Therefore, you must first connect the sensor to the Arduino, upload the sketch found in the menu File – Examples – Dallas Temperature – OneWireSearch. Next, launch Tools - Port Monitor. Arduino must find our sensor, write its address and current temperature readings. We copy or simply write down the address of our sensor. Open the sketch Arduino_WG12864B_Term, look for the line:

Byte addr=(0x28, 0xFF, 0xDD, 0x14, 0xB4, 0x16, 0x5, 0x97);//address of my sensor

We write the address of your sensor between the curly braces, replacing the address of my sensor.

Stock:

//u8g.setPrintPos(44, 64); u8g.print(sec); // Output seconds to control the correctness of the move

Serves to display the seconds next to the “Data” inscription. This is necessary to accurately set the passage of time.
If the clock is fast or behind, you should change the value in the line:

If (micros() - prevmicros >494000) ( // change to something else to correct it was 500000

I empirically determined the number at which the clock runs quite accurately. If your clock is in a hurry, you should increase this number; if you are lagging behind, you should decrease it. To determine the accuracy of the move, you need to display the seconds. After precise calibration of the number, seconds can be commented out and thus removed from the screen.

The idea for this project appeared and captivated me during my vacation.

The thought went something like this: “It would be cool to have a robotic arm that could be controlled by my own!” And after some time I began to develop and implement this project. I hope you find it interesting!

The main components of the project are the glove and the robotic arm itself. Arduino was used as a controller. The movement of the robotic arm is provided by servomotors. The glove is equipped with bending sensors: variable resistors that change their bending resistance. They are connected to one side of the voltage divider and fixed resistors. The Arduino reads the change in voltage as the sensors bend and transmits the signal to the servo motors, which rotate proportionally. A video of the working project is below.

The hand design is taken from the open-source project InMoov. On the project page you can download 3-D models of all nodes and print them on a 3-D printer.

Below are all the steps to implement your own glove-controlled robotic arm.

Required materials

For the project you will need:

All! You can start your robotic arm project!

Printing a hand

The hand is part of an open-source project called InMoov. This is a robot that is printed on a 3-D printer. The hand is just a separate unit of the overall structure. Download from this page and print the following details:

Auriculaire3.stl

WristsmallV3.stl

Just in case, I am attaching a clickable list of parts, because some of them have been removed from the main project page.

RobCableFrontV1.stl

RobRingV3.stl (I had to make extra holes in this part to make my servos fit)

RobCableBackV2.stl

RobServoBedV4.stl

(These are two “skin” parts - they are not necessary from the point of view of structural rigidity and its functioning)


In total it took about 13-15 hours to print. Depends on print quality. I used the MakerBot Replicator 2X. I recommend printing finger parts at standard or high resolution to avoid unwanted friction in the design.


Connecting bend sensors to Arduino

To connect bend sensors to Arduino, we need to include a voltage divider in the circuit. Bend sensors are essentially a variable resistor. When used in conjunction with a fixed resistor, the difference in voltage between the two resistors can be monitored. You can track the difference using Arduino analog pins. The connection diagram is shown below (red connector is voltage, black is ground, blue is the connector of the signal itself, which connects to the analog input of the Arduino).


The resistors in the photo have a nominal value of 22 kOhm. The colors of the wires correspond to the colors shown in the connection diagram.

All GND pins from the sensors are connected to a common ground. Ground goes to the GND pin on the Arduino. +5V on Arduino is connected to the common power supply pin from all sensors. Each blue signal connector connects to a separate analog input on the microcontroller.




I assembled the circuit on a small circuit board. It is advisable to choose smaller board sizes in order to attach them to a glove in the future. You can attach our assembled diagram to the glove using an elementary thread and a needle. In addition, do not be lazy and immediately use electrical tape on the exposed contacts.




Installing sensors on the glove

We can start installing the sensors and our circuit board on the glove itself. First, drill a small hole in the plastic of the sensors. Holes are drilled in places where the sensing element has ended. IMPORTANT! Never drill a hole into sensitive material. After this, put on a glove. Make marks with a pencil or pen at the top of each joint. You will use these places to mount the sensors. The bend sensors are attached with regular thread. Sew the sensors to the glove. Use the hole you made on the ends of the sensor. In places where the joints are marked, the sensors are “grabbed” by the thread on top. All this is shown in more detail in the photo below. The circuit board is sewn to the glove in a similar manner to the sensors. Please note that for the fingers to move, you must leave a certain margin of length of the conductors. This must be taken into account when installing our circuit board and choosing the length of the connectors from it to the sensors.






I won't go into detail about this step. It is covered in great detail on the InMoov website (under "Assembly Sketches" and "Assembly Help"):

When you assemble the arm, make sure that the nodes are installed correctly in terms of orientation in space. Don't forget to drill out the holes in the fingers of the robotic arm for 3 mm fasteners to reduce friction between the joints. From the outside I filled the bolts with glue.


Don't rush to install the line. First check the functionality of the servo motors.

Checking servomotors

At this point, the servos should already be installed in the back of your robotic arm. To connect the servos to the Arduino and power supply, I used a small breadboard. Connect each servo motor's positive pin (red) to one breadboard rail and the negative pin (black or brown) to the other rail.

IMPORTANT! Remember to connect the Arduino pin to the negative rail: remember that all the ground pins must be connected to each other. The VCC pin can connect to different power supplies, but the GND must be the same.

Download the program to the Arduino (the program file is attached). Make sure that the connections of sensors, servomotors, etc. It was right. Put on the glove and turn on the Arduino. The servo motors should rotate depending on which finger you move. If the servos move, then everything is working!


If you are a more experienced Arduino user and know how to check the current values ​​from the bend sensors, you can adjust the range in the program to suit your realities. I'm assuming that all bend sensors are roughly the same, but if they are not, calibrating the sensors will definitely help you.

If the servos are not working correctly, make sure that you have connected them correctly (for example, when I was working on this project, I, as usual, forgot to connect the GND pin of the Arduino to the GND of the power supply and all the servos. In this case, nothing will work). Make sure everything works out before moving on.

Adding fishing line

Adding fishing line is probably the most difficult and demanding part of the robotic arm project. There are instructions for this on the InMoov website. The concept is simple, but its implementation is practically not so easy. Please note that this part of the project requires focus and patience. The only difference between my version and the design on InMoov is the use of glue. Thanks to this, we can get more flexible settings when calibrating the servos. To do this, just melt the glue and tighten the bolts we need. Although, of course, the reliability of the design decreases. In the end, after final setup and calibration, we can use a different fixation option at any time.

To calibrate the servos, rotate the rotors so that the fingers of the robotic arm are on the table. Connect your Arduino and power supply. Align the drive rockers so that when the arm is fully “lying,” the tension is maximum.


Explaining the calibration process is quite difficult. In addition, the instructions with InMoov, for example, did not suit me. That is, when fastening, you need to show your imagination and adapt to your realities - such as: the type of rocking chair, the type of fishing line or thread, design and assembly errors, the installation distance of the servomotors relative to the joints of the robotic arm.

Fortunately, this is the last stage of the project!

Afterword


Despite the fact that there are much more complex and precise (and expensive) designs, the above project is very interesting and has excellent potential for practical application. Such designs should not be used in direct contact with a person, due to the lack of accuracy of the concept itself. But industry, medicine, etc. For tasks without increased requirements for the accuracy of joint movements, our robotic arm is quite suitable. Well, from the point of view of further “upgrading” the hand, this field is generally unplowed. Starting from wireless control, ending with the replacement of drives, dimensions, and the development of additional degrees of freedom.

This is why I love Arduino: you can very quickly and for little money build a breadboard or prototype of a device that is not only easy to program, but can also perform real interesting tasks.

Leave your comments, questions and share personal experience below. New ideas and projects are often born in discussions!

Integrated home utility management systems, known as “Smart Home,” are gaining increasing popularity. Widespread implementation of these systems is hampered by sufficient high cost of components elements and installation work. A smart home based on Arduino is a solution that is quite accessible to everyone who has at least a little knowledge of electronics.

What is Arduino

Arduino is the brand under which they produce hardware and software for independent construction of automation and telecontrol systems.

In essence, this is a modular constructor with wide capabilities. Arduino hardware consists of a large assortment of printed circuit boards on which various sensors, actuators and expansion cards are organized. The core of the system is boards with programmable microcontrollers different levels complexity from Arduino Pro Mini to Arduino Mega. Expansion cards allow you to use a large number of external devices.

On a small printed circuit board a microcontroller, some discrete elements, quartz and various types connectors, including vertical pins, with the help of which shelving structures are assembled with the addition of expansion cards. Atmega family chips are used as microcontrollers. The controller type determines functionality boards depending on the number of inputs and outputs.

Such a widespread moduleArduino Unowith microcontrollerAtmega328 has the following characteristics:

  • Digital inputs/outputs – 14
  • Of these, 6 are PWM
  • Analog inputs – 6
  • Memory – 32 KB
  • Power supply – 7-12 V
  • Price – 950 rubles

Digital contacts can be programmed to perform a specific function. It can be an input or an output. These inputs/outputs can work with devices that require only two levels to operate. This is a logical unit or level close to the supply voltage and logical low level corresponding to zero. Two-level sensors can be connected to the digital inputs. These include a magnet-reed switch pair. This sensor reacts to the opening of doors and windows. Many security and fire alarm sensors operate on this principle.

Digital outputs can control the operation of electromagnetic relays, which in turn turn on and off the power outlets to which various household appliances are connected. A smart one from Arduino will cost much less than a ready-made industrial kit.

Analog inputs, through analog-to-digital converters, transmit information about the status of temperature sensors, light sensors and some other devices to the controller. By comparing sensor readings with commands stored in memory, the central unit of the system can control devices that require a smooth change in power. Six outputs connected to a pulse-width modulator allow smooth control of load power. For example, adjust the brightness of a lamp, adjust the temperature of a heater, or control the speed of an electric motor.

Most powerful and multifunctional board of this line is Arduino Mega. Mounted on a printed circuit board controllerAT mega 2560 , discrete elements, USB port for power connection. The board has 54 universal pins that can be programmed to perform I/O functions. 14 of them can control analog devices using pulse width modulation. 16 analog inputs are designed to connect any analog devices.

Controller board Arduino Mega costs around 1,500 rubles. The easiest way to program it is using a personal computer via a USB port.

Peripheral modules for Arduino

The controller board is the core of the system, but you cannot connect any devices to it. The outputs have a small load capacity and limited current. To organize a management system household appliances external power modules, communication devices and other devices will be required. This is not a problem since there are a large number of peripheral modules designed for Arduino controllers.

Here are just a few of them:

  • Gas analyzer – MQ-2
  • Light sensor – 2CH-Light-2
  • External temperature sensor – DS18B20-PL
  • Room temperature and humidity sensor – DHT-11
  • Motor Drivers – L298N, L9110
  • Relay modules – 1ch5V, 4ch5V
  • Module remote control IC2262/2272

The sensor that detects gas leaks in the room reacts to propane and butane, which are components domestic gas. The module has sensitivity adjustment and analog/digital outputs. A light sensor can be part of an automated light control system. It consists of two independent channels with individual sensitivity adjustment. The outdoor temperature sensor is designed to operate at temperatures from -55 to +125 degrees. Room sensor temperature and humidity intended. Temperature range from 0 to +55 0 C and humidity from 20 to 90%.

Since the supply voltage of Arduino modules ranges from 7 to 12 volts, any standard sensors that have the same operating levels can be used to organize a security or fire alarm.

Motor Drivers allow you to control single-phase, two-phase, four-phase and stepper motors. With the help of such devices you can open and close blinds or curtains. Servo drives connected to the drivers allow you to regulate the flow of coolant in heating radiators. Relay keys are indispensable in the Smart Home system. Controlled by a logical unit potential of +5 volts, the relays allow switching loads in circuits AC up to 10 amperes at voltages up to 250 volts.

You can use them to turn on and off electrical sockets, electric pumps and other systems.

The remote control module consists of a remote control and receiving device. The remote control is equipped with four buttons and transmits commands to the receiving unit at a distance of up to 100 meters. All peripheral modules have the same supply voltage and are compatible with any Arduino microcontrollers.

Organization of the Smart Home system

Without certain skills, knowledge circuit diagrams and the basics of electronics, it is better not to undertake the “Smart Home” system in full.

Programming microcontrollers of the Arduino line carried out in C/C++ language.

To begin with, you can write simple programs that can turn an LED on and off or control the operation of a microelectric motor. There are many examples of such programs. They use simple operators like: if, while, then and others. They allow even schoolchildren to write programs. When the first programs are executed correctly, you can try to assemble more complex devices that will use PWM outputs for smooth light control.

In order to make a “Smart Home” using Arduino with your own hands, you need to draw up a technical project, which will indicate the number of sensors and actuators for each room. You can start with one room where a few simple functions will be implemented. Some of them will be performed based on signals from external sensors, and some based on timer signals. When a person gets up for work in the morning, the Arduino controller will turn on the electric kettle or coffee maker based on a timer signal. If it is dark outside, which is detected by the external sensor, the lamp in the room will gradually light up. A comfortable room temperature can also be set for both sleeping and waking up.

For a small number of functions, an Arduino Uno microcontroller and a set of peripheral modules are suitable.

To control household appliances, you will need relay keys that will turn electrical outlets on and off. To control the light you will need a motion detector. If the smart system is installed in the kitchen, it is necessary to provide automatic activation of the hood, a domestic gas leak sensor and a water leak sensor. As a fire alarm element, a smoke detector must be installed in the room.

Conclusion

The Arduino controller will allow you to complete a smart home project and within a relatively small amount. If you calculate all the costs of equipping a three-room apartment, the amount is unlikely to exceed 30-40 thousand rubles. If you reduce the number of functions, the budget will be even more modest.