Sunday, November 27, 2016

Week 4 - Electronic Dice

This week, we were supposed to build a circuit that digitally simulates rolling a die. The last time I attempted this, I was able to get the thing working, but not correctly. It would show some numbers perfectly, but others (4, if I remember correctly) would display random LEDs. This time, I started out with that in mind. For my first step, I decided to find an online tutorial demonstrating how to achieve the desired results. I found several, including some that used an LED numerical display. Unfortunately, I don’t have that numeric display. So, I eliminated those immediately. Then, I settled on one that the maker seemed very confident about. As it turns out, that confidence was either unfounded, or the instructions presented were too confusing. So, I found another tutorial that seemed more put together, and actually had a schematic that I could work from. I bypassed nearly all the instructions and pictures, and focused almost entirely on the schematic. Built the circuit, downloaded and verified the code, uploaded said code to my Arduino and had an LED that wouldn’t light up. But, it was a simple matter of wire tracing. I quickly discovered that I had two leads running to 1 LED and none to the one at the opposite end of that string of LEDs. I moved that wire and, voila! It worked perfectly. The saying: “The more you do it, the easier it gets!” is true, especially in something like this.


The code I used for this (without comments) is below:
i nt pinLeds1 = 10;
int pinLeds2 = 9;
int pinLeds3 = 7;
int pinLed4 = 8;
int buttonPin = 6;
int buttonState;
long ran;
int time = 2000;

void setup ()
{
  pinMode (pinLeds1, OUTPUT);
  pinMode (pinLeds2, OUTPUT);
  pinMode (pinLeds3, OUTPUT);
  pinMode (pinLed4, OUTPUT);
  pinMode (buttonPin, INPUT);
  randomSeed(analogRead(0));
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH){
    ran = random(1, 7);
    if (ran == 1){
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 2){
      digitalWrite (pinLeds1, HIGH);
      delay (time);
    }
    if (ran == 3){
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 4){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
    }
    if (ran == 5){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
   }
   if (ran == 6){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds2, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
   }
  }
  digitalWrite (pinLeds1, LOW);
  digitalWrite (pinLeds2, LOW);
  digitalWrite (pinLeds3, LOW);
  digitalWrite (pinLed4, LOW);
}


The circuit, itself, can be seen in the photo below. I found that the 2 most difficult parts of this week were: 1) keeping the wires from pushing the LEDs out of alignment or covering them up, and 2) finding a tutorial or instructional for this circuit that actually worked and was easy enough to follow.




The schematic that I used to build the above circuit is found below.



And, here is the build in action.



This week’s build was, at first, a bit difficult to find in the real world. However, once I stopped thinking of purely physical aspects and considered digital applications, as well as those that use a numeric display, I realized that this is something that is used in many different areas with some modifications. For example, we play a game called Farkle. In the physical world, we use physical dice. However, we have recently discovered digital versions of the game which use various forms of digital dice. Also, our refrigerator uses a similar circuit and coding to display temperatures and other settings. The difference with the refrigerator is that it is not displaying random numbers (we hope), but uses data from sensors in the appliance to tell the numeric displays what areas to light up. I think there may be a way to use this challenge build with some modifications to display the speed on my “boosted board” project that I want to build.



Saturday, November 19, 2016

Week 3 - Circuits Getting More Complex

This week’s project was to create 2 circuits, then combine them in some way to make one working circuit. I chose to start with circuit 4’s chasing lights option and have the 8 yellow LEDs chase up to the RGB which would then light up in sequence and after the 8 yellow LEDs and turn back off in reverse order followed by the 8 yellow LEDs. It was a success, except that for some reason the green portion of the RGB wasn’t very easy to see and none of the RGB elements would light up very brightly.

The following are shots of my codes from all 3 circuits. I have also attached PDF files of each code. The screenshots only show a small portion of the code, so I decided to include the files for reference purposes.






Here is a picture of each of the circuits as they were built on the Arduino breadboard. They are in order: Circuit 3, Circuit 4, Challenge circuit.





The schematics (following the same order) are pictured below:





And, finally, the video, demonstrating each of the circuits in action.



This project was a great challenge to me. It reminded of several things that I had not originally recalled about combining code. As many of you have probably figured out, it is not as simple as simple tacking one set of code onto another set. You have to take each section (declarations, routines, etc.) and put the code from each of those sections into the proper portion of the code you are adding on to, as well as ensuring that all variables are properly defined, not in conflict, proper pins/ports are addressed, and so on. It didn’t take me long to remember that lesson that was such a thorny issue to work through last time. In fact, if I remember correctly, I gave up on combining the code sections last time and just wrote a whole new set of code for this project. It was at that point that I realized exactly how things are laid out within the code itself.


Where would you find things like these circuits in the real world? The RGB circuit can be found in status lights on many different pieces of equipment. For example, my cordless Weedeater has status lights on the charger to indicate the condition of the battery. If the charge is between 90 and 100%, the LED lights up green. If it is 60-89%, it lights up orange. If it is below 50%, it lights up red. This is the same sort of circuit but with different inputs that determine which color element lights up. I have seen similar lights on cardboard presses to indicate when it is in operation, in error state, or safe to open the door. The chasing LEDs are found in Christmas lights, lights around dance floors, and directional lights such as the emergency beacons on police vehicles and ambulances. Oh yeah, I just remembered a common chasing LED setup: the brake lights on many modern motorcycles and some cars use LEDs that chase around the edge of the enclosure for higher visibility than the standard steady-burning lights provide. Watch the video below for a sample of these type of brake lights.


Thursday, November 10, 2016

Week 2 - Circuit 2 - Potentiometer



This week’s project involved building another simple circuit that was, basically, an upgrade to last week’s circuit. This circuit created a blinking LED, but included the ability to control blink rate via a potentiometer otherwise known as a variable resistor. The code I used for that circuit can be seen in the screenshot below.




This is a picture of the circuit itself.




Here’s a picture of my schematic for the circuit.




Below is my video of the project, with my usual commentary.




Here’s my vlog commentary about this challenge, how I worked through it, and my final reflection. There wasn’t much difficulty this week, at least not with the circuit itself. For those who don’t want to watch the video, I’ll include a text explanation below the video.




Notice! The text below is a rough transcript of the content of the video above. You are welcome to peruse both or just one.




So, this week’s challenge, at first sounded like it would be more challenging than last week’s. However, after studying the schematic in the Arduino guide, I realized that it was just an extension or upgrade of last week’s circuit. Once I realized this, everything having to do with the circuit was much easier than anticipated. One difficulty I had with the circuit was that it simply did not want to work. I checked everything and could find nothing wrong. Instead of trying to trace out wires for a 4th time, I decided to go ahead and pull it all apart and re-build the circuit from scratch, triple checking the orientation of the potentiometer. It all worked great.

The real challenge I had this week came before I got to that part of the project, however. I had not used my Arduino since before this summer. So, I did not have my original IDE software installed and had to download the newest version when we started this class. Apparently, Arduino has made some changes to their code library format requirements. When I downloaded the USK Guide Code library, the new IDE did not like it. It kept insisting that it was invalid. I checked online to see if others have had the same problem. They had! And, the fix was what I had thought about doing before I went and checked for a solution. What I read was: remove the library and all associated files from the IDE program folder and place them somewhere else, independent of the Arduino files. I did this, reset the Arduino itself, uploaded the code to the Arduino. No more invalid library error code.

The extension challenges were interesting and somewhat of a challenge, but not enough to cause me real difficulty. That will come with some of the later circuits.

Where do we find potentiometers in real life? They are everywhere. Volume controls, light dimmer controls, electric motor speed controls, etc. There is a particular application that I am going to try out for myself in the next few months. Our son will not ride a bicycle. He just sits on it and pushes it around. Recently, I discovered boosted boards. They are essentially extra long, motorized skate boards with remote controls. I thought about buying one for our son and adding a handle bar to compensate for his lack of coordination, but then found out the price. WAY OUT OF OUR BUDGET!!!! But, I figure I can build one with some of the electric motors and other parts we have lying around. I plan to use a potentiometer, attached to one of the handle bar grips, to control the speed of the motor. This way, the whole project would cost very little, would be safer than a regular boosted board, and would give our son the motivation to get out and move more, In fact, I might just set it up with really large wheels so that he can ride it off road, instead of needing to get out in the street.

Friday, November 4, 2016

Week 1 - Circuit 1 - Blinking LED

This week’s project was a very basic circuit and code to run that circuit. The purpose of the circuit and code was to create a blinking LED that would turn on for 1 second, then turn off for 1 second and repeat until it was turned off.
The code for this Arduino circuit was as simple as the circuit itself. That is to say, about as simple as it can get. The screenshot below is my version of that code. It is almost identical to the sample code, because there was really no need to make any changes other than cleaning up a few extra spaces.




Here is a picture of the circuit, including the Arduino and Breadboard. As you can see from the image, the circuit was very simple. But, as you might also notice, I made it slightly more complex than necessary for the sake of standardization. I could have eliminated the second white (-) wire by simply connecting the resistor directly from the circuit to the negative power strip on the breadboard. However, I know that other circuits will be too complex to allow for such direct connections, so I chose to get into the habit of connecting this way, instead.




This is the schematic of the circuit. Again, it’s very simple and straightforward.




This is my video of the cirucuit and some of my steps in creating it, as well as the extensions I did. I hope to have better lighting for future videos. This one was somewhat spur of the moment as I had some difficulties, at first, getting the Arduino and my laptop to talk to each other. I’ll explain that more, below.




Struggles with this week’s challenge: The first and biggest challenge I had was getting my Arduino and laptop to play nicely with each other. I had typed out my code, verified it, and saved it. Then, once I had my circuit built on the breadboard, I hooked up my Arduino to my laptop and attempted to upload my code to the Arduino. The IDE said that the Arduino was connected and recognized. However, at the very end of attempting to upload the code, I was presented with an error saying that the computer could not open the device. I tried multiple troubleshooting steps, including re-installing the drivers for the Arduino, with no success. I was beginning to think something had happened to my Arduino since the last time I used it, even though it seems impossible since it is stored in a hard case out of reach of children and animals. Finally, I found something online that suggested checking to see if the ports were correctly identified. When I checked them, they all looked to be correct, but I went ahead and reset them, anyway. Voila! It worked.


One of the biggest things I learned through this challenge is to step back, take a breath and approach from a new angle. Even when things appear to be perfect, and it’s something you’ve done a million times, there can still be something you’re not seeing just because you are too close to the subject.