Due to Covid-19, my entire school had to do virtual learning. Luckily, through trial and tribulation my engineering teacher, Ms.White, delivered to use the materials we needed to do all of our projects. Our first project was building a functional robot. The materials included were:
A-B Cable
Arduino Uno
Continuous Rotation Servo with Servo Screws and Servo Horns
Breadboard
Ultrasonic Distance Sensor
HM-10 Bluetooth Module
AA Battery Holders (4)
AA Batteries (16)
Today we were informed of our first project. We are going to build an automated robot, this will be fun!
Our Project Plan will includes all the important factors we will need in order to create an amazing automated robot.
Today we learned what circuit diagrams are, we learned that circuit diagrams are models or visual displays of electric circuits that simulate what a model would look like in real life. The purpose of a circuit diagram is to simulate what a circuit would look like with basic images, that are meant to represent parts of a circuit. These help engineers design these circuits in real life
Today we also made circuit pictures in Tinkercad. This circuit picture was far more accurate than the previous model because I could test the circuit in order to see if it worked or not. A circuit picture is very useful because it shows how a circuit should be wired in order to work correctly.
Before we started to design our robots, we looked up designs that might inspire us. The designs we looked up mainly used the materials that we had available and used non-expensive materials. During the researching process we also looked up relevant project information like how the robot should be wired.
Design 1 seems to have two big wheels in front and a smaller wheel in back. The material used as a base is transparent and looks flimsy from the picture. But the engineer did design a curved front so that the wheels wouldn't hit anything. Arduino and breadboard are on top but wire can be easily unplugged. Motors are sandwiched in the middle but this robot has no distance sensor.
Design 2 has four big wheels and what looks like a metal frame. This design uses four motors instead of two but I could probably change that so it would only need two. I like the black and yellow color scheme, I might implement that in my design. The base of the robot looks strong and stable. The Arduino and bread-broad are on top and easily accessible.
Design 3 has four wheels and treads along with a distance sensor in front that simulate eyes. These treads could be very useful for my robot since my robot will only have two motors. The Arduino is in a secure location. The sensor should stop the robot offline programming to stop it from bump into walls. In addition the treads could let the robot get more traction when outside.
In class, we used this model in order to connect our motors, breadboard, Arduino together.
We used circuit-diagram.org to create a circuit diagram of our circuit design.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo myservo2;
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1);// waits 15ms for the servo to reach the position
}
for (pos = 160; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
This is the design I choose, I believe I can obtain robot treads and change the design to fit my materials. Instead of 3D printed materials I will be using cardboard.
Production
In class, I made a circuit that was based off of this picture. My robot has very similar motors, breadboard, Arduino, and battery placements.
I used circuit-diagram.org to update my circuit diagram and to include my batteries.
#include <Servo.h>
Servo Right; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo Left;
int pos = 0; // variable to store the servo position
void setup() {
Right.attach(9);// attaches the servo on pin 9 to the servo object
Left.attach(10);// attaches the servo on pin 10 to the servo object
}
void loop() {
Right.write(0);
Left.write(180);
delay (2000);
Right.write(180);
Left.write(0);
delay (2000);
Right.write(90);
Left.write(180);
delay (2000);
Right.write(90);
Left.write(0);
delay (2000);
}
I plan for my robot will go from my library, left to my dining room, left into my kitchen, and then toward the living room.
This is me describing my robot design.
Move forward
Turn Left
Move forward
Turn right
Move Forward
Turn Left
Move Forward
Testing
This is the final video of my robot completing the path I set.
When creating my robot my wheels were uneven, this caused the robot the turn a lot to the right. I fixed it by detaching the wheels and hot gluing them.
When creating my robot I put all my batteries on one side, this caused the robot to be uneven. I fixed it by making two separate battery packs for each side.
Originally my robot had a wheel on the front of it, this stopped the robot from turning. I fixed it by replacing the wheel with a sloped piece of cardboard.
When creating my robot I realized the wheels weren't getting a-lot of traction on the ground. I fixed this problem by making cardboard battery packs and weighing my wheels down with batteries.
Today we labeled our wires so that if our robot gets unplugged, we can easily plug it back in again.
During class today my teacher wanted to test our understanding of our code. She gave each person in the class pseudo code that we have to make the robot complete. This was the code I was given:
90 degree standard turn to the left
Forward for 5 seconds.
180 degree tank turn to the left
Stop for three seconds
Backwards three seconds
For extra credit:
After the above commands get your robot to do a full 360 tank turn to the right and a full tank 360 degree tank turn to the left.
// defines pins numbers
const int trigPin = 2;
const int echoPin = 3;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
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;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
Ultrasonic sensors work by emitting sound waves that reflect back to them. They then calculate distance based on the time it took for the wave to return.
As it moves, the data the sensor gives off will change.
Right.write(90);
Left.write(90);
delay (3000);
Right.write(60);
Left.write(60);
delay (1110);
Right.write(76);
Left.write(111);
delay (4950);
Right.write(60);
Left.write(90);
delay (2600);
Right.write(90);
Left.write(90);
delay (3000);
Right.write(111);
Left.write(77);
delay (3000);
Right.write(90);
Left.write(111);
delay (5200);
Right.write(60);
Left.write(90);
delay (5200);
A function is a block reusable code that is used to perform one or more actions.
#include <Servo.h>
Servo Right; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo Left;
int pos = 0; // variable to store the servo position
void setup() {
Right.attach(9);
Left.attach(10);// attaches the servo on pin 9 to the servo object
void Forward(){
Right.write(76);
Left.write(111);}
void Rightturn(){
Right.write(90);
Left.write(111);}
void Leftturn(){
Right.write(76);
Left.write(90);}
void RightTankTurn(){
Right.write(111);
Left.write(111);}
void LeftTankTurn(){
Right.write(76);
Left.write(76);}
void Backward(){
Right.write(111);
Left.write(76);}
void Stop(){
Right.write(90);
Left.write(90);}
}
void loop() {
Stop();
delay (5000);
Forward();
delay (10500);
LeftTankTurn();
delay (1300);
Forward();
delay (30000);
LeftTankTurn();
delay (650);
Froward();
delay (9000);
RightTankTurn();
delay (1500);
Forward();
delay (28000);
LeftTankTurn();
delay (900);
Forward();
delay (40000);
}
Today I installed my ultra-sonic distance sensor to the front of my robot with tape. This installation is temporary and in the future I will make it more secure and permanent.
The code to the left is made as an example of a if/else statement. The function is meant to do homework if needed and relax if homework isn't needed.
This circuit displays how the batteries, Arduino, sensor, and the motors were all connected. The batteries provide power to all the applications, partly through the Arduino.
#include <Servo.h>
Servo Right;
Servo Left;
int trigPin = 9;
int echoPin = 10;
int distance;
long duration;
void setup() {
Right.attach(12);
Left.attach(11);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);// put your setup code here, to run once:
}
void ultra() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
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;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
void Forward() {
Right.write(76);
Left.write(111);
}
void Rightturn() {
Right.write(90);
Left.write(111);
}
void Leftturn() {
Right.write(76);
Left.write(90);
}
void RightTankTurn() {
Right.write(111);
Left.write(111);
}
void LeftTankTurn() {
Right.write(76);
Left.write(76);
}
void Backward() {
Right.write(111);
Left.write(76);
}
void Stop() {
Right.write(90);
Left.write(90);
}
void loop() {
if (distance <= 10) {
Stop();
}
else(Forward);
}
Redesign
This phase includes me remaking my robot to improve its capabilities. I also added a bluetooth function to get extra credit.
All Electronic Components Must be Enclosed (includes everything but the servo horns and the wheels).
Function requirements/constraints
Needs to function (can’t bee too heavy).
No slipping allowed.
The weight must balance equally-- needs to be stable, not having the body of the robot touching the ground.
Select materials that are rigid enough for their intended function (not sagging).
Usability Constraints
Have some type of easily removable door/cover/etc?
Easy battery Access
Easy access to Arduino 5V
Easy access to breadboard Red Row
Easy access to the reset button.
Easy access to the “B” end of the Arduino A-B Cable port.
Aesthetic Requirements/Constraints
Size--not bigger than a microwave.
Covering is colorful and neatly crafted / uses any materials that you have at home.
Craftsmanship--
Neat
Clean Glue edges
Pieces and parts match up (edges fit together).
This website provided a guide to connecting a servo and bluetooth module to an Arduino. The downside is that this guide uses a android application.
The bluetooth module is designed to wirelessly communicate information. It communicates via serial communication which makes it easy to control with a wireless controller.
It is fairly easy to connect your PC to a bluetooth module. First you open System Preferences and click the Bluetooth icon. Then click on Set Up New Device. The Bluetooth Module will appear as linvor.
You will need a specific passcode to pair the Bluetooth module and your Mac. Therefore, click on Passcode Option and enter your bluetooth module's passcode. Then just wait until the pairing is completed.
A three wheeled robot available on amazon that has two front wheels and one back wheel. The robot also has a camera. The only problem is that the wires are exposed.
This robot is similar to a robot in the video game rainbow six siege. The majority of the robot is 3d printed and has an opening in the front for the ultrasonic distance sensor.
A nimble robot with two servo motors, a powerful metal gear servo for leaning into corners and an all new motor controller. The wires aren't covered but they easily can be.
These thumbnail sketches show what my new robot will look like from the top, front, and bottom. I want to make my robot look like a racing drone.
My robot has two front wheels and one back wheel. It will back battery packs on each side. A unique design feature of my robot will be it's angled middle that makes the robots body slanted. This design may put a lot of stress on the middle of the robot but if I balance out the weight then the robot should stay stable.
I redesigned my robot to make it larger, faster, and easier to wire. I also put the wheels in the front to make turning easier. To close off my robot I made tape hinges to open and close the top. The batteries are held in the back of the robot to power it and weigh it down.
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#include <Dabble.h>
#include <Servo.h>
Servo Left;
Servo Right;
int a = 180;
int b = 0;
int c = 200;
void setup() {
// put your setup code here, to run once:
Left.attach(11);
Right.attach(12);
Serial.begin(250000); // make sure your Serial Monitor is also set at this baud rate.
Dabble.begin(9600); //Enter baudrate of your bluetooth.Connect bluetooth on Bluetooth port present on evive.
}
void Forward() {//define forward
Left.write(180);
Right.write(0);
}
void Leftturn() {//define left tenk turn
Left.write(80);
Right.write(0);
}
void Rightturn() {//define right tank turn
Left.write(180);
Right.write(80);
}
void Backward() {//define backward
Left.write(0);
Right.write(180);
}
void Adjustspeed() {
}
void loop() {
Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
Serial.print("KeyPressed: ");
if (GamePad.isUpPressed())
{
Serial.print("UP");
Forward();
delay(200);
}
else {
Left.write(90);
Right.write(90);
}
if (GamePad.isDownPressed())
{
Serial.print("DOWN");
Backward();
delay(200);
}
else {
Left.write(90);
Right.write(90);
}
if (GamePad.isLeftPressed())
{
Serial.print("Left");
Leftturn();
delay(200);
}
else {
Left.write(90);
Right.write(90);
}
if (GamePad.isRightPressed())
{
Serial.print("Right");
Rightturn();
delay(200);
}
else {
Left.write(90);
Right.write(90);
}
if (GamePad.isSquarePressed())
{
Serial.print("Square");
}
if (GamePad.isCirclePressed())
{
Serial.print("Circle");
}
if (GamePad.isCrossPressed())
{
Serial.print("Cross");
}
if (GamePad.isTrianglePressed())
{
Serial.print("Triangle");
Left.write(180);
}
else {
Left.write(90);
}
if (GamePad.isStartPressed())
{
Serial.print("Start");
}
if (GamePad.isSelectPressed())
{
Serial.print("Select");
}
Serial.print('\t');
int a = GamePad.getAngle();
Serial.print("Angle: ");
Serial.print(a);
Serial.print('\t');
int b = GamePad.getRadius();
Serial.print("Radius: ");
Serial.print(b);
Serial.print('\t');
float c = GamePad.getXaxisData();
Serial.print("x_axis: ");
Serial.print(c);
Serial.print('\t');
float d = GamePad.getYaxisData();
Serial.print("y_axis: ");
Serial.println(d);
Serial.println();
}
In this video, my robot is being controlled by my phone through a bluetooth module.
Analyse the Brief
This is the start of our Kinetic Sculpture project. We start by reading over our brief to understand what rules we need to implement.
This project will be our first gear related project. In this project we will be learning about all forms of motion.
Our Project Plan will includes all the important factors we will need in our project. We will also learn out how to convert one kind of morion to another.
My cardboard automata will convert rotational motion to linear motion. When creating my cardboard automata, I modeled it after the tower of Sauron.
Research
We started using Inkscape today to learn how to make our gears. We started by making a face and other shapes to get used to Inkscape.
Today, we downloaded and started using Inkscape in our class. The red image was the first image I made using shapes and displacement. I then created a face to test out Inkscape's capabilities.
Today we got a tutorial on how to create a pattern for our gear. To create this gear:
We created two circles, one was bigger than the other
We used path difference to make a circle with a hole in it
We made three of these circles and connected them
We cut the largest circle in half and put it in the gear
We then went to edit - clone - tiled clone
From there we changed Shift X: Per column to negative one-hundred
Then we went to rotation, divided 360 by the number of columns we wanted to get per column, and changed the number of columns
Finally we moved the center point of the shape to wherever we wanted the middle to be and pressed create
Idea Development
For this phase we will be deciding what our project will look like. We started thinking about what each of our gears and our gear layout.
To plan out my gear I drew in in google draw and on a piece of paper. My gear has four sections with circular-stars on each of them.
I used the lessons I learned to create my gear in Inkscape. I decided to create a cross that was also modeled after a ninja star. To create my gear I made rectangles in a T shape and used other squares to give the rectangles slanted sides. I then made four tiled clones and used path difference to make T shaped holes in the gear. Next, I made a star and a circle and united them. I used these star circles to make holes in the gear. Finally, I made a circle in the middle of the gear
Today we got a tutorial on how to create a pattern for our second gear. To create this gear:
First, we created a random shape with the Inkscape tools
Then we made a circle and removed it's fill so that only the border was visible
We placed that circle in the middle of our gear
We then went to Path - Path Effects - Plus - Pattern along path
Next we copied our random shape
Finally we selected our circle and pressed pattern copied shape
By using three gears, my drive gear can turn the final gear in the same direction as it turns.
As long as the drive gear is two times smaller than the gear it is turning, the big gear would turn half as fast as the drive gear.
We used gears and cams to manipulate a cardboard piece in a linear fashion. The piece was pushed up and down by the cam that was connected to a small gear.
In this project four motors are manipulating rods through triangular cams. The rods have circular pieces that rotate as they slide along the Cams. These rods are either directly connected to the clock pieces or are connected via a rectangular pice of acrylic. Gravity forces the rod to rest on the Cam, which moves up and down. This, along with the mechanical slots behind the rods lead to the liner motion of the clock pieces.
From the drive shaft, Ms.White uses two layers of gear. One layer uses a middle sized gear to manipulate a larger gear. The other layer uses two gears to manipulate a large gear than is almost identical to the first large gear. These gears converge and are place on top of each-other. By spinning in opposite directions these gears seemingly show a single gear that has moving internal parts.
In my gearbox I will use linear and rotational motion. At the end of the cardboard I have two overlapping gears of different sizes that move in opposite directions.
Production
This is the phase where we finalize our design in Inkscape. We also finished setting up and testing our motor and sensor.
We finished setting up, designing, and finalizing our gear layout. Each of my gears has a unique design that made. The drive gears overlap with each other and move both layers simultaneously.
This is the acrylic that I designed to hold my gears.
We designed our hobby motor setup in tinkercad. This is our design, but I have substituted the diode for an led.
//Transistor 'Base' pin or input pin of motor driver ic to Arduino PWM Digital Pin 3
const int motorPin = 3;
int Speed; //Variable to store Speed, by defaul 0 PWM
int flag;
void setup()
{
pinMode(motorPin, OUTPUT); //Set pin 3 as an OUTPUT
Serial.begin(9600); //Init serial communication
//Print a message:
Serial.println("Give a number from 50 to 255."); //Why minimun value 50? Because with values below 50 the motor doesn't spin ;)
Serial.println(""); //Blank line
}
void loop()
{
//Check if incoming data is available:
if (Serial.available() > 0)
{
// If it is, we'll use parseInt() to pull out only numbers:
Speed = Serial.parseInt();
flag=0;
}
//Valid range is from 50 to 255
if (Speed>=50 && Speed<=255){
//Send PWM value with analogWrite to Arduino pin 3 and print a message to serial monitor
analogWrite(motorPin, Speed);
//Print message only once
if (flag==0){
//Print PWM value
Serial.print("Motor spinning with ");
Serial.print(Speed);
Serial.println(" PWM");
flag=1;
}
}
delay(1000);
}
//
Through tinkercad I added the ultrasonic distance sensor to my previous design and connected all the correct
//Transistor 'Base' pin or input pin of motor driver ic to Arduino PWM Digital Pin 3
const int motorPin = 3;
int Speed; //Variable to store Speed, by defaul 0 PWM
int flag;
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorPin, OUTPUT); //Set pin 3 as an OUTPUT
Serial.begin(9600); //Init serial communication
//Print a message:
Serial.println("Give a number from 50 to 255."); //Why minimun value 50? Because with values below 50 the motor doesn't spin ;)
Serial.println(""); //Blank line
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
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;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
//Check if incoming data is available:
if (Serial.available() > 0)
{
// If it is, we'll use parseInt() to pull out only numbers:
Speed = Serial.parseInt();
flag=0;
}
//Valid range is from 50 to 255
if (Speed>=50 && Speed<=255){
//Send PWM value with analogWrite to Arduino pin 3 and print a message to serial monitor
analogWrite(motorPin, Speed);
//Print message only once
if (flag==0){
//Print PWM value
Serial.print("Motor spinning with ");
Serial.print(Speed);
Serial.println(" PWM");
flag=1;
}
}
delay(1000);
}
//
I adjusted my previous code to have my ultrasonic distance sensor and motor work together.
//Transistor 'Base' pin or input pin of motor driver ic to Arduino PWM Digital Pin 3
const int motorPin = 3;
int Speed; //Variable to store Speed, by defaul 0 PWM
int flag;
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorPin, OUTPUT); //Set pin 3 as an OUTPUT
Serial.begin(9600); //Init serial communication
//Print a message:
// Serial.println("Give a number from 50 to 255."); //Why minimun value 50? Because with values below 50 the motor doesn't spin ;)
// Serial.println(""); //Blank line
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
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;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
//Check if incoming data is available:
// if (Serial.available() > 0)
{
// If it is, we'll use parseInt() to pull out only numbers:
Speed = Serial.parseInt();
flag=0;
}
//Valid range is from 50 to 255
if (distance >=1 && distance <=10){
//Send PWM value with analogWrite to Arduino pin 3 and print a message to serial monitor
analogWrite(motorPin, 80);
delay(1000);}
else if (distance >=10 && distance <=20) {
analogWrite(motorPin, 110);
delay(1000);}
else if (distance >=20 && distance <=30) {
analogWrite(motorPin, 140);
delay(1000);}
else if (distance >=30 && distance <=40) {
analogWrite(motorPin, 170);
delay(1000);}
else if (distance >=40 && distance <=50) {
analogWrite(motorPin, 200);
delay(1000);}
//Print message only once
if (flag==0){
//Print PWM value
Serial.print("Motor spinning with ");
Serial.print(Speed);
Serial.println(" PWM");
flag=1;
}
delay(1000);
}
//
Testing
This phase includes me testing to make sure my layout works correctly. I also tested my electronics to make sure everything works.
This is the final laser printed gear layout explanation. In this video I display how my layout moves and how it is designs.
This is the video of my motor successfully turning my gears inside my gearbox.
After adjusting my code for the limitations of my motor and sensor, I was able to make my sculpture work without touching it. It starts out at a certain speed to get the sensor started and decreases in speed as an object gets further and further away.
Evaluation
This is the final part of my project where I evaluate my design. In this phase I test my sculpture to see how well it works.
I've hidden and installed all my electronics. This is my final documentation and explanation video of my ultrasonic distance sensor controlling my kinetic sculpture. In the video my wires are exposed but I have a cover for my enclosure.
//Transistor 'Base' pin or input pin of motor driver ic to Arduino PWM Digital Pin 3
const int motorPin = 3;
int Speed; //Variable to store Speed, by defaul 0 PWM
int flag;
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorPin, OUTPUT); //Set pin 3 as an OUTPUT
Serial.begin(9600); //Init serial communication
//Print a message:
// Serial.println("Give a number from 50 to 255."); //Why minimun value 50? Because with values below 50 the motor doesn't spin ;)
// Serial.println(""); //Blank line
analogWrite(motorPin, 150);
}
void loop()
{
delay(50);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH, 30000);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
//Check if incoming data is available:
// if (Serial.available() > 0)
{
// If it is, we'll use parseInt() to pull out only numbers:
Speed = Serial.parseInt();
flag=0;
}
//Valid range is from 50 to 255
if (distance >=1 && distance <=10){
//Send PWM value with analogWrite to Arduino pin 3 and print a message to serial monitor
analogWrite(motorPin, 255);
delay(4000);}
else if (distance <=0) {
analogWrite(motorPin, 0);
delay(4000);}
else if (distance >=10 && distance <=20) {
analogWrite(motorPin, 225);
delay(4000);}
else if (distance >=20 && distance <=30) {
analogWrite(motorPin, 210);
delay(4000);}
else if (distance >=30 && distance <=40) {
analogWrite(motorPin, 195);
delay(4000);}
else if (distance >=40 && distance <=50) {
analogWrite(motorPin, 180);
delay(4000);}
else if (distance >=50 && distance <=60) {
analogWrite(motorPin, 165);
delay(4000);}
else if (distance >=60 && distance <=70) {
analogWrite(motorPin, 150);
delay(4000);}
else if (distance >=70 && distance <=80) {
analogWrite(motorPin, 145);
delay(4000);}
else if (distance >=80 && distance <=90) {
analogWrite(motorPin, 145);
delay(4000);}
else if (distance >=90) {
analogWrite(motorPin, 50);
delay(4000);}
//Print message only once
if (flag==0){
//Print PWM value
Serial.print("Motor spinning with ");
Serial.print(Speed);
Serial.println(" PWM");
flag=1;
}
delay(1000);
}
//
Science - This was used in the project through the electricity we used. Electricity is a form of energy resulting from the existence of charged particles.
Engineering - This was used through the design of the gear layout. I had to distance my gears far enough apart that they turned smoothly and all fit on the acrylic.
Math - This was used in my code to determine the motors speed and delay times. As the sensor increased than the speed of the motor decreased, it was inversely proportional.
Technology - This was used in through the motor, wires, and sensor I used in my design. These pieces worked together by turning the motor as the sensor sensed an object.
Art - This was used in the design of each of my gears. I made unique designs on each of my gears so that they looked cool as the span.
This school year was the year of COVID, a pandemic that sweep the globe. It made many projects difficult and inconvenient. But through our determination we were able to make amazing projects that we can be proud of. The most challenging part of engineering this year was troubleshooting our designs over and over, but in the end I am proud of my robot and Kinetic Sculpture. These project have been a fun experience and I am proud of everything this class lead me to do.