Lima Moreira
Published © GPL3+

Funny Robot with Arduino

You'll learn how to create your first and funny robot with LED's and Arduino.

IntermediateFull instructions provided3 hours297
Funny Robot with Arduino

Things used in this project

Story

Read more

Custom parts and enclosures

Funny Robot - STL File

Schematics

Gerber Files - NEXTPCB Printed Circuit Board

Code

Source code

Arduino
void loop()
{
  // medida do sinal em centimetros
  cm = 0.01723 * readUltrasonicDistance(4, 5);
  // para converter o valor de centimetros em polegadas basta dividir por 2.54
  inches = (cm / 2.54);
  
  /*ANOTACOES
 distancia minima  3   
distancia maxima  336   
intervalo 333   
Quantidade de leds  8   
relação cm/leds = 41.625    
led_azul1 3 cm a 44.625 cm
led_azul2 44.625 cm  a 86.25 cm
led_amarelo1  86.25 cm a 127.875 cm
led_amarelo2  127.875 cm a 169.5 cm
led_vermelho1 169.5 cm a 211.125 cm
led_vermelho2 211.125 cm a 252.75 cm
led_verde1  252.75 cm  a 294.375 cm
led_verde2  294.375 cm a 336 cm

  */
  //INICIO - CONDICAO LEDS
  if((cm>=3)&&(cm<44.625)){
    digitalWrite(Led_azul1, HIGH);
    digitalWrite(Led_azul2, LOW);
    digitalWrite(Led_amarelol,LOW);
    digitalWrite(Led_amarelo2,LOW);
    digitalWrite(Led_vermelho1, LOW);
    digitalWrite(Led_vermelho2, LOW);
    digitalWrite(Led_verde1,LOW);
    digitalWrite(Led_verde2,LOW);
  }
  else if((cm>=44.625)&&(cm<86.25)){
    digitalWrite(Led_azul1,LOW);
    digitalWrite(Led_azul2,HIGH);
    digitalWrite(Led_amarelol,LOW);
    digitalWrite(Led_amarelo2,LOW);
    digitalWrite(Led_vermelho1, LOW);
    digitalWrite(Led_vermelho2, LOW);
    digitalWrite(Led_verde1,LOW);
    digitalWrite(Led_verde2,LOW);
  }
  else if((cm>=86.25)&&(cm<127.875)){
    digitalWrite(Led_azul1, LOW);
    digitalWrite(Led_azul2, LOW);
    digitalWrite(Led_amarelol,HIGH);
    digitalWrite(Led_amarelo2,LOW);
    digitalWrite(Led_vermelho1, LOW);
    digitalWrite(Led_vermelho2, LOW);
    digitalWrite(Led_verde1,LOW);
    digitalWrite(Led_verde2,LOW);
  }
  else if((cm>=127.875)&&(cm<169.5)){
    digitalWrite(Led_azul1, LOW);
    digitalWrite(Led_azul2, LOW);
    digitalWrite(Led_amarelol,LOW);
    digitalWrite(Led_amarelo2,HIGH);
    digitalWrite(Led_vermelho1, LOW);
    digitalWrite(Led_vermelho2, LOW);
    digitalWrite(Led_verde1,LOW);
    digitalWrite(Led_verde2,LOW);
  }
   else if((cm>=169.5)&&(cm<211.125)){
    digitalWrite(Led_azul1, LOW);
    digitalWrite(Led_azul2, LOW);
    digitalWrite(Led_amarelol,LOW);
    digitalWrite(Led_amarelo2,LOW);
    digitalWrite(Led_vermelho1, HIGH);
    digitalWrite(Led_vermelho2, LOW);
    digitalWrite(Led_verde1,LOW);
    digitalWrite(Led_verde2,LOW);
  }
   else if((cm>=211.125)&&(cm<252.75)){
    digitalWrite(Led_azul1, LOW);
    digitalWrite(Led_azul2, LOW);
    digitalWrite(Led_amarelol,LOW);
    digitalWrite(Led_amarelo2,LOW);
    digitalWrite(Led_vermelho1, LOW);
    digitalWrite(Led_vermelho2, HIGH);
    digitalWrite(Led_verde1,LOW);
    digitalWrite(Led_verde2,LOW);
  }
  else if((cm>=252.75)&&(cm<294.375)){
    digitalWrite(Led_azul1, LOW);
    digitalWrite(Led_azul2, LOW);
    digitalWrite(Led_amarelol,LOW);
    digitalWrite(Led_amarelo2,LOW);
    digitalWrite(Led_vermelho1, LOW);
    digitalWrite(Led_vermelho2, LOW);
    digitalWrite(Led_verde1,HIGH);
    digitalWrite(Led_verde2,LOW);
  }
  else if((cm>=294.375)&&(cm<336)){
    digitalWrite(Led_azul1, LOW);
    digitalWrite(Led_azul2, LOW);
    digitalWrite(Led_amarelol,LOW);
    digitalWrite(Led_amarelo2,LOW);
    digitalWrite(Led_vermelho1, LOW);
    digitalWrite(Led_vermelho2, LOW);
    digitalWrite(Led_verde1,LOW);
    digitalWrite(Led_verde2,HIGH);
  }
  //FIM - CONDICAO LEDS
  inches = (cm / 2.54);
  Serial.print(inches);Serial.print("in, ");Serial.print(cm);Serial.println("cm");delay(100); // aguarda 100 milisegundos
}

Credits

Lima Moreira

Lima Moreira

8 projects • 2 followers

Comments