domingo, 19 de junho de 2016

Testes de verde: OBR 2016

Para quem está nos ajudando através do Vakinha, fizemos os testes de verde do robô e o GAP (interrupção de linha). São 7 meses pesquisando como fazer um sensor de cor para verde e, no final, bastou usar uma solução simples que encontramos o Laboratório de Garagem.
"Se eu vi mais longe, foi por estar sobre ombros de gigantes."
Issac Newton

Fonte: http://arduino.labdegaragem.com/Guia_preview/SPK_9_cores_ldr.html

segunda-feira, 13 de junho de 2016

Desviar do Akira

#include <Servo.h>

// Teste de motor
Servo motor_d;
Servo motor_e;

void setup() {
  // put your setup code here, to run once:
motor_d.attach (4);
motor_e.attach (5);
pare();
}

void loop() {
  // put your main code here, to run repeatedly;
  delay (3000);
  direita();
  delay (870);
  pare ();
  frente();
  delay (1538);
  esquerda();
  delay (800);
  frente();
  delay (3207);
  esquerda();
  delay (800);
  pare();
  frente();
  delay (1538);
  direita();
  pare();
  delay (5000);
}

void re(){
  motor_d.write (180);
  motor_e.write (70);
}
void frente(){
  motor_d.write (0);
  motor_e.write (110);
}
void direita(){
  motor_d.write (180);
  motor_e.write (130);
}
void esquerda(){
  motor_d.write (0);
  motor_e.write (50);
}
void pare(){
  motor_d.write (90);
  motor_e.write (90);
}





sexta-feira, 3 de junho de 2016

Controle do aspirador com sensor de ultrassom

//Controle do aspirador com sensor de ultrassom
#include <Servo.h>

Servo braco;

int const abaixar = 140;
int const levantar = 5;

int emissor = 9;
int receptor = 10;
long duration, cm;

void setup() {
  // put your setup code here, to run once:
pinMode (12, OUTPUT);
braco.attach (7);

pinMode (emissor, OUTPUT);
pinMode (receptor, INPUT);
braco.write (levantar);
Serial.begin (9600);
}

void loop() {
  sonar();
  delay (100);
  Serial.println (cm);
  if (cm==12){
  // baixar
  for (int x=levantar; x<abaixar; x++){
  braco.write (x);
  delay (6);
  Serial.println (braco.read());
  }
 
//Liga o ventilador
digitalWrite (12, HIGH);
delay (2500);

// levantar
 for (int x=abaixar; x>levantar; x--){
  braco.write (x);
  delay (6);
  Serial.println (braco.read());
  }

//desliga o ventilador
digitalWrite (12, LOW);
delay (2500);
/*
//abaixar
for (int x=levantar; x<abaixar; x++){
  braco.write (x);
  delay (6);
  }
delay (7000);
*/  }

}

int sonar(){
  digitalWrite(emissor, LOW);
  delayMicroseconds(2);
  digitalWrite(emissor, HIGH);
  delayMicroseconds(5);
  digitalWrite(emissor, LOW);
 
  duration = pulseIn(receptor, HIGH);

  cm = microsecondsToCentimeters(duration);

return cm;
}


long microsecondsToCentimeters(long microseconds)
{
 
  return microseconds / 29 / 2;
}

quinta-feira, 2 de junho de 2016

Calibração de sensores - Wall-e e Akira

long duration, inches, cm;
 int emissor = 9;
 int receptor=10;

void setup() {
Serial.begin (9600);
 pinMode(emissor, OUTPUT);
  pinMode(receptor, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  delay (250);
  int ir_d = analogRead(A1);
  int ir_e = analogRead(A2);
  int sensor_d = analogRead(A3);
  int sensor_e = analogRead(A4);
  sonar();
   Serial.print(ir_d);
  Serial.print(", ");
 Serial.print(ir_e);
  Serial.print(", ");
  Serial.print(sensor_d);
  Serial.print(", ");
 Serial.println(sensor_e);
 Serial.print(", ");
 Serial.println(cm);
  Serial.println();
}

  int sonar(){
  digitalWrite(emissor, LOW);
  delayMicroseconds(2);
  digitalWrite(emissor, HIGH);
  delayMicroseconds(10);
  digitalWrite(emissor, LOW);
  duration = pulseIn(receptor, HIGH);

  // convert the time into a distance

  cm = microsecondsToCentimeters(duration);
return cm;
 }

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}