Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
![]() |
| |||||
Hand tools and fabrication machines | ||||||
![]() |
| |||||
![]() |
| |||||
![]() |
|
We came to the competition and just did all we could with little prep. There are three arduinos made to complete three main functions: motion, animation, and writing.
The project is controlled via IR remote, and it has an animated face on the back on the LCD screen. There is a weapon added to the front, and a writing component was designed and built to be added. However, it did not make the final iteration.
#include <Servo.h>
Servo ml,mr;
int i,j;
float pi= 3.1428;
float l=6; //l = 6 cm length of link
float x,y,dl,dr,hl,hr;
float pl1,pl2,pr1,pr2;
int tl,tr;
float angle_left(float x, float y){
Serial.println("Left : ");
dl= sqrt((x*x)+(y*y)); //distace between origin left and (x,y) point
hl=sqrt((l*l)-((dl/2)*(dl/2))); //height of the triangle
pl1=atan2(hl,dl/2); // phi 1, angle between d and axis
pl2=atan2(y,x); // phi 2, angle between d and l
tl= (pl1+pl2)*180/pi; // anglie between axis and l
Serial.println(hl);
Serial.println(pl1*180/pi);
Serial.println(pl2*180/pi);
Serial.println(tl);
return tl;
}
float angle_right(float x, float y){
x-=6;
Serial.println("Right : ");
dr= sqrt(((x)*(x))+(y*y)); //distace between origin right and (x,y) point
hr=sqrt((l*l)-((dr/2)*(dr/2))); //height of the triangle
pr1=atan2(hr,dr/2); // phi 1, angle between d and axis
pr2= atan2(y,x); // phi 2, angle between d and l
tr=(pr2-pr1)*180/pi;
Serial.println(hr);
Serial.println(pr1*180/pi);
Serial.println(pr2*180/pi);
Serial.println(tr);
return tr;
}
// Extreme Left Point
void xleft(){
mr.write(110);
ml.write(110);
}
// Extreme Right Point
void xright(){
mr.write(45);
ml.write(45);
}
// Extreme Top Point
void xtop(){
mr.write(90);
ml.write(90);
}
//Extreme Bottom Point
void xbottom(){
mr.write(60);
ml.write(120);
}
void vertical_straight_line(){
x=3;
y=6;
for(y=6;y<12;y+=0.5){
ml.write(angle_left(x,y));
mr.write(angle_right(x,y));
delay(50);
}
for(y=11;y>5;y-=0.5){
ml.write(angle_left(x,y));
mr.write(angle_right(x,y));
delay(50);
}
}
void horizontal_straight_line(){
x=0;
y=6;
for (x;x<7;x+=1){
ml.write(angle_left(x,y));
mr.write(angle_right(x,y));
delay(500);
}
}
void setup() {
ml.attach(5);
mr.attach(6);
Serial.begin(9600);
}
void loop() {
int i[2][2] = {{3,3},{3,0}};
int v[3][2] = {{2,3},{3,0},{4,3}};
int a[5][2] = {{3,4},{1,2},{3,0},{5,2},{5,0}};
int n[3][2] = {{2,0},{2,3},{5,0}};
//int a[8][2]={{1, 1}, {0, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 2}, {3, 1}, {2, 1}}; //making 0
//int a[12][2]={{1, 1}, {0, 2}, {0, 3}, {1, 4}, {2, 5}, {3, 5}, {4, 4}, {5, 3}, {5, 2}, {4, 1}, {3, 0}, {2, 0}}; //making O or diamond
//int a[12][2]={{0,0}, {1,1}, {2,2}, {3,3}, {4,4}, {5,5},{5,5}, {4,4}, {3,3}, {2,2}, {1,1}, {0,0}};// making / diagonal line
//int a[20][2]={{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{1,5},{2,5},{3,5},{4,5},{5,5},{5,4},{5,3},{5,2},{5,1},{5,0},{4,0},{3,0},{2,0},{1,0}}; // making [] square
for (int i=0;i<sizeof(i)/4;i+=1){
x=a[i][0];
y=a[i][1]+5;
ml.write(angle_left(x,y));
mr.write(angle_right(x,y));
delay(300);
}
for (int i=0;i<sizeof(v)/4;i+=1){
x=a[i][0];
y=a[i][1]+5;
ml.write(angle_left(x,y));
mr.write(angle_right(x,y));
delay(300);
}
for (int i=0;i<sizeof(a)/4;i+=1){
x=a[i][0];
y=a[i][1]+5;
ml.write(angle_left(x,y));
mr.write(angle_right(x,y));
delay(300);
}
for (int i=0;i<sizeof(n)/4;i+=1){
x=a[i][0];
y=a[i][1]+5;
ml.write(angle_left(x,y));
mr.write(angle_right(x,y));
delay(300);
}
#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04
#define echoPin2 5
#define trigPin2 4
#define echoPin3 6
#define trigPin3 7
#define echoPin4 9
#define trigPin4 8
// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
long duration2;
int distance2;
long duration3;
int distance3;
long duration4;
int distance4;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
pinMode(trigPin2, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin2, INPUT); // Sets the echoPin as an INPUT
pinMode(trigPin3, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin3, INPUT); // Sets the echoPin as an INPUT
pinMode(trigPin4, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin4, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
Serial.println("with Arduino UNO R3");
}
void loop() {
int i;
int realdist[5] = {0,0,0,0,0};
int realdist2[5] = {0,0,0,0,0};
int realdist3[5] = {0,0,0,0,0};
int realdist4[5] = {0,0,0,0,0};
for(i=0;i<=4;i++)
{
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(20);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
//Serial.print("Distance: ");
//Serial.print(distance);
//Serial.println(" cm");
realdist[i] = distance;
}
distance = (realdist[0] + realdist[1] + realdist[2] + realdist[3] + realdist[4])/5;
Serial.print("Distance 1 ");
Serial.println(distance);
for(i=0;i<=4;i++)
{
// Clears the trigPin condition
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration2 = pulseIn(echoPin2, HIGH);
// Calculating the distance
distance2 = duration2 * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
//Serial.print("Distance: ");
//Serial.print(distance);
//Serial.println(" cm");
realdist2[i] = distance2;
}
distance2 = (realdist2[0] + realdist2[1] + realdist2[2] + realdist2[3] + realdist2[4])/5;
Serial.print("Distance 2 ");
Serial.println(distance2);
for(i=0;i<=4;i++)
{
// Clears the trigPin condition
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration3 = pulseIn(echoPin3, HIGH);
// Calculating the distance
distance3 = duration3 * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
//Serial.print("Distance: ");
//Serial.print(distance);
//Serial.println(" cm");
realdist3[i] = distance3;
}
distance3 = (realdist3[0] + realdist3[1] + realdist3[2] + realdist3[3] + realdist3[4])/5;
Serial.print("Distance 3 ");
Serial.println(distance3);
for(i=0;i<=4;i++)
{
// Clears the trigPin condition
digitalWrite(trigPin4, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin4, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin4, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration4 = pulseIn(echoPin4, HIGH);
// Calculating the distance
distance4 = duration4 * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
//Serial.print("Distance: ");
//Serial.print(distance);
//Serial.println(" cm");
realdist4[i] = distance4;
}
distance4 = (realdist4[0] + realdist4[1] + realdist4[2] + realdist4[3] + realdist4[4])/5;
Serial.print("Distance 4 ");
Serial.println(distance4);
}
#include <LiquidCrystal.h>
//animated face code
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
}
void loop() {
int i;
for (i = 0;i < 10;i++)
{
lcd.begin(16, 2);
lcd.print(" 0 0 ");
lcd.setCursor(0,1);
lcd.print(" ______ ");
delay(100);
}
for (i = 0;i <=3;i++)
{
lcd.begin(16, 2);
lcd.print(" o o ");
lcd.setCursor(0,1);
lcd.print(" ______ ");
delay(100);
}
for (i = 0;i <=8;i++)
{
lcd.begin(16, 2);
lcd.print(" - - ");
lcd.setCursor(0,1);
lcd.print(" ______ ");
delay(100);
}
for (i = 0;i <=3;i++)
{
lcd.begin(16, 2);
lcd.print(" o o ");
lcd.setCursor(0,1);
lcd.print(" ______ ");
delay(100);
}
for (i = 0;i < 10;i++)
{
lcd.begin(16, 2);
lcd.print(" 0 0 ");
lcd.setCursor(0,1);
lcd.print(" ______ ");
delay(100);
}
for (i = 0;i <6;i++)
{
lcd.begin(16, 2);
lcd.print(" ( .)( .) ");
lcd.setCursor(0,1);
lcd.print(" <----> ");
delay(100);
}
for (i = 0;i < 6;i++)
{
lcd.begin(16, 2);
lcd.print(" (.)(.) ");
lcd.setCursor(0,1);
lcd.print(" <----> ");
delay(100);
}
for (i = 0;i < 6;i++)
{
lcd.begin(16, 2);
lcd.print(" (. )(. ) ");
lcd.setCursor(0,1);
lcd.print(" <----> ");
delay(100);
}
for (i = 0;i < 6;i++)
{
lcd.begin(16, 2);
lcd.print(" (.)(.) ");
lcd.setCursor(0,1);
lcd.print(" <----> ");
delay(100);
}
for (i = 0;i < 8;i++)
{
lcd.begin(16, 2);
lcd.print(" ((.)(.)) ");
lcd.setCursor(0,1);
lcd.print(" <----> ");
delay(100);
}
for (i = 0;i < 10;i++)
{
lcd.begin(16, 2);
lcd.print(" ((x)(x)) ");
lcd.setCursor(0,1);
lcd.print(" ______ ");
delay(100);
}
}
int IR_RECEIVE_PIN = 11;
#define MOTOR_ENA 10
#define MOTOR_ENB 6
#define MOTOR_IN1 12
#define MOTOR_IN2 8
#define MOTOR_IN3 5
#define MOTOR_IN4 4
#include "IRremote.h"
#define slow 64
#define normal 128
#define fast 255
#include <Servo.h>
//IRrecv irrecv(RECEIVER); // create instance of 'irrecv'
decode_results results;
int Speed;
void FWR(int Steps){
analogWrite(MOTOR_ENA, Speed);
digitalWrite(MOTOR_IN1, LOW);
digitalWrite(MOTOR_IN2, HIGH);
analogWrite(MOTOR_ENB, Speed);
digitalWrite(MOTOR_IN3, HIGH);
digitalWrite(MOTOR_IN4, LOW);
delay(Steps);
}
void BCK(int Steps){
analogWrite(MOTOR_ENA, Speed);
digitalWrite(MOTOR_IN1, HIGH);
digitalWrite(MOTOR_IN2, LOW);
analogWrite(MOTOR_ENB, Speed);
digitalWrite(MOTOR_IN3, LOW);
digitalWrite(MOTOR_IN4, HIGH);
delay(Steps);
}
void StopM(int Steps){
digitalWrite(MOTOR_IN1, HIGH);
digitalWrite(MOTOR_IN2, HIGH);
digitalWrite(MOTOR_IN3, HIGH);
digitalWrite(MOTOR_IN4, HIGH);
delay(Steps);
}
void LFT(int Steps){
analogWrite(MOTOR_ENA, Speed);
digitalWrite(MOTOR_IN1, LOW);
digitalWrite(MOTOR_IN2, HIGH);
analogWrite(MOTOR_ENB, Speed);
digitalWrite(MOTOR_IN3, LOW);
digitalWrite(MOTOR_IN4, HIGH);
delay(Steps);
}
void RHT(int Steps){
analogWrite(MOTOR_ENA, Speed);
digitalWrite(MOTOR_IN1, HIGH);
digitalWrite(MOTOR_IN2, LOW);
analogWrite(MOTOR_ENB, Speed);
digitalWrite(MOTOR_IN3, HIGH);
digitalWrite(MOTOR_IN4, LOW);
delay(Steps);
}
Servo myservo;
void setup() {
Serial.begin(9600);
Serial.println("L293D DC motor test");
IrReceiver.begin(IR_RECEIVE_PIN);
pinMode(MOTOR_ENA, OUTPUT);
pinMode(MOTOR_IN1, OUTPUT);
pinMode(MOTOR_IN2, OUTPUT);
pinMode(MOTOR_ENB, OUTPUT);
pinMode(MOTOR_IN3, OUTPUT);
pinMode(MOTOR_IN4, OUTPUT);
myservo.attach(9);
pinMode(3, OUTPUT);
}
int waaaa()
{
if (IrReceiver.decode())
{
int x = 0;
Serial.print("Code: ");
Serial.println(IrReceiver.decodedIRData.decodedRawData);
Serial.println(" ");
IrReceiver.resume();
if (IrReceiver.decodedIRData.decodedRawData == 3108437760)
{
x = 1;
return x;
}
else if (IrReceiver.decodedIRData.decodedRawData == 3158572800)
{
x = 2;
return x;
}
else if (IrReceiver.decodedIRData.decodedRawData == 3141861120)
{
x = 3;
return x;
}
else if (IrReceiver.decodedIRData.decodedRawData == 3927310080)
{
x = 4;
return x;
}
else if (IrReceiver.decodedIRData.decodedRawData == 4161273600)
{
x = 5;
return x;
}
else if(IrReceiver.decodedIRData.decodedRawData == 3910598400)
{
x = 6;
return x;
}
else if(IrReceiver.decodedIRData.decodedRawData == 4077715200)
{
x = 7;
return x;
}
else
{
return 0;
}
}
}
void flagDown() { // attaches the servo on pin 9 to the servo object
myservo.write(120);
digitalWrite(3,LOW);
}
void flagUp()
{
myservo.write(180);
int i;
digitalWrite(3,HIGH);
delay(700);
digitalWrite(3,LOW);
delay(700);
digitalWrite(3,HIGH);
delay(700);
digitalWrite(3,LOW);
delay(700);
digitalWrite(3,HIGH);
delay(700);
digitalWrite(3,LOW);
delay(700);
digitalWrite(3,HIGH);
delay(700);
}
void loop()
{
Speed = fast;
switch(waaaa())
{
case 1: FWR(250);break;
case 2: RHT(250);break;
case 3: LFT(250);break;
case 4: BCK(250);break;
case 5: StopM(250); break;
case 6: flagUp(); break;
case 7: flagDown();break;
}
}
Comments
Please log in or sign up to comment.