Controlling an LED light with an Arduino UNO - Python Language

 Here is an example of a Python code for controlling an LED light 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 light_on() and light_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: (you can click on each link and find these things on amazon to buy it).

  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. LED light: It will be controlled by the relay
  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 LED light. 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 LED light on or off.

The circuit diagram for the example I provided would consist of connecting the relay module to the Arduino board, connecting the LED light to the relay module, and connecting a power supply to the Arduino and the relay module.

The specific connections will depend on the relay module you are using. You can refer to the relay module's datasheet or user manual for detailed instructions on how to wire it up.

Here is a simple circuit diagram that shows the general idea of how to wire the relay module to the Arduino and the LED light:

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.

You can also find circuit diagrams and wiring examples on various sites like Instructables, Arduino forum and also on YouTube.

It's also worth noting that you can use this concept to control other devices like fans, motors, or even appliances with some modifications.

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.