Cov txheej txheem:

PWM ESP32 - Dimming LED Nrog PWM ntawm ESP 32 Nrog Arduino IDE: 6 Kauj Ruam
PWM ESP32 - Dimming LED Nrog PWM ntawm ESP 32 Nrog Arduino IDE: 6 Kauj Ruam

Video: PWM ESP32 - Dimming LED Nrog PWM ntawm ESP 32 Nrog Arduino IDE: 6 Kauj Ruam

Video: PWM ESP32 - Dimming LED Nrog PWM ntawm ESP 32 Nrog Arduino IDE: 6 Kauj Ruam
Video: ESP32 PWM with Arduino IDE 2024, Kaum ib hlis
Anonim
PWM With ESP32 | Dimming LED Nrog PWM ntawm ESP 32 Nrog Arduino IDE
PWM With ESP32 | Dimming LED Nrog PWM ntawm ESP 32 Nrog Arduino IDE

Hauv cov lus qhia no peb yuav pom yuav ua li cas tsim PWM cov cim nrog ESP32 siv Arduino IDE & PWM yog siv los tsim cov txiaj ntsig sib piv los ntawm ib qho MCU thiab qhov sib piv tawm tuaj yeem yog ib qho ntawm 0V txog 3.3V (yog esp32) & los ntawm 0V rau 5 V.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau

Rau qhov kev qhia no koj yuav xav tau cov hauv qab no: ESP32

220 ohm resistors

Xim coj

daim ntawv qhia zaub mov

Ob peb dhia

Kauj ruam 2: Nkag siab PWM ntawm ESP32

Nkag siab PWM ntawm ESP32
Nkag siab PWM ntawm ESP32

ESP32 muaj 16 Channel PWM maub los thiab cov 16 Channels no muaj kev ywj pheej thiab tuaj yeem teeb tsa ntawm nws tus kheej kom tau txais PWM cov cim nrog cov khoom sib txawv rau qhov xav tau sib txawv. 0 txog 15) pwm Channels in ESP32. Koj yuav tsum xaiv koj tus PWM channel. >> Tom qab qhov no peb yuav tsum xaiv qhov zaus rau PWM, peb tuaj yeem mus rau 5000hz. >> Ntawm no peb muaj kev daws teeb meem ntawm 1 txog 16bits hauv ESP32 tab sis rau qhov kev qhia no peb yuav mus rau 8 ntsis xwb uas txhais tau tias ci ntsa iab yuav raug tswj los ntawm qhov muaj txiaj ntsig 0 txog 255. >> Koj yuav tsum teeb tsa LED rau PWM kom ua li ntawd koj yuav tsum siv kab kab hauv qab no thiab hauv qhov ntawd koj yuav tsum tau hais txog lub ledchannel (peb siv channel 0 ntawm ESP32) koj siv rau PWM & zaus yog zaus (peb siv 5000hz) ntawm PWM & kev daws teeb meem koj siv (peb siv 8bit daws teeb meem).ledcSetup (ledChannel, freq, daws teeb meem); Qhov muaj txiaj ntsig hauv peb kis: const int freq = 5000; const int cojChannel = 0; const int daws teeb meem = 8; >> tom qab ntawd hais txog qhov LED tus pin koj xav tau los ntawm kev siv cov lus txib hauv qab no: ledcAttachPin (ledPin, ledChannel);- ntawm no ledPin yog tus lej tsis. Qhov peb yuav siv & cojChannel yog cov channel uas peb yuav tsum xaiv rau PWM.5. Thaum kawg, txhawm rau tswj lub teeb ci LED siv PWM, koj siv cov haujlwm hauv qab no: >> qhov tseem ceeb tseem ceeb ntawm txoj cai yuav yog cov lus txib hauv qab no uas yuav sau cov lus sib piv rau LED tus pin: ledcWrite (ledChannel, lub luag haujlwm ua haujlwm); cov lus txib saum toj no xav tau 'ledChannel' & 'dutyCycle' qhov twg cov channel yog tus lej naj npawb peb yuav siv thiab lub voj voog ua haujlwm yog tus nqi peb tau sau raws li tso tawm rau tus pin LED.

Kauj Ruam 3: Kev Sib Txuas

Kev sib txuas
Kev sib txuas

Qhov kev txuas yog yooj yim heev. Koj yuav tsum txuas LED nrog Resistor rau GPIO16 raws li qhia hauv schmatics.

Kauj Ruam 4: Nruab ESP32 BOARDS hauv Arduino IDE

Nruab ESP32 BOARDS hauv Arduino IDE
Nruab ESP32 BOARDS hauv Arduino IDE

Nco ntsoov tias koj muaj Arduino IDE hauv koj lub PC thiab koj tau teeb tsa ESP32 Boards hauv koj Arduino IDE, thiab yog tias nws tsis yog qhov xwm txheej thov ua raws cov lus qhia hauv qab no ntawm kuv kom nruab nws.:

Kauj ruam 5: Code

Code
Code

Thov luam cov cai hauv qab no thiab rub nws mus rau koj tus ESP32: // tus lej ntawm tus pinconst LED coj mus rau ledPin = 16; // 16 sib raug rau GPIO16 // teeb tsa PWM cov khoom sib txuas int freq = 5000; const int ledChannel = 0; const int daws teeb meem = 8; void teeb tsa () {// teeb tsa LED PWM functionalitites ledcSetup (ledChannel, freq, daws teeb meem); // txuas cov channel mus rau GPIO kom tswj tau ledcAttachPin (ledPin, ledChannel);} lub voj void () {// nce LED ci rau (int dutyCycle = 0; dutyCycle <= 255; dutyCycle ++) {// hloov LED ci ntsa iab nrog PWM ledcWrite (ledChannel, dutyCycle); ncua (15); } // txo qhov ci ci LED rau (int dutyCycle = 255; dutyCycle> = 0; dutyCycle-) {// hloov qhov ci ci LED nrog PWM ledcWrite (ledChannel, dutyCycle); ncua (15); }}

Kauj Ruam 6: Xeem PWM Kev Ua Haujlwm

Xeem PWM Kev Ua Haujlwm
Xeem PWM Kev Ua Haujlwm

Tom qab xa cov cai koj yuav pom koj cov LEDs siv zog hloov pauv uas coj peb mus rau qhov kawg ntawm cov lus qhia no. Kev lom zem siv PWM nrog ESP32 hauv koj cov phiaj xwm.

Pom zoo: