Foto del robot
Ficheros stl
Lista de componentes
Dos comportamientos, autónomo y dirigido
Conexiones.
Sensor de distancia HC-04:
- pin 7 -> triger
- pin 8 -> echo
- GND
- 5v
Matriz 8×8:
- pin 10 -> cs
- pin 11 -> din
- pin 13 -> clk
- GND
- 5v
Control de Motores L9110:
- pin 3 -> motor A-1B
- pin 5 -> motor A-1A
- pin 6 -> motor B-1B
- pin 9 -> motor B-1A
- GND
- 5v
Bluetooth.
- pin 2 a RX de bluetooth
- pin 4 a TX de bluetooth
Esquema de conexiones.
Código de test de motores.
const int AIB = 5;
const int BIA = 6;
const int BIB = 9;byte velo1 = 220;
byte velo2 = 220;void setup(){
pinMode(AIA, OUTPUT);
pinMode(AIB, OUTPUT);
pinMode(BIA, OUTPUT);
pinMode(BIB, OUTPUT);
parar();
Serial.begin(9600);
Serial.println(«En el setup»);
}
void loop(){
Serial.println(«avanza»);
avanza();
delay(2000);
Serial.println(«stop»);
parar();
delay(2000);
Serial.println(«atras»);
retroceder();
delay(2000);
Serial.println(«stop»);
parar();
delay(2000);
}
void avanza() {
analogWrite(AIA, velo1);
analogWrite(AIB, 0);
analogWrite(BIA, velo2);
analogWrite(BIB, 0);
delay(50);
}
void parar() {
analogWrite(AIA, 0);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, 0);
delay(50);
}
void retroceder() {
analogWrite(AIA, 0);
analogWrite(AIB, velo1);
analogWrite(BIA, 0);
analogWrite(BIB, velo2);
delay(50);
}
void derecha() {
analogWrite(AIA, velo1);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, velo2);
delay(50);
}
void izquierda() {
analogWrite(AIA, 0);
analogWrite(AIB, velo1);
analogWrite(BIA, velo2);
analogWrite(BIB, 0);
delay(50);
}
Código de test de matriz 8×8.
#include «LedControlMS.h»
#define NumMatrix 1 // Cuantas matrices vamos a usar
int randomNumber;
// por la posición de la matriz la imáganes las diseñamos giradas
char tmp = ‘8’;const uint64_t IMAGES[] = {
0x10387cfe38383838,
0x0010307fff7f3010,
0x38383838fe7c3810,
0x003c428181423c00,
0x180c060303060c18
};
const int IMAGES_LEN = sizeof(IMAGES)/8;LedControl lc = LedControl(12, 11, 10, NumMatrix); // Creamos una instancia de LedControlvoid setup()
{
for (int i = 0; i < NumMatrix ; i++)
{
lc.shutdown(i, false); // Activar las matrices
lc.setIntensity(i, 8); // Poner el brillo a un valor intermedio
lc.clearDisplay(i); // Y borrar todo
}
// randomSeed(analogRead(A0)); //Establecemos la semilla fija
for (int i = 5; i >= 0; i++) {
// randomNumber = random(0, 10); //Genera un numero aleatorio entre 0 y 9
// lc.displayChar(0, randomNumber);
lc.displayChar(0, i);
delay(1000);
}
}
int i = 0;
void loop() {
displayImage(IMAGES[i]);
if (++i >= IMAGES_LEN ) {
i = 0;
}
delay(100);
}void displayImage(uint64_t image) {
for (int i = 0; i < 8; i++) {
byte row = (image >> i * 8) & 0xFF;
for (int j = 0; j < 8; j++) {
lc.setLed(0, i, j, bitRead(row, j));
}
}
}
Código de test sensor distancia.
#define echoPin 8 // Arduino pin tied to echo pin on the ultrasonic sensor.void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}void loop() {
// put your main code here, to run repeatedly:
long duracion, distancia ;
digitalWrite(trigPin, LOW); // trigger desactivado
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // Activamos el pulso
delayMicroseconds(10); // Esperamos 10µs.
digitalWrite(trigPin, LOW); // Cortamos el pulso
duracion = pulseIn(echoPin, HIGH) ;
distancia = duracion * 0.017 ;
if (distancia >=200) distancia =0;
Serial.println(String(distancia)) ;
}
Código de test de bluetooth.
// pin 2 Rx de Bluetooth
// pin 4 Tx de Bluetooth
SoftwareSerial mySerial(4, 2); // RX, TXvoid setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println(«Goodnight moon!»);// set the data rate for the SoftwareSerial port
}void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}