Devices & Components
Arduino Uno Rev3
Development Board, Motor Control Shield
DC Motor, 12 V
Hardware & Tools
Hot glue gun (generic)
Project description
Code
arduino
arduino
upload this in arduino
1#include <AFMotor.h> 2#include <Servo.h> 3AF_DCMotor motor(1);#the pin in which your motor is in adafruit motor shield 4AF_DCMotor motor1(4);#the pin in which your motor 2 is in adafruit motor shield 5Servo servo1; 6void setup() { 7motor.setSpeed(200); 8motor1.setSpeed(200); 9motor.run(RELEASE); 10motor1.run(RELEASE); 11Serial.begin(9600); 12} 13 14void loop() { 15 16 if (Serial.read()=='b'){ 17 motor.run(BACKWARD); 18 motor1.run(BACKWARD); 19 20 } 21 else if(Serial.read()=='f'){ 22 motor.run(FORWARD); 23 motor1.run(FORWARD); 24 25 } 26 else if(Serial.read()=='s'){ 27 motor.run(RELEASE); 28 motor1.run(RELEASE); 29 } 30 else if(Serial.read()=='r'){ 31 motor.run(BACKWARD); 32 motor1.run(FORWARD); 33 } 34 else if(Serial.read()=='l'){ 35 motor.run(FORWARD); 36 motor1.run(BACKWARD); 37 } 38 39 40 41}
arduino
arduino
upload this in arduino
1#include <AFMotor.h> 2#include <Servo.h> 3AF_DCMotor motor(1);#the pin in which your motor is in adafruit motor shield 4AF_DCMotor motor1(4);#the pin in which your motor 2 is in adafruit motor shield 5Servo servo1; 6void setup() { 7motor.setSpeed(200); 8motor1.setSpeed(200); 9motor.run(RELEASE); 10motor1.run(RELEASE); 11Serial.begin(9600); 12} 13 14void loop() { 15 16 if (Serial.read()=='b'){ 17 motor.run(BACKWARD); 18 motor1.run(BACKWARD); 19 20 } 21 else if(Serial.read()=='f'){ 22 motor.run(FORWARD); 23 motor1.run(FORWARD); 24 25 } 26 else if(Serial.read()=='s'){ 27 motor.run(RELEASE); 28 motor1.run(RELEASE); 29 } 30 else if(Serial.read()=='r'){ 31 motor.run(BACKWARD); 32 motor1.run(FORWARD); 33 } 34 else if(Serial.read()=='l'){ 35 motor.run(FORWARD); 36 motor1.run(BACKWARD); 37 } 38 39 40 41}
python
python
run it in python after uploading arduino pragram in arduino
1import keyboard,serial 2ser=serial.Serial('com6',9600) 3while True: 4 if keyboard.ispressed('w'): 5 ser.write(b'f') 6 elif keyboard.is_pressed("s"): 7 ser.write(b'b') 8 elif keyboard.is_pressed("d"): 9 ser.write(b'r') 10 elif keyboard.is_pressed("a"): 11 ser.write(b'l') 12 else: 13 ser.write(b's')
Downloadable files
20210518_175536_PN6RpX1LBP.jpg
20210518_175536_PN6RpX1LBP.jpg

20210518_175536_PN6RpX1LBP.jpg
20210518_175536_PN6RpX1LBP.jpg

Comments
Only logged in users can leave comments