Controlling Fan Using Arduino

Introduction

In this article, I am going to explain how to control a fan by using two buttons, using Arduino. Arduino will be used to control the fan by clicking the button.
 
Parts Lists
 
Hardware Parts
  • Arduino Uno
  • Fan
  • Bread Broad
  • HookUp Wires 
Software Parts
  • Arduino IDE
  • Python IDLE 
Connection

Connecting the fan to the Arduino Board is simple. Given below are the instructions for connecting the fan.

 Fan  Board
 Postive Side  10
 Negative Side  Gnd

Programming

Arduino Programming
  1. int Fan = 10;    
  2. char mydata = 0;    
  3. voidsetup()     
  4. {    
  5.     pin Mode(Fan, OUTPUT);    
  6.     Serial begin(9600);    
  7. }    
  8. void loop()    
  9. {    
  10.     my data = int(serial.read());    
  11.     if (y data = = '1') digitalWrite(Fan, HIGH);    
  12.     if (mydata = = '0') digitalWrite(Fan, LOW);   
  13. }  
In the Arduino Side, run the above program. If we set 1, it will be high and if we set 0, it will be low.
 
Python Programming
  1. import Serial    
  2. import time    
  3. from tkiner import*    
  4. def Fan_on();    
  5. arduinoData.write(b '1')    
  6. def Fan_off( );    
  7. arduinoData.Write(b '0')    
  8. Fan_control_Window=Tk( )    
  9. btn = Button(Fan_control_window,text = "Fan on",command = Fan_on)    
  10. btn2 = Button(Fan_control_window,text = "Fan off",command = Fan_off)    
  11. btn.pack( )    
  12. btn2.pack()    
  13. arduinoData= Serial.Serial("COM4",9600)   
Explanation

In Python, the above program is used to connect the Serial monitor with the Board. For creating the ON and OFF buttons in Python, the following code will be used:
  1. Fan_control_Window=Tk( )    
  2. btn = Button(Fan_control_window,text = "Fan on",command = Fan_on)    
  3. btn2 = Button(Fan_control_window,text = "Fan off",command = Fan_off)    
Output

Up Next
    Ebook Download
    View all
    Learn
    View all