‘p’ here is a variable it can be anything. The above command is for setting up the channel and also for setting up the frequency of the PWM signal. P = IO.PWM(output channel, frequency of PWM signal) We will get PWM output from this pin.Īfter setting the pin as output we need to setup the pin as PWM output pin, We are setting GPIO19 (or PIN35) as output pin. So we tell here either we are going to represent the pin here by ‘35’ or ‘19’. We can refer the GPIO pins of PI, either by pin number on board or by their function number. Below command tells the PI to ignore the warnings and proceed with the program. In that case, we will receive warnings while executing the program. Sometimes, when the GPIO pins, which we are trying to use, might be doing some other functions.
We are also renaming “GPIO” to “IO”, so in the program whenever we want to refer to GPIO pins we will use the word ‘IO’. We are going to import GPIO file from library, below function enables us to program GPIO pins of PI. We will talk about few commands which we are going to use in PYHTON program. Once everything is connected as per the circuit diagram, we can turn ON the PI to write the program in PYHTON. In order to reduce the voltage fluctuations, we will be connecting a 1000uF capacitor across the power supply as shown in the Circuit Diagram. This spiking will heat up the transistor heavily, so we will be using Diode (1N4007) to provide protection to transistor against Inductive Spiking. The motor is an induction and so while switching the motor, we experience inductive spiking. Here one should pay attention that wrongly connecting the transistor might load the board heavily. This transistor here drives the high power DC motor by taking PWM signal from PI. So we are going to use an NPN transistor (2N2222) as a switching device. So if we connect the motor directly to PI for speed control, the board might get damaged permanently.
#Raspberry pi fan control software#
All the basic Hardware and Software requirements are previously discussed, you can look it up in the Raspberry Pi Introduction, other than that we need:Īs said earlier, we cannot draw more than 15mA from any GPIO pins and DC motor draws more than 15mA, so the PWM generated by Raspberry Pi cannot be fed to the DC motor directly. Here we are using Raspberry Pi 2 Model B with Raspbian Jessie OS. With the power limit in mind, we can only connect low power motor here, if you want to drive high power motor, consider powering it from a separate power source. We are talking about this here because we are connecting the DC motor to +3.3V. You can draw 100mA safely from the +3.3V rail. There is a fuse on the PI board which will trip once you apply high load. So drawing High current from this power rail affects the Processor. This power rail is connected in parallel to processor power. There are +5V (Pin 2 & 4) and +3.3V (Pin 1 & 17) power output pins on the board for connecting other modules and sensors. So one should not tamper with these things unless you know what you are doing. So we can draw a maximum of 3mA in average from each of these GPIO pins. And the sum of currents from all GPIO Pins cannot exceed 50mA. To know more about GPIO pins, go through: LED Blinking with Raspberry PiĮach of these 17 GPIO pin can deliver a maximum of 15mA. With special GPIO put aside, we have 17 GPIO remaining. Some of these pins perform some special functions. But out of 40, only 26 GPIO pins (GPIO2 to GPIO27) can be programmed.
There are 40 GPIO output pins in Raspberry Pi 2. We have discussed about PWM in the previous tutorial. PWM (Pulse Width Modulation) is a method used for getting variable voltage out of constant power source. In this tutorial we will Control the Speed of a DC motor using Raspberry Pi and PWM technique. We have discussed LED Blinky, Button Interfacing and PWM generation in previous tutorials.