My Robot
YOU NEED :
- 1x ARDUINO UNO
- 1x TAMIYA UNIVERSAL PLATE SET
- 1x TAMIYA TRACK & WHEEL SET
- 1x TAMIYA MOTOR GEARBOX
- 1x L298 Dual H-Bridge Motor Driver
- 1x 9g Servo
- 1x Ir Sharp Sensor
- Plexiglass
- 1x SPDT Switch
- Some Wires
- Hot Glue Gun
- 3x 9 v Battery
- 1x Test PCB
-1x L0875
-1x 1uf capacitor
-1x 10uf capacitor
Arduino Code:
#include
Servo MS;
int a = 4;
int b = 5;
int c = 6;
int d = 7;
int x;
int pos = 0;
void setup()
{
Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
MS.attach(3);
}
void loop()
{
int S;
int F;
int D;
int sensorValue = analogRead(A2);
float vol = sensorValue * (5.0 / 1023.0);
Serial.println(vol);
if(vol >= 0.7)
{
MS.write(0);
pos = 0;
delay(500);
Serial.println(pos);
MS.write(90);
pos = 90;
delay(500);
Serial.println(pos);
MS.write(180);
pos = 180;
delay(500);
Serial.println(pos);
MS.write(90);
pos = 90;
delay(500);
Serial.println(pos);
if(pos == 0 && vol >= 0.7)
{
S = 1;
}
if(pos == 0 && vol <= 0.7)
{
S = 0;
}
if(pos == 90 && vol >= 0.7)
{
F = 1;
}
if(pos == 90 && vol <= 0.7)
{
F = 0;
}
if(pos == 180 && vol >= 0.7)
{
D = 1;
}
if(pos == 180 && vol <= 0.7)
{
D = 0;
}
if(S == 0 && F == 1 && D == 1)
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
}
if(S == 1 && F == 0 && D == 1)
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
}
if(S == 1 && F == 1 && D == 0)
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
}
if(S == 1 && F == 1 && D == 1)
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
}
Serial.println(S);
Serial.println(F);
Serial.println(D);
}
if(vol <= 0.7 )
{
MS.write(90);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
}
}
Pin conecttion :
L298N :
-pin 1, 8, 15 to gnd arduino and to 9v battery anode;
-pin 2, 3 to motor 1;
-pin 13, 14 to motor 2;
-pin 4, 6, 9, 11 to battery cathode
-pin 5, 7, 10, 12 to arduino digital pin (digital pin 4, 5, 6, 7 );
Servo :
-gnd to arduino gnd;
-red wire to 5v arduino;
-white wire (signal) to digital pin 3 arduino;
IR Sharp Sensor :
-gnd to arduino gnd;
-red wire to 5v arduino;
-white wire (signal) to analog pin A2 arduino
- 1x ARDUINO UNO
- 1x TAMIYA UNIVERSAL PLATE SET
- 1x TAMIYA TRACK & WHEEL SET
- 1x TAMIYA MOTOR GEARBOX
- 1x L298 Dual H-Bridge Motor Driver
- 1x 9g Servo
- 1x Ir Sharp Sensor
- Plexiglass
- 1x SPDT Switch
- Some Wires
- Hot Glue Gun
- 3x 9 v Battery
- 1x Test PCB
-1x L0875
-1x 1uf capacitor
-1x 10uf capacitor
Arduino Code:
#include
Servo MS;
int a = 4;
int b = 5;
int c = 6;
int d = 7;
int x;
int pos = 0;
void setup()
{
Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
MS.attach(3);
}
void loop()
{
int S;
int F;
int D;
int sensorValue = analogRead(A2);
float vol = sensorValue * (5.0 / 1023.0);
Serial.println(vol);
if(vol >= 0.7)
{
MS.write(0);
pos = 0;
delay(500);
Serial.println(pos);
MS.write(90);
pos = 90;
delay(500);
Serial.println(pos);
MS.write(180);
pos = 180;
delay(500);
Serial.println(pos);
MS.write(90);
pos = 90;
delay(500);
Serial.println(pos);
if(pos == 0 && vol >= 0.7)
{
S = 1;
}
if(pos == 0 && vol <= 0.7)
{
S = 0;
}
if(pos == 90 && vol >= 0.7)
{
F = 1;
}
if(pos == 90 && vol <= 0.7)
{
F = 0;
}
if(pos == 180 && vol >= 0.7)
{
D = 1;
}
if(pos == 180 && vol <= 0.7)
{
D = 0;
}
if(S == 0 && F == 1 && D == 1)
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
}
if(S == 1 && F == 0 && D == 1)
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
}
if(S == 1 && F == 1 && D == 0)
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
}
if(S == 1 && F == 1 && D == 1)
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
}
Serial.println(S);
Serial.println(F);
Serial.println(D);
}
if(vol <= 0.7 )
{
MS.write(90);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
}
}
Pin conecttion :
L298N :
-pin 1, 8, 15 to gnd arduino and to 9v battery anode;
-pin 2, 3 to motor 1;
-pin 13, 14 to motor 2;
-pin 4, 6, 9, 11 to battery cathode
-pin 5, 7, 10, 12 to arduino digital pin (digital pin 4, 5, 6, 7 );
Servo :
-gnd to arduino gnd;
-red wire to 5v arduino;
-white wire (signal) to digital pin 3 arduino;
IR Sharp Sensor :
-gnd to arduino gnd;
-red wire to 5v arduino;
-white wire (signal) to analog pin A2 arduino