Sensors "Arduino": description, characteristics, connection, reviews

Table of contents:

Sensors "Arduino": description, characteristics, connection, reviews
Sensors "Arduino": description, characteristics, connection, reviews
Anonim

The Arduino platform is one of the best for building various automated systems. Moreover, many universities and colleges use Arduino to introduce students to the field of robotics. Indeed, Arduino is a very lightweight, but at the same time powerful platform for constructing various robots and smart systems. And of course, so that it all takes less time, ready-made sensors are sold. There are a huge number of them in stores, so it’s quite difficult to get confused in choosing the right one. In this article, we will look at some of the main Arduino sensors, and how they work.

Sensors for arduino
Sensors for arduino

Where to buy

The fact is that the sensors in our stores cost a lot of money. And if you are going to start exploring the Arduino platform, then you just need to know where you can buy them at a low price. The answer is simple - Chinese stores. It could beAliexpress, Joom, Pandao and others. Almost all stores buy sensors there and sell them with a huge margin, which reaches up to 300%. Of course, you will have to wait for some time, and you cannot be sure of the quality of the goods, but paying three times more for the same sensor is also not worth it. Example: Aliexpress has a set of 36 sensors that costs 800 rubles. The same set is sold in a Russian store for 3.5 thousand rubles. So it's up to you.

Where to buy sensors for arduino
Where to buy sensors for arduino

Servo drive

Servo drive is used in the design of robots and various smart systems. With the help of a servo, you can open doors, find out the degree of rotation and much more. But mostly it is used in the creation of robots. The maximum angle of rotation of the servo: 180 degrees. But sometimes in the open spaces of Aliexpress you can also see options with a 360-degree rotation angle. This is a pretty basic element, almost all lessons on Arduino with sensors start with it. The servo is easy to connect, the control code is very simple.

To connect the servo, only three wires are used: ground, power, logic. The signal wire (usually yellow or brown) is connected to any PWM (pulse wide modulation) enabled pin on the Arduino.

Connecting Servo to Arduino
Connecting Servo to Arduino

Code example:


include // include the library to work with Servo servo1; // declare a servo variable of type "servo1" void setup() // procedure setup { servo1.attach(11); //bind servo to analog output 11 } void loop() // procedure loop { servo1.write(0); // set rotation angle to 0 delay(2000); // wait 2 seconds servo1.write(90); // set rotation angle to 90 delay(2000); // wait 2 seconds servo1.write(180); // set rotation angle to 180 delay(2000); // wait 2 seconds }

First, we add the library that is already in the Arduino to the code, then we indicate which pin the servo is connected to. As you can see, working with a servo is really very simple, the control is just one operator.

Price on Aliexpress: 80–100 rubles.

DHT-11

DHT-11 is used to measure temperature and humidity. This temperature sensor for Arduino is the most popular because of its price and features. Measures temperature in the range from 0 to 50 degrees, and humidity from 20 to 80%. Also on sale is another version of this sensor, DHT-22, it has a larger measurement range, but it also costs several times more. For simple projects, its use is not advisable, so everyone prefers the DHT-11, which does an excellent job of measuring. Power can be supplied from 3.3 to 5V. In general, the sensor itself has 4 connection pins, but there are DHT-11 modules on sale, it is much more convenient to work with them, since the connection is through 3 pins and you do not need to suffer with resistors.

Connection. This temperature sensor is connected to the Arduino using three contacts: ground, power and logic.

Connecting dht11 to arduino
Connecting dht11 to arduino

Code example:


include"DHT.h" define DHTPIN 2 // Same pin number mentioned above DHT dht(DHTPIN, DHT11); void setup() { Serial.begin(9600); dht.begin(); } void loop() { delay(2000); // 2 second delay float h=dht.readHumidity(); //Measure humidity float t=dht.readTemperature(); //Measure temperature if (isnan(h) || isnan(t)) { // Check. If the reading fails, "Read Failed" is printed and the program exits Serial.println("Read Failed"); return; } Serial.print("Moisture: "); Serial print(h); Serial.print("%\t"); Serial.print("Temperature: "); Serial print(t); Serial.println("C"); //Displaying indicators on the screen }

At the very beginning, as when working with a servo, the library is connected. By the way, about the library. Initially, it is not in the Arduino package, this library needs to be downloaded. There are several versions of this library, in our example the most standard one is used. Be careful when downloading, because the syntax may be different and the code will not work. Further, it is also written to which contact the sensor is connected and its version (DHT11 or DHT22). Like working with a servo, working with this sensor for Arduino is very easy, using only a few operators. By the way, often the servo and dht11 work together, for example, when creating automatic windows that will open if the room or greenhouse is too hot.

Price on Aliexpress: 80–100 rubles.

Soil moisture sensor

This sensor is used whendesign of automatic irrigation. With it, you can measure soil moisture, and then process this data and, if necessary, water the plant. There are many variants of this sensor for Arduino on sale, but the FC-28 model is popular. Quite a budget option, so everyone loves it and uses it in their projects. The sensor has two probes that conduct electricity through the ground. With dry soil, the resistance is greater, and with wet soil, less. Basically, this sensor is used only in small projects, this is due to the fact that the probes are made of poor material and sooner or later, during active work, they become corroded, after which the sensor stops working. The lifetime of the sensor can be increased by activating it only when taking data from the ground, for example, once every 6 hours. Some craftsmen even change the probes to better ones, made by themselves, or even assemble a humidity sensor for Arduino from scratch.

Connecting the soil moisture sensor is quite simple. Usually it comes with a potentiometer and a comparator to control the sensitivity of the sensor. In total, it has three contacts: logic, power and ground. It can be connected to both digital and analog contacts. By the way, it is more convenient to work in analog mode.

Connecting soil moisture sensor to arduino
Connecting soil moisture sensor to arduino

Code example:


int sensor_pin=A0; int output_value; void setup() { Serial.begin(9600); Serial.println("Reading data from the sensor"); delay(2000); } void loop() { output_value=analogRead(sensor_pin);output_value=map(output_value, 550, 0, 0, 100); Serial.print("Moisture: "); Serial.print(output_value); Serial.println("%"); delay(1000); }

First of all, we determine the contacts to which the sensor is connected to the Arduino. Then we read the data from it and display it. As with other sensors, the FC-28 is easy to work with. And all thanks to ready-made libraries and sensors.

Price on Aliexpress: 30–50 rubles.

PIR sensor

This motion sensor for Arduino is used in the construction of various security systems. Detects moving elements from 0 to 7 meters. We will not consider the principle of operation, let's move on to connecting this sensor to Arduino.

Judging by the reviews, it is also connected using three contacts: logic, power and ground. It works through digital outputs.

Connecting motion sensor to arduino
Connecting motion sensor to arduino

Code example:


define PIN_PIR 2 define PIN_LED 13 void setup() { Serial.begin(9600); pinMode(PIN_PIR, INPUT); pinMode(PIN_LED, OUTPUT); } void loop() { int pirVal=digitalRead(PIN_PIR); Serial.println(digitalRead(PIN_PIR)); //If movement is detected if (pirVal) { digitalWrite(PIN_LED, HIGH); Serial.println("Motion detected"); delay(2000); } else { //Serial.print("No motion"); digitalWrite(PIN_LED, LOW); } }

We determine the contacts to which the sensor is connected, after which we check for movement. Working with it is very convenient and easy, but there are cases of false positives.

Price forAliexpress: 30-50 rubles.

drawing conclusions

Above, the main sensors for Arduino were considered, which are the very first to be studied by novice radio amateurs. As you can see, they are quite inexpensive, they connect easily, and reading data takes only a couple of lines. In addition to them, there are still a huge number of other sensors, even for measuring the pulse! It is most profitable to buy them on Aliexpress in sets, so they will cost even cheaper. It's easy to create, the main thing is to remember the three basic rules of robotics!

Recommended: