Thursday, November 26, 2020

Simon Says - Week 5 Adventures in Making Challenge

 

This week we were challenged to pick another project from the book or in my case from the SparkFun website.  I looked through the Arduino book and at the SparkFun website and decided I liked the sound of the Simon Says projects.  Mainly because I love the game Simon Says.  Following the diagram on the website, it was pretty easy to set up, even though I changed most of the locations on the breadboard because mine was set backwards compared to the diagram but I could easily figure it out and got the board all set up.  Simon Says uses a piezo buzzer, 4 LEDs – red, blue, green, and yellow, 4 - 330-ohm resistors, 4 pushbuttons, 17 jumper wires, along with the Arduino and the breadboard.  Like I said the setup was pretty easy but I was nervous about the piezo buzzer because mine was bigger than the one shown, but I was able to get it in the same spot on the board and just had to adjust one or two of the jumper wires positions.  Then I set out to read the code and see what I understood of it and typed the code in.  I verified the code and got no errors.  So, I plugged in the Arduino and uploaded the code to the board, and I got the noise and the LEDs started blinking.  They LEDs kept blinking until I hit a push button, I was a little shocked because I had been so worried about this build since I thought it might be harder than I could handle.

          In my excitement of everything working I ended up noticing that the green LED wasn’t lighting up like the others.  So, I went back to the diagram and made sure everything was in the right spot and it looked like it was, so then I thought that maybe I needed to change something in the code since my setup was a little different than the diagram.  I found out though that the pins and didn’t change so that wasn’t the deal.  I then went back to the breadboard and looked at the wires going to the green LED and saw that my jumper wire was in i13 and it needed to be in i12 so I moved it and hoped that was the problem.  I then plugged the Arduino back in and reloaded the code and it worked.  Wahoo!!!  Then I pushed a push-button and I realized that I think the resistor for the blue LED and the cathode end of the yellow might have been in the same line or too close so I changed the cathode of the yellow LED to 21 from 19 on the breadboard and the negative.  I was hoping this would fix the problem and it did.  I was proud of myself for not getting frustrated when there were some issues.  I had fun playing with it trying to see if I could make it to the end, which was 13 in a row.  Apparently, I can’t remember that mean light sequences. HAHA!!!

          I then went to the code and found that I could adjust the number of times needed to get to the end, so I changed it to 5 so I could see what it did when I got that many in a row.  Well, it makes noise and the LEDs all start blinking again.  I also saw that the response time was set at 3000 ms (3 seconds), so I changed it to 2000 ms (2 seconds) and that was okay until I got to round 10 and I wasn’t able to move fast enough to get the push button pushed.  I then changed it to 1000 ms (1 second) and I could only get 5 rounds before I wasn’t fast enough to answer.  After playing with the time, I decided that 3 seconds was the right amount of time. 

Simon Says setup notes.

 

Pictures of the circuit from different angles.

 

Tinkercad diagram I made. The purple cords aren’t on my board but I needed them to get the LEDs to connect correctly in the diagram so the code would work in Tinkercad.

 

Video of Simon Says.

          I enjoyed this build as it was one that was interactive and fun.  It is also one that I would build again and play with my children.  They both had fun playing with it and thought that it was cool that mom could make that.  This type of circuit can be seen in the Simon game, as well as other electronic games that children enjoy playing.  All the lights, colors, and music make it fun and entertaining. 

Thursday, November 19, 2020

Digital Die - Week 4 Adventures in Making Challenge

 

Digital Die, not dice should be the title.  Dice is for more than one die, but if you only have one it is die.  A random piece of information I know, I guess from growing up in a very serious game family.  Anyway, on to this goal of this week, I was supposed to build a circuit and figure out the code that would allow the circuit to light up LEDs to represent numbers like are on a die.  Before I could do this build, I needed to do the basic push button build since I hadn’t done it yet and I wanted to make sure I understood how it worked and could see the code for it.  Here is a couple of pictures of this build.

Left picture: Push Button circuit.

Right picture: Showing the circuit works.


        Now that I understood the push button, I was ready to tackle the build.  I knew that each LED needed a resistor and a jumper wire leading from the positive (anode-long) side of the LED back to a PIN.  The resistors needed to be on the negative (cathode-short) side of the LED and going into a negative slot on the breadboard.  I also know that I need power to the breadboard from the 5V pin and that I need a Ground (negative) from Arduino to both sides of the breadboard since I was using both sides of the breadboard.  I got the Arduino and the breadboard all set up.  I was ready for the code part but I wanted to make sure I understood all the parts that I thought I needed and check to make sure I didn’t see anything else I needed. So, I spent a couple hours looking at the Reference page on the Arduino website.  I ended up calling it a night and would start the code the next day.  The first thing I did in my code was set up all the global codes, this included all the LEDs and telling which pin they were, the push button and its pin, then gave buttonState (so that when it was pushed the Arduino would recognize it, and last a time constraint so that the LEDs would turn off after 2 seconds.  Then, I had to set up the void setup () by making sure I had each LED marked as an OUTPUT and then the push button marked as an INPUT.  I also had to make sure that I had a randomSeed so that I would get a random number each time I pushed the button instead of getting the same number each time.  The last thing I had to do for the code was the void loop ().  I had to make sure the button was recognized as a digitalRead so that if it was high it would run a random search for a number.  I had to then do if statements for each number and use digitalWrite and give the certain pins needed to make each number 1-6 like they are on a die.  Lastly, I had to tell it that once the delay (time) was up that all LEDs needed to turn off or go LOW.   I had it all typed in and I hit verify to make sure there were no errors.  To my surprise, I didn’t get any errors.  I still am in shock that I got no errors.  I then uploaded the code to the Arduino and got nothing.  The circuit didn’t do anything.  I thought that it was probably a push button error because I was still a little confused on exactly the right way for things to go. This is when I noticed that I had the positive jumper wire from 5V (the power to the board) in the + part of the breadboard and realized that the push button needed to have the power since it was the one controlling the LEDs.  I moved the wire to c5 and moved the jumper wire leading from PIN5 to the push button to g5.  This is when I got the lights to work but it appeared that the push button wasn’t doing anything because the LEDs just were lighting up.  So, I decided to pull out the push button to see if it was doing anything, and to my surprise, it was because once I took it out the LEDs went dark.  This is when I put it back so I could keep looking at it and try to figure out what was wrong.  This is when I saw that the positive jumper wire and the jumper wire going from Arduino to the push button were on the same row but on different sides.  I vaguely remembered from my reading and research for this build something about how the legs on the push button run in a row with each other only one way.  I decided to move the push button jumper wire from g5 to g3, so it wasn’t connected to the power through the legs of the push button anymore.  Doing this allowed me to be able to push the button and control the LEDs lighting up.  I might have screamed I was so excited that I got it to work.

        As I was pushing the button and making sure each number showed up so I knew that I had it coded right, I noticed that I coded 3 to be three LEDs in a row instead of a diagonal like on a die.  So, I changed it in the code and checked it and it was right this time. 

Here is the code I used:

int Led1pin = 12;
int Led2pin = 8;
int Led3pin = 7;
int Led4pin = 11;

int Led5pin = 10;

int Led6pin = 9;

int Led7pin = 6;
int buttonpin = 5;
int buttonState;
long ran;
int time = 2000;

void setup ()
{
  pinMode (Led1pin, OUTPUT);
  pinMode (Led2pin, OUTPUT);
  pinMode (Led3pin, OUTPUT);
  pinMode (Led4pin, OUTPUT);

  pinMode (Led5pin, OUTPUT);
  pinMode (Led6pin, OUTPUT);
  pinMode (Led7pin, OUTPUT);
  pinMode (buttonpin, INPUT);
  randomSeed(analogRead(0));
}

void loop()
{
  buttonState = digitalRead(buttonpin);
  if (buttonState == HIGH){
    ran = random(1, 7);
    if (ran == 1){
      digitalWrite (Led7pin, HIGH);
      delay (time);
    }
    if (ran == 2){
      digitalWrite (Led1pin, HIGH);

        digitalWrite (Led6pin, HIGH);
      delay (time);
    }
    if (ran == 3){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led2pin, HIGH);

        digitalWrite (Led3pin, HIGH);
      delay (time);
    }
    if (ran == 4){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led3pin, HIGH);

        digitalWrite (Led4pin, HIGH);
      digitalWrite (Led6pin, HIGH);
      delay (time);
    }
    if (ran == 5){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led3pin, HIGH);

        digitalWrite (Led4pin, HIGH);
      digitalWrite (Led6pin, HIGH);
      digitalWrite (Led7pin, HIGH);
      delay (time);
   }
   if (ran == 6){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led2pin, HIGH);

        digitalWrite (Led3pin, HIGH);
      digitalWrite (Led4pin, HIGH);
      digitalWrite (Led5pin, HIGH);
      digitalWrite (Led6pin, HIGH);
      delay (time);
   }
  }
  digitalWrite (Led1pin, LOW);
  digitalWrite (Led2pin, LOW);
  digitalWrite (Led3pin, LOW);
  digitalWrite (Led4pin, LOW);

  digitalWrite (Led5pin, LOW);
  digitalWrite (Led6pin, LOW);
  digitalWrite (Led7pin, LOW);

}

The setup I used for the circuit.

My circuit that I made on Tinkercad.
Trying out something new instead of my
hand-drawn circuits.

Top left picture is the circuit just set up.  Other three are the
showing different numbers through the LEDs that are lit up.

Video of the circuit.

        The next part of the challenge was to “roll” the die 100 times and keep track of the number it showed and make a graph showing the number of times each number randomly came up.

        My final reflection for this build is that the push button was used to create randomization.  I also learned that the push button needs to have power and that the power and wire leading to a PIN on the Arduino that is linked to the push button need to not be on the same row even if they are on opposite sides of the breadboard.  This build really had me nervous and stressed after I first read about it because I wasn’t really sure where to start but thankfully Dr. B had a short video that helped calm me down and made me realize that I can do this and that it is okay to fail and fail again.  For this build, I needed to really pay close attention to details as it had more jumper wires and pieces needed that I needed to make sure everything got in the right place.  This program and circuit could be seen in gaming and is probably used in Vegas.  I think this could be a fun way to use a die or dice (if two or more are needed) to get a number for the children while playing a game or to answer a question.  Overall, I feel that this week went smoother than I thought for the build.

 

        Here is a picture of the layout of my maker space.  Now, this really caused me to spend a lot of time on it because the SketchUp program he suggested was super difficult to use, at least for me. But thanks to some useful YouTube videos I was able to create the space below.

The left wall is green to use as a green screen, the black boxes
 on the tables are 3D printers, and the storage on the bottom 
wall are open space storage that can hold small boxes with supplies.  
There are two windows on the top wall and the door on the bottom wall in the left corner.

Another view of the room.


Saturday, November 14, 2020

RGB and Multiple LEDs along with a Challenge Build - Week 3 - Adventures of Making

 

This week we had two builds to do and then a challenge of combining two or more builds and making the code work.  The first build was the Driving an RGB LED and the second build was Driving Multiple LEDs. Then for the challenge, I decided I wanted to combine these two challenges and see if I could get them both to work.

         First, Driving an RGB LED was pretty easy to set up and the code made sense for the most part.  The first part of the code has the RGB go through the 8 colors that can be created with it and a delay(1000) which is 1000 milliseconds.  Then the code has the RGB step through the colors the RGB can make by using the variable “x” and having “x” count from 0 to 767.  It uses if/else statements to figure out what color is to be being displayed at that time.  Below is the code I used, a picture of the circuit, and diagrams of the circuit (one I drew and one a fritz).

Picture of my set up.


                                                      Picture of what my board looks like.


Diagrams of the circuit.

Here are pictures of the code I used.  I had to use multiple and get
creative to get it all together.

         Once I got everything set up and the code all ready, I hit upload and the RGB started going through the eight colors, except green was missing.  I didn’t realize green wasn’t showing up until the second loop through when it just went off for a time and then continued.  I looked at the board to realize that the resistor that was supposed to be from d5 to f5 was actually in d5 to f6, so I fixed it and the next cycle I got green.  Now that everything was working, I went to clean up the code and after I got it all cleaned up, I hit verify and got an error message saying that showRGB wasn’t defined.  I looked at it and realized I took the curly bracket out on accident.  I put it back in and it verified again and didn’t get an error.  Wahoo.


RGB working video.

RGB explanation video. 

         Second, Driving Multiple LEDs again was easy to set up the code made sense, though I am not sure I could have figured out how to write the code to make it do all the different things it could.  This program had the circuit turning on LEDs oneAfterAnother, oneOnATATime, pingPong, marquee, and randomLED.  I learned that you can put // in front parts of the functions that are in the void setup() and that makes it become like a comment that the Arduino doesn’t recognize so it doesn’t do anything for it.  This allows you to have different functions that you can run one at a time using the same circuit setup and not have to have a different set of code for each one.  Below is the code I used, a picture of the circuit, and the diagrams of the circuit (one I drew and one a fritz).

Code pictures

Picture of the set up for 
the Multiple LEDs.
Picture of the circuit.

Diagrams of the circuit.

         The code above is the cleaned-up code.  I started with the messy and cleaned it up. I verified the cleaned-up code and got no errors.  I then went through and checked to make sure each loop worked.  They all still worked.  Below is a video with all the different loops working.

 

Video of all the different loops together.

         Last, I moved on to the challenge for the week where I was to put 2 or 3 circuit codes into one program and make the circuit work. I was able to do this by using the two codes and circuits from this week.  I set up by board with the multiple LEDs and then added the RGB, this was the easy part.  Now I needed to combine the two codes to make both work together.  The first time I tried to combine the two codes I started with the Multiple LEDs code and then went in and added the RGB code.  When I hit verify, I got an error saying missing terminating apostrophe instead of a semicolon, so I added the semicolon instead of the apostrophe (typing too fast error) and verified again.  I still got an error saying expected ‘or’, “before ‘void’” this took me a minute to figure out because it wasn’t as clear as the other code.  So, I went back to the printed code I had and realized that I forgot a semicolon after 11 above the line, so I fixed that and tried again.  Third time trying and it works, I got no errors, thank goodness.  I do like that it highlights the area where the error is even if I don’t understand what the error is telling me, it helped me figure it out even if it took a minute.  I now uploaded it to the board and only the multiple LEDs light up and nothing happened to the RGB.  I watched some videos about combining codes to see if I could figure it out.  After about three hours I decided it was time to quit for the night and try again tomorrow afternoon.  So, I started again the next day by making sure each code still worked individually and they both did.  This helped me know that they are correct and that it was the way I was combining them that was creating the problems.  This time I started with the RGB code and added the multiple LED code to it. I verified it and got a couple of error codes about ‘{‘ not being a token.  So, I removed them and verified again and it came back all good (no errors). I then uploaded it to the board and the RGB went through its loop and then the multiple LEDs went through its oneAfterAnotherLoop.  I first thought the RGB wasn’t doing anything but after waiting longer I realized it was still going through the colors just slowly and when it got back to red, it turned off as did the multiple LEDs and the whole thing started over again.  Below is a picture of my setup, the diagram of my circuit for the challenge, the code used, and a video of all it working.

 

Challenge setup.

Challenge diagram.


Pictures of the code used for challenge.


Here is a video of the challenge build.

Challenge Video

         Overall, this week the two builds we were given to do were easy to setup up the circuits and the codes seemed to make sense but again, I am not sure I would have been able to come up with them.  The challenge part of this week also was easy for the circuit setup but the coding part was frustrating and I am still not sure why I worked the way I did it the second time but not the way I did it the first time.  The RGB can be seen in video game consoles because they need to show different colors all in the same area at once.  I also think that it is used in controllers for video games that light up different colors in one spot as the player uses it.  The Multiple LEDs circuit can be seen on a flashing marquee sign that is trying to get peoples attention but it is also used in my husbands’ keyboard for his computer as it is backlit and changes colors slowly or fast depending on what he wants it to do (normally on slow because fast gives him a headache).  He can also make it light in different patterns and ways just like I was able to get the multiple LED circuit to do.  I am hoping that I have learned enough that I will be able to complete my own build setup and code to make that build work that we supposedly have coming up next week.  Now to take a day brain break before next week's Adventures in Making and class work.

Saturday, November 7, 2020

Adventures in Making - Using a Potentiometer

 

This week in my ETEC 568 class – Makerspaces I was challenged to build a circuit where I could control an LED with a potentiometer. The first thing I did was go to my book to look up what a potentiometer was so I knew what it was supposed to do. I learned that a potentiometer is a resistor with a knob that will control the voltage going to the LED causing it to get brighter or dimmer or to blink faster or slower depending on what it was coded to do.  Now that I understood what was going to happen, I set out to build the circuit.  Once I had all the materials, I followed the directions from the sparkfun Reading a Potentiometer and things were going well until I got the spark fun potentiometer (or pot) and the one in the directions had all the pins in a row and mine had two pins on one side and the third on the other.  This threw me for a loop and I spent quite a bit of time trying to find the answer to how it was supposed to go in the board compared to the one in the directions.  Needless to say, I never really found that answer so I put the pot in a7, c7, and b11 in my breadboard because this was the way that it would sit flush with the breadboard.  I got all the other wires and pieces in place, then added the code to the Arduino IDE and sent it to my UNO.  Well, guess what happened, I got an error message saying that it didn’t recognize/find the board.  I closed the program and tried again and again.  I couldn’t figure out what was going on because the program verified the code and I didn’t get an error until I tried to send it to the UNO.  I should have remembered from one of the videos I watched last week that I needed to hear that noise saying the computer recognizes the board.  I didn’t hear the noise but I didn’t realize that until a few hours later.  I asked my husband if he had another USB A/B cord, to which he thought he did but didn’t.  Thankfully I was already searching Amazon for a new one when it showed that it was the code for Cannon printers and that is the printer we have. I took that cord and tried it and still go nothing.  So, my husband said either the board is bad or the port is bad or the USB cord is bad. I was hoping it was just the cord, so I ordered one but didn’t want to just sit and wait.  I remembered reading in my book about a 9V battery cord, so I got that out with a 9V and put the red into pin 13 and the black into the GND, and guess what it lit up so I knew that it wasn’t the board.  This is when I with the help of my husband realized that it had something to do with the ground wire because when I unplugged it the LED would blink.  So, we unplugged all the wires that had to do with the pot and the LED was still blinking. I was glad that the board was bad and I decided I needed to unplug everything and start over with the build. This time I decided to turn the pot so that it didn’t go all the way into the breadboard putting one leg at a6, one at a8, and the last at e7.   I now know thanks to some wonderful classmates that the way I had it the first time had both the positive and negative in the same row which was causing it to short out since they can’t be in the same row.

1st set up attempt.

Picture of non-working pot setup.

 

  Top picture: 2nd setup, 2nd setup diagram – working circuit

Below is the cleaned-up code I used to make the LED blink and control how fast or slow it was blinking.

 Here is a picture of the circuit as well as a video showing it working and me explaining what I did.

Working pot circuit.

 

After getting the initial challenge to work I went to play with the circuit and code play for the week.  First, I tried to see if I could control using two digital pins instead of one digital and one analog.  So, I changed A0 to pin 8 both on the board and in the code and when I did this, I got a blinking LED still but I wasn’t able to control it with the pot.  Then I thought I wonder if in the code I need to change pin 8 to be input rather than an output if that would allow me to control it.  Well, it didn’t, so I wasn’t able to control the blinking of the LED when I used two digital pins.  As I thought about this setup, I wondered if analogRead needed to be changed to digitalRead to make it work.  I tried it and I got a LED that stayed on but I wasn’t able to control it with the pot. The same thing happened when I tried to use two analog pins instead of one digital and one analog.  I moved pin 13 to A1 on the board and changed it in the code.  When I did this the LED didn’t light up, so I couldn’t control the LED with the pot.   While I was in the second set up, I wondered if I needed to change digitalWrite to analogWrite in the code to make it work, so I did that but still got nothing.


Now, I moved on to the Extension Challenge part of the week.  The first challenge was to control 2 LEDs with the same brightness or same blink rate. At first, I had a red and blue LED and I was able to control the two lights with the same blink rate but not the same brightness since they were different color LEDs.  For this set up I had the LEDs in series.  So, I decided to see if changing to two of the same color (2 blue LEDs) would allow me to be able first, to control the same brightness and blink rate at the same time, again this was in series.  When I did this, I was able to control both LEDs with the same rate of blink and brightness. Below is a picture of the LEDs in a series

   

This is when I realized that I probably needed to put each LED on its own pin, so I went back to a blue and red LED and left the blue where it was in i20, i21 and put the red in h26 and h27, the jumper wire from i26 to PIN 8, and the resistor in g22 and negative.  I then went and added the second LED to the code and when I did this, I was able to control both LEDs with the same rate and brightness.  

Below is a picture, video, and code for this.  




The second part of the Extension Challenge was to see if I could control two LEDs with one potentiometer but have either one gotten dim while the other got brighter or one blink fast while the other blinked slow.  I tried switching the HIGH and LOW for the LEDs in the code to be opposite of each other and this just caused them to blink opposite of each other.  Then I tried adding a delayTime=100 into the code and put that after the first LED in the code to see if this would cause the blue LED to blink faster than the red.

This too just caused them to blink opposite of each other.  So, after a few hours of messing with it and looking for a solution I gave up and decided that was enough.

Here are the codes I used to try and get the second extension challenge to work.

                                        First one below:                                            


 Second one below:

This build taught me again that making sure the positive and negative aren’t in the same row causing a short is important and will cause lots less frustration if I make sure to not do that anymore.  It was also again clear that the coding in the program has to be right in order for me to get the outcome I want.  While I wasn’t successful in getting the second part of the extension challenge to work I know there is a way and it is probably simple but since I am new to this whole thing and don’t know all the other possible codes I could use and didn’t find one that would allow it to work I still learned some important things.  I can find potentiometers in the volume knobs of televisions, or the wall knob for a ceiling fan that allows the fan to speed up or slow down and even to turn off and on. I would assume they are also used in the big flashing arrows on roads that tell you to move over to another land because of construction.  I look forward to seeing videos or explanations next week of this week and seeing where I was off.  I also realized that I have classmates that are more creative than I am when it comes to the way they share their information on their blogs.  This is again showing me that while I thought I knew a lot about technology and technology things that I really only know about the things I use all the time and not about all the programs, apps, and things out there.

Final Post: Personal Retrospective

  WOW!!   I am not sure where to begin.   When I saw the assignments and things in week 1, I wasn’t sure what I had really gotten myself i...