Devices & Components
Arduino Uno Rev3
DC motor (generic)
Male/Male Jumper Wires
9V Battery Clip
Servos (Tower Pro MG996R)
Female/Female Jumper Wires
Ultrasonic Sensor - HC-SR04 (Generic)
Breadboard (generic)
Male/Female Jumper Wires
9V battery (generic)
Dual H-Bridge motor drivers L293D
Software & Tools
Arduino Web Editor
Arduino IDE
Project description
Code
servo software
arduino
1#include <Servo.h> 2 3Servo myservo; 4 5int pos = 0; 6 7void setup() 8{ 9 myservo.attach(9); 10} 11 12void loop() 13{ 14 for(pos = 0; pos < 180; pos += 1) 15 { 16 myservo.write(pos); 17 delay(15); 18 } 19 for(pos = 180; pos>=1; pos-=1) 20 { 21 myservo.write(pos); 22 delay(15); 23 } 24}
servo software
arduino
1#include <Servo.h> 2 3Servo myservo; 4 5int pos = 0; 6 7void 8 setup() 9{ 10 myservo.attach(9); 11} 12 13void loop() 14{ 15 for(pos 16 = 0; pos < 180; pos += 1) 17 { 18 myservo.write(pos); 19 delay(15); 20 21 } 22 for(pos = 180; pos>=1; pos-=1) 23 { 24 myservo.write(pos); 25 delay(15); 26 27 } 28}
robot software
arduino
1#define echopin 8 // echo pin 2#define trigpin 9 // Trigger pin 3 4 5int maximumRange = 30; 6long duration, distance; 7 8void setup() { 9 Serial.begin (9600); 10 pinMode (trigpin, OUTPUT); 11 pinMode (echopin, INPUT ); 12 pinMode (4, OUTPUT); 13 pinMode (5, OUTPUT); 14 pinMode (13, OUTPUT); 15 pinMode (6, OUTPUT); 16 pinMode (7, OUTPUT); 17} 18 19void loop () 20{ 21 22 { 23 digitalWrite(trigpin,LOW); 24 delayMicroseconds(2); 25 26 digitalWrite(trigpin,HIGH); 27 delayMicroseconds(10); 28 29 duration=pulseIn (echopin,HIGH); 30 31 distance= duration/58.2; 32 delay (50); 33 Serial.println(distance); 34 } 35 36 if (distance >= 30 ){ 37 digitalWrite(4,HIGH); 38 digitalWrite(5,HIGH); 39 digitalWrite(6,LOW); 40 digitalWrite(7,LOW); 41 delay (200); 42 } 43 44 else if (distance >=15 && distance <= 25) { 45 digitalWrite (4,HIGH); 46 digitalWrite (5,LOW); 47 digitalWrite (6,LOW); 48 digitalWrite (7,LOW); 49 delay (1000); 50 } 51 else if (distance < 15){ 52 digitalWrite (4, LOW); 53 digitalWrite (5, LOW); 54 digitalWrite (6,HIGH); 55 digitalWrite (7,HIGH); 56 delay (1000); 57 digitalWrite (4,LOW); 58 digitalWrite (5,HIGH); 59 digitalWrite (6,LOW); 60 digitalWrite (7, LOW); 61 delay (1000); 62 63 64 } 65 66} 67
Downloadable files
servo control
servo control

obstacle robot
obstacle robot

servo control
servo control

obstacle robot
obstacle robot

Comments
Only logged in users can leave comments