I have an Arduino Uno. I wan to connect it with the laptop via cable to send the data from excel sheet. Excel sheet is having only one column having ten entries of numbers ranging from 1 to 10. I want to send the one digit from the column at a time to Arduino. Then after 5 seconds, the digit in the next cell will be sent to Arduino. Then Arduino will compare this number with the Threshold set in the program. If the digit sent from the excel is higher than the threshold, it will turn on the LED.
For this I have python code script to read data from excel and following IDE code:
Python Script
import serial
import time
Serial port configuration (replace with your Arduino's port)
ser = serial.Serial('COM3', 9600)
Open Excel sheet (replace with your actual file path)
import openpyxl
wb = openpyxl.load_workbook('data.xlsx')
sheet = wb['Sheet1'] # Assuming data is in Sheet1
Threshold value
threshold = 5
Loop through each cell in the first column (A)
for cell in sheet['A']:
# Get the value as an integer
value = int(cell.value)
# Send the value to Arduino
ser.write(str(value).encode()) # Convert to bytes for serial communication
# Delay for 5 seconds
time.sleep(5)
# Check if value is higher than threshold
if value > threshold:
# Send "1" to turn on LED (replace with appropriate command for your LED control)
ser.write(b'1')
else:
# Send "0" to turn off LED (replace with appropriate command for your LED control)
ser.write(b'0')
# Wait for 1 second before sending the next value
time.sleep(1)
Close serial connection
ser.close()
IDE Code:
#include <SoftwareSerial.h>
// Define RX and TX pins (adjust based on your connection)
#define RX_PIN 0
#define TX_PIN 1
// Define LED pin
#define LED_PIN 13
// Create software serial object
SoftwareSerial serial(RX_PIN, TX_PIN);
// Set the threshold
int threshold = 5;
void setup() {
// Initialize serial communication
serial.begin(9600);
// Set LED pin as output
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// Check if data is available
if (serial.available()) {
// Read the received data
int received_value = serial.read() - '0';
// Compare with the threshold
if (received_value > threshold) {
// Turn on the LED
digitalWrite(LED_PIN, HIGH);
} else {
// Turn off the LED
digitalWrite(LED_PIN, LOW);
}
}
}
Now when I run python code, I am getting following error:
I have tried following solutions:
1.) Restarting computer
2.) Uninstalling and Installing drivers
3.) checking that only one application is using COM port at a time
4.) Changing COM ports
Also wanted to share that I can upload code to Arduino using IDE successfully. But in the python, the above error persists.
However error still persist. Any help greatly appreciated.


