ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING Arduino. Connecting simple sensors. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Radio amateur designer The built-in ADC of the microcontroller, considered in the previous part of the review, makes it easy to connect various analog sensors to the Arduino board, which convert the measured physical parameters into electrical voltage. An example of a simple analog sensor is a variable resistor connected to the board, as shown in Figure 1. 3. It can be of any type, for example, SP33-32-2 (Fig. 10). The value of the resistor in the diagram is indicated approximately and can be either less or more. However, it should be remembered that the smaller the resistance of the variable resistor, the more current it consumes from the power supply of the microcontroller. And when the resistance of the signal source (in this case, a variable resistor) is more than XNUMX kOhm, the ADC of the microcontroller works with large errors. Please note that the resistance of a variable resistor as a signal source depends on the position of its slider. It is equal to zero in its extreme positions and maximum (equal to a quarter of the nominal resistance) in the middle position.
It is convenient to use a variable resistor when you want to change the parameter smoothly, and not in steps (discretely). As an example, consider the work given in Table. 1 program that changes the brightness of the LED depending on the position of the variable resistor slider. The string U = U/4 is needed in the program in order to convert the ten-bit binary number returned by the ADC to an eight-bit number, accepted as the second operand by the analogWrite () function. In the case under consideration, this is done by dividing the original number by four, which is equivalent to discarding the two least significant bits. Table 1 A variable resistor of an appropriate design can serve as a rotation angle or linear displacement sensor. Similarly, many radio elements can be connected to it: photoresistors, thermistors, photodiodes, phototransistors. In a word, devices whose electrical resistance depends on various environmental factors. On fig. 3 shows a diagram of connecting a photoresistor to the Arduino. When the illumination changes, its electrical resistance changes and, accordingly, the voltage at the analog input of the Arduino board. The photoresistor FSK-1 indicated in the diagram can be replaced by any other, for example, SF2-1.
In table. 2 shows a program that turns an Arduino board with a photoresistor connected to it into a simple light meter. While working, it periodically measures the voltage drop across the resistor connected in series with the photoresistor, and transmits the result in arbitrary units through the serial port to the computer. On the Arduino debug terminal screen, they will be displayed as shown in Fig. 4. As you can see, at a certain moment the measured voltage dropped sharply. This happened when a brightly lit photodiode was obscured by an opaque screen. Table 2
To obtain illumination values in lux (standard units of the SI system), you need to multiply the results obtained by a correction factor, but you will have to select it experimentally, and individually for each photoresistor. This will require an exemplary light meter. A phototransistor [1] or a photodiode (Fig. 5) is connected to the Arduino in a similar way. Using several photosensitive devices, it is possible to design the simplest vision system for a robot [2]. It is also possible to implement many classical designs known to a wide range of radio amateurs at a new technical level - a cybernetic model of a night butterfly [3, p. 134-151] or a model of a tank moving towards the light [4, p. 331, 332].
Similarly to the photoresistor, a thermistor is connected to the Arduino (Fig. 6), which changes its electrical resistance depending on temperature. Instead of the MMT-4 thermistor indicated on the diagram, the main advantage of which is a sealed case, you can use almost any other, for example, MMT-1 or imported.
After an appropriate calibration [5, p. 231-255] such a device can be used to measure temperature in all kinds of home weather stations, thermostats and similar structures [6]. It is known that almost all LEDs can serve not only as light sources, but also as light receivers - photodiodes. The fact is that the LED crystal is in a transparent case and therefore its pn junction is accessible to light from external sources. In addition, the housing of the LED, as a rule, has the shape of a lens that focuses external radiation on this transition. Under its influence, for example, the reverse resistance of the pn junction changes. By connecting the LED to the Arduino board according to the diagram shown in fig. 7, one and the same LED can be used both for its intended purpose and as a photosensor [7]. The program illustrating this mode is shown in Table. 3. Her idea is that first, a reverse voltage is applied to the pn junction of the LED, charging its capacitance. The cathode of the LED is then isolated by configuring the pin of the Arduino it is connected to as an input. After that, the program measures the duration, dependent on ambient light, of discharging the capacitance of the pn junction of the LED by its own reverse current to a logic zero level.
Table 3 In the above program, the variable t is declared as unsigned int - an unsigned integer. A variable of this type, unlike an ordinary int that takes values from -32768 to +32767, does not use its most significant bit to store the sign and can take values from 0 to 65535. The program calculates the discharge time in the while(digitalRead (K)!=0)t++ loop. This loop is executed, incrementing t by one each time, until the parenthesized condition is true, i.e., until the LED cathode voltage goes low. Sometimes it is required that the robot not only receive information about the illumination of the surface on which it moves, but also be able to determine its color. A color sensor of the underlying surface is implemented, illuminating it alternately with LEDs of different luminescence colors and comparing, using a photodiode, the levels of signals reflected from it under different illumination [8]. The connection diagram of the color sensor elements with the Arduino board is shown in fig. 8, and the program serving it - in table. 4.
Table 4 The procedure for measuring the signals received by the photodiode under different illumination of the surface is repeated many times, and the results obtained are accumulated in order to eliminate random errors. The program then selects the largest of the accumulated values. This allows you to roughly judge the color of the surface. To more accurately determine the color, it is necessary to complicate the processing of the results, taking into account not only the largest of them, but also its ratio with the smaller ones. It is also necessary to take into account the real brightness of LEDs of different luminescence colors, as well as the spectral characteristics of the applied photodiode. An example of a color sensor design consisting of four LEDs and a photodiode is shown in Fig. 9. The optical axes of the LEDs and the photodiode should converge at one point on the surface under study, and the devices themselves should be located as close as possible to it in order to minimize the effect of extraneous illumination.
The assembled sensor requires careful individual calibration on surfaces of different colors. It is reduced to a selection of coefficients by which the measurement results obtained under different illumination should be multiplied before comparison. A robot equipped with such a sensor can be taught to perform interesting motion algorithms. For example, he will be able to move around the working field of one color without violating the boundaries of "forbidden" zones painted in a different color. The programs discussed in the article can be found at ftp://ftp.radio.ru/pub/2016/10/asensors.zip. Literature
Author: D. Lekomtsev See other articles Section Radio amateur designer. Read and write useful comments on this article. Latest news of science and technology, new electronics: A New Way to Control and Manipulate Optical Signals
05.05.2024 Primium Seneca keyboard
05.05.2024 The world's tallest astronomical observatory opened
04.05.2024
Other interesting news: ▪ The longest-lived vertebrate identified ▪ Jupiter doesn't revolve around the sun ▪ Global warming is causing coral bleaching ▪ Telephone conversation excites the cerebral cortex News feed of science and technology, new electronics
Interesting materials of the Free Technical Library: ▪ section of the site Home workshop. Article selection ▪ article Principles of organization and tasks of the disaster medicine service. Basics of safe life ▪ article Why are there no numbers in IKEA product names? Detailed answer ▪ article Asphalt concrete worker-welder. Standard instruction on labor protection
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |