I met a 12-year-old gay man on the Internet by chance and helped him develop his thinking and skills from scratch.

Project column: blog.csdn.net/m0_38106923…


This blog will design a light with adjustable brightness, let’s take a look ~

Brightness adjustable lamp, the key is adjustable, traditional LED only on (light), off (off) two states, through PWM technology can achieve the brightness adjustment.

The official name of PWM is pulse width modulation, which is an analog control mode. The use of digital output signals of a microprocessor to control an analog circuit is a very effective technique, widely used in many fields from measurement and communication to power control and conversion.

We can easily define PWM technology in terms of duty cycle and frequency required to repeat duty cycle per second. The duty cycle highlights the time the signal switches between the ON and OFF positions, expressed as a percentage. If the signal remains on for half of the total duty cycle and off for the other half, the duty cycle will be 50%.

The following figure shows the duty cycle as a percentage associated with the ON and OFF digital signals ON the waveform.

The principle of PWM illumination adjustment is to change the LED brightness by changing the duty cycle to achieve the effect of adjusting the brightness and off degree.

I am going to use the rotary potentiometer to control the LED lamp to achieve brightness adjustment. The knob potentiometer is an analog voltage output signal connected to the analog signal port, and the LED lamp is connected to the digital port that can output PWM signal. The wiring is as follows:

Through the programming control, it can be seen that the PWM output range is between 0 and 250, and the effect is as follows:

Next, you need to know the range of value sampled by the knob potentiometer ADC. Turn the knob potentiometer and print the range of value between 0 and 1023 using the serial port. The effect is as follows:

So you can design, if the value of the knob is more than 250, it will always keep the 250 maximum output, the program design is as follows:

Finally, you can realize the dimming effect.