This week we were challenged to make a circuit using a motor and a sensor.
Since I hadn’t used either one in a build, I decided I needed to first
build two circuits, one with a motor and one with a sensor. I decided to do the Digital Hour Class from
my Arduino Starter Kit Project Book because it had a tilt sensor, and then I
decided to use SparkFun’s circuit 3A: Servo Motors. Then I would combine the servo motor with a
tilt sensor.
The first, build I did was the Digital Hour Class. I gathered the needed materials of 6-LEDs, 6-220 ohm resistors, 1-10kohm resistor, 1- tilt sensor, and 9 jumper wires. I followed the diagram in my Arduino Starter Kit Project Book and made the adjustments I needed because my board is backward compared to the diagram. After I got all the pieces into the breadboard, I set out to write the code from the website so I could hopefully understand it better. As I was writing the code out, I got to the long interval=600000 and realized that this was the part where the code tells the Arduino how long to wait before turning on an LED. Since the build was for an hourglass and it had 6 LEDs that meant that every 10 minutes an LED should come one until all are lit up after an hour. I didn’t want to wait an hour so I made a note to change that to 2 minutes (120000 ms). Now that I had the code written I typed it into the Arduino IDE and hit verify. I got an error, it said because of a numerical # and highlighted the line. I looked and realized that there was a 0 where there was supposed to be a closed ) bracket. I fixed it and verified it again and all was clear, so I plugged in my Arduino and uploaded the code to it. Then I waited for something but I knew I needed to wait 2 minutes since that was the time, I set it to turn on an LED. I was happy to see the first LED come on and waited to see if the other 5 would come on. They did so after 12 minutes was up, I picked up the board to tilt it so it would reset the circuit. Well, it didn’t work, so I decided to change the time to 5 seconds so that I could troubleshoot and not have to wait 12 minutes but instead was 30 seconds. After uploading the adjusted code to the Arduino, I waited 30 seconds and again picked up the board and nothing happened. I was even able to take out the tilt sensor and nothing happened, the LEDs were all still on. I got to this point and didn’t really know what to do so I was going to move on to the servo circuit. Before I took the board apart, I decided to look at the diagram and my board and compare them. This is when I noticed that I had my wire going from tilt to the Arduino pin 8 was in i26 but needed to be in i27, which is on the negative side of the tilt with the resistor. Once I did this and reuploaded the code and waited 30 seconds I tilted the sensor back and the lights went off. I let the circuit go a few more times and moved the sensor back when I decided to see if I picked it up and tilted the board that would work and it did.
Hour Glass (tilt sensor) setup
Code used
Diagram for Hourglass circuit. (The purple
wires aren’t in my
circuit but I needed them to get the resistors
to be in the right spot.)(Made in Tinkercad)
Pictures of the circuit set up (2 top pictures)
Showing the circuit working (2 bottom
pictures)
Video of my first attempt at the Hourglass circuit.
Video of Hourglass working.
Next
up was the Servo Motor build which I used the SparkFun circuit 3A. I got the servo motor, 8 jumper wires, and a potentiometer. I followed the diagram
and set the board all up. Again, I wrote
out the code to help me understand it better.
I found it interesting that because servo is in the Arduino library you
can tell the Arduino that by the first line of the code being #include <servo.h>. Once I was done writing it, I set out to type
it into the Arduino IDE, and to my surprise (not) I got an error message
because I forgot to delete the void setup and void loop that automatically
populates when you start a new code in the IDE.
I deleted and reverified and got no errors. This is when I plugged in my
board and uploaded the code to the board.
Nothing!! So, I tried moving the wire from f4 to i4 to see if it worked
better not sharing a hole with a leg of the potentiometer. It worked but seemed to be when I moved the
potentiometer and not the knob. So, I
decided to move it back to f4 and make sure the potentiometer was in the board
the best it could be and remembered from our earlier build that I would just
need to hold the potentiometer down some.
It then seemed to work, so not sure exactly why it didn’t work the first
time but I would have to guess because the connection wasn’t great.
Servo motor setup
Code for Servo
Servo video
Now
comes the fun where I combine the servo with a tilt. Since I had just finished the servo circuit,
I decided to take out the potentiometer and put the tilt in that spot. I had to remove some wires and move a few
around so that they were in the right spot for the tilt sensor. So, since the board was all ready, I had to
look at the codes for both circuits and see how to combine them. After looking
at the two codes I had an idea of how to combine them but decided to see if I
could find a code online that was close to what I was thinking. Well I found one in the Arduino forum and I tried
it even though I wasn’t quite sure why I needed to say anything about pin13
since I had nothing plugged into it.
After getting it ready I verified and no errors, so I plugged in the
board and uploaded the code to it. But it
was a no go, so I tried to comment out parts to see if the other would
work. Again, nothing made the code
work. So back to the internet I went and
ended up finding a Slideshare that had Make: Basic Arduino Projects that
had a build with servo and tilt sensor. So,
I looked at the code and wrote it out and it made more sense to me than the
other. Now I typed in this code and verified
it and got no errors. Plugged the board
back in and uploaded the code to the board.
Once the code got to the board the servo blade moved a little bit. So, I picked up the board and the servo
moved. Wahoo!! This was set at moving 45 degrees, I wanted
to see what happened if I changed it to 160 degrees. I didn’t do 180 degrees because I read that
it wasn’t good for the servo to do that.
It moved 160 degrees. While
watching the blade moved, I thought about a protractor and wondered if I drew
45, 90, and 160 degrees on a piece of paper and lined up the servo if I could
get the blade to move that amount of degrees.
It did though I would have to adjust the servo after changing the code
to have the blade lining up with the line on the paper. This circuit could be used for a digital
protractor which would be fun for students to use in class.
Set up and materials for Servo controlled by
Tilt Sensor.
Pictures of Servo controlled by the tilt sensor.
Diagram of the Servo with tilt sensor circuit.
(Green isn’t there but needed to make the circuit work in Tinkercad).
This
last challenge reminded me that it is important to make sure all wires and
resistors are on the right side of the piece that you are trying to make
work. When I started this class I wasn’t
so sure if I was going to be able to make it because the coding was like a
foreign language to me. While I have
learned a lot, I still do fully understand every single part of the code,
especially when it is up to me to come up with the code, but am better at
understanding a code that is written for me.
The building of the circuit is fun and pretty easy for me so that helps
balance the coding not being as easy.