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
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;
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){
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;}
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;
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);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
sure = pulseIn(echoPin, HIGH);
uzaklik = sure / 29.1 / 2;
Serial.println(uzaklik);
if (uzaklik < 15)
{
geri();
delay(150);
sag();
delay(250);
}
else {
ileri();
}
}
void ileri(){
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
analogWrite(MotorRE, 150);
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
analogWrite(MotorLE, 150);
}
void sag(){
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
analogWrite(MotorRE, 0);
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
analogWrite(MotorLE, 150);
}
void geri(){
digitalWrite(MotorR1, LOW);
digitalWrite(MotorR2, HIGH);
analogWrite(MotorRE, 150);
digitalWrite(MotorL1, LOW);
digitalWrite(MotorL2, HIGH);
analogWrite(MotorLE, 150);
}
“Line Follower” Car Codes
#define SensorSol 10
#define SensorOrta 11
#define SensorSag 12
void setup() {
pinMode(SensorSol, INPUT);
pinMode(SensorOrta, INPUT);
pinMode(SensorSag, INPUT);
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);
}
#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
void setup() {
pinMode(SensorSol, INPUT);
pinMode(SensorOrta, INPUT);
pinMode(SensorSag, INPUT);
pinMode(MotorR1, OUTPUT);
pinMode(MotorR2, OUTPUT);
pinMode(MotorL1, OUTPUT);
pinMode(MotorL2, OUTPUT);
}
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();
}
void ileri(){
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
analogWrite(MotorRE, 150);
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
analogWrite(MotorLE, 150);
}
void sag(){
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
analogWrite(MotorRE, 0);
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
analogWrite(MotorLE, 150);
}
void sol(){
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
analogWrite(MotorRE, 150);
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
analogWrite(MotorLE, 0);
}
void dur(){
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
digitalWrite(MotorRE, LOW);
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
digitalWrite(MotorLE, LOW);
}
Light Follower Robot Codes
#include <dmoto.h>
dmoto Light;
float ldrRemove =0;
void setup() {
Serial.begin(9600);
Light.pinSet();
Light.Stop();
}
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);
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);
}
}
Published: Oct 29, 2021
Latest Revision: Oct 29, 2021
Ourboox Unique Identifier: OB-1218589
Copyright © 2021