Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com
This free e-book was created with
Ourboox.com

Create your own amazing e-book!
It's simple and free.

Start now

Code Hunters Our Car e-Journal (Common Product)

  • Joined May 2019
  • Published Books 25
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com

 

MATERIALS TO BE USED IN CAR BUILDING

 

 

 

Necessary materials:

 

 

Arduino UNO
Multi-Purpose Robot Platform
L298N Dual Motor Driver Board with Voltage Regulator
HC06 Bluetooth Module
Battery
Jumper Cable

3
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com

 

Codes Of The Car Controlled By Bluetooth

 

 

const int motorA1  = 5;
const int motorA2  = 6;
 const int motorB1  = 10;
const int motorB2  = 9;
int i=0;   int j=0;
int state;
int vSpeed=255;


8

 

 

void setup() {
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
Serial.begin(9600);}

void loop() {
if(digitalRead(BTState)==LOW) { state='S'; }
if(Serial.available() > 0){
9

 

 

state = Serial.read();       }
if (state == '0'){
vSpeed=0;}
else if (state == '1'){
vSpeed=100;}
else if (state == '2'){
 vSpeed=180;}
else if (state == '3'){
vSpeed=200;}
else if (state == '4'){
vSpeed=255;}
10

 

Car Codes to Overcome Obstacles by Sensing Obstacles

 

#define echoPin 12

#define trigPin 13

#define MotorR1 7

#define MotorR2 6

#define MotorRE 9

#define MotorL1 5

#define MotorL2 4

#define MotorLE 3

long sure, uzaklik;

11

 

 

void setup() {

pinMode(echoPin, INPUT);

pinMode(trigPin, OUTPUT);

pinMode(MotorL1, OUTPUT);

pinMode(MotorL2, OUTPUT);

pinMode(MotorLE, OUTPUT);

pinMode(MotorR1, OUTPUT);

pinMode(MotorR2, OUTPUT);

pinMode(MotorRE, OUTPUT);

Serial.begin(9600);

 

}

12

 

 

void loop() {

 

digitalWrite(trigPin, LOW);

delayMicroseconds(5);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

 

sure = pulseIn(echoPin, HIGH);

uzaklik = sure / 29.1 / 2;

13

 

 

Serial.println(uzaklik);

 

if (uzaklik < 15)

{

geri();

delay(150);

sag();

delay(250);

}

else {

ileri();

}

}

14

 

 

void ileri(){

 

digitalWrite(MotorR1, HIGH);

digitalWrite(MotorR2, LOW);

analogWrite(MotorRE, 150);

 

digitalWrite(MotorL1, HIGH);

digitalWrite(MotorL2, LOW);

analogWrite(MotorLE, 150);

 

}

15

 

 

void sag(){

 

digitalWrite(MotorR1, HIGH);

digitalWrite(MotorR2, LOW);

analogWrite(MotorRE, 0);

 

digitalWrite(MotorL1, HIGH);

digitalWrite(MotorL2, LOW);

analogWrite(MotorLE, 150);

 

 

}

16

 

 

void geri(){

 

digitalWrite(MotorR1, LOW);

digitalWrite(MotorR2, HIGH);

analogWrite(MotorRE, 150);

 

digitalWrite(MotorL1, LOW);

digitalWrite(MotorL2, HIGH);

analogWrite(MotorLE, 150);

 

}

17

 

 

“Line Follower” Car Codes

 

 

#define SensorSol 10
#define SensorOrta 11
#define SensorSag 12

void setup() {

  pinMode(SensorSol, INPUT);
  pinMode(SensorOrta, INPUT);
  pinMode(SensorSag, INPUT);

18
Serial.begin(9600);
  Serial.println("Cizgi Sensoru Testi");
  delay(2000);
}

 

void loop() {
  Serial.print(digitalRead(SensorSol));
  Serial.print(",");
  Serial.print(digitalRead(SensorOrta));
  Serial.print(",");
  Serial.println(digitalRead(SensorOrta));
  delay(100);
}
19
#define SensorSol 10
#define SensorOrta 11
#define SensorSag 12

#define MotorR1 6
#define MotorR2 7
#define MotorRE 9

#define MotorL1 5
#define MotorL2 4
#define MotorLE 3

20

 

 

void setup() {

  pinMode(SensorSol, INPUT);
  pinMode(SensorOrta, INPUT);
  pinMode(SensorSag, INPUT);

  pinMode(MotorR1, OUTPUT);
  pinMode(MotorR2, OUTPUT);

  pinMode(MotorL1, OUTPUT);
  pinMode(MotorL2, OUTPUT);

}

21
void loop() {
  if(digitalRead(SensorSol) == 0 && digitalRead(SensorOrta) == 1 && digitalRead(SensorSag) == 0){
    ileri();
  }

  if(digitalRead(SensorSol) == 0 && digitalRead(SensorOrta) == 0 && digitalRead(SensorSag) == 1){
    sag();
  }
  if(digitalRead(SensorSol) == 1 && digitalRead(SensorOrta) == 0 && digitalRead(SensorSag) == 0){
    sol();
  }

22
void ileri(){

  digitalWrite(MotorR1, HIGH);
  digitalWrite(MotorR2, LOW);
  analogWrite(MotorRE, 150);

  digitalWrite(MotorL1, HIGH);
  digitalWrite(MotorL2, LOW);
  analogWrite(MotorLE, 150);


}
23

 

void sag(){

  digitalWrite(MotorR1, HIGH);
  digitalWrite(MotorR2, LOW);
  analogWrite(MotorRE, 0);

  digitalWrite(MotorL1, HIGH);
  digitalWrite(MotorL2, LOW);
  analogWrite(MotorLE, 150);


}
24

 

void sol(){

  digitalWrite(MotorR1, HIGH);
  digitalWrite(MotorR2, LOW);
  analogWrite(MotorRE, 150);
  digitalWrite(MotorL1, HIGH);
  digitalWrite(MotorL2, LOW);
  analogWrite(MotorLE, 0);

}
25

 

 

void dur(){

  digitalWrite(MotorR1, HIGH);
  digitalWrite(MotorR2, LOW);
  digitalWrite(MotorRE, LOW);

  digitalWrite(MotorL1, HIGH);
  digitalWrite(MotorL2, LOW);
  digitalWrite(MotorLE, LOW);

}
26

Light Follower Robot Codes

 

 

#include <dmoto.h>

dmoto Light;

float ldrRemove =0;

void setup() {

Serial.begin(9600);

Light.pinSet();

Light.Stop();

}

27

 

 

void loop() {

ldrRemove = abs(Light.LdrRightValue() – Light.LdrLeftValue());

Serial.print(Light.LdrRightValue());

Serial.print(” “);

Serial.print(Light.LdrLeftValue());

Serial.print(” “);

Serial.println(ldrRemove);

delay(30);

28

 

if (Light.LdrRightValue() > Light.LdrLeftValue() && ldrRemove > 80)

{

Light.Left(150,70);
}
if (Light.LdrRightValue() < Light.LdrLeftValue() && ldrRemove > 80)
{
Light.Right(70,150);

  }
if (ldrRemove < 80)
{
Light.Forward(150);

  }

}

29
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com
Code Hunters Our Car e-Journal (Common Product) by MRT  - Ourboox.com
This free e-book was created with
Ourboox.com

Create your own amazing e-book!
It's simple and free.

Start now

Ad Remove Ads [X]
Skip to content