3.3 Schematics for experiment
When button is pressed down, a high voltage level can be obtained. Then it will trigger Arduino to control the blink of LED. Certainly, we can let the LED blink when the button is pressed down. Its schematic is shown in Figure 3-4, which can be viewed as extension from the first experiment by adding a button.
Figure 3-4 Experiment principle diagram
And its real circuit is shown in Figure 3-5.
Figure 3-5 Circuit block
After the circuit is prepared by Figure 3-5, Program 3 can be run, which is also presented as follows.
01 //Program 3: How to control the blink of LED by Arduino and button
OK, at this time, when you push down the button, LED can be lighted. But, unfortunately, if you unpress the button, an expected result happens. That is, the LED is still lighting, even if the button loosed. Furthermore, if you hold an end of dupont line by your hand, the LED is still light, as shown in Figure 3-6. But why?
Figure 3-6 Holding an end of dupont, LED is still light
It turns out that, there exists interference around one’s body or environment to some extent. Therefore, even if the button doesn’t be pressed, LED can light. Then, the interface will affect our such experiment by a voltage level, which can trigger the Arduino board to control the state of LED. Certainly, the interface would be different from difference of body and environment. So, when the button is pressed down, because of the flexibility of button, the button cannot trigger the Arduino board with a high voltage level quickly and steadily. There exist some jitters for some time. The length of time is different and determined by the mechanical features. In general, the time is 5~10ms. This is a very important parameter to design a control system. The phenomenon is shown in Figure 3-7. Before or after pressing the button, there exist some jitters. So, we must delete these jitters to avoid the error decision.
Figure 3-7 Jitters appearance
To avoid doing an error choice, we must remove the appearance. There are many ways to remove jitters from hardware and software. It is worth noting that, even if the voltage threshold is set as a value bigger than 512 (512 is a pwm value. In the next sections, we will introduce its principle) in Program 3, the jitter appears as well. What’s more, during the process of our experiment, when i=1000, the LED would light in case the button doesn’t push down. So, we must remove the jitter according to the principle.
Figure 3-8 schematic after adding a bias resistor