spionjaakm
Published

Bluetooth Car

Bluetooth Car with solar panel

IntermediateShowcase (no instructions)8 hours158
Bluetooth Car

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
DC Motor, 12 V
DC Motor, 12 V
×4
LDR, 5 Mohm
LDR, 5 Mohm
×1
LED (generic)
LED (generic)
×4
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
Battery, 3.7 V
Battery, 3.7 V
×1
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

screenshot_4_HddBafUm0y.png

Code

Untitled file

Arduino
#include <AFMotor.h>

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

#define OLED_RESET     4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000
};

AF_DCMotor M1(1);
AF_DCMotor M2(3);
AF_DCMotor M3(2);
AF_DCMotor M4(4);

char bluetooth = 0;

int switchLights = 24;
int sensorLights = A0;


int frontLights = 22;
int backLights = 23;


int statsSwitch = 0;
int statsSensorLights = 0;
int LaststatsSensorLights = 0;
int statsLights = 0;
int lastStatsLights = 0;
int lights = 0;

int speeds = 250;
int lastSpeed;

String directions, lastDirection;



void setup() {

  Serial.begin(9600);

  M1.setSpeed(speeds);
  M2.setSpeed(speeds);
  M3.setSpeed(speeds);
  M4.setSpeed(speeds);
  M1.run(RELEASE);
  M2.run(RELEASE);
  M3.run(RELEASE);
  M4.run(RELEASE);


  pinMode(frontLights, OUTPUT);
  pinMode(backLights, OUTPUT);
  pinMode(switchLights, INPUT);
  pinMode(sensorLights, INPUT);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
  display.display();
  delay(2000);


  display.clearDisplay();

  display.setTextSize(1.5);
  display.setTextColor(WHITE);
  display.setCursor(10, 0);
  display.println(F("BT CAR"));
  display.setCursor(10, 16);
  display.println(F("By SpionjaakM"));


  display.display();
  delay(2000);

  display.clearDisplay();






}

void loop() {

  M1.setSpeed(speeds);
  M2.setSpeed(speeds);
  M3.setSpeed(speeds);
  M4.setSpeed(speeds);

  Light();
  if (Serial.available() > 0) {
    bluetooth = Serial.read();
    Serial.println(bluetooth);
  }
  if (bluetooth == '0')Stop();
  if (bluetooth == '1')forward();
  if (bluetooth == '2')backward();
  if (bluetooth == '3')left();
  if (bluetooth == '4')right();
  if (bluetooth == '+')speeds = speeds + 30;
  if (bluetooth == '-')speeds = speeds - 30;
  if (bluetooth == 's')statsLights++;

  bluetooth = 0;


  if (speeds > 250) speeds = 250;
  if (speeds < 130) speeds = 130;

  statsSensorLights = analogRead(sensorLights);
  statsSwitch = digitalRead(switchLights);
  if (statsSwitch == 1) {
    statsLights++;
    delay(500);
  }

  switch (statsLights) {

    case 3:
      statsLights = 1;
      break;

    default:
      break;

  }
  outputDisplay();




}



void outputDisplay() {

  if (lastStatsLights != lights  || LaststatsSensorLights != statsSensorLights) {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0, 0);
    display.print(F("Outside lights:"));
    if (statsSensorLights <= 200) {
      display.println(F(" NO"));
    }
    else {
      display.println(F(" YES"));
    }
    display.setCursor(0, 10);
    display.print(F("LIGHTS:"));
    if (lights == 1) display.println(F(" ON"));
    if (lights == 0) display.println(F(" OFF"));

    display.setCursor(0, 20);
    display.println(F("By SpionjaakM"));


    display.display();



    lastStatsLights = lights;
    LaststatsSensorLights = statsSensorLights;

  }

  else if (lastDirection != directions || lastSpeed != speeds) {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0, 0);
    display.print(F("DIRECTION: "));
    display.println(directions);
    display.setCursor(0, 10);
    display.print(F("SPEED: "));
    display.println(speeds);
    display.setCursor(0, 20);
    display.println(F("By SpionjaakM"));


    display.display();



    lastDirection = directions;
    lastSpeed = speeds;


  }











  /*display.clearDisplay();

    display.setTextSize(1.5);
    display.setTextColor(WHITE);
    display.setCursor(10, 0);
    display.println(F("BT CAR"));
    display.setCursor(10, 16);
    display.println(F("BY SPIONJAAKM"));


    display.display();*/

}


void Light() {
  if (statsSensorLights <= 200 || statsLights == 1) {

    digitalWrite(backLights, HIGH);
    digitalWrite(frontLights, HIGH);
    lights = 1;
  }


  else {
    digitalWrite(backLights, LOW);
    digitalWrite(frontLights, LOW);
    lights = 0;
  }


}


void Stop() {

  directions = "Stop";
  M1.run(RELEASE);
  M2.run(RELEASE);
  M3.run(RELEASE);
  M4.run(RELEASE);

}
void forward() {

  directions = "FORWARD";
  M1.run(FORWARD);
  M2.run(FORWARD);
  M3.run(FORWARD);
  M4.run(FORWARD);
}
void backward() {

  directions = "BACKWARD";
  M1.run(BACKWARD);
  M2.run(BACKWARD);
  M3.run(BACKWARD);
  M4.run(BACKWARD);
}
void left() {

  directions = "LEFT";
  M1.run(BACKWARD);
  M2.run(FORWARD);
  M3.run(BACKWARD);
  M4.run(FORWARD);
}
void right() {

  directions = "right";
  M1.run(FORWARD);
  M2.run(BACKWARD);
  M3.run(FORWARD);
  M4.run(BACKWARD);
}

Credits

spionjaakm
1 project • 0 followers

Comments