rdnjbrothers
Published © GPL3+

KEYBOARD CONTROLLED Arduino Car | Python + Arduino

This project is a arduino car which will coontrolled by keyboard using python and arduino.

BeginnerFull instructions provided3,152
KEYBOARD CONTROLLED Arduino Car | Python + Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Development Board, Motor Control Shield
Development Board, Motor Control Shield
×1
DC Motor, 12 V
DC Motor, 12 V
×2

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

20210518_175536_PN6RpX1LBP.jpg

Code

arduino

Arduino
upload this in arduino
#include <AFMotor.h>
#include <Servo.h> 
AF_DCMotor motor(1);#the pin in which your motor is in adafruit motor shield
AF_DCMotor motor1(4);#the pin in which your motor 2 is in adafruit motor shield
Servo servo1;
void setup() {
motor.setSpeed(200);
motor1.setSpeed(200); 
motor.run(RELEASE);
motor1.run(RELEASE);
Serial.begin(9600);
}

void loop() {
 
 if (Serial.read()=='b'){
  motor.run(BACKWARD);
  motor1.run(BACKWARD);

 }
 else if(Serial.read()=='f'){
  motor.run(FORWARD);
  motor1.run(FORWARD);

 }
 else if(Serial.read()=='s'){
  motor.run(RELEASE);
  motor1.run(RELEASE);
 }
 else if(Serial.read()=='r'){
  motor.run(BACKWARD);
   motor1.run(FORWARD);
 }
 else if(Serial.read()=='l'){
  motor.run(FORWARD);
  motor1.run(BACKWARD); 
 }
 
  
 
}

python

Python
run it in python after uploading arduino pragram in arduino
import keyboard,serial
ser=serial.Serial('com6',9600)
while True:
    if keyboard.ispressed('w'):
        ser.write(b'f')
    elif keyboard.is_pressed("s"):
        ser.write(b'b')
    elif keyboard.is_pressed("d"):
        ser.write(b'r')
    elif keyboard.is_pressed("a"):
        ser.write(b'l')
    else:
        ser.write(b's')  

Credits

rdnjbrothers

rdnjbrothers

1 project • 0 followers

Comments