Mecanum Robot
We developed a robotic car using Mecanum wheels, an Arduino Mega, and TT motors. To fully leverage the 12 distinct movement capabilities of the Mecanum wheels, we wrote a custom control code. Additionally, we created a mobile application with MIT App Inventor to seamlessly control the robot's movements, ensuring both precision and user-friendly operation. We also integrated a parking sensor into the robotic car. The system features a visual indicator that lights up purple when there are no obstacles ahead and transitions to green, yellow, and red as the robot approaches an object. A buzzer is activated in the yellow and red zones to provide additional warnings. When the red light is triggered, indicating that the robot is very close to a collision, we programmed the motors to stop immediately, ensuring safety and preventing impact.
Supplies
Mecnum Robot project supplies
-Mecanum wheel x 4
-Ardunio Mega
-TT motor or yellow geared motor x 4
-Buzzer
-220ohm resistor x 3
-RGB diode led
-Jumper cable
-HC-05 Bluetooth module
-Small Breadboard
-Ultrasonic Sensor Sonar Distance 40khz
-Arduino Motor Shield (based on the L298N motor driver)
- 100nF ceramic capacitor x 4
-LiPo battery pack
Coding on Ardunio
#include <AFMotor.h> // Adafruit motor kütüphanesi
// Motor tanımlamaları
AF_DCMotor motorFrontRight(3);
AF_DCMotor motorFrontLeft(4);
AF_DCMotor motorBackRight(2);
AF_DCMotor motorBackLeft(1);
// mesafe_on sens. ön
int trigPin_on = 33;
int echoPin_on = 31;
// mesafe_on sens. arka
int trigPin_arka = 32;
int echoPin_arka = 34;
// Buzzer
int buzzerPin = 38;
// sağ ön
int redPin_sag_on = A13;
int bluePin_sag_on = A14;
int greenPin_sag_on = A15;
// sağ arka
int redPin_sag_arka = A12;
// sol arka
int redPin_sol_arka = A6;
// sol ön
int redPin_sol_on = A9;
int bluePin_sol_on = A8;
int greenPin_sol_on = A7;
char currentCommand = 's'; // Varsayılan olarak durma komutu
long sure_on;
long mesafe_on;
long sure_arka;
long mesafe_arka;
// Zamanlama için değişkenler
unsigned long previousMillis = 0;
const long ledInterval = 100; // LED'ler için zaman aralığı
void setup() {
Serial.begin(9600); // USB üzerinden iletişim
Serial1.begin(9600); // Bluetooth modülü ile iletişim
Serial.println("Bluetooth motor kontrol sistemi başlatıldı.");
// Motor başlangıç ayarları
motorFrontRight.setSpeed(0);
motorFrontLeft.setSpeed(0);
motorBackRight.setSpeed(0);
motorBackLeft.setSpeed(0);
motorFrontRight.run(RELEASE);
motorFrontLeft.run(RELEASE);
motorBackRight.run(RELEASE);
motorBackLeft.run(RELEASE);
// Sensör ve LED pinlerini çıkış olarak ayarla
//mesafe_on ön
pinMode(trigPin_on, OUTPUT);
pinMode(echoPin_on, INPUT);
//mesafe_on arka
pinMode(trigPin_arka, OUTPUT);
pinMode(echoPin_arka, INPUT);
pinMode(buzzerPin, OUTPUT);
//sağ ön çıkış pinleri
pinMode(redPin_sag_on, OUTPUT);
pinMode(bluePin_sag_on, OUTPUT);
pinMode(greenPin_sag_on, OUTPUT);
//sağ arka
pinMode(redPin_sag_arka, OUTPUT);
//sol ön
pinMode(redPin_sol_on, OUTPUT);
pinMode(bluePin_sol_on, OUTPUT);
pinMode(greenPin_sol_on, OUTPUT);
//sol arka
pinMode(redPin_sol_arka, OUTPUT);
}
void loop() {
// Bluetooth üzerinden komut al
if (Serial1.available()) {
char command = Serial1.read();
Serial.print("Gelen komut: ");
Serial.println(command);
currentCommand = command; // Gelen komutu kaydet
kontrolHareketleri(currentCommand); // Motor kontrol fonksiyonunu çağır
}
// mesafe_on sensörü ölçümünü güncelle
mesafe_onOlc_on();
// LED ve buzzer kontrolü (zamanlama ile)
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= ledInterval) {
previousMillis = currentMillis; // Zamanlayıcıyı sıfırla
ledVeBuzzerKontrol_on(); // LED ve buzzer kontrolü
}
}
// Hareket Fonksiyonları
void kontrolHareketleri(char(komut)) {
switch (komut) {
case 'f':
hareketIleri();
break;
case 'x':
hareketGeri();
break;
case 'e':
hareketSagyukarikay();
break;
case 'q':
hareketSolyukariKay();
break;
case 's':
Dur();
break;
case 'd':
SagaGit();
break;
case 'a':
SolaGit();
break;
case 't':
Don();
break;
case 'k':
SolaDon();
break;
case 'u':
SagaDon();
break;
case 'c':
SagaArkaKay();
break;
case 'z':
SolaArkaKay();
break;
default:
Dur();
break;
}
}
void hareketIleri() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(200);
motorFrontLeft.run(FORWARD);
motorFrontRight.run(FORWARD);
motorBackLeft.run(FORWARD);
motorBackRight.run(FORWARD);
}
void hareketGeri() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(200);
motorFrontLeft.run(BACKWARD);
motorFrontRight.run(BACKWARD);
motorBackLeft.run(BACKWARD);
motorBackRight.run(BACKWARD);
}
void hareketSolyukariKay() {
motorFrontLeft.setSpeed(0);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(0);
motorFrontLeft.run(RELEASE);
motorFrontRight.run(FORWARD);
motorBackLeft.run(FORWARD);
motorBackRight.run(RELEASE);
}
void hareketSagyukarikay() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(0);
motorBackLeft.setSpeed(0);
motorBackRight.setSpeed(200);
motorFrontLeft.run(FORWARD);
motorFrontRight.run(RELEASE);
motorBackLeft.run(RELEASE);
motorBackRight.run(FORWARD);
}
void Dur() {
motorFrontLeft.setSpeed(0);
motorFrontRight.setSpeed(0);
motorBackLeft.setSpeed(0);
motorBackRight.setSpeed(0);
motorFrontLeft.run(RELEASE);
motorFrontRight.run(RELEASE);
motorBackLeft.run(RELEASE);
motorBackRight.run(RELEASE);
}
void SagaGit() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(200);
motorFrontLeft.run(FORWARD);
motorFrontRight.run(BACKWARD);
motorBackLeft.run(BACKWARD);
motorBackRight.run(FORWARD);
}
void SolaGit() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(200);
motorFrontLeft.run(BACKWARD);
motorFrontRight.run(FORWARD);
motorBackLeft.run(FORWARD);
motorBackRight.run(BACKWARD);
}
void Don() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(200);
motorFrontLeft.run(FORWARD);
motorFrontRight.run(BACKWARD);
motorBackLeft.run(FORWARD);
motorBackRight.run(BACKWARD);
}
void SolaDon() {
motorFrontLeft.setSpeed(0);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(0);
motorBackRight.setSpeed(200);
motorFrontLeft.run(RELEASE);
motorFrontRight.run(FORWARD);
motorBackLeft.run(RELEASE);
motorBackRight.run(FORWARD);
}
void SagaDon() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(0);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(0);
motorFrontLeft.run(FORWARD);
motorFrontRight.run(RELEASE);
motorBackLeft.run(FORWARD);
motorBackRight.run(RELEASE);
}
void SagaArkaKay() {
motorFrontLeft.setSpeed(0);
motorFrontRight.setSpeed(200);
motorBackLeft.setSpeed(200);
motorBackRight.setSpeed(0);
motorFrontLeft.run(RELEASE);
motorFrontRight.run(BACKWARD);
motorBackLeft.run(BACKWARD);
motorBackRight.run(RELEASE);
}
void SolaArkaKay() {
motorFrontLeft.setSpeed(200);
motorFrontRight.setSpeed(0);
motorBackLeft.setSpeed(0);
motorBackRight.setSpeed(200);
motorFrontLeft.run(BACKWARD);
motorFrontRight.run(RELEASE);
motorBackLeft.run(RELEASE);
motorBackRight.run(BACKWARD);
}
// Ön mesafe_on ölçüm fonksiyonu
void mesafe_onOlc_on() {
digitalWrite(trigPin_on, LOW);
delayMicroseconds(2);
digitalWrite(trigPin_on, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin_on, LOW);
sure_on = pulseIn(echoPin_on, HIGH, 30000);
mesafe_on = (sure_on / 2) / 29.1;
}
// Arka mesafe_on ölçüm fonksiyonu
void mesafe_onOlc_arka() {
digitalWrite(trigPin_arka, LOW);
delayMicroseconds(2);
digitalWrite(trigPin_arka, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin_arka, LOW);
sure_arka = pulseIn(echoPin_arka, HIGH, 30000);
mesafe_arka = (sure_arka / 2) / 29.1;
}
// LED ve buzzer kontrolü
void ledVeBuzzerKontrol_on() {
if (mesafe_on > 0 && mesafe_on <= 5) {
motorFrontLeft.setSpeed(0);
motorFrontRight.setSpeed(0);
motorBackLeft.setSpeed(0); // DURDUR
motorBackRight.setSpeed(0);
motorFrontLeft.run(RELEASE);
motorFrontRight.run(RELEASE);
motorBackLeft.run(RELEASE);
motorBackRight.run(RELEASE);
ledKontrol_on(255, 0, 0); // Kırmızı LED
digitalWrite(buzzerPin, HIGH);
delay(100);
ledKontrol_on(0,0,0); //kapat
digitalWrite(buzzerPin, LOW);
delay(100);
} else if (mesafe_on > 5 && mesafe_on <= 15) {
ledKontrol_on(255, 255, 0); // Sarı LED
digitalWrite(buzzerPin, HIGH);
delay(200);
ledKontrol_on(0,0,0); //kapat
digitalWrite(buzzerPin, LOW);
delay(200);
} else if (mesafe_on > 15 && mesafe_on <= 25) {
ledKontrol_on(0, 255, 0); // Yeşil LED
digitalWrite(buzzerPin, LOW);
delay(300);
ledKontrol_on(0,0,0); //kapat
digitalWrite(buzzerPin, LOW);
delay(300);
} else if (mesafe_on > 25) {
ledKontrol_on(255, 0, 255); // Mor LED
digitalWrite(buzzerPin, LOW);
}
}
// ARKA LED ve buzzer kontrolü
void ledVeBuzzerKontrol_arka() {
if (mesafe_arka > 0 && mesafe_arka <= 10) {
digitalWrite(redPin_sag_arka, HIGH);
digitalWrite(redPin_sol_arka, HIGH); // Kırmızı LED
digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(redPin_sag_arka, LOW);
digitalWrite(redPin_sol_arka, LOW);
digitalWrite(buzzerPin, LOW);
delay(100);
}
}
// Ön LED kontrol fonksiyonu
void ledKontrol_on(int red, int green, int blue) {
analogWrite(redPin_sag_on, red);
analogWrite(greenPin_sag_on, green);
analogWrite(bluePin_sag_on, blue);
analogWrite(redPin_sol_on, red);
analogWrite(redPin_sol_on, green);
analogWrite(redPin_sol_on, blue);
}
Downloads
ThinkerCad
// Pin tanımlamaları
const int trigPin = 7;
const int echoPin = 6;
const int ledPin = 8;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Seri haberleşme başlat
}
void loop() {
// Mesafe ölçümü
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
int distance = duration * 0.034 / 2; // Mesafeyi cm cinsinden hesapla
// Mesafe bilgisine göre yanıp sönme hızını ayarla
int delayTime;
if (distance <= 10) { // Çok yakın
delayTime = 100; // Hızlı yanıp sönme
} else if (distance <= 30) { // Orta mesafe
delayTime = 300; // Orta hız
} else { // Uzak
delayTime = 700; // Yavaş yanıp sönme
}
// LED'i yanıp söndür
digitalWrite(ledPin, HIGH);
delay(delayTime);
digitalWrite(ledPin, LOW);
delay(delayTime);
// Mesafeyi seri monitöre yazdır
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
}