📜 ⬆️ ⬇️

Motion sensor for switching radio stations - part I

Hi, Habr! From this text you will understand that I began to read "Young Radio Amateur" and fell in love with this book and its author, and now I really want to do something similar for those who take the first steps with Arduino - so that it is simple and understandable.


The principle of echolocation to determine the distance to the object is the basis of the motion sensor, which we will use.

I hope the article will be interesting not only for beginners, but will also save time and more advanced users, as I tried to collect in one place information on the ultrasonic rangefinder, including datasheets, TTX, specs, illustrations and libraries from various sources.

In the last post, we almost mechanically collected a couple of Shilds and reprogrammed our MC for one and the other. It was no more difficult than loading a new song into the player. Thus, we learned how, in principle, you can play with this constructor, and we can continue to play like this, changing the already-made shields and sketches. But I want to collect something of my own.
')
So let's try almost seriously and without fear to look into the eyes of the circuitry and programming, and independently add an additional sensor to the finished circuit. For all the time the text you have about a 10 seconds to pick up a soldering iron, sorry if that.

What we learn in the course of assembling a new device:
1. How to read a ready-made device diagram (the so-called schematic diagram) and find there what we need.
2. What are the pins on Arduino and why. How to choose the right one.
3. How to ping a new component from a computer (port monitor in IDE). How to check that the new component is working.
4. We will learn a little about how one of the sketches was written.
5. How to add an ultrasonic sensor to the finished radio circuit.

Objective: to add a new component to the finished radio device: an ultrasonic distance sensor in order to use it to switch stations.

If you have only Arduino herself and this sensor, you can also participate in this project and almost completely repeat all the steps described in the text. In this case, you stop at the moment when you set up an interesting such ultrasonic line. I want to go ahead and try to tune in radio stations with a wave of my hand. So.

Decision:

As you remember, I have a newbie kit , which includes a ready-made expansion card for Arduino with all the necessary components to assemble a radio. The radio is going to be no more complicated than the Lego constructor according to the instructions, or even without, because Most of the components simply cannot be planted on the “wrong” board - their legs are so conveniently located. At the initial stage, the radio looks like this:



Which in itself is beautiful. A recent handful of "details" played with live music. However, this is not enough for me and I want to add this sensor here, get acquainted:



Name: ultrasonic range finder type HC-SR05
For Google: 5 pin ultrasonic, ultra-sonic ranger SRF05
Libraries:
NoBlind_Ultrasonic , which I use in my project
NewPing , which, as the author promises, has a higher speed
Datashit in Russian: TTX in pdf
Excellent datasheet: specification in English, the most complete
Wiki site datasheet: briefly, in English
Designation on the diagram:


For a start, some entertaining physics.

What you need to know about ultrasonic distance sensors




They work on the principle of dolphins, bats and whales. Some of these guys have poor eyesight, some in the water or at night are not particularly visible, like any normal person. Therefore, they rely on sound. This principle is echolocation: the sound is sent, it reaches the object and, reflected from it, comes back. Since, roughly speaking *, the speed of sound is fixed, so you can understand how much the object is, if you know how much sound has returned.


This guy can fly at night and not bump into you and other trees, because it measures the distance to objects by ultrasound. =)

A person can find out how far the thunderstorm is: first we see lightning (because the speed of light is faster), and then we hear thunder. If you count how many seconds the distance between the flash and the rumble of thunder, and know the speed of sound - 340.29 m / s, you can calculate the distance to thunderstorm in meters:
Speed ​​= Time * Distance
For example:
20s * 340m / s = 6800m = 6.8 km

We do not hear the sound used by the sensor, since our ear does not hear vibrations at frequencies above 20 kHz. But animals hear this sound.


The range of sounds heard for us is from 20 Hz to 20 kHz, i.e. our ear cuts off infrasound and ultrasound.

On this principle rodent repellents are arranged. In order not to upset your pets, do not poke a working sensor in their ear, because for them it works very loudly. Fortunately, it sends sound at a distance of no further than 200-400 cm, i.e. the animal may simply move away from the sound source and not listen to it. Also, the sound from the sensor "flows" not in all directions, but mainly forward, scattering on the sides - you will feel this when setting up the radio you will try to hold your hand strictly above the sensor itself so that your hand can "see" the device better:



In any case, if there are animals at home, then for stationary projects, you may be better off using other motion sensors. For example, the distance can be measured using infrared rays, in this case, take the IFC sensor.

And one more important point. You can not switch radio stations, for example, a cat. The fact is that from the fluffy objects the sound is reflected somehow, namely - it is absorbed by them. That is why at the repbaz the walls are upholstered with something soft: it is soundproofing, so that the musicians cannot be heard while they are playing at full volume in the studio (well, or they beat their heads against the wall - this is how it goes).

image
The soft floor at the rehearsal base not only collects dust, but also absorbs sound.

* More precisely , the speed of sound is also influenced by the temperature and density of the medium in which it is distributed.

The hotter the air, the faster the sound propagates, because the speed of sound in gases increases with increasing temperature. When the air temperature rises by 1 °, the speed of sound in it increases by 0.59 m / s. In our situation with a thunderstorm, the scatter of sound speeds is not that big , so the speed of sound is more or less fixed for us: in winter, when it is cold, there are no thunderstorms, and in summer, when +50 - +100 - there is no, as a rule us. =) If you want to learn more about the propagation of sound waves, I, for example, liked this article .


As can be seen from the table, we are not much mistaken if, calculating the distance to a thunderstorm, we take the speed of sound for 340 m / s.


Although it is difficult for me to fully understand this video about the principles of operation of the ultrasonic sensors directly due to the many terms and fast tempo, it is very pleasant to watch and listen to it.

Task: if you managed to watch the video above, then try to answer the question why our sensor seems to have two sensors on one board and write your answer in the comments.

That's it. Congratulations, you are an expert in sound distribution and echolocation! You can move on.

Installation of the sensor on the expansion card for Arduino


Where to connect the sensor? How to choose a place for it? Is there any free space on our expansion board? At once I will make a reservation that the sensor can be put both on the expansion card and directly on the Arduino legs themselves. And how to choose them, we now find out. So.

Let's take the scheme of our finished shild from here from the section "schemes". Here's what it looks like:



This is called a circuit diagram. This is principled because here, in principle, it is shown what is connected to, but this diagram does not reflect the actual location of the components on the board. But her, in theory, easy and convenient to read. I was initially uncomfortable, because in fact, at the end of the Arduino there is not a single leg, and in this diagram we see the D2-D6 legs on it, which at first simply tore my template. But if you get used to it, the scheme is so basic that it simplifies everything to the state of “squares” and simply answers the question “what is connected to what” - then it becomes easier to work with it.

To read the legends, you can use a brief “dictionary” , but I recommend doing it not now, especially since our scheme mostly reflects ready-made components, and not board details, for each of which there is a symbol on the diagram. Now, do not be alarmed, we will try to find in this scheme a “place” for only one new sensor. Please note that at the bottom of the diagram there are buttons:



There are three of them, K1-K3. We already “stuck” them where necessary, when we assembled the radio according to the instructions . However, there are 2 more “button” slots on the board: K4 and K5. They just look like four holes, but they are not the same. We are only interested in those of the pairs of holes that are indicated on the board by a square contact.

Mistress note:

Why do the buttons have two contacts, and we use one at a time?
  • Square contacts lead to Arduino's D5 and D6 lines. Round is "earth."
  • To connect the buttons you need two contacts, because when the button is pressed, the signal line closes (pulled up to power through a resistor) and ground.
  • When connecting the sensor, the ground is needed only for power. We'll take the earth a little later from the Arduino connector, so in our case the second pins will not be needed.
.



This is how we will supplement the circuit with a sensor (Photoshop Med Skills)

Task: look at the schematic diagram of the entire radio device again. How many and what legs Arduino still "free"? Can we hang on this Arduino something else within this device, in addition to our ultrasonic sensor? We are waiting for your answers in the comments.

To solder!


Where there are holes on the Arduino expansion board, we can add so-called pin connectors \ connectors \ pins, which are denoted by the letters PLS-XXX, where instead of XXX there is a necessary number, depending on the number of pins. They are sold in the form of long combs, from which PLS-1, PLS-2, etc. can be separated. They look like this:

image

Irreplaceable thing in the household! If started Arduino. So, contacts K4 and K5 have two holes each, which means they are called PLS-2. We will add one pin each to the square of them and thus bite off two PLS-1. Now you can solder.


Instead of a thousand words: this is the same place with the buttons from the diagram above, but now you can see it on the board.

Sensor pins


The sensor has 5 pins. They will allow us to “ask him a question”, to get an “answer”. Well, connect it to the power supply. Information which pin means it can be taken from the datasheets or on the site of the store where you bought the sensor. It is a pity that neither there nor there, as a rule, does not sign anything in detail, therefore, especially for our article - get acquainted, the sensor pins:


MK is a microcontroller. Our Arduino is a microcontroller that we can program as we want.

What is characteristic, the purpose of the Oc pin even on the most overseas sites remains vague . There they write: “the purpose of the Oc pin still needs to be hacked.” I managed to “hack” after a few minutes of googling. The official datasheet states that this contact is not connected to anything, lol .

Everything is simple and even predictable here: two power contacts and two to send / receive a signal. Therefore, we take 4 wires "mother-mother" and prepare the sensor for boarding the board:


Until now everything went well, however, where to connect each of the 4 wires and why?

There is such an anecdote: one person wanted to learn how to make a dead loop. He bought an aviation magazine, where it was described in the article, boarded a plane and flew. At first everything went well: he carried out the instructions described in the journal and successfully entered the dead loop. Then he turned the page, and there: exit from the dead loop in the next issue .

You and I are lucky that we are not learning to make a loop under my articles. Because now I will give you a little rest. I hope, until now, it was clear and interesting to read. Now you have a little time until I prepare the second, final part of the post, where we will understand:

We will answer the remaining questions and assemble the finished device, as well as program it. Subscribe to updates - I will be pleased.

Right now I invite you to answer this question: what is more interesting for you in Arduino - to assemble the components or to program the device? Why?

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


All Articles