Cov txheej txheem:

Controllig LED los ntawm Potentiometer: 6 Kauj Ruam
Controllig LED los ntawm Potentiometer: 6 Kauj Ruam

Video: Controllig LED los ntawm Potentiometer: 6 Kauj Ruam

Video: Controllig LED los ntawm Potentiometer: 6 Kauj Ruam
Video: Lesson 98: Arduino 10 LED Push button Projects, Potentiometer LED Voltmeter and Traffic Light 2024, Hlis ntuj nqeg
Anonim
Controllig LED los ntawm Potentiometer
Controllig LED los ntawm Potentiometer

Yav dhau los, peb tau siv Serial Monitor los xa cov ntaub ntawv mus rau pawg tswj hwm, uas yuav ua rau pom kev paub txog software tshiab. Hauv zaj lus qhia no, cia saib yuav ua li cas hloov lub teeb ci ntawm LED los ntawm lub zog ntsuas, thiab tau txais cov ntaub ntawv ntawm lub zog ntsuas hauv Serial Monitor kom pom nws tus nqi hloov pauv.

Kauj Ruam 1: Cheeb Tsam

- Arduino Uno board * 1

- USB cable * 1

- Tus tiv thaiv (220Ω) * 1

- LED * 1

Potentiometer * 1

- Daim phiaj * 1

- Jumper xov hlau

Kauj Ruam 2: Txoj Cai

Txoj Cai
Txoj Cai

Linear potentiometer yog cov khoom siv hluav taws xob sib piv. Yog li dab tsi yog qhov sib txawv ntawm tus nqi analog thiab tus lej? Yooj yim muab, txhais tau tias digital rau/tawm, qib siab/qib nrog tsuas yog ob lub xeev, piv txwv li 0 lossis 1. Tab sis cov ntaub ntawv lub xeev ntawm cov cim sib piv yog kab, piv txwv li, los ntawm 1 txog 1000; lub teeb liab tus nqi hloov pauv lub sijhawm tsis txhob qhia tus lej tseeb. Cov teeb liab analog muaj xws li cov teeb pom kev zoo, av noo, kub thiab lwm yam.

Kauj Ruam 3: Daim Duab Schematic

Schematic Daim duab
Schematic Daim duab

Kauj ruam 4: Cov txheej txheem

Hauv qhov kev sim no, lub zog ntsuas tau siv los ua qhov faib hluav taws xob, lub ntsiab lus txuas cov khoom siv rau txhua ntawm nws peb tus pin. Txuas tus pin nruab nrab ntawm lub hwj chim rau tus pin A0 thiab lwm ob tus pin rau 5V thiab GND feem. Yog li ntawd, qhov hluav taws xob ntawm lub hwj chim ntsuas hluav taws xob yog 0-5V. Tig lub pob qhov rooj ntawm lub zog, thiab qhov hluav taws xob ntawm tus pin A0 yuav hloov. Tom qab ntawd hloov qhov hluav taws xob ntawd mus rau tus lej digital (0-1024) nrog AD hloov pauv hauv pawg tswj hwm. Los ntawm cov phiaj xwm, peb tuaj yeem siv cov txiaj ntsig digital hloov pauv los tswj lub teeb ci ntawm LED ntawm pawg tswj hwm.

Kauj ruam 1:

Tsim lub voj voog.

Kauj ruam 2:

Rub tawm cov cai los ntawm

Kauj ruam 3:

Tshaj tawm cov duab kos rau Arduino Uno board

Nyem rau Upload icon txhawm rau upload cov cai rau pawg tswj hwm.

Yog tias "Ua tiav uploading" tshwm rau hauv qab ntawm lub qhov rais, nws txhais tau hais tias daim duab tau ua tiav tiav.

Tig tus ncej ntawm lub hwj chim thiab koj yuav tsum pom qhov ci ntawm LED hloov.

Yog tias koj xav tshuaj xyuas qhov hloov pauv tus nqi, qhib Serial Monitor thiab cov ntaub ntawv hauv lub qhov rais yuav hloov pauv nrog koj txoj kev tig ntawm lub pob qhov rooj potentiometer. Qhov kev sim no tseem tuaj yeem hloov mus rau lwm tus raws li koj nyiam. Piv txwv li, siv lub zog ntsuas los tswj lub sijhawm luv rau LED ntsais muag.

Kauj ruam 5: Code

// Tswj los ntawm potentiometer

// Tig

tus ncej ntawm lub hwj chim thiab koj yuav tsum pom qhov ci ntawm LED hloov.

// Web site: www.primerobotics.in

/******************************************/

qhov

int analogPin = 0; // analog input pin txuas rau

qhov

int ledPin = 9; // coj coj mus rau

int ib

inputValue = 0; // sib txawv los khaws tus nqi los ntawm sensor

int ib

outputValue = 0; // sib txawv los khaws cov txiaj ntsig tso tawm

/******************************************/

tsis muaj dab tsi

teeb ()

{

Serial.begin (9600); // teeb tsa cov lej

kev sib txuas lus baudrate li 9600

}

/******************************************/

tsis muaj dab tsi

voj ()

{

inputValue = analogRead (analogPin); // nyeem cov ntawv

tus nqi los ntawm potentiometer

Serial.print ("Cov tswv yim:"); // luam tawm

"Tswv yim"

Serial.println (inputValue); // luam tawm

inputValue

outputValue = daim ntawv qhia (inputValue, 0, 1023, 0, 255); // Hloov los ntawm 0-1023 piv rau tus lej ntawm tus lej ntawm 0 txog 255

Serial.print ("Cov zis:"); // luam tawm

"Tso Tawm"

Serial.println (outputValue); // luam tawm

Cov txiaj ntsig

analogWrite (ledPin, outputValue); // tig lub

LED nyob ntawm qhov tso tawm tus nqi

ncua (1000);

}

/*******************************************/

Pom zoo: