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
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
- int Fan = 10;
- char mydata = 0;
- voidsetup()
- {
- pin Mode(Fan, OUTPUT);
- Serial begin(9600);
- }
- void loop()
- {
- my data = int(serial.read());
- if (y data = = '1') digitalWrite(Fan, HIGH);
- if (mydata = = '0') digitalWrite(Fan, LOW);
- }
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
- import Serial
- import time
- from tkiner import*
- def Fan_on();
- arduinoData.write(b '1')
- def Fan_off( );
- arduinoData.Write(b '0')
- Fan_control_Window=Tk( )
- btn = Button(Fan_control_window,text = "Fan on",command = Fan_on)
- btn2 = Button(Fan_control_window,text = "Fan off",command = Fan_off)
- btn.pack( )
- btn2.pack()
- 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:
- Fan_control_Window=Tk( )
- btn = Button(Fan_control_window,text = "Fan on",command = Fan_on)
- btn2 = Button(Fan_control_window,text = "Fan off",command = Fan_off)
Output