Contents
In our previous lessons, we have already enabled the program to perform calculations, make judgments, and control lights and buzzers. However, if a program always runs strictly following fixed instructions, it still cannot "perceive the world" in essence.
In this chapter, we are going to do something really important: π endow the program with the ability to "perceive the world".
- 7.1 Press to Turn on the Light? Implement Simple Press Control with Buttons! ββ Mechanical Button Module
- 7.2 Triggerable Without Pressing? Unlock Contactless Touch Sensing Tricks! ββ TTP223-Based Touch Key Module
- 7.3 Want to brighten the lights or turn up the volume? Implement parameter adjustment with a slider! ββ Slide Potentiometer Module
- 7.4 Does Your Robot Car Fear Hitting the Wall? Hereβs How to Detect If an Object Reaches the End! ββ Limit Switch Sensor
- 7.5 How to detect flames at home in time? Quickly detect flames and trigger an alarm! ββ Flame sensor module based on PT334
- 7.6 Lights turn on automatically when someone approaches? Implement motion-activated auto-triggering! ββ Pyroelectric infrared human proximity sensor module
- 7.7 Shake your phone to wake the screen? Hereβs how to detect minor vibrations! ββ Ball-type vibration sensor module based on SW-520D
- 7.8 Reacts to the slightest touch? Build a highly sensitive vibration detection device! ββ Spring-type vibration sensor module based on SW-18010P
- 7.9 How to make a small car run along the black line automatically without deviation? Realize automatic line tracking without off-track! ββ Single-channel line tracking module based on TCR5000L
- 7.10 Auto Turn on Lights When It Gets Dark? Detect Light Intensity with a Simple Module! ββ GL5516-Based Light Intensity Sensor Module
- 7.11 How to Give Early Warning of Gas Leaks? Teach You to Detect Harmful Gases! ββMQ Series Gas Sensor Modules
- 7.12 Worried about sunburn while soaking up the sun? Check UV intensity with one click! ββ UV sensor module based on GUVA-S12SD
- 7.13 Wondering about the indoor temperature and humidity? Get precise measurements of your environment's temperature, humidity, warmth and dryness! ββ Temperature & Humidity Sensor Module (DHT11/22 Sensor)
- 7.14 Need Precise Light Intensity Control? Achieve High-Precision Light Sensing Detection with a Chip! ββ Light Intensity Sensor Module Based on the BH1750 Chip
- 7.15 Measure Distance Without Touching? Precision Non-Contact Ranging Tips! ββ Laser Ranging Module Based on VL53L0X Chip
- 7.16 How to Implement Motion-Controlled Dice Rolling? Perceive Device Attitude and Motion! ββ 6-Axis Gyroscope Module Based on MPU6050
Just imagine: without you pressing any buttons, the development board can "see" that it's dark and turn on the light automatically, "sense" that the temperature is too high and trigger an alarm automatically, and "detect" harmful gases and send an immediate alert β this is the magic of sensors! They can convert those "invisible and intangible" environmental information such as light, temperature, flame, human proximity, and gas changes into digital signals that the development board can understand, turning programs from "passive execution" into "active perception" to truly realize "intelligent response".
A sensor building block acts as the "interpreter" connecting the development board to the outside world: it helps the development board "read" the environmental data collected by the sensor, and then enables you to perform corresponding actions through program logic (such as conditional judgment and delay).
1. What is "perception"?
Think about how we ourselves perceive the world:
- Seeing flames, one knows there is danger π₯
- When it senses someone approaching, it will turn its head to take a look π
- Notice that the environment is too dark, and will go to turn on the light π‘
- When there's an odd smell in the air, it makes people feel uncomfortable π·
These judgments do not arise out of nowhere; instead, they stem from sensation.
In electronic systems, sensors function as the "sensory organs":
- It takes changes in the real world
- convert into data that can be read by the program
π Understand sensors in one sentence:
Sensors are what enable a program to "know what is happening outside".
2. Different sensors have different sensing methods.
In this chapter, you will be introduced to a wide variety of sensors, but they do not all "sense" in the same way.
Some sensors function more like a switch:
- Is there any flame?
- Has anyone passed by?
- Was there any shaking?
Some sensors function more like a :
- Is the light bright or dim?
- Is the gas concentration high?
- Is the ultraviolet radiation strong?
There are also some sensors that are inherently very "smart":
- They will calculate the temperature, distance and attitude on their own.
- The program only needs to "ask them questions" via communication methods.
π Therefore, the sensors introduced in this chapter are not arranged in a random manner; instead, they are presented progressively from the simple to the complex and from the intuitive to the abstract in a step-by-step fashion.
3. What will you learn in this chapter?
After completing the study of this chapter, you will be able to:
- β Use sensors to enable programs to react to environmental changes
- β Understand the difference between "event triggering" and "value judgment"
- β Learn to set reasonable judgment thresholds for different sensors
- β Read data from smart sensors using graphical blocks
- β Lay a "perceptual foundation" for subsequent comprehensive projects
More importantly, you will find that:
Programs no longer merely execute commands, but instead operate in a cycle of "observe β orient β act".
4. Description of the Content Structure of This Chapter
In this chapter, we will follow the pace of "from simple to complex, from manual reading to direct block-based invocation" to get to know 12 extremely practical sensors one by one:
- We'll start with the easiest-to-use scene-aware sensors (flame, human proximity, ball/spring vibration, line-tracking, GL5516 light intensity, MQ gas, and ultraviolet sensors). Most of them read data via analog or digital signals, which helps us understand the core principles of sensors;
- Relearn the precision sensors for direct block tuning (DHT11/22 temperature and humidity, BH1750 light intensity), experience the convenience of "one-click data reading", and compare the difference with manual reading;
- Final Challenge Advanced Intelligent Sensors (VL53L0X laser ranging, MPU6050 6-axis gyroscope), which equip the development board with advanced capabilities of "distance measurement" and "attitude sensing", laying a solid foundation for building complex integrated projects.
Each sensor will work in coordination with:
- Clear Life Analogies
- Simple and runnable example
- Hands-on mini-projects that you can practice directly
Youβll find that once you equip a development board with its βsensory organsβ, you can create so many cool and amazing tricks with it!
β¨ Chapter Introductory Reflection
Before we start, please take a moment to think about this:
- If a system has no sensors at all, what kinds of "intelligent responses" can it make?
- If you were to design a "smart classroom", what information would you most want it to be able to perceive?
With these questions in mind, letβs dive into the world of sensors together π