Arduino Bootcamp Projects - Controlling a CPU Fan with a Button - Part 2 | Lee Assam | Skillshare

Arduino Bootcamp Projects - Controlling a CPU Fan with a Button - Part 2

Lee Assam, University Instructor, Software Developer

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
8 Lessons (11m)
    • 1. Introduction

      0:46
    • 2. Parts that are needed

      0:24
    • 3. Circuit diagram modifications

      0:24
    • 4. Changes in wiring up our circuit

      0:48
    • 5. Uploading the code and project demonstration

      1:41
    • 6. Explanation of the code and understanding pull up resistors

      4:59
    • 7. Further explanation on how the circuit works

      1:06
    • 8. Summary

      0:26

About This Class

4b1e9e8b

In this project, we will build on our previous CPU fan project - Part 1 and will learn how to use the Arduino to control a CPU fan with a button. By pressing the button we will be able to cycle through three speeds of the fan (low, medium and high).

We will understand how you can use buttons to control electronic components and you will also be introduced to the built-in internal pullup resistors in Arduino and get familiar with how they work and how they can be applied.

Learning Objectives:

  • Using a button to control our fan
  • Understanding an internal pullup resistor via INPUT_PULLUP on the Arduino

If you would like to learn more about the Arduino and build projects like these, check out my Udemy Course:

Arduino Bootcamp: Learning Through Projects

Normally $150, but only $10 with the COUPON link below! Over 90% DISCOUNT! Act fast as only limited coupons left

https://www.udemy.com/arduino-bootcamp/?couponCode=ARDUINOSKILLS

Transcripts

1. Introduction: in part two of our CPU fan project, you will build on our previous listen and learn how to control the speed of a CPU fun by using a push button switch. Essentially, when the button is pressed, weaken cycle through three speeds of operation, no medium speed and then high speed. Let's take a look at the objectives. By successfully completing this project, you will have mastered the following items. We will understand how we push buttons which can be used to control the speed of our friends, and we will be introduced to internal pullup resistors and how to configure them in our greenoe. If you're ready to begin, let's get this project started. 2. Parts that are needed: Yeah, the parts we will need aren't we know you know a USB cable bread board. See if you fund 8 to 20 woman's sister on M j E 1 82 n p N power transistor, a push button switch connecting wires on a 12 volt DC power supply. 3. Circuit diagram modifications: next. Take a look at the circuit diagram for our project. There's only one modification will need. We have included a push button switch that has two connections. One of this, which goes to pin five on the Arduino and the other end of the switch goes to the ground. Real. That's it. That's only modifications that will need from our previous circuit. 4. Changes in wiring up our circuit: Let's go ahead and make the changes that are needed for this project. We will introduce a push button switch. One end of a switch goes to Penn five in the Arduino, and the other end of the switch goes to be grown real. Also, you'll remember that we need to connect the D C Power Jack in our city, So go ahead and connect to that. That completes the additional wiring that will need. 5. Uploading the code and project demonstration: Let's go ahead and upload the code for a circuit, right? No, that's complete. That's tested out. The the switch has three speeds of operation. The when I pressed the switch, one time for the first time is gonna be low. And the second time find is going to be spending a medium. The third time it's going to be spinning all the way on and then 1/4 time it's going to shut the final and then we will cycle through those so I'll go ahead. So there is Lou a press it again for medium. It's now going at medium speed than high speed one more time. Now the fine is currently at high speed. And then if I press it again, the fund should shut off. All right, you happen one more time. Most feed mediums feed high speed and then off. And there it is 6. Explanation of the code and understanding pull up resistors: Let's take a look at the code. Initially, we define our motor pin as 11. This is the same as in the previous program. Also, we define the button pen as five, since we connect one end of our switch to pin 500 amino. Next, we have a global state variable and were using this to store the steet. But which the push button switches the current speed. So we initialize that 20 Initially, in our set of function, you do a pin mode when the motor pin setting that as an output here is where we set the pin mode on the button pin as an input pull up. So we are, in fact here initializing the internal pullup resistor on the button pin. We do an analog rated to the mood up in on we pass in zero, meaning we want to initially tell me, Find off on we set up our initial serial connection before we go into the loop function. Let's quickly take a look at the documentation for input pull up. So I'm going to google that 10 mood function. So I'm gonna look up that pin mood documentation here, and as you can see for the mod variable. It can be input output, and we have seen these two previously and input pull up someone, a quick one, that input pull up, and it's gonna take us into some details about that particular constant. So if we school down a bit here, we will see pins configured as input pull up. So they 80 mega microcontroller has internal pullup resistors, resistors that connect to power internally that you can access. So if you prefer to use these instead of external pullup resistors, you can use the input, pullup argument and pinball. Essentially, what we're doing is, as the name implies, input pull up actually pulls up that value to are high. So by default, if you were to take a digital reading off that input pin because that resistor is pulling it up to five bulls, a reading would be high. So that has implications of, you know when we take our reading any circuit and we'll show you shortly what that means. So next we continue in our loop function, we do it. If a digital read of our button pin is low, that means that our switch was pressed. You cycle through the States if the current state of zero. And that's what we initially had when we set up our program. So this is assuming that this is the first time in if the state was zero, we're gonna set the front and in Lewis setting, we doing an elaborate to the motor pin, and we're mopping the value of three sort of that 1/3 of the range on our range spans from zero to Maine and we're mapping that an equivalent value between zero and 2 55 So that will do an analog right, And we set the state we implemented toe one. So the next time we loop, if the do a digital read only button then and it's Luke expressed again, state would have been one. So if status weren't we come in here and we set the front in a medium setting. So, no, we'll do an elaborate ormeau tip in, and we'll map 66 is about 2/3 away in a range between zero and nine and remarked that the equivalent value between zero. And 2 55 we set our state to, and we continue one. If we come in status to We're gonna write it now to the highest setting on the fun. So it will mark 9029 on, then we do 0 to 55. Actually, this would equate to 2 55 So this is like we're doing an unlevel right to motor pen. The value of this expression was gonna meet to 55. He said the estate to three. We loop again, And if you press it another time, if status three we shut off the fund. So we do analog, greater mood up in zero, and we start on state at zero, and we start the process all over again. In between, the actors sort of, you know, the bowels and mechanism. We're just gonna do a delay before we continue. Any other additional readings on the question wouldn't switch. So this is just to make sure that, you know, we don't pick up any be bounced readings that were not intending to. So that's it. That's our program 7. Further explanation on how the circuit works: just to quickly revisit the operation of the push button switch. And it's normal state as the pullup resistor is enabled on Penn five. If he would take a digital reading with only switch being pressed, it would be high. So in that case, we know that the switch is not being engaged on its high in its normal state. When we push the switch, these two terminals actually are connected. So current is going to flew through the internal resistance back down to ground. And if he would to take a reading at in five, it is going to be low. Since the current is gonna be flowing through the resistor that Bibles, it's going to dropped across the resistor, so you'll get a lower reading. That's how you determine if the switch was pushed. So by using this logic, were able to cycle through the various states off the push witness which and have cycle truly states of our fund. So hopefully that provide some clarity on the operation of the switch and all the circuit 8. Summary: to summarize. In this project, you learned how to control a CPU fund using a push button switch on the Arduino. You will also introduced to the concept of pullup resistors and how they're configured on enable in Arduino Great project with some great concepts. I hope you're getting pumped. Let's move on to our next project.