RC Auto with GPS on Arduino Nano Platform



My idea: to find out the maximum speed in the radio-controlled car and remembering when turning off the power, add turning on the headlights when speeding up, turning on turn signals when turning, turning on brake lights when braking, turning on side lights when parking, flashing lights when you press a button on the machine (maximum speed reset button) .

The machine that is used in the configuration:
  • Servo "HARD HS3004"
  • Engine "Leopard 4370KV";
  • Regulator for the Leopard V2 engine
  • Battery Li-Pol 7.2V 30C 5000mA;
  • Receiver "2.4Ghz" 3 channels;
  • 2.4Ghz Digital Proportional R / C system control panel

The task is to do with a typewriter:
  1. Set all lights and button
  2. Install arduino equipment
  3. Download the program in arduino
  4. Program setting

Installation of light lights. I took ready-made LEDs with wires from the RC Car Flashing Light System kit.


Installation of headlights (they are also dimensions) and turn signals


Installation of Nano and GPS arduino equipment, secured everything with double-sided tape and screws


LCD installation on the rear window, secured with screws

What is needed for assembly:
Arduino Nano, price from 200 r.
GPS receiver, price from 900 r.
LEDs, price from 100 r. / White LEDs, 3 pcs. (headlights and reverse), red 2 pcs. (brake), orange 2 pcs. (turn signals)
Wires, price from 100 r.
LCD and I2C, price from 200 r.
Button and resistor, price from 100 r. / Button (speed reset and flashing lights) and 10 kOhm resistor

The project price was 1600 rubles.

1. Arduino Nano



2. LCD 1602 and I2C


LCD


The back of the LCD and the I2C module soldered to it

3. GPS-GY-NEO-6MV2 (GPS receiver)


GPS receiver

Install the arduino program in the computer and upload the sketch to arduino.

If there is not enough library, then you need to download and install them on your computer: LiquidCrystal_I2C.h, EEPROM.h, Wire.h, SoftwareSerial.h, TinyGPS.h.

The sketch itself:
SKETCH
#include
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2); //I2C: SDA pin A4 / SCL pin A5 /VCC pin +3,3V /GND pin GND
#include
#include
TinyGPS gps;
SoftwareSerial ss(4, 3); // GPS: RX pin D4, TX pin D3, VCC pin +5V ,GND pin GND
static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
float flat, flon; //
unsigned long fix_age, time, date, speed, course; //
int value;
int value2;
int pin = 7; //поворотник D7
int pins = 8; //движение D8
int pin1 = 11;//Светодиод оранжевый: влево D11
int pin2 = 12;// Светодиод оранжевый: вправо D12
int pin3 = 10;// Светодиоды красные: тормоз D10
int pin4 = 9;// Светодиоды белые : вперед D9
int pin6 = 6;// Светодиод белый : задний ход D6
unsigned long duration1;//центр 1372 ,влево 1834 ,вправо973
unsigned long duration2;//тормоз 1834 ,вперед 973
int pin7 = 2;// Светодиод мигалка красная: pin D2
int pin8 = 13;// Светодиод мигалка синяя pin D13
const int buttonPin = 5; // Кнопка (сброса) номер входа, подключенный к кнопке pin D5
int buttonState = 0; // переменная для хранения состояния кнопки
void setup()
{
pinMode(pin, INPUT);
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pins, INPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin8, OUTPUT);
pinMode(buttonPin, INPUT); // инициализируем пин, подключенный к кнопке, как вход
Serial.begin(115200); //для отладки
ss.begin(9600); //gps
Serial.println("RRRR777");
lcd.init(); // инициализация ЖК
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("RRRR777 2015");
lcd.setCursor(0, 1);
lcd.print(" GPS RCavto");
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем с
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем с
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500);
digitalWrite(pin7, LOW); //
digitalWrite(pin8, LOW); //
delay(500); // ждем
lcd.clear();
delay(500);
}
void loop()
{
duration1 = pulseIn(pin, HIGH);
duration2 = pulseIn(pins, HIGH);
if ((duration1 > 1500) && (duration1 < 2000))
{digitalWrite(pin1, HIGH); // зажигаем светодиод LEFT
delay(250); // ждем секунду
digitalWrite(pin1, LOW); // выключаем светодиод
}
if ((duration1 < 1300) && (duration1 > 800))
{digitalWrite(pin2, HIGH); // зажигаем светодиод RIGHT
delay(250); // ждем секунду
digitalWrite(pin2, LOW); // выключаем светодиод
}
if ((duration2 > 1480) && (duration2 < 2000))//ФАРЫ
{ analogWrite(pin4, 20); //габариты задние
analogWrite(pin3, 255); // зажигаем светодиод фары
delay(500); // ждем
}
if ((duration2 < 1480) && (duration2 > 800)) //ТОРМОЗ
{analogWrite(pin4, 255); // светодиод тормоз
analogWrite(pin3, 20); // зажигаем светодиод фары габариты+*
digitalWrite(pin6, LOW); // выключаем светодиод
delay(50);
}
if ((duration2 < 1400) && (duration2 > 800))//Задний ход
{//digitalWrite(pin4, LOW); // зажигаем светодиод
digitalWrite(pin6, HIGH); // зажигаем светодиод
delay(500); // ждем секунду
}
float flat, flon;
unsigned long age, date, time, chars = 0;
unsigned short sentences = 0, failed = 0;
float h = gps.f_speed_kmph(); // speed in km/hr
int h1 = (h-(int)h)*100;
Serial.println(h);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Mersedes GT3"); // название машины
lcd.setCursor(0, 1);
lcd.print("S=");
lcd.print(h);
lcd.setCursor(8, 1);
lcd.print("MS=");
value = EEPROM.read(0); //чтение из памяти
value2 = EEPROM.read(1);
lcd.print(value);
lcd.print(".");
lcd.print(value2);
buttonState = digitalRead(buttonPin);// считываем значения с входа кнопки
if (buttonState == HIGH)// LOW) ///
{
EEPROM.write (0,0);
EEPROM.write (1,0);
lcd.setCursor(8, 1);
lcd.print("MS=RESET");
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем с
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500);
lcd.setCursor(0, 1);
lcd.print("Rusticktigr777@mail.ru");
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем с
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500);
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500); // ждем с
digitalWrite(pin8, HIGH); //
digitalWrite(pin7, LOW); //
delay(500); // ждем
digitalWrite(pin7, HIGH); //
digitalWrite(pin8, LOW); //
delay(500);
digitalWrite(pin7, LOW); //
digitalWrite(pin8, LOW); //
}
if (h > value)//RECORD
{
EEPROM.write (0,h);
EEPROM.write (1,h1);
}
smartdelay(500);
}
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
static void print_float(float val, float invalid, int len, int prec)
{
if (val == invalid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i Serial.print(' ');
}
smartdelay(0);
}
static void print_int(unsigned long val, unsigned long invalid, int len)
{
char sz[32];
if (val == invalid)
strcpy(sz, "*******");
else
sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i sz[i] = ' ';
if (len > 0)
sz[len-1] = ' ';
Serial.print(sz);
smartdelay(0);
}
static void print_date(TinyGPS &gps)
{
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long age;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
if (age == TinyGPS::GPS_INVALID_AGE)
Serial.print("********** ******** ");
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
month, day, year, hour, minute, second);
Serial.print(sz);
}
print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
smartdelay(0);
}


Connecting wires to arduino:
Wires
I2C: SDA pin A4 / SCL pin A5 / VCC pin + 3.3V / GND pin GND (set maximum brightness and backlight)
GPS: RX pin D4, TX pin D3, VCC pin + 5V, GND pin GND
Reset button (normally open button): one contact VCC pin + 5V, another contact on pin D5, resistor on pin D5 and pin GND
LEDs: Headlights (dimensions) white "+" on pin D9
LEDs: Lights on the rear (dimensions) red "+" on pin D10
LED: Reverse white “+” on pin D6
LEDs: Front lights (dimensions) white “+” on pin D9
LED: Turn left orange “+” on pin D11
LED: Turn right orange “+” on pin D12
LED: Flasher red "+" on pin D2
Light odiod: Flasher blue "+" on pin D13
For all LEDs “-” on pin GND We

connect the wire for the turn signals on pin D7 from the input of the servo turns (three wires are usually white to it and solder the wire to pin D7, red - power plus, black - power minus, connects to the receiver) .

We connect the wire for movement to pin D8 from the input of the engine servo (three wires: usually it is white, solder to it and output the wire to pin D8, red - power plus, black - power minus, connects to the receiver).

The power for Arduino is taken directly from the “+” battery to the VIN pin (in my 7.2V). Common GND wire for Arduino directly from the battery “-”.


Setting: if it does not work correctly when cornering or moving, then through the program on the computer we change the values ​​to our own: in the lines if ((durationX> XXXX) && (durationX <XXXXX)) if the data is not being processed and the green LED on the GPS, TX board is on / RX you may need to swap RX pin D4, TX pin D3,)

PS The idea turned out to be simple, knowing the programming, you can add the temperature in the engine and notification about it to this machine, add the hours, tachometer and video camera to the Mercedes-Benz GT3 .

Good luck to all!

Also popular now: