Cov txheej txheem:

Tswj LED Brightness Nrog Potentiometer Nrog Arduino: 3 Kauj Ruam
Tswj LED Brightness Nrog Potentiometer Nrog Arduino: 3 Kauj Ruam

Video: Tswj LED Brightness Nrog Potentiometer Nrog Arduino: 3 Kauj Ruam

Video: Tswj LED Brightness Nrog Potentiometer Nrog Arduino: 3 Kauj Ruam
Video: Varying brightness of LED using PWM on Rpi 2024, Lub Xya hli ntuj
Anonim
Image
Image

Hauv txoj haujlwm no, peb yuav tswj kev ci ntsa iab ntawm LED siv qhov sib txawv tsis kam muab los ntawm potentiometer. Nov yog txoj haujlwm yooj yim heev rau tus pib tab sis nws yuav qhia koj ntau yam txog potentiometer thiab LED ua haujlwm uas yuav tsum tau ua ua ntej ua haujlwm.

Peb tseem tuaj yeem tswj LED ci ntsa iab yam tsis muaj lub zog ntsuas. nyem qhov txuas hauv qab no txhawm rau txheeb xyuas qhov haujlwm no

txuas: - Coj kev tswj qhov ci ci yam tsis muaj lub hwj chim.

Kauj Ruam 1: Cov Cheeb Tsam Yuav Tsum Tau

  1. Arduino -
  2. Potentiometer -
  3. LED -
  4. Resistor (220 txog 1000 ohms) -
  5. Jumper xov hlau -

Kauj ruam 2: Circuit Schematic

Circuit Schematic
Circuit Schematic
Circuit Schematic
Circuit Schematic

Pin 11 coj anode

A0 wiper yog

Vc5v wb

Gnd davhlau ya nyob twg 3 ntawm lub hwj chim, cathode ntawm LED

Kauj Ruam 3: Arduino Code

Arduino analogRead muaj nuj nqi yog siv los ntsuas qhov ntsuas hluav taws xob ntawm 0 txog 5 volts thiab hloov nws mus rau hauv tus lej digital ntawm 0 txog 1023. Qhov laj thawj rau tus nqi 1023 yog vim qhov analog rau digital hloov pauv yog 10-ntsis ntev. Raws li analogWrite ntawm PWM muaj lub luag haujlwm hloov pauv nruab nrab ntawm 0 txog 255 uas yog vim li cas peb yuav faib tus nqi nyeem los ntawm 4 hauv txoj cai.

CODE

const int POTENTIOMETER_PIN = 0;

int analog_value = 0;

void teeb tsa () {

// muab koj cov cai teeb tsa ntawm no, kom khiav ib zaug:

pinMode (11, NTAWV);

pinMode (POTENTIOMETER_PIN, INPUT);

}

void voj () {

// muab koj cov cai tseem ceeb ntawm no, kom rov ua dua:

analog_value = analogRead (POTENTIOMETER_PIN);

// tus nqi ntawm analog_value yog los ntawm 0 txog 1023 thiab lub luag haujlwm ntawm PWM yog 0 txog 255.

analogWrite (11, analog_value/4);

}

Pom zoo: