Speed Control of Fan using GSM Interfaced with Atmel AVR Microcontrollers

There are many methods to control the speed of fan. I will use simple method through timer of Atmel AVR Microcontrollers. But keep in mind that this project is little bit advance level project. If you don’t have the idea of GSM then read these articles first.

Basics of GSM module
LED control using GSM Module (Beginner Level)


  • Turn on/off the Fan
  • 4 Speed Levels (Can add more levels as much as you want)
  • Any phone number can send the message
  • Reply message will be send to user about Present state
  • Respond in 3-4 Seconds

Hardware Part:

Fan Speed Control Using GSM
Figure 1: Fan Speed Control Using GSM

To understand the speed controlling of fan using GSM, first you have to understand only speed controlling part. Here in this project I used PWM method to control the fan speed. I hope you have a good idea of PWN and if not then don’t worry I am going to explain here some basics of PWM.

What is Pulse Width Modulation (PWM):

Pulse Width Modulation technique have various applications in power electronics. Majorly it is used to control the voltage at your desired level without any losses. Other voltage control methods involve a lot of losses but in this method only switching losses of switching devices included. I will describe this method through an example of 12 volt fan speed control.

Fan running at full speed:

Suppose we want to turn on the fan at its full speed and we have a supply of 12 volt then we don’t need to use any PWM technique. Direct 12 volt supply will be given to fan.

Fan running at half speed:

Now if we want to cut its speed to half then we need to give 6 volts to it but the question here is how can we give those 6 volts through just a signal of microcontroller? The answer is PWM technique. Look at the figure below:

50% Duty Cycle Waveform
Figure 2: 50% Duty Cycle

If somehow we are able to make such PWM wave form of 50% duty cycle then through some switching device we will able to get 6 volt. Every peak of the wave will be still 12 volt but the average voltage will be 6 volts. Make sure that the frequency of this switching should be greater than 100Hz.

Fan running at 30% duty cycle:

The formula for input and output voltage is as follows:

Output voltage = Duty Cycle x Input voltage


Output voltage = 30 % x 12 volt

Output Voltage = 3.6 volts

At 3.6 volts fan speed will be 30 percent of full speed

How to use a Microcontroller to control voltage?

There are lots of switching devices available according to their uses. I used a MOSFET IRF9530 for controlling the speed of fan. I just have to put it in between my circuit and control it through Atmega8 microcontroller which is from the family of Atmel AVR Microcontrollers as shown in the circuit.

Circuit Diagram of Fan Speed Control GSM Based
Figure 3: Complete Circuit Diagram of Fan Speed Control GSM

We just have to implement this simple circuit and the rest will be taken care of by your microcontroller. A transformer will step down the voltage, Rectifier Bridge will convert it into DC and a 4.7uf 25 volt capacitor will remove the ripples. At the terminals of capacitor we will get 19 volt approximately. We cannot give those 19 volts to the fan. So through PWM we will regulate the voltage at 12 volt.

How to get required PWM Signal?

Timer registers are present in the Atmel AVR Microcontrollers to generate required PWM signals. If you have no idea of timers then don’t worry I will enlighten that much timer part as much this project required. There are three timers present in the Atmega8 microcontroller timer0, timer1 and timer2. I will use timer1 of the Atmega8 Microcontroller to generate PWM signals.

Timer Initialization function:

void timer1_init()
                TCCR1A = 0x83;
                TCCR1B = 0x02; // system clk/8 (From prescaler) & Timer Initialization
                OCR1A = 800;    

I initialized TCCR1A register as 10 bit PWM mode in such way that whenever counter register completes its counts with respect to OCR1A register value, a toggle will occur at 15th pin of Atmega8 which is PORTB1. In pin configuration of Atmega8 you will notice that OCR1A is written with PB1. In fact this is a specialized pin in Atmega8 for PWM generation. After initialization of Timer1 through TCCR1A and TCCR1B registers toggling will be start here at this pin according to the value of OCR1A register. As it is 10 bit PWM mode so we have to set value of OCR1A from 0 to 1024 according to formula.

2^10 = 1024

Pin Configuration of Atmega8
Figure 4: Pin configuration of Atmega8

Waveform at OCR1A = 512

50% Duty Cycle
Figure 5: 50% Duty Cycle

Waveform at OCR1A = 280

30% Duty Cycle
Figure 6: 30% Duty Cycle

Software parts example according to GSM module:

I will send message of “fstop”, ”f1”, “f2”, “fon” etc to the GSM module to work accordingly.

To stop the Fan:

                       OCR1A = 0;
string_transmit("Fan is off");

To get half speed of fan:

OCR1A = 400;
string_transmit("Fan is running at speed level 2");

To get ¾ speed of fan:

  OCR1A = 600;
  string_transmit("Fan is running at speed level 3");

What is the ‘send()’ Function?

As I written in the specifications that your project will be able to reply the user according to present state as well. So this function will help you to get the cell number of the user and reply the user as well.

void send(){      

s=35 and e=50 is the element places where cell phone number of user is present.  So this function will get the cell number and transmit it to GSM module through the AT+CMGS command.

I think that’s enough for fan speed control. If you need more help feel free to contact and don’t forget to like our facebook page. 🙂

 To download complete code click the button below:
Complete Code


Electrical engineering is my profession, my hobby and my passion. I completed bachelors of electrical engineering in 2015. Currently I am working with a utility company which provides electricity to its consumers. Power Electronics, Embedded Systems and Energy Metering are my fields of specialization. In free time I listen music and watch movies.

What do you think?