ETEC 568 MakerSpaces: Week 6 Blog Post

For Week 6, our Arduino challenge was to make our own project using either a motor, a sensor, or a motor controlled by sensors. I looked at several different projects and ended up deciding on going with a simple project so I could tackle making it my own in some way. I decided to use the servo motor and found an Instructables.com guide explaining how to set the motor up to get the propeller to rotate.

The guide can be found here.

I used the code from the guide and set up the build based on this picture:

This was a little tricky because my servo motor did not have a place to attach the wires directly, so it didn’t look exactly like the picture which is always intimidating for me at first. Instead of placing the wires directly into the servo motor, my motor had wires built into the motor with a white box at the end of the wires where more wires could be attached.

And here is the build completed:

Here is a breakdown of what is going on:

-The breadboard is not being used! (That was a first for me)

-I connected my RED wire to the motor’s RED wire hole which then connected to 5V on the Arduino

-I connected my BLACK wire to the motor’s BLACK wire hole which then connected to GROUND on the Arduino

-I connected my GREEN wire to the motor’s WHITE wire hole which then connected to PIN3 on the Arduino

Below is the code used in the tutorial:

// Include the Servo library

#include <Servo.h>

// Declare the Servo pin

int servoPin = 3;

// Create a servo object

Servo Servo1;

void setup() {

// We need to attach the servo to the used pin number

Servo1.attach(servoPin);

}

void loop(){

// Make servo go to 0 degrees

Servo1.write(0);

delay(1000);

// Make servo go to 90 degrees

Servo1.write(90);

delay(1000);

// Make servo go to 180 degrees

Servo1.write(180);

delay(1000);

}

After uploading the code and plugging the Arduino in, I received an error message telling me that there was a problem uploading to the board. I could not figure out what was wrong and finally realized that the USB hub that I have been using was the culprit of the problem! I tried plugging the Arduino into one of the USB ports attached directly to my laptop and the error went away. Just to make sure, I then tried connecting my keyboard and mouse to the USB hub and they also did not work so, unfortunately, it is time for a new USB hub. However, I was relieved that the Arduino itself was not broken and also glad that the build and code I had used worked.

I was happy to see that the code for this guide was short. My only hope for dissecting this project and making it my own was to examine the code and try to understand each part so that I could add something myself. After reading the code and comments as well as the breakdowns in the guide, I was able to follow along with it better than I thought but I still had some questions, so I ended up looking up some of the newer terms to make sure I was understanding correctly. It was hard for me to wrap my head around what “include” and “servo” really meant but I knew it had to do with the motor of course. After some additional googling, I was better able to understand why the include and servo had to be in the code to make the motor work.

Now that I understood the code better, I was ready to incorporate something of my own into the original project. As you can see, in the video above which used the original code from the tutorial, the propeller is spinning to 0 degrees, then 90 degrees, and then 180 degrees and it repeats this over and over. I thought this was a bit boring, so I decided to incorporate the random function into the code instead of sticking to the same pattern.

Even though I have had some experience in this class with using the random function, I was still unsure of how to put it in the code myself. I used this website to help me understand how setting up the random numbers would work.

This page explained that when using random, the first number inputted is inclusive which means that the motor will use that number in its range when deciding how far to turn. However, the second number in the random is exclusive which means that higher number inputted will not be apart of the range that the motor considers when turning. Because of this, I decided to make the low number 0 and the highest number 181. By doing this, I was still including the range of the original code but instead of only turning to 0, 90, and 180, the new code would tell the motor to turn to any degree in between 0 to 180. I thought this would be more exciting!

Here is the new code. To help myself learn and stay on track, I added my own comments when writing the code so I didn’t get confused. This technique was extremely helpful and really helped me to better understand that “include” is telling the Arduino to basically consider the code that is already built into the servo motor. This is still difficult for me to understand and I’m not sure if that is really a correct way to put it but I’m pretty sure that is the gist of it.

New code with Random Function:

#include <Servo.h> //include servo library. This allows you to use servo functions so that we can use the motor.

Servo Servo1; //making a Servo object named “Servo1”

void setup() {

Servo1.attach(3); //telling the motor to take input from pin3

}

void loop(){

Servo1.write(0); //this is telling the motor to reset its position to 0 degrees

delay(1000); // motor waits 1000ms

Servo1.write(random(0,181)); //the random function generates a number between 0 and 180

delay(1000);

}

I can think of many extensions to this project that I wish I had had the time and energy to figure out. Unfortunately, I started feeling sick this week right before the weekend. This was pretty good timing in some ways because I didn’t have to try to get through work sick but also bad because the weekends are the only time I have to really sit down and dive into these Arduino challenges. It all ended up working out though because not setting my sights too high helped me to really understand the basics better and was a great way to introduce me to the servo motor. I would now feel more comfortable tackling a bigger project that involved a motor because of my experience working with this one.

Some of the extension ideas I had were using a button to turn the motor on and off. I thought of this one pretty early on because I got annoyed very quickly with the constant noisiness of the motor. I was plugging and unplugging my red wire working through the project because that was the only way to get the motor to be quiet! Another idea I had was to add LED lights and make them light up with the spinning of the motor but I am not sure how that would work exactly. I also saw lots of more advanced projects online using motors with robots, toy railroads, and all kinds of crazy things. However, these ideas are actually not that crazy because they are everywhere in all kinds of toys and electronics.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Veloce example of a superior CPQ

Coding Chronicles- 7

Profit Formula Challenge

Rubik’s Cube Puzzles

Rails + Docker + Gitlab = ❤

Awesome Resources for College Students to Get Started in the Real World of Software — March 2017

Dash: A Beginner’s Guide

Creating well-behaved views in Android

NumPy For Machine Learning

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dena

Dena

More from Medium

ETEC 568 MakerSpaces: Week 3 Blog Post

assignment #?: the ugly duckling.

Metaverse and its potential for retail and consumer brands (Part-3)

Tuesday and Wednesday, 2021–12–07 & 08.