I have started a project on arduino where i require it to communicate with python.I have gone through web and found a sample code on arduino python serial communication where,it lights up the LED when 1 is enterd. Both python and arduino code are working but the LED is not lighting up. The board is functioning properly since,i have tried other basic examples
Arduino code:
I
void setup()
{
pinMode(12,OUTPUT);
digitalWrite(12,LOW);
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0)
{
if(Serial.read() == 1)
{
digitalWrite(12,HIGH);
delay(2000);
}
}
else
{
digitalWrite(12,LOW);
}
}
Python Code:
import serial
import time # Required to use delay functions
arduinoSerialData = serial.Serial('/dev/ttyACM0', 9600) # Create Serial port object called arduinoSerialData
time.sleep(2) # wait for 2 secounds for the communication to get established
print ("Enter 1 to turn ON LED and 0 to turn OFF LED")
while 1: # Do this forever
var =input() # get input from user
var=var.encode()
arduinoSerialData.write(var)