Fan speed adjustment experiment
Experimental phenomena
Use potentiometer to adjust DC motor speed
Theoretical study
Use the learned potentiometer analog value sampling and PWM output experiment, combined with DC motor drive, to achieve the effect of motor speed regulation
Schematic diagram
Code writing
The development board information of the experiment chooses Arduino Leonardo
#define pot A0//电位器引脚对象
int iapin = 6;
int ibpin = 5;
int val = 0;
int potbuffer = 0;//读取数据缓存变量
void setup() {
// put your setup code here, to run once:
pinMode(iapin, OUTPUT);
pinMode(ibpin, OUTPUT);
digitalWrite(ibpin,LOW);
}
void loop() {
potbuffer = analogRead(pot);
val = map(potbuffer, 0, 1023, 0, 255);
analogWrite(iapin, val);
delay(100);
}