Arduino Bootcamp Projects - Controlling a CPU Fan with Keyboard Input - Part 1 | Lee Assam | Skillshare

Arduino Bootcamp Projects - Controlling a CPU Fan with Keyboard Input - Part 1

Lee Assam, University Instructor, Software Developer

Arduino Bootcamp Projects - Controlling a CPU Fan with Keyboard Input - Part 1

Lee Assam, University Instructor, Software Developer

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

    • 2. Parts that are needed

    • 3. Understanding transistors and how they work

    • 4. Explaining the circuit diagram

    • 5. We need additional power for our circuit

    • 6. Wiring up the circuit

    • 7. Uploading the code and project demonstration

    • 8. Explanation of the code

    • 9. Summary

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


In this project, we will be controlling a CPU fan and will allow the user to utilize the Serial Monitor in the Arduino IDE to enter the speed of the fan.

We will also understand transistors and discuss how they work to operate as switches. It is a great project to understand pulse width modulation in Arduino as well and how it can be used to control electronic components.

Learning Objectives:

  • What is a transistor
  • The different ways a transistor can be used
  • How an npn transistor works
  • Using the Serial Monitor on the Arduino IDE
  • How to accept and process keyboard input in your Arduino programs

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

Meet Your Teacher

Teacher Profile Image

Lee Assam

University Instructor, Software Developer


Hi, I am Lee Assam. I bring to the table 18+ years of programming, development and IT experience. I have a Bachelor's degree in Electrical and Computer Engineering and a Master's Degree in Computer Science.

I teach at Universities on topics ranging from Software Development to Electrical Engineering and prototyping. I like coming up with new ideas and prototyping them using the Arduino and Raspberry Pi platforms.

My passion and hobby is Arduino and the Internet of Things. I have been playing around with the Arduino and the Raspberry Pi platforms since their inception, and I use my Electrical Engineering background coupled with software development skills to create and develop exciting projects. I prefer a hands-on, project-based learning approach and use my teaching backg... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: In this project, we will learn how to control the speed of a CPU fun by getting input from the user. We will also learn about transistors and how they applied in electron ICS and will specifically incorporate an NPM transistor. In our project. We will also be introduced to the serial monitor in Arduino for debugging and getting input from the user. Let's take a look at the objectives for this project. By successfully completing this project, we would have mastered the following items. You will understand what is a transistor in the different ways that a transistor can be used. You understand the basics of an NPM transistor. We will also use the serial monitor in Arduino to accept input industry output. And finally we will learn how toe process input that is received from the keyboard and use that affect our articular. Second, if you are ready to begin, let's get this project started 2. Parts that are needed: here of the parts we will need honored. We know you know the U. S B cable a bread board, the CPU fund 2 21 resistor an M g E 1 82 n p N power transistor connecting wires and a 12 volt DC power supply. 3. Understanding transistors and how they work: Let's first talk about a foundational component. Electron ICS. The transistor transistors form the building blocks of all our modern electronic circuitry . In fact, we have gotten so good at manufacturing and miniaturizing transistors that billions yes, billions with a B of them can fit on a chip the size of your thumb. Leo. If we look at a single transistor, however, it is composed of semiconductor material and consists of three leads a base on emitter on a collector. We will learn more about the operation of the transistor shortly. Transistors can be thought of as miniature switches and primarily operate in to logic states on and off transitions usually have to mean modes of operation. They can be used as switches to quickly switch a circuit on and off fire an electrical signal. This can be controlled very accurately up to thousands of times a second, and they can also be used to amplify signals in a circuit. In our circuit, we are primarily using the transistor as a switch to turn our motor on and off. Let's take a look in more detail about how a transistor operates. We're using an NPM bipolar junction transistor or N p N b j T transistor. For short, Another type of transistor is a PNP transistor. The difference between these two lies in the direction of the beast current and how it has to be applied to turn only transistor. For an MP in transistor, we need to apply current to the base to turn only transistor. You can think of the operation as a switch for motor in order to tune our motor on fire an electrical signal which we can manipulate. Using the Arduino, we apply an analog voltage output from a can of the yard. We go to the base of the transistor. This effectively turns a transistor on, causing the circuit to be complete, and current will now flow through our motor. Turning on our fun down on the ground the fund turns on. We are using the M G E 1 82 np in power transistor as it can handle higher currents and voltages passing through it. We are actually incorporating pulse with modulation as well to also control the speed of the fund. The longer the own beauty cycle that is applied, the faster the final Spence. We will see this in more detail later on when we examine the court 4. Explaining the circuit diagram: Let's take a look at our circuit diagram for a project. This is our and J E 1 82 and being a power transistor. And the pins Mabel, that from left to right are the emitter. The collector is the center pin and the base on the right hand side. So first we connect the ground of pin on the Arduino to the ground wheel. Then, in worrying over transistor, we collect from the emitter to ground. Our collector pin goes to the negatives of the fund. The other positive pin of the fun for our CPU fund for a motor goes to V N off the Arduino . And then finally, from pin 11 of Arduino, we go through a to 21 resistor to the base or the right pin of Lord transistor. That is our circuit diagram. 5. We need additional power for our circuit: the difference in this circuit compared to the other circuits that we've done, is that we'll also need a secondary power source for the Arduino. This is because in order to drive the motor for fun, we require ah, higher voltage. In a higher current, you can use an external a see adapter, which provides 12 rules that we connect directly to the D. C. Jack of our agree no to power our fund. 6. Wiring up the circuit: Let's go ahead and weigh up our circuit. First, we're going to take a look at our transistor. The emitter is a left. Been the collector is the center pin on the base is the right pitch, so they have made it easy for you on the M G e 1 82 Depends are labelled, so that would help you out in wiring up the transistor. So let's go ahead and connect the transistor analysts wicket. First, we will connect the ground. Pinot neared. We noted the ground real. Next we're going to connect the emitter of our transistor to ground, then the from the base. There is a to 20 ohm resistor, so we'll make that connection now. The other end of that resist er goes to pain level earlier and we know now it's time to connect our CPU fund. This is Theseus. If IQ fun that I have, um, there are a couple of connections here. There's a bigger Molex connection and there's also a smaller collection for our pins that we may use. So I'll just use this. The black wire is the negative, and the put the red wire is the positive in this here. So from the collector of our sister, we're gonna go to the negative, read the fund. So that's the center pin. I'm gonna go here to the black wire on defend. And then finally, from our of the end on our end, we know we're going to go to the positive panel, defend Safavian and a positive Clinton. Remember, the only other thing that you need to do is that you also have to connect up the, um, DC power supply. So there, um, if you have a jack collector Barrel Jack connector that can go into the actual DC power supply here, we'll wait a while until we upload the code. Then we'll connect that. So that's that so sick it 7. Uploading the code and project demonstration: Let's go ahead and upload the code while the quarters uploading, going to open the serial monitor so you can get to the serial monitor from this icon on the right hand side of the artery. No, I d. On in D. C. Really monitor. If there is any cereal that print line commands that have been issued in your program, the text will show up in these year of Monitor Onda. Also, there is an input box for sending instructions, so a user type instructions and send this to the Arduino program. That's essentially what we're doing in our project. We're asking the user to enter a number between zero and nine to control the speed of our fan. Zero will shut the fund completely off. Nine will be the highest speed of a fan on any number in the range. Between zero and nine will adjust the speed accordingly. So let's go ahead and send five. So as you can see, it turns are found on. This is about mid speed. We're gonna increase this to seven. All right? No, it's spinning even faster. And then I'm going to go all the way to night and this is the highest speed to shut our finals. We'll send the zero instruction and as you'll see that shuts defined completely off, please remember that when you collect your sick it that you should have your DC power supply plugged in your external BC Power supply Because the Arduino by itself cannot provide the voltage and current needed to drive the fund. So you need an external power supply, so please remember that. 8. Explanation of the code: Okay, let's delve into the code now. So in our program, be at the beginning. We feels to finally moved her payments Been 11. Remember? That was, Ah, the pin that's going to generate the pulse width modulated signal to the transistor. Next, in our set of function, we have been mood resetting the motor pin as an output. And initially, we are turning the find off. So we do an analog right to our motor pin on. We're sending zero. So that's gonna shut the fan off. In order to communicate with the serial monitor, we have some initial set up. We do a serial begin 9600. That's the board rate that we're going to communicate with the serial monitor on or at. And then we're gonna display our instructions. Cereal, that print line, enter a number between zero. And so that shows up in our serial monitor when we run our program next in a loop function . Basically, we are pulling and checking to see if the user has sent and sent any instructions to the Arduino. So we do a serial that available. If that's the case, we're gonna get input from the user. We first extract the character, but he user entered. So we do a car ch equal to serial dot Read You read that car to end. Basically, we're checking to see if that character was a number. So if it is between zero a nine, what we want to do is convert that character to an integer so we can achieve this in the clever way here by doing ch minus the zero character. And this would convert our character that we read in into an Inter Joe speed. And then we proceed to do an analog right to be motive pin passing in. And here we used the map Foshan to mark our speed between zero and nine. I mean passing between 0 to 2 55 So that is how we able to do on a log right to the motor pin on a justice speed. Accordingly, depending on the input that came in from the user 9. Summary: to summarize. In this project, you learned how to accept user input to control a CPU fun. You will also introduced a common electrical component, a transistor, and you're sure how it works? Cereal monitor was introduced, and it is 100 feature for debugging and communicating with your circuit by a keyboard input . We also learned how to read input from the user and use this just the operation of our circuit. It was a simple project, but quite a lot of new concepts were learned here. Let's move on to part two of this project, where we make some slight modifications to enable our fund to be controlled the fire a but