Introduction :
In the previous post we was implement different python_Arduino base projects but some students face one common problem like interconnection between python IDE with arduino UNO
So in this Article we will see How to interconnection between python IDE with arduino UNO Let’s get started :

Simple project Idia :
Friends I’m going to show you simple project on how to tell your arduino to blink using Python code.i.e. The main logic behind this tutorial is to turn ON the LED when I will type ‘1’ and turn off when i will give input command ‘0’ .
Pre-requirement :
Software apps :
- Python IDLE
- Arduino IDE
- PySerial
Hardware components :
- Arduino Uno
- LED
- Breadboard
- Wires
- 220 Ohms resistor
Procedure (interconnection between python IDE with arduino UNO):
Step 1: How to Install Python IDE on Your PC/Computer :
Follow below step one by one
1.You need to visit to python official website and download it (i.e. python.org)
2. Next step is installation of software file and necessary directory
Step 3: Install PySerial library
Intro about Pyserial
For read and write serial data to Arduino we can use Pyserial library
How to install it ?
You need to simply visit to PySerial’s Download Page and following the steps bellow :
1.First Download the PySerial and installed it
import serial
Step 4: Python Code for interconnection between python IDE with arduino UNO
import serial #Serial imported for Serial communication
import time #Required to use delay functions
ArduinoUnoSerial = serial.Serial('com15',9600)
#Create Serial port object called ArduinoUnoSerialData time.sleep(2) #wait for 2 secounds for the communication to get established
print ArduinoUnoSerial.readline() #read the serial data and print it as line
print ("You have new message from Arduino")
while 1: #Do this forever
var = raw_input() #get input from user
if (var == '1'): #if the value is 1
ArduinoUnoSerial.write('1') #send 1 to the arduino's Data code
print ("LED turned ON")
time.sleep(1)
if (var == '0'): #if the value is 0
ArduinoUnoSerial.write('0') #send 0 to the arduino's Data code
print ("LED turned OFF")
time.sleep(1)
if (var == 'fine and you'): #if the answer is (fine and you)
ArduinoUnoSerial.write('0'#send 0 to the arduino's Data code
print ("I'm fine too,Are you Ready to !!!")
print ("Type 1 to turn ON LED and 0 to turn OFF LED")
time.sleep(1)
Arduino Code For Interconnection Between Python IDE With Arduino UNO
int data;
int LED=13;
void setup() {
Serial.begin(9600); //initialize serial COM at 9600 baudrate
pinMode(LED, OUTPUT); //declare the LED pin (13) as output
digitalWrite (LED, LOW); //Turn OFF the Led in the beginning
Serial.println("Hello!,How are you Python ?");
}
void loop() {
while (Serial.available()) //whatever the data that is coming in serially and assigning the value to the variable “data”
{
data = Serial.read();
}
if (data == '1')
digitalWrite (LED, HIGH); //Turn On the Led
else if (data == '0')
digitalWrite (LED, LOW); //Turn OFF the Led
}
Run the above code. If light blinking successfully in given input command then it’s works.
Summary :
In this article we saw How to interconnection between python IDE with arduino UNO . If you have any query regarding this article then please comment me
BEST OF LUCK!!
Resource : Arduino official site
Also see following python arduino projects