Robot Art Show

For this project, a partner and I built a piece of code with hardware to make a robot respond to certain inputs. When a button is pressed on our robot, a corresponding LED is lit and a servo (robotic arm) moves to a certain angle. To let you know of this action a piezo buzzes a certain note depending on which button is pressed.

Our code, (note that when you see a // this shows our notes for what each line of code does and the robot doesn't read it):


//set the pins for the buttons and LEDs

int firstKeyPin = 2;

int secondKeyPin = 3;

int thirdKeyPin = 4;


int greenLED = 13;

int blueLED = 12;

int redLED = 11;


int buzzerPin = 10;


//sets up the servo, all servo code is from circuit 3A and edited

#include <Servo.h>

int servoPosition;

Servo myservo;


void setup() {

//set the button pins as inputs

pinMode(firstKeyPin, INPUT_PULLUP);

pinMode(secondKeyPin, INPUT_PULLUP);

pinMode(thirdKeyPin, INPUT_PULLUP);

//tells arduino which pins are the outputs

pinMode(13, OUTPUT);

pinMode(12, OUTPUT);

pinMode(11, OUTPUT);

pinMode(buzzerPin, OUTPUT);

myservo.attach(9); //sets pin that the servo is attached to

}


void loop() {


if (digitalRead(firstKeyPin) == LOW) { //if the first key is pressed

tone(buzzerPin, 262); //tells the piezo to play a certain note

digitalWrite(13, HIGH); //turn on the LED

delay(100); //wait 100 milliseconds

digitalWrite(13, LOW); //turn the LED off

myservo.write(60); //moves the servo to that position

delay(500); //how long the servo has to move to its position

}

if (digitalRead(secondKeyPin) == LOW) { //if the second key is pressed

tone(buzzerPin, 330);

digitalWrite(12, HIGH);

delay(100);

digitalWrite(12, LOW);

myservo.write(110);

delay(750);

}

if (digitalRead(thirdKeyPin) == LOW) { //if the third key is pressed

tone(buzzerPin, 392);

digitalWrite(11, HIGH);

delay(100);

digitalWrite(11, LOW);

myservo.write(160);

delay(1000);

}

else {

noTone(buzzerPin); //if no key is pressed turn the buzzer off

}

myservo.write(servoPosition); //default set servo position to 10 degrees

}


/*

note frequency

c 262 Hz

d 294 Hz

e 330 Hz

f 349 Hz

g 392 Hz

a 440 Hz

b 494 Hz

C 523 Hz

*/



Shown here is the diagram of our circuit:


Here is a video of our working model in a simulation:

Circuit design Robot Art Show | Tinkercad.webm

To build this amazing piece of code and robot, we first had to learn and experiment with coding. We did this by practicing wiring circuits with the SparkFun Inventor's Kit. We learned about different components that can be used through code to do cool actions. From making a piezo play the happy birthday song, to making motors run on command we experimented with these projects until we had a grasp about how the code worked for different components and how they are wired.

We also experimented with electricity and how changing the voltage of an electromagnet would change how much weight it could carry. The write-up for this experiment is shown below. In this experiment we learned how magnetic fields could be made by wrapping wire around a metal object and running voltage through it. We found that the more voltage we run through the wire the more weight it could pick up. This is because we made the magnetic field stronger by running the more through it.

Zackary Brownstone - Electromagnet Lab

Concepts:

  • Coulomb's Law: A law that dictates that like charges repel and opposite charges attract. This happens with a force proportional to the product of that charges and inversely proportional to the square of the distance between them .

  • Parallel Circuit: A circuit with branches each with a separate path for the flow of charge/electrons.

  • Series Circuit: A circuit with a single path and multiple components one after another on the same path.

  • Current: The flow of charge/electricity through a circuit.

  • Voltage: Potential energy difference from one side of the component to the other side.

  • Resistance: Amount the current is slowed or resisted through an obstacle.

  • Power: Rate of transferring electrical energy through a circuit.

  • Ohm's Law: A law that states that the current through a conductor between two points is directly proportional to the voltage across the two points.

What I've learned from coding:

My takeaways from coding is how you really need to define and make sure you account for every component and nothing more or less. When coding you should probably have a checklist to make sure you don't get distracted in all the various components you are trying to take account for and take everything one step at a time. Focus on the first LED and then build off of that to all the buttons and different components after that. When my partner and I first started coding we got lost in all the code and it took extra time to build the main parts of our code.

Two things I did well on this project was critical thinking and collaboration. Critical thinking came into part here because to write code you need to understand all the components you are coding for and how they work with each other. Collaboration was because my partner and I worked together most of the time to get this code working. If we didn't communicate then we wouldn't know which parts were successfully coded and what we still needed to work on and the project would take forever to finish.

Two things I didn't do well this project were conscientious learner and communicator. Conscientious learner because even at this point in the project I still don't 100% understand everything we learned and coded. There are still parts that don't make much sense to me and that I am confused about. Communicator because there were certain points I could have communicated more to my partner and maybe the project would have been simpler and been finished quicker.