Trybotics Logo

Python (pySerial) + Arduino + DC Motor

DESCRIPTION

This quick tutorial shows the simple operation of a DC motor using a Python GUI. To make Python to communicate with an Arduino board we will be using the pySerial package. pySerial is a Python library which provides support for serial connections over a variety of different devices.

Description:

Adafruit motor shield, Arduino board (Mega), DC motor, 1k ohm resistors (2), LEDs (2), hook-up wires and breadboard.

Description:

In this setup,
green LED -> Pin 30 of Arduino board
red LED -> Pin 32 of Arduino board
DC Motor -> Channel 3 (M3) of motor shield

Description:

Description:

Connect the desired Arduino board to PC (in this case I’m using an Arduino Mega). Open Arduino IDE and select the appropriate COM port and board. The code below is uploaded to the Arduino board by clicking on the Upload button.

Description:

Description:

Description:

Description:

Description:

Description:

Description:

NOTE: Make sure the same COM port number is used in the Python code.

References:
pySerial: https://pyserial.readthedocs.io/en/latest/shortintro.html
Tkinter: https://docs.python.org/3/library/tkinter.html#tkinter-modules


Description:

Description:

A simple GUI opens with 3 buttons – FORWARD, REVERSE and EXIT.

Depending on the motor connection wiring, the motor runs in the desired direction with the click of the FORWARD or REVERSE button. The EXIT button closes the serial port and ends the program execution.

Description:


YOU MIGHT ALSO LIKE