Here is an example of a Python code for controlling a fan with an Arduino UNO board and a relay module:
This code uses the PySerial library to establish a serial connection with the Arduino on the COM3 port. The fan_on()
and fan_off()
functions are used to send the '1' and '0' commands to the Arduino through the serial connection.
The while loop is used to constantly check for user input, and the corresponding '1' or '0' command is sent to the Arduino when the user inputs 'on' or 'off' respectively.
For this example you will need: (go to links to purchase these things on Amazon)
- Arduino UNO board
- A relay module: It's an electronic switch that can be controlled by an electric current. It can be used to control high voltage devices from a low voltage controller like Arduino.
- Jumper wires: To connect the relay module to the Arduino
- Fan: It will be controlled by the relay , The specific fan model that can be used for the above example would depend on the current and voltage rating of the fan, as well as the capacity of the relay module you are using. For example, if you are using a relay module that can handle up to 10A of current, you would want to choose a fan that has a current rating of less than or equal to 10A. You can find a wide range of fans, such as ceiling fans, table fans, exhaust fans, etc. in the market.
- Havells Leganza 1200mm Ceiling Fan
- Usha Striker 600mm Ceiling Fan
- Crompton Greaves High Speed 48" Ceiling Fan
- Bajaj Ultima PT01 200mm Table Fan
- Orient Electric Desk-25 400mm Table Fan
- Usha Maxx Air 400mm Table Fan
- Havells Ventilair DSP 230mm Exhaust Fan
- Luminous Vento Deluxe 8" Exhaust Fan
- Usha Crisp Air 150mm Exhaust Fan
- Power supply for the Arduino and the relay
- Breadboard or protoboard: To connect and prototype the circuit
The role of the Arduino in this setup is to act as the controller for the relay, which in turn controls the fan. The Python code is used to send commands to the Arduino through a serial connection, which the Arduino then uses to control the relay and turn the fan on or off.
Here is the circuit diagram for this example:
Please note that this circuit diagram is a general example and the pinout of the relay module may vary depending on the manufacturer. It's always a good idea to refer to the relay module's datasheet or user manual for specific pinout and wiring instructions.
Also, be careful with the current and voltage rating of your fan and the relay module. It should be matched with the capacity of the relay module.
No comments:
Post a Comment