Simply and stably sense you - innovative production of infrared sensor switch

Publisher:trendsetter9Latest update time:2011-02-21 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
A trip to the hotel's toilet
Our family has been poor peasants for eight generations, living in a small mountain village in the northeast. Although we have never seen any grand occasions, we have beautiful mountains and rivers, and life is not bad. My fascination with electronic production since childhood was also limited by the environment. It was difficult for me to go to the city, and I had never seen any new gadgets. When I was 13 years old, my father's friend's son got married and prepared a banquet in the city, inviting our family of three to go. Their wedding was really grand, held in the most luxurious hotel in the center of Tieli City. The hotel was magnificent, the floor was shining, and there was a big "Xi" character on the wall. It has been a long time, and I can't remember more details, but there is only one thing that impressed me deeply. The dishes came, including my favorite prawns, paired with a big bottle of Coke, I closed my eyes, opened my mouth, and ate it to my heart's content. After eating and drinking, I came to the toilet door of the luxury hotel. The toilet was also magnificent, the floor was shining, and there was a big "Male" character on the wall. Yes, it was here. I walked in and saw a row of urinals. Urinals were not unusual, I had seen them before. What was unusual was that there was a slogan on the urinals, which read "A small step forward, a big step for civilization." What was even more unusual was that there was a square metal plate under the slogan, and a black square glass in the middle of the metal plate. I was studying while urinating, and I found that from time to time a small red light would light up from inside the black glass. I moved my body forward and backward, and the small red light also flashed. When I turned to leave, I suddenly heard the sound of "rushing" water. I immediately looked back, and the small red light started flashing again. As soon as I walked away, it flushed again. Was there someone watching behind the black glass? I was a little shy and didn't dare to go over to study again. When I came to the sink, I found that there were no valve switches on the row of faucets. I tapped the water outlet, but there was no response. Suddenly I found that there was also a black glass under the water outlet. I stretched my hand over it, and water flowed out naturally. I was sure that there was no one behind the black glass. It should be a sensor that could sense my hand. But how did it sense it? After washing my hands and preparing to go out, I found the hand dryer next to the door. There was also a piece of black glass at the bottom of the hand dryer. When I put my hand under it, a warm air appeared.


This trip to the bathroom in a luxury hotel shocked me. It turns out that the switches of electrical appliances can be so smart that they can sense me without us touching them. My mind started to work at high speed, imagining the application of this technology in my own home. My mother can wash vegetables without turning on the faucet, and the lights at home can be turned on and off without pressing them hard. The TV, electric fan, and grandma's radio at home can all be equipped with this kind of induction switch. Install it on the door and connect it to the doorbell. As long as someone stands at the door, the doorbell will ring. My friends will definitely be scared when they come to my house to find me. Thinking about it, I couldn't help laughing out loud.

From digital circuits to single-chip microcomputers

After entering college, there are many bookstores in the school. Before I discovered single-chip microcomputers, I had been wandering in the electronic technology section of the bookstore. There are many books about electronic production there, all of which are my favorites. My favorite books are books like 500 examples of electronic production. Many of the productions in them are simple and practical. One day, I suddenly found an example of making an infrared induction hand dryer in a book. It immediately brought me back to that unforgettable experience - a trip to the bathroom of a luxury hotel. I want to realize my dream as a teenager, I want to realize this production. In the following days, I began to study the principle and circuit of the infrared induction hand dryer.
It turns out that the so-called induction switch only uses infrared rays that are invisible to the human eye to sense objects. The core component of the induction switch is the infrared reflection sensor. The infrared reflection sensor includes an infrared light emitting diode and an infrared photosensitive diode, both of which face in the same direction and are encapsulated in a plastic shell. When in use, the infrared light emitting diode lights up and emits an infrared light that is invisible to the human eye. If there is no object in front of the sensor, then this infrared light will dissipate in the universe at a speed of 299792458m/s (the speed of light).
But if there is an opaque object in front of the sensor, the infrared light will be reflected back and will shine on the infrared photosensitive diode next to it. After the infrared photosensitive diode receives the infrared light, the resistance value of its output pin will change. By judging the change of this resistance value, it can sense the object in front and then control the switch of the electrical appliance.
After understanding the principle and seeing the circuit schematic in the book, I had a new doubt. The infrared light-emitting diode should have the same driving circuit as the ordinary diode. Can't it be used to add an infrared photosensitive diode and a transistor to amplify the received signal to drive the relay? Why do we need to add two chips, NE555 and CD4069, to complicate a simple matter? After reading the introduction in the following article, I realized that the purpose of doing so was to prevent interference from ambient light. Infrared rays are hidden everywhere in the environment we live in. The sun is the most common infrared light source, and there are also fire, lights, infrared remote controls and some unpredictable light sources. The question is, with so many infrared light sources around us, how can the infrared photosensitive diode in the sensor know which light is infrared light in the environment and which light is infrared light emitted by its neighbors? So the genius engineer thought of the method of modulation and demodulation. They modulated the infrared light-emitting diode at a certain frequency, that is, let it flash at a certain frequency. A circuit is designed at one end of the infrared photodiode so that the receiving end can filter out the infrared light source of this frequency. Like a radio, the sensor can filter out interference from other frequency light sources by transmitting at its own frequency and receiving at its own frequency.


Haha, after reading the principle, a fire was ignited in my heart. Then I rushed to the electronics market at a speed of 70km/h (by car). I prepared all the components and made the physical object according to the schematic diagram. I have to admire my welding skills at that time. I used a small perforated board to make the circuit small and compact. However, after connecting the power supply, the problem came. When I put my hand on the sensing area, the indicator light did not light up. Later I found that this was caused by the mismatch between the transmitting frequency and the receiving frequency. Because the RC circuit is used to generate the frequency, simply put, the frequency is generated by the charging and discharging cycle of the capacitor, so the frequency is easy to change with temperature. It took me a lot of time to debug the circuit. Without the help of an oscilloscope, it is so difficult to achieve success by repeatedly modifying the resistance and capacitance values! When the classmates put their hands on the sensing area and the indicator lighted up, all the difficulties of debugging were transformed into a sense of accomplishment, which was geometrically multiplied by the words of praise from the classmates.
Like a movie, the story reaches a climax, and every step after that is a fall. My classmates only saw the bright side. The problems that quietly appeared behind the scenes became our pain when we were alone. On a sunny afternoon, strong light shone into the room. The induction switch was in an unstable state due to the strong light. It kept switching on and off by itself and did not respond to reflective objects. The infrared remote control of the TV that is commonly used at home can also cause the induction switch to malfunction. Even if it is placed in a dark corner, there will be an annoying problem, that is, when there is a reflective object, it will keep switching on and off, and the relay will be attracted very quickly, like a telegraph. This is because the reflective object is just at the critical point of the induction zone, that is, the dividing line between "sensing" and "not sensing". The slight approach or departure of the object will cause the switch state to change. No one would want the lights in their home to be like lightning or the faucets to be like musical fountains. These problems combined make the application of induction switches very unsatisfactory. I worked hard to convert all the light switches in my home into induction switches, but my father changed them back to traditional switches in less than a month. Gradually, my interest in the induction switch was replaced by my passion for making audio-controlled switches and time-delay switches. A few weeks later, I broke up with the infrared induction switch.
One day after that, I started to learn microcontrollers. A few months ago, I became interested in the analog-to-digital converter (ADC) built into the microcontroller and kept exploring its wonderful uses. The DIS.MUSIC3 colorful music display uses ADC to collect audio signals. Suddenly one day, I thought, can I use a microcontroller with ADC function to replace the traditional digital circuit and make the infrared induction switch more stable? After searching on the Internet for a long time, I couldn't find the production of infrared sensors based on microcontrollers. This situation is both good and bad for me. The good thing is that if the production is successful, it will be another innovative production of mine; the bad thing is that I don't have any reference materials, and I can't even guarantee whether my idea is feasible. The process of my learning microcontrollers seems to be a sine wave, starting from the basics, then developing applications, and then independently completing innovative production, and finally returning to the research of basic technical issues. In the following days, I did the most research on infrared knowledge. I did many experiments, used different infrared light sources to study, and found their characteristics and differences. Then I started to study the infrared sensor switch with simple circuit making and high stability. At the end of the study, I was surprised that the hardware circuit could be so simple, so simple that there were no redundant components - single-chip microcomputer, infrared reflection sensor, LED indicator and power supply. In the previous version, a wire was required to be added to the hardware circuit, but later I modified the program algorithm and this wire was gloriously laid off.
Yes, program algorithm - a weapon that kills people invisibly. If the difference between humans and animals is that humans have rationality and wisdom, then the difference between single-chip microcomputer and digital-analog circuit is that single-chip microcomputer has program control. The single-chip microcomputer program accurately handles time and status, and the powerful software reduces the hardware cost to the lowest and can be copied at zero cost. I love programming, it gives me endless fun and unimaginable innovation possibilities. If I were a college student about to graduate, I would write a paper about this innovative production to make my supervisor smile; if I were an author of the "Radio" magazine focusing on popular science, I could only use a small chapter to briefly talk about the basic principles of this production. But before that, let's take advantage of our enthusiasm and make this infrared sensor switch based on the single-chip microcomputer by ourselves, experience its exquisite design, and test its anti-interference ability.
I built the circuit on the breadboard, and the power supply is a 4.5V DC power supply composed of 3 No. 5 batteries. Because the circuit is very simple, I also specially defined the IO interface for the plug-in layout on the breadboard. So we don't even need wires, just plug the single-chip microcomputer, infrared reflection sensor and LED indicator into the designated holes. The following points are worth noting: the single-chip microcomputer needs to use the STC12C2052AD series with ADC function; when burning the program, choose to use the internal RC oscillator; there is no specific model of infrared reflection sensor, I use RPR220, you can also use other models.
Test the experimental circuit built on the breadboard. Do you feel its simplicity and stability? When the LED indicator is connected to the P1.7 interface, it is a non-latching induction switch, that is, the LED light turns on when there is a reflective object, and turns off when the object leaves. It is suitable for induction water faucet lights. When the LED indicator is connected to the P1.6 interface, it
is a latching induction switch, that is, the LED light turns on when the induction switch is triggered once, and the LED light turns off when it is triggered twice. It is suitable for induction light switches. If the LED indicator is replaced with a relay, it can be used to control other electrical appliances. Electrical appliances can be anything you can think of. I believe that you, like me, have had such a dream for a long time. Now is the time to realize it.
In addition to practical switch modification plans, infrared induction switches can also turn home life into science fiction movies. Would a table that can sense you shock everyone? The upper surface of an ordinary table is embedded with a frosted glass plate. When the tabletop is empty, the table is nothing special. But when we put our hands, cups or newspapers on it, the corresponding position will emit light. It turns out that hundreds of LED lights and induction devices are installed under the glass. As long as the table senses that something is placed on it, the microcontroller will control the LED lights at the corresponding position to light up. Changing the program of the microcontroller can also play more tricks.
If I use this infrared induction switch of mine, can I also realize this science fiction work? When writing this article, I am also studying this technology, hoping that it can be realized with our commonly used microcontroller. If it can be realized, I will write another article to share with you. That table and that induction lamp will become your work and your elaborate work.

Key issues and solutions


From the first experience of infrared induction switches in the toilet when I was young, to the principles and problems of traditional circuit production, to the use of microcontrollers to realize more stable induction switch designs, and finally to the application of induction switches in electrical switches and induction desktops. Infrared induction switches have gradually moved from toilets to living rooms, from complexity to simplicity, and from fluctuations to stability. So who wants to know how microcontrollers achieve stable induction? What is the secret? Here I will share with you some basic principles of technical implementation. If you have better solutions and improvement suggestions, or if you are a senior expert in this field, you are welcome to communicate with me. Without further ado, I will show you my ugliness here!

1. How to remove the interference of ambient light?

Different from the previous modulation and demodulation method, after using the ADC function, another solution will make the test more efficient. That is to use the dual detection method. The prerequisite is that the microcontroller can control the switch of the infrared light-emitting diode. First, use the ADC function to read the analog value of the voltage connected to the ADC interface, and the value ranges from 0 to 255 (decimal). When the infrared light received by the infrared photosensitive diode is strong, the value read by the ADC is large, otherwise it is small. What we need to do is to control the infrared light-emitting diode to read the ADC value once when it is emitting light, and then let the infrared light-emitting diode go out, and read the ADC value again. Let's assume that there is no interference from other infrared light sources. When the infrared light-emitting diode is off, the infrared light-sensitive diode should not detect the light source, and the value read by the ADC should also be 0; when the infrared light-emitting diode is on and there is no reflective object, the value read by the ADC should also be very small, close to 0; when there is a reflective object, the infrared light-sensitive diode detects the light source, and the value read by the ADC will become larger. If there is interference from other light sources, a larger value will be read when the infrared light emitting diode is off. The larger the difference between the values ​​read out by the double detection, the weaker the interfering light source, and vice versa. Through this double detection, we can determine whether the received infrared light is emitted by the transmitter. The difference between the values ​​of the two detections is the final value we need. The final value will be involved in the following algorithm processing and is also the key data for our judgment and processing. The microcontroller needs to control the high-speed switch of the infrared light emitting diode to collect data faster.

Final value = the value read out by the ADC when the infrared light emitting diode is on - the value read out by the ADC when the infrared light emitting diode is off

2. How to solve the problem of inductive fluctuations at the critical point?

Triggering when slightly forward and shutting down when slightly backward is the problem of critical points. The root of the problem is that the critical point of triggering and the critical point of shutting down are at the same distance. As long as the two critical points are separated in the system based on the single-chip microcomputer, this problem can be solved. We know that the data that the single-chip microcomputer needs to process is the "final value", which is the difference between the values ​​read by the ADC when the infrared light-emitting diode is on and off. The final value is also a variable that changes continuously from 0 to 255. The closer the reflection is to the sensor, the larger the "final value". If we set it in the program, when the "final value" is greater than a certain value (for example, 200), the switch is triggered, and when it is less than this value, the switch is shut down, then the effect of such programming is an unstable switch with a single critical point. Since the single-chip microcomputer can imitate an unstable switch, it is naturally easy to create a stable switch! Just write the program settings and you can easily make it stable. The design of double critical points only requires two conditional judgments of values: when the "final value" is greater than a certain value (such as 200), the switch is triggered, and when the "final value" is less than another value (such as 150), the switch is turned off. In this way, an intermediate area is created between 150 and 200. When the reflection physics moves back and forth in this area, the switch remains in its original state, either judging or triggering. This design of double critical points actually gives the reflection object a space for movement, reduces the stability requirements for the reflection object, and the system state naturally stabilizes. In the actual debugging process, the two values ​​of the double critical points can be modified according to the needs of the application. For example, when making an automatic faucet, the range of hand movement is large, so a larger activity area should be reserved. If it is a sensor for an automatic tracking car, a smaller activity area can be used, or even a single critical point can be used to implement it. The design of double critical points is inspiring. You can use this design to do more things, or use it in the stability design of other sensors.

3. How to increase the success rate and reliability of sensing?

The "final value" processing and double critical point design can increase the stability of the system. It is normal to have several failures and errors in multiple data collections. But if these errors affect the state of the switch, who is responsible for this failure? There are many typos in my articles, and the editors of the magazine said that I am hopeless. When you see this article, you should know one thing, that is, several editors have stared at me and helped me correct the typos in the article. In the end, what everyone sees is a beautiful and fluent article. While thanking the editors, I also want to equip our infrared sensor switch with several "editor teachers" to check the collected data. Once an error occurs, the current data is abandoned and re-collected. This design is actually a kind of redundancy. I designed a loop detection statement in the program to detect and judge the collected data 20 times in a row. If there is an error in 1 of the 20 times, all current data will be abandoned immediately and re-tested. 20 consecutive detections are already very stable. Of course, you can also use 50 or 100 consecutive detections for greater stability, but the system's response speed will slow down and the sensitivity will also decrease. The contradiction between sensitivity and stability is rigid. In actual testing, you just need to find the number of detections that is suitable for the target system. "Final value", double critical points and 20 consecutive detections sound like very complicated things, but they are just a few simple statements in the program. The focus of the design is not on the complexity of the program, but on the design idea of ​​the entire system. The following is a key program section to share with you. This simple program includes the above three anti-interference designs.

4. How to increase the sensing distance?

Experiments have shown that the sensing distance of the infrared sensor based on the single-chip microcomputer and the ADC accuracy of the single-chip microcomputer, the double critical point value, the power of the infrared light-emitting diode, and the sensitivity of the infrared photosensitive diode are all related to the reflective effect of reflection physics. The general sensing distance will not exceed 20cm. However, it is enough for the design of the on-off induction switch. To increase the sensing distance, the following aspects can be improved. However, a longer sensing distance will cause the system to generate many uncertain factors, but the effect is not good
. RAM_H = Read_ADC; //Read the value of the ADC
port when the LED is on RAM_L = Read_ADC; //Read the value of the ADC port when the LED is off RAM_H = RAM_H - RAM_L; //Take the difference between the two detection values ​​to avoid interference from ambient light
if(RAM_H > 0x06){ //Distance when turned on (should be less than the distance when turned off) CON++; //Count plus 1
CON2 = 0 ;
if(CON > 20){ //20 consecutive detections to avoid interference
CON = 0; LED_Y = 0; //LED indicator lights up } } if(RAM_H < 0x03){ //Distance when turned off CON2 ++; CON = 0; if(CON2 > 20){ CON2 = 0; LED_Y = 1; //LED indicator turns off } } The program part of "final value", double critical points and 20 consecutive detections If a longer transmission distance is required in some special cases, we need to use new software and hardware solutions to deal with it. ☆ Improve the accuracy of ADC, for example, replace the 8-bit ADC with a 10-bit or 12-bit ADC. ☆ Set the value of the double critical point to be smaller. ☆ Use the LED driver circuit to increase the power of the infrared light-emitting diode (i.e., increase the brightness). ☆ Install a signal amplifier circuit at one end of the infrared photosensitive diode. ☆ Try to use reflective objects with good reflective effects (such as white paper, mirrors). 5. How to further improve the anti-interference ability? The last question is the interference of the same frequency ambient light. In my experiment, such a problem has not occurred yet, it only exists in theoretical reasoning. But the possibility of this interference is not zero, so it must be explained. The so-called same frequency interference is to assume that there is such an infrared light source around the infrared sensor switch, which also lights up and goes out at a certain frequency, and this frequency is exactly the same as the on and off frequency of the infrared light-emitting diode in the infrared sensor switch, and the period is the same. This coincidence is not just for the lucky lottery winners. When multiple infrared sensors are used at the same time at a close distance, the problem will naturally arise. If the distance between them cannot be changed, the only way to solve it is to use frequency hopping. Frequency hopping technology has become a necessary function on mobile phones and cordless phones. In order to prevent eavesdropping or when a certain channel is occupied, the phone will automatically switch to another channel to make communication more stable and reliable. For infrared sensor switches, frequency hopping is not that complicated. As long as the on and off time of the infrared light-emitting diode is constantly changed in the program, and different frequencies are used for detection, the chance of other interfering light sources also hopping at the same frequency will be very small. In addition, with the 20-time continuous detection function introduced earlier, the possibility of encountering interference is almost zero.




















With the addition of the above five functions, the system's stability has reached its peak, and such a stable design does not change the hardware production at all. It is still the same few components, and whether it is stable or not depends entirely on the design of the program. The microcontroller is so magical that it creates excellent performance invisibly and takes you to experience the inherent power of streamlined design.


Longer-distance cross-beam sensor solution

There is another situation, which is the need of application. If an infrared sensor switch is used to make an electronic finish line for a race, it would be a better solution to install the infrared transmitting tube and the receiving tube at both ends of the runway. Usually there are no obstacles on the finish line, and the emitted infrared signal is easily received. When someone passes the finish line, the person's body blocks the route of the infrared light, and the receiving end cannot receive the signal and triggers the switch to complete the timing of the race. The same design can also be used as an anti-theft alarm. This cross-beam sensor requires a long transmission distance, generally 2~5m. If this is the application, it is necessary to change the software and hardware solution. 38kHz modulation of infrared is not a good solution. The 38kHz modulated infrared signal is generated by a single-chip microcomputer, and the receiving end uses the infrared sensor TSOP1838 which integrates signal demodulation, amplification and output. The circuit design is also simple, and the effective range of the beam can reach 7~10m. I am currently studying related technologies, and this is just a starting point, hoping to help friends who are studying this technology. Use your talents to apply this technology to life. Make automatic hand dryers, induction faucets, induction light switches, smart tracking cars, anti-theft alarms, induction desktops, competition timers, etc. The infrared induction switch based on the single-chip microcomputer will become a must-have for your electronic competitions, product design, and fun DIY. This is the innovative production of infrared induction switches, which can simply and stably sense you.





Reference address:Simply and stably sense you - innovative production of infrared sensor switch

Previous article:ARM Notes
Next article:The use of single chip microcomputer serial port and "Bluetooth" electrical measurement system

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号