Hardware components | ||||||
![]() |
| × | 1 | |||
| × | 1 | ||||
![]() |
| × | 1 | |||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
![]() |
| × | 1 | |||
Hand tools and fabrication machines | ||||||
![]() |
| |||||
| ||||||
First, the chassis in wood and hard cardboard is fine for quick prototyping. And low cost.
1 / 4 • top view
The idea is to create an autonomous Car to be programmed by Arduino IDE.
1 / 5 • sonar ultrasonic sensor
Detail of the HC06 Bluetooth interfaces:
Top view
.........................................
If you did like this project you can donate some cents of Crypto currency
Bitcoins SV in the following address.
1sAZQMy5Ci1G88CmbucFJDsF7TxeXAcko
or bitcoin cash in the address:
qzmjpeqrlgd3flltpavm9t2xh0nz8y97mggajvvqnv
or Stellar XLM in the address:
GBAWDPQ4FTRXWE2ZUWVYYZ7XSCQGBYZGOWQMAHSA2FPGJ5QTLF4IJ3NX
thanks
#include "pitches.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX del arduino a los contrarios en el HC06.
int Trig=5;
int Echo=3;
int remoto=12;
int aux;
int INA=2;
int INB=4;
//int ENA=9;
int INC=7;
int IND=8;
//int ENB=10;
//Variable en la que se va a almacenar el valor correspondiente a la distancia
int Dist,Dist1,Dist2;
float LOutput,ROutput;
char blueToothVal; //value sent over via bluetooth
char lastValue; //stores last state of device (on/off)
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
void setup() {
pinMode (Trig, OUTPUT);
pinMode (Echo, INPUT);
pinMode (remoto, INPUT);
pinMode(INA,OUTPUT);
pinMode(INB,OUTPUT);
pinMode(INC,OUTPUT);
pinMode(IND,OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
ultrasonido (Dist);
Dist1=Dist;
aux=digitalRead(remoto);
if (aux==LOW)
{
movto();
}
else
{
Bluetooth();
delay(500);
}
}
void movto()
{
if (Dist>45)
{
//Adelante
LOutput=-1;
ROutput=1;
PWMControl();
}
else
{
//Hacia atrs
LOutput=1;
ROutput=-1;
PWMControl();
delay(1500);
//Gira en sentido horario, hacia la derecha
LOutput=1;
ROutput=1;
PWMControl();
delay(500);
}
}
void PWMControl(){
if(LOutput > 0){
digitalWrite(INA, HIGH);
digitalWrite(INB, LOW);
}
else if(LOutput < 0){
digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
}
else{
digitalWrite(INA, HIGH);
digitalWrite(INB, HIGH);
}
if(ROutput > 0){
digitalWrite(INC, HIGH);
digitalWrite(IND, LOW);
}
else if(ROutput < 0){
digitalWrite(INC, LOW);
digitalWrite(IND, HIGH);
}
else{
digitalWrite(INC, HIGH);
digitalWrite(IND, HIGH);
}
//analogWrite(ENA, min(255, abs(LOutput) + LMotor_offset));
//analogWrite(ENB, min(255, abs(ROutput) + RMotor_offset));
}
//Este mdulo calcula y devuelve la distancia en cm.
/*
Puedes poner el cdigo del mdulo directamente en el loop o utilizar el mdulo
para reducir el nmero de lneas de cdigo del loop o reutilizar el cdigo
*/
void ultrasonido (int &Distancia){
//Para estabilizar el valor del pin Trig se establece a LOW
digitalWrite (Trig, LOW);
delay(10);
//Se lanzan los 8 pulsos
digitalWrite (Trig, HIGH);
delay(10);
digitalWrite (Trig, LOW);
/*
Se mide el tiempo que tarda la seal en regresar y se calcula la distancia.
Observa que al realizar pulseIn el valor que se obtiene es tiempo, no distancia
Se est reutilizando la variable Distancia.
*/
Distancia= pulseIn (Echo, HIGH);
Distancia=Distancia/58;
delay(10);
}
void Bluetooth(){
if(mySerial.available())
{//if there is data being recieved
blueToothVal=mySerial.read(); //read it
switch (blueToothVal) {
case 'f':
LOutput=-1;
ROutput=1;
PWMControl();
mySerial.println("f = forward");
musica_inicio();
break;
case 'r':
LOutput=1;
ROutput=-1;
PWMControl();
mySerial.println("r = reverse");
break;
case 'i':
LOutput=-1;
ROutput=-1;
PWMControl();
mySerial.println("i = Izquierda");
break;
case 'd':
LOutput=1;
ROutput=1;
PWMControl();
mySerial.println("d = Derecha");
break;
default:
mySerial.println("f = forward , r = reverse , d = Derecha , i = Izquierda. Programa --> coche1.ino");
LOutput=0;
ROutput=0;
PWMControl();
break;
}
}
}
void musica_inicio()
{
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(9, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void musica()
{
// funcion = tone(pin, frequency, duration) Piratas del Caribe
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,100);
delay(100);
tone(9,293.66,100);
delay(100);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,100);
delay(100);
tone(9,293.66,100);
delay(100);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,200);
delay(200);
tone(9,293.66,100);
delay(100);
tone(9,293.66,100);
delay(100);
tone(9,440,100);
delay(100);
tone(9,523.25,100);
delay(100);
tone(9,587.33,100);
delay(200);
tone(9,587.33,100);
delay(200);
tone(9,587.33,100);
delay(100);
tone(9,659.25,100);
delay(100);
tone(9,698.45,100);
delay(200);
tone(9,698.45,100);
delay(200);
tone(9,698.45,100);
delay(100);
tone(9,783.99,100);
delay(100);
tone(9,659.25,100);
delay(200);
tone(9,659.25,100);
delay(200);
tone(9,587.33,100);
delay(100);
tone(9,523.25,100);
delay(100);
tone(9,523.25,100);
delay(100);
tone(9,587.33,100);
delay(300);
tone(9,440,100);
delay(100);
tone(9,523.25,100);
delay(100);
tone(9,587.33,100);
delay(200);
tone(9,587.33,100);
delay(200);
tone(9,587.33,100);
delay(100);
tone(9,659.25,100);
delay(100);
tone(9,698.45,100);
delay(200);
tone(9,698.45,100);
delay(200);
tone(9,698.45,100);
delay(100);
tone(9,783.99,100);
delay(100);
tone(9,659.25,100);
delay(200);
tone(9,659.25,100);
delay(200);
tone(9,587.33,100);
delay(100);
tone(9,523.25,100);
delay(100);
tone(9,587.33,100);
delay(400);
tone(9,440,100);
delay(100);
tone(9,523.25,100);
delay(100);
tone(9,587.33,100);
delay(200);
tone(9,587.33,100);
delay(200);
tone(9,587.33,100);
delay(100);
tone(9,698.45,100);
delay(100);
tone(9,783.99,100);
delay(200);
tone(9,783.99,100);
delay(200);
tone(9,783.99,100);
delay(100);
tone(9,880,100);
delay(100);
tone(9,932.33,100);
delay(200);
tone(9,932.33,100);
delay(200);
tone(9,880,100);
delay(100);
tone(9,783.99,100);
delay(100);
tone(9,880,100);
delay(100);
tone(9,587.33,100);
delay(300);
tone(9,587.33,100);
delay(100);
tone(9,659.25,100);
delay(100);
tone(9,698.45,100);
delay(200);
tone(9,698.45,100);
delay(200);
tone(9,783.99,100);
delay(200);
tone(9,880,100);
delay(100);
tone(9,587.33,100);
delay(300);
tone(9,587.33,100);
delay(100);
tone(9,698.45,100);
delay(100);
tone(9,659.25,100);
delay(200);
tone(9,659.25,100);
delay(200);
tone(9,698.45,100);
delay(100);
tone(9,587.33,100);
delay(100);
tone(9,659.25,100);
delay(400);
tone(9,880,100);
delay(100);
tone(9,1046.50,100);
delay(100);
tone(9,1174.66,100);
delay(200);
tone(9,1174.66,100);
delay(200);
tone(9,1174.66,100);
delay(100);
tone(9,1318.51,100);
delay(100);
tone(9,1396.91,100);
delay(200);
tone(9,1396.91,100);
delay(200);
tone(9,1396.91,100);
delay(100);
tone(9,1567.98,100);
delay(100);
tone(9,1318.51,100);
delay(200);
tone(9,1318.51,100);
delay(200);
tone(9,1174.66,100);
delay(100);
tone(9,1046.50,100);
delay(100);
tone(9,1046.50,100);
delay(100);
tone(9,1174.66,100);
delay(300);
tone(9,880,100);
delay(100);
tone(9,1046.50,100);
delay(100);
tone(9,1174.66,100);
delay(200);
tone(9,1174.66,100);
delay(200);
tone(9,1174.66,100);
delay(100);
tone(9,1318.51,100);
delay(100);
tone(9,1396.91,100);
delay(200);
tone(9,1396.91,100);
delay(200);
tone(9,1396.91,100);
delay(100);
tone(9,1567.98,100);
delay(100);
tone(9,1318.51,100);
delay(200);
tone(9,1318.51,100);
delay(200);
tone(9,1174.66,100);
delay(100);
tone(9,1046.50,100);
delay(100);
tone(9,1174.66,100);
delay(400);
tone(9,880,100);
delay(100);
tone(9,1046.50,100);
delay(100);
tone(9,1174.66,100);
delay(200);
tone(9,1174.66,100);
delay(200);
tone(9,1174.66,100);
delay(100);
tone(9,1396.91,100);
delay(100);
tone(9,1567.98,100);
delay(200);
tone(9,1567.98,100);
delay(200);
tone(9,1567.98,100);
delay(100);
tone(9,1760,100);
delay(100);
tone(9,1864.66,100);
delay(200);
tone(9,1864.66,100);
delay(200);
tone(9,1760,100);
delay(100);
tone(9,1567.98,100);
delay(100);
tone(9,1760,100);
delay(100);
tone(9,1174.66,100);
delay(300);
tone(9,1174.66,100);
delay(100);
tone(9,1318.51,100);
delay(100);
tone(9,1396.91,100);
delay(200);
tone(9,1396.91,100);
delay(200);
tone(9,1567.98,100);
delay(200);
tone(9,1760,100);
delay(100);
tone(9,1174.66,100);
delay(300);
tone(9,1174.66,100);
delay(100);
tone(9,1396.91,100);
delay(100);
tone(9,1318.51,100);
delay(200);
tone(9,1318.51,100);
delay(200);
tone(9,1174.66,100);
delay(100);
tone(9,1108.73,100);
delay(100);
tone(9,1174.66,100);
delay(200);
tone(9,1174.66,100);
delay(200);
tone(9,1318.51,100);
delay(200);
tone(9,1396.91,100);
delay(200);
tone(9,1396.91,100);
delay(100);
tone(9,1396.91,100);
delay(100);
tone(9,1567.98,100);
delay(200);
tone(9,1760,300);
delay(400);
tone(9,1396.91,100);
delay(100);
tone(9,1174.66,100);
delay(100);
tone(9,880,300);
delay(600);
tone(9,1864.66,300);
delay(400);
tone(9,1396.91,100);
delay(100);
tone(9,1174.66,100);
delay(100);
tone(9,932.33,300);
delay(600);
tone(9,587.33,100);
delay(100);
tone(9,440,100);
delay(200);
tone(9,587.33,100);
delay(300);
tone(9,554.36,100);
delay(400);
tone(9,1567.98,100);
delay(100);
tone(9,1567.98,100);
delay(100);
}




_ztBMuBhMHo.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)



_3u05Tpwasz.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)
Comments