Python + Arduino + Mu = projects better than ever before!

Python + Arduino + Mu = projects better than ever before! © GPL3+

Adding Python to Arduino projects, plus an editor with pyserial pre-installed, equals amazing projects!

  • 13 respects

Components and supplies

Ph a000066 iso (1) ztbmubhmho
Arduino UNO
Or another Arduino- compatible device.

Apps and online services

About this project

In this project I am going to teach any beginner Arduino / Python programmer how to use pyserial to control your serial ports with Python code. You can't run code directly from the Python editor to your Arduino, but through the pyserial library you can send and receive messages from your device.

Step 1: Installing the Editor

Mu editor is a great editor, perfect for beginners because of its easy to use design. It also comes with a built in pyserial library, so no additional downloads are necessary. To download Mu, click here and select the correct installer for your operating system. Install and then open it.

If you need the Arduino IDE, click here.

Step 2: The Arduino Part

Now just open the Arduino IDE and paste the Arduino code shown in the code section below into it and upload it to your board.

Step 3: The Python Part

Back to Mu. The first time you open it, Mu shows a "mode" window. For now select "Python 3". Later you can change this by clicking the "Mode" button in the top left corner of the screen. Paste the Python code (shown below in the code section) into Mu. Now you must find the port your board is connected to. It shows this in the bottom right corner of the Arduino IDE. Type this in place of COM12. (Line 4 in the Python code.) Now run the code. Enter 1 to turn the on board LED on and 0 to turn it off.

Questions? Problems? Ideas? See comment section below. Have a great day and don't forget to respect this project!


Arduino codeArduino
int datafromUser=0;
void setup() {
  // put your setup code here, to run once:
  pinMode( LED_BUILTIN , OUTPUT );

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available() > 0)

  if(datafromUser == '1')
    digitalWrite( LED_BUILTIN , HIGH );
  else if(datafromUser == '0')
    digitalWrite( LED_BUILTIN, LOW);
Python codePython
import serial
import time

arduino=serial.Serial('COM12', 9600)
time.sleep(2)                       #sleep 2 secs

print("Enter 1 to turn ON LED and 0 to turn OFF LED")       #print some output

while 1:                            #loop forever


    if datafromUser == '1':         #datafromUser equals 1?
        arduino.write(b'1')         #send '1' over serial port
        print("LED  turned ON")     #print some output

    elif datafromUser == '0':       #datafromUser equals 0?
        arduino.write(b'0')         #send '0' over serial port
        print("LED turned OFF")     #print some output


Similar projects you might like

Chrome Dino Game "Revamped" with arduino and python

Project tutorial by yashastronomy

  • 1 comment
  • 7 respects

ARMin: Simple Robot Arm Controller Using Python

Project tutorial by HyperChiicken

  • 1 comment
  • 13 respects

Python Software for Arduino RFID

Project tutorial by Hamza Khalid

  • 17 respects

Attendance System Using Arduino and RFID with Python

Project tutorial by Embedotronics Technologies

  • 26 respects

ARMin v2: Simple Robot Car and Arm Controller Using Python

Project tutorial by HyperChiicken

  • 14 respects
Add projectSign up / Login