A keyboard control system and method based on a single-chip microcomputer
By using a microcontroller-based keyboard control system, which utilizes a human body capacitance change detection circuit and a Bluetooth module to transmit data, the problems of easy damage and low key accuracy of traditional keyboards are solved. This achieves high-response speed and low-cost keyboard control, and enhances human-computer interaction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING UNIV OF INFORMATION SCI & TECH
- Filing Date
- 2023-03-14
- Publication Date
- 2026-04-21
AI Technical Summary
Traditional mechanical keyboards are easily damaged and noisy, capacitive keyboards have low key actuation rates, and infrared projection keyboards have poor accuracy and sensitivity in bright light, failing to meet diverse usage needs.
A microcontroller-based keyboard control system is adopted, which utilizes a human body induction capacitance change detection circuit, converts voltage changes through a capacitance integration circuit and a Schmitt trigger, combines an STM32F407VGT6 microcontroller counter and timer to process capacitance, and uses a Bluetooth module to transmit keyboard status data.
It improves key accuracy, reduces the number of microcontroller I/O pins used, achieves low-cost, high-response keyboard control, and enhances the fun of human-computer interaction and ease of operation.
Smart Images

Figure CN116126152B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of microcontroller intelligent control technology, specifically a microcontroller-based keyboard control system and method. Background Technology
[0002] In recent years, with the continuous development of technology, more and more electronic products have emerged. Computer processor performance is constantly improving, and monitor resolution and image quality are also continuously increasing. The types of computer keyboards are also constantly increasing; mechanical keyboards and capacitive keyboards are currently the two main types used in computers. With the continuous expansion of microcontroller applications, such as in smart furniture, smart toys, and instruments, microcontrollers offer advantages such as low cost, high integration, low power consumption, multiple control functions, and flexible assembly into various intelligent control devices. With the continuous maturation of Bluetooth technology, using microcontrollers in conjunction with Bluetooth communication technology enables the control of intelligent devices within a relative distance, making the devices more intelligent and easier to operate.
[0003] With the emergence of various electronic devices, the demand for keyboards is constantly increasing. Traditional mechanical keyboards rely on manual force to trigger keys. Each key has an independent switch; physical pressure closes the switch, opening the circuit and triggering the key. This provides a good user experience, but prolonged use can damage the switches and generate noise. Capacitive keyboards determine key activation based on capacitance. However, the capacitance changes over time, leading to a decrease in key actuation rate. Currently under development, infrared projector keyboards require a smooth surface for projection and become very unclear in bright light, making them highly dependent on the operating environment and resulting in poor accuracy and sensitivity. Summary of the Invention
[0004] To address the shortcomings mentioned in the background technology, the present invention aims to provide a keyboard control system and method based on a microcontroller. This system utilizes a human body induction capacitive contact circuit to measure changes in circuit capacitance. The human body induction capacitance is stable and has a small value, making it suitable for circuit measurement, thus increasing the fun of human-computer interaction. The microcontroller's counter and timer are used to calculate the capacitance, resulting in accurate calculations and a fast response speed. The Bluetooth module's communication protocol connects to the display device, enabling fast transmission and low cost.
[0005] The objective of this invention can be achieved through the following technical solution: a keyboard control system based on a microcontroller, comprising:
[0006] Detection circuit module: Used to detect whether the capacitance distribution of the circuit has changed. The change in input capacitance is converted into a change in voltage through a capacitance integration circuit, and then amplified and transmitted to the Schmitt trigger. The Schmitt trigger outputs a transient response to the voltage change. If the capacitance distribution of the circuit has changed, a sampling signal is sent to the main control module.
[0007] Main control module: After receiving the acquisition signal, it uses the counter and timer inside the microcontroller to collect and process the circuit capacitance, obtain the capacitance change, monitor the capacitance change and set a threshold, obtain keyboard key status data by comparing the capacitance change with the threshold, and send the obtained keyboard key status data to the Bluetooth module.
[0008] Bluetooth module: Used to send keyboard key status data to the display module via Bluetooth protocol after receiving the keyboard key status data;
[0009] Display module: After receiving the keyboard key status data sent by the Bluetooth module, it displays the key values.
[0010] Optionally, the detection circuit module consists of a capacitor integrator circuit and a Schmitt trigger. The capacitor integrator circuit is used to proportionally amplify the voltage signal and improve the signal's anti-interference capability, while the Schmitt trigger is used to detect the charging and discharging time.
[0011] Optionally, the detection circuit module detects whether the capacitance distribution of the circuit has changed: when the human body connects to the circuit through a conductive medium, the Schmitt trigger detects a change in the charging and discharging time, thereby indicating a change in the capacitance distribution of the circuit.
[0012] Optionally, the main control module uses an STM32F407VGT6 microcontroller, based on a high-performance 32-bit RISC core, with an operating frequency of 168MHz.
[0013] Optionally, the main control module monitors the capacitance change and sets a threshold to obtain keyboard key state data as follows: When the human body is not in contact with the circuit, in the capacitor integration circuit, R2 = R3 = 2R1, R4 = 100R2, C0 is the initial total circuit capacitance, and the input voltage Vin = VCC * [R2 / (R2+R4)] serves as the input of the comparator and is amplified to the Schmitt trigger as the steady-state value of the trigger. When the human body touches the pencil trajectory, the pin is pulled high to charge the pencil trajectory. At this time, the circuit capacitance increases, and the input of the comparator... A voltage drop is transmitted to the Schmitt trigger; below the steady-state value, the Schmitt trigger outputs a low level. Pulling the pin low discharges the pencil trajectory, reducing the circuit capacitance. This causes the comparator's input voltage to rise, which is then transmitted to the Schmitt trigger; above the steady-state value, the Schmitt trigger outputs a high level. The main control module's counter counts the high and low levels and samples them multiple times to ensure sufficient data. The main control module's timer determines the high and low level durations T(high) and T(low), counting machine cycles. The microcontroller's machine cycle T(cycles) = 1 / Fs, where Fs is the crystal oscillator frequency. T(high) = number of machine cycles * T(cycles), T(low) = number of machine cycles * T(cycles). The capacitor's charging time is T = R4 * C (total capacitance). The total capacitance of the circuit, obtained from T(high) and T(low), is compared with a threshold value to determine the button's state.
[0014] Optionally, the main control module sets the threshold as follows: As the environment changes, the size of the capacitor in the circuit will inevitably be affected. Therefore, before the system starts running, initialization is required to reduce errors. After the system is powered on, when the human body is not in contact with the circuit, the main control module calculates the charging and discharging time of the initial capacitor C0. The initial capacitance of the circuit is obtained by T = R4 * C(initial). The circuit is sampled multiple times, and the difference between all the sampled data and the initial capacitance C0 is averaged C(average). Therefore, the threshold is set to C0 + C(average). The total capacitance of the circuit is obtained by T(high) and T(low) and compared with the threshold to determine whether the human body capacitance is added to the circuit and thus determine whether the button is pressed.
[0015] Optionally, the Bluetooth module used is the HC05 Bluetooth module, with a baud rate range of 4800 to 1382400, and is compatible with 5V or 3.3V microcontroller systems.
[0016] Optionally, the main control module includes a data acquisition unit and a data processing unit.
[0017] Optionally, the data acquisition unit uses a counter to count the high and low level changes of the circuit charging and discharging, uses a timer to calculate the change in capacitance by the high and low level pulse duration, and sends the change in capacitance to the data processing unit for processing.
[0018] The data processing unit is used to monitor the received changes in capacitance and set a threshold, and compare the changes in circuit capacitance with the threshold to obtain keyboard key status data.
[0019] A keyboard control method based on a microcontroller, the method comprising the following steps:
[0020] The circuit detects whether the capacitance has changed; if it has, the change in capacitance is measured.
[0021] By monitoring the change in capacitance and setting a threshold, keyboard key status data can be calculated.
[0022] The key values are displayed based on the obtained keyboard key status data.
[0023] The beneficial effects of this invention are:
[0024] In the process of using this invention, the circuit capacitance is first detected to see if it changes. If it does, the change in capacitance is detected and collected. Then, the change in capacitance is monitored and a threshold is set to calculate the keyboard key status data. Finally, the key value is displayed based on the obtained keyboard key status data. This invention utilizes the adverse effects of human body capacitance changes on the circuit, the conductivity of the pencil trajectory, and the capacitance change characteristics caused by different trajectory lengths, thereby reducing the number of microcontroller I / O pins used. In the case of multi-channel single detection, the key accuracy is high. Attached Figure Description
[0025] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0026] Figure 1 This is a schematic diagram illustrating the principle of the present invention;
[0027] Figure 2 This is a schematic diagram of the process of this invention. Detailed Implementation
[0028] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0029] like Figure 1As shown, a keyboard control system based on a microcontroller includes:
[0030] Detection circuit module: Used to detect whether the capacitance distribution of the circuit has changed. The change in input capacitance is converted into a change in voltage through a capacitance integration circuit, and then amplified and transmitted to the Schmitt trigger. The Schmitt trigger outputs a transient response to the voltage change. If the capacitance distribution of the circuit has changed, a sampling signal is sent to the main control module.
[0031] Main control module: After receiving the acquisition signal, it uses the counter and timer inside the microcontroller to collect and process the circuit capacitance, obtain the capacitance change, monitor the capacitance change and set a threshold, obtain keyboard key status data by comparing the capacitance change with the threshold, and send the obtained keyboard key status data to the Bluetooth module.
[0032] Bluetooth module: Used to send keyboard key status data to the display module via Bluetooth protocol after receiving the keyboard key status data;
[0033] Display module: After receiving the keyboard key status data sent by the Bluetooth module, it displays the key values.
[0034] It should be further explained that, in the specific implementation, the detection circuit module uses a capacitor integrator circuit and a Schmitt trigger. When a human body is connected to the circuit through a conductive medium, the total capacitance of the circuit changes, thus altering the charging and discharging time. To reduce external interference, a Schmitt trigger is used instead of a conventional comparator, resulting in more accurate detection.
[0035] It should be further explained that, in this embodiment, the circuit source uses a switch-controlled 5V to 3.3V power module. The 5V input is passed through an X1117 positive voltage output low-dropout three-terminal linear regulator circuit, finally outputting 3.3V to power the microcontroller. The circuit uses two capacitors connected in parallel, which helps stabilize the voltage, especially when the battery's internal resistance is relatively high. The capacitors can stabilize voltage drops under heavy loads and smooth the charging current, thus reducing charging current ripple.
[0036] Further explanation is needed regarding the implementation process. The main control module utilizes the STM32F407VGT6, based on a high-performance 32-bit RISC core, operating at a frequency of up to 168MHz. The core features a single-precision floating-point unit, supporting all ARM single-precision data processing instructions and data types. The STM32F407VGT6 integrates high-speed embedded memory, up to 4KB of spare SRAM, and an enhanced range I / O. External devices connect to two APB buses, three AHB buses, and a 32-bit multi-AHB bus matrix. Its primary function in this design is the detection and preprocessing of human body capacitance, as well as the Bluetooth communication protocol between the host computer and the STM32. Secondly, when a human body comes into contact with a conductor connected to the circuit, it changes the circuit's capacitance distribution. By continuously charging and discharging the pencil's trajectory, the STM32 controller counts the charging and discharging time, indirectly obtaining this capacitance variable. Monitoring this change and setting a threshold determines the state of the keyboard keys.
[0037] It should be further explained that the HC05 Bluetooth module is used in the specific implementation. This Bluetooth module is a high-performance master-slave integrated Bluetooth serial port module that can pair with various Bluetooth-enabled devices. Its baud rate range is 4800–1382400, and it is compatible with 5V or 3.3V microcontroller systems. Once Bluetooth devices are successfully paired and connected, we can ignore the internal Bluetooth communication protocol and directly use Bluetooth as a serial port. When a connection is established, the two devices share a single channel, i.e., the same serial port. One device sends data to the channel, and the other device can receive data from the channel.
[0038] It should be further explained that, in the specific implementation process, the detection method in this embodiment adopts single-line multi-point detection. This detection method correctly identifies the trigger state of multiple buttons when using a single wire. By filtering and segmenting the input signal, a completely independent data area can be clearly allocated to each button. The threshold comparison of the area is used to determine which button on the wire is triggered.
[0039] It should be further explained that, in the specific implementation process, the main control module monitors the change in capacitance and sets a threshold to obtain the keyboard key status data as follows:
[0040] When the human body is not in contact with the circuit, in the capacitor integrating circuit, R2 = R3 = 2R1, R4 = 100R2, C0 is the initial total capacitance of the circuit, and the input voltage Vin = VCC * [R2 / (R2+R4)] serves as the input of the comparator and is amplified to the Schmitt trigger, becoming its steady-state value. When the human body comes into contact with the pencil trajectory, the high pin charges the pencil trajectory, increasing the circuit capacitance. This lowers the comparator's input voltage, which is then sent to the Schmitt trigger. When the voltage is below the steady-state value, the Schmitt trigger outputs a low level. Conversely, the low pin discharges the pencil trajectory, decreasing the circuit capacitance. This raises the comparator's input voltage, which is then sent to the Schmitt trigger. When the voltage is above the steady-state value, the Schmitt trigger outputs a high level. The main control module's counter counts the high and low levels and samples them multiple times to ensure sufficient data. The main control module's timer determines the high and low level durations T(high) and T(low). The timer counts machine cycles; the microcontroller's machine cycle T(cycle) = 1 / Fs, where Fs is the crystal oscillator frequency. T(High) = Number of machine cycles * T(week), T(Low) = Number of machine cycles * T(week). The charging time of the capacitor is T = R4 * C(total capacitance). The total capacitance of the circuit obtained by T(High) and T(Low) is compared with the threshold to determine the state of the button.
[0041] The main control module sets a threshold for the capacitance variable to compare with the key state. The threshold setting process is as follows: As the environment changes, the size of the capacitance in the circuit will inevitably be affected. Therefore, initialization must be performed before the system starts running to reduce errors. After the system is powered on, when the human body is not in contact with the circuit, the main control module calculates the charging and discharging time of the initial capacitor C0. The initial capacitance of the circuit is obtained by T = R4 * C(initial). The circuit is then sampled multiple times, and the difference between all the sampled data and the initial capacitance C0 is averaged C(average). Therefore, the threshold is set to C0 + C(average). The total capacitance of the circuit is obtained by T(high) and T(low) and compared with the threshold to determine whether the human body capacitance is added to the circuit, and thus whether the key is pressed.
[0042] It should be further explained that the main control module includes a data acquisition unit and a data processing unit.
[0043] It should be further explained that the data acquisition unit uses a counter to count the high and low level changes of the circuit charging and discharging, uses a timer to calculate the change in capacitance by the high and low level pulse duration, and sends the change in capacitance to the data processing unit for processing.
[0044] The data processing unit is used to monitor the received changes in capacitance and set a threshold, and compare the changes in circuit capacitance with the threshold to obtain keyboard key status data.
[0045] To achieve the above process, the specific implementation method of this invention patent is as follows:
[0046] The keyboard is drawn with a pencil. A person presses a specific key, and the capacitance of that person's finger affects the entire circuit. An STM32F4 controller collects and processes the data, monitoring the capacitance change and setting appropriate thresholds to determine the key state. The STM32F4 connects to a Bluetooth chip via its serial port, sending data to a host computer or mobile device using a specified Bluetooth protocol. The pressed key value is then displayed on the mobile device.
[0047] The specific principle is as follows: The capacitance of a human body sensor is normally tens of pF. When a person's finger touches the keyboard marked with a pencil, the distributed capacitance in the circuit changes. By continuously charging and discharging the pencil trace, and counting the charging and discharging time using an STM32F4 controller, the change in capacitance is indirectly obtained. By monitoring this change and setting an appropriate threshold, the key state is determined by comparing the change with the threshold. The processed data is then sent to a host computer or mobile device via a Bluetooth chip using a predetermined Bluetooth protocol. The mobile device displays the key value, ultimately realizing the function of a human body sensor keyboard.
[0048] In the description of this specification, references to terms such as "an embodiment," "example," "specific example," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this disclosure. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0049] The foregoing has shown and described the basic principles, main features, and advantages of this disclosure. Those skilled in the art should understand that this disclosure is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of this disclosure. Various changes and modifications can be made to this disclosure without departing from its spirit and scope, and all such changes and modifications fall within the scope of this disclosure as claimed.
Claims
1. A keyboard control system based on a microcontroller, characterized in that, include: Detection circuit module: Used to detect whether the capacitance distribution of the circuit has changed. The change in input capacitance is converted into a change in voltage through a capacitance integration circuit, and then amplified and transmitted to the Schmitt trigger. The Schmitt trigger outputs a transient response to the voltage change. If the capacitance distribution of the circuit has changed, a sampling signal is sent to the main control module. Main control module: After receiving the acquisition signal, it uses the counter and timer inside the microcontroller to collect and process the circuit capacitance, obtain the capacitance change, monitor the capacitance change and set a threshold, obtain keyboard key status data by comparing the capacitance change with the threshold, and send the obtained keyboard key status data to the Bluetooth module. The main control module monitors the capacitance change and sets a threshold to obtain keyboard key status data as follows: When the human body is not in contact with the circuit, in the capacitor integration circuit, R2=R3=2R1, R4=100R2, C0 is the initial total circuit capacitance, and the input voltage Vin=VCC. [R2 / (R2+R4)] serves as the input of the comparator and is amplified to the Schmitt trigger, which then outputs the steady-state value. When a person touches the pencil track, the high pin charges the pencil track, increasing the circuit capacitance and decreasing the comparator's input voltage, which is then sent to the Schmitt trigger. When the voltage is below the steady-state value, the Schmitt trigger outputs a low level. Conversely, the low pin discharges the pencil track, decreasing the circuit capacitance and increasing the comparator's input voltage, which is then sent to the Schmitt trigger. When the voltage is above the steady-state value, the Schmitt trigger outputs a high level. The main control module's counter counts the high and low levels and samples them multiple times to ensure sufficient data. The main control module's timer determines the high and low levels' durations, Thigh and Tlow. The timer counts machine cycles. The microcontroller's machine cycle Tcycle = 1 / Fs, where Fs is the crystal oscillator frequency, and Thigh = the number of high-frequency machine cycles. T_week, T_low = number of low-cycle periods in the machine T is the charging time of the capacitor, which is T=R4. The total capacitance C is obtained by comparing the total capacitance of the circuit (T high and T low) with the threshold to determine the state of the button. Bluetooth module: Used to send keyboard key status data to the display module via Bluetooth protocol after receiving the keyboard key status data; Display module: After receiving the keyboard key status data sent by the Bluetooth module, it displays the key values.
2. The keyboard control system based on a microcontroller according to claim 1, characterized in that, The detection circuit module consists of a capacitor integrator circuit and a Schmitt trigger. The capacitor integrator circuit is used to proportionally amplify the voltage signal and improve the signal's anti-interference capability. The Schmitt trigger is used to detect the charging and discharging time.
3. The keyboard control system based on a microcontroller according to claim 2, characterized in that, The process by which the detection circuit module detects whether the capacitance distribution of the circuit has changed is as follows: when the human body connects to the circuit through a conductive medium, the Schmitt trigger detects a change in the charging and discharging time, thereby indicating a change in the capacitance distribution of the circuit.
4. The keyboard control system based on a microcontroller according to claim 1, characterized in that, The main control module uses an STM32F407VGT6 microcontroller, based on a high-performance 32-bit RISC core, with an operating frequency of 168MHz.
5. A keyboard control system based on a microcontroller according to claim 1, characterized in that, The main control module sets the threshold as follows: Changes in the environment inevitably affect the capacitance in the circuit. Therefore, initialization is required before the system starts operating to reduce errors. After the system is powered on, and before the human body touches the circuit, the main control module calculates the charging and discharging time of the initial capacitor C0 using T=R4. The initial capacitance of the circuit is obtained by C0, and multiple data acquisitions are performed on the circuit. The average value C_average of all the acquired data and the initial capacitance C0 is taken. Therefore, the threshold is set as C0 + C_average. The total capacitance of the circuit is obtained by T_high and T_low and compared with the threshold to determine whether the human body capacitance is added to the circuit, and thus determine whether the button is pressed.
6. A keyboard control system based on a microcontroller according to claim 1, characterized in that, The Bluetooth module used is the HC05 Bluetooth module, with a baud rate range of 4800~1382400, and is compatible with 5V or 3.3V microcontroller systems.
7. A keyboard control system based on a microcontroller according to claim 1, characterized in that, The main control module includes a data acquisition unit and a data processing unit.
8. A keyboard control system based on a microcontroller according to claim 7, characterized in that, The data acquisition unit uses a counter to count the high and low level changes of the circuit charging and discharging, uses a timer to calculate the change in capacitance by the high and low level pulse duration, and sends the change in capacitance to the data processing unit for processing. The data processing unit is used to monitor the received changes in capacitance and set a threshold, and compare the changes in circuit capacitance with the threshold to obtain keyboard key status data.
9. A keyboard control method based on a microcontroller, characterized in that, Applied to a microcontroller-based keyboard control system as described in claim 1, the method includes the following steps: The circuit detects whether the capacitance has changed; if it has, the change in capacitance is measured. By monitoring the change in capacitance and setting a threshold, keyboard key status data can be calculated. The key values are displayed based on the obtained keyboard key status data.
Citation Information
Patent Citations
Realizing method of capacitance type inductive key, inductive key circuit and keyboard
CN101907961A