![]() StateDown = digitalRead(Down) // Read Down button state StateUp = digitalRead(Up) // Read Up button state Serial.begin(9600) // Start communication with serial monitor ICR1 = 8191 // Set the number of PWM steps OCR1A = 3240 // Start PWM just below MOSFET turn on Fast PWM mode, no clock prescaling possible PinMode(Down, INPUT_PULLUP) // Apply internal pull up for Down button PinMode(Up, INPUT_PULLUP) // Apply internal pull up for Up button ![]() Int stateDown // Variable for state of Down button ![]() Int stateUp // Variable for state of Up button The Arduino code is presented below, and you can use two buttons to control the fan speed. Project 1: Control the fan speed connected to the Arduino pin You can connect a couple of push buttons to control the fan speed, or you can update the code to change the fan speed at a fixed interval of time. In this section, we will walk through the example Arduino code to test the Fan circuit. > Read our article about How Easy Is It To Learn Arduino? Arduino Code Example For The Arduino And The Fan Project We can now proceed with the required Arduino program to run the fan. Step 6: Verify the complete connectionsĬongratulations. Make sure the voltage rating matches the supply voltage. The cathode of the diode goes to the positive terminal of the fan.Ĭonnect the positive supply voltage to the DC fan’s positive cable (red). The anode of the diode goes to the negative terminal of the fan. Step 4: Connect the pull-down resistorĬhoose a resistor value between 220 Ohms to 100 kOhms.Ĭonnecting the resistor between the ground and the GATE helps keep the MOSFET in OFF condition when the Arduino is not connected or accidentally the gate connection between the Arduino UNO and the GATE pin of the MOSFET opens. You can control the speed of a two-wire DC fan using PWM. ![]() Notice that Pin 5 of the UNO is a PWM compatible pin. Step 3: Connect the Power pinĬonnect the Arduino UNO’s pin 5 to the MOSFET gate. Connect the DC fan’s source pin to the Arduino’s GND pin.Īlways start with the ground connections.Ĭonnecting the GND pins first avoids accidental damage to the boards. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |