Devices & Components
Arduino Uno Rev3
USB-A to B Cable
Project description
Code
Arduino Code
arduino
This code is for arduino and you need to upload this code before running python code
1int datafromUser=0; 2void setup() { 3 // put your setup code here, to run once: 4 pinMode( LED_BUILTIN , OUTPUT ); 5 Serial.begin(9600); 6} 7 8void loop() { 9 // put your main code here, to run repeatedly: 10 if(Serial.available() > 0) 11 { 12 datafromUser=Serial.read(); 13 } 14 15 if(datafromUser == '1') 16 { 17 digitalWrite( LED_BUILTIN , HIGH ); 18 } 19 else if(datafromUser == '0') 20 { 21 digitalWrite( LED_BUILTIN, LOW); 22 } 23 24} 25
Arduino Code
arduino
This code is for arduino and you need to upload this code before running python code
1int datafromUser=0; 2void setup() { 3 // put your setup code here, to run once: 4 pinMode( LED_BUILTIN , OUTPUT ); 5 Serial.begin(9600); 6} 7 8void loop() { 9 // put your main code here, to run repeatedly: 10 if(Serial.available() > 0) 11 { 12 datafromUser=Serial.read(); 13 } 14 15 if(datafromUser == '1') 16 { 17 digitalWrite( LED_BUILTIN , HIGH ); 18 } 19 else if(datafromUser == '0') 20 { 21 digitalWrite( LED_BUILTIN, LOW); 22 } 23 24} 25
Python3 Code
python
1import serial 2import time 3 4arduino=serial.Serial('COM1', 9600) 5time.sleep(2) 6 7print("Enter 1 to turn ON LED and 0 to turn OFF LED") 8 9while 1: 10 11 datafromUser=input() 12 13 if datafromUser == '1': 14 arduino.write(b'1') 15 print("LED turned ON") 16 elif datafromUser == '0': 17 arduino.write(b'0') 18 print("LED turned OFF") 19
Downloadable files
untitled
For this project you just need arduino board and usb cable
untitled

untitled
For this project you just need arduino board and usb cable
untitled

Comments
Only logged in users can leave comments