Controlling a fan with an Arduino UNO board and a Relay module - Python Language

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)

  1. Arduino UNO board
  2. 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.
  3. Jumper wires: To connect the relay module to the Arduino
  4. 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.
    1. Havells Leganza 1200mm Ceiling Fan
    2. Usha Striker 600mm Ceiling Fan
    3. Crompton Greaves High Speed 48" Ceiling Fan
    4. Bajaj Ultima PT01 200mm Table Fan
    5. Orient Electric Desk-25 400mm Table Fan
    6. Usha Maxx Air 400mm Table Fan
    7. Havells Ventilair DSP 230mm Exhaust Fan
    8. Luminous Vento Deluxe 8" Exhaust Fan
    9. Usha Crisp Air 150mm Exhaust Fan
  5. Power supply for the Arduino and the relay
  6. 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

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.