Introduction
The main objective of the experiment served as a way to show the concept of prioritizing events with the Arduino Uno. This lab involved two separate LED sequences that were controlled by two separate buttons. The first sequence named group1 was controlled by a pushbutton known as PB1. Similarly, a second group was created known as group2, controlled by a second pushbutton known as PB2. When either pushbutton was pressed a one of two possible LED sequences would begin causing the LEDs to light up and count in binary, with the most important being the furthest from the left. PB1 was given a higher priority over PB2, which in theory would omit what PB2 did if pressed shortly after the group2 sequence begins. When PB1 was pressed, starting the initial sequence, the LEDs would light up and count up to 15 without any interruptions despite pressing PB2 during the sequence. However, if the initial sequence started with PB2 and PB1 pressed during the group2 sequence, an override would occur and the LEDs woud begin counting group1. After the overriding group1 sequence concluded, the sequence for group2 would finish its own sequence.
The following report will be broken in to sections, Section 2 will consist of the Design Methodology, which will go further in-depth with the hardware and software used in the lab. After which come will be the Results and Analysis, additional concerns for design and alternative design. Finally the Broader Impact section will discuss real world examples if microcontrollers being used for, economical, global and environmental issues.
1.1 Arduino Uno Microcontroller
The Arduino Uno microcontroller board uses a Atmega328P micro controller. On the controller board there are 14 digital I/O pins and 6 analog pins [1]. Each individual pin can provide or receive 20 mA of current [1]. The Arduino Uno has a power jack and a USB port that is used to provide power to the Arduino Uno. The Arduino also has a operating voltage of 5v [1]. Arduino Uno also has 32Kb of flash RAM, 2Kb of SRAM, and 1Kb of EEPROM [1]. A picture of an Arduino Uno is shown below in Figure 1.
1.2. Other Hardware
The following lab used eight LEDs, ten 220 Ohm resisters, a USB power cable, and 2 pushbuttons. LED can simply be characterized as a diode that is designed to give off light in the form of photons [2]. This occurs when a diode is forward biased and the electrons are moving from the n-type side to the p-type side [2]. When an electron from the n-type side travels to the p-type side the electron will fill a hole and will disappear [2]. This interaction will produce light as the electron is going from a position of higher energy to a position of lower energy in an atom. The excess energy is given off in the form of a photon and appears to the viewer a light. The 220 ohm resistors are passive circuit elements that provides the circuit with 220 Ohms of electrical resistance [3]. Resistance in a circuit limits the number of electrons that pass through the circuit [3]. A passive element means that the resistor will always absorb power not give it. The USB power cable is a 6 FT power cord that provides 5v from a computers USB port to the Arduino. A pushbutton is a button that connect two sides when the button is pressed and disconnects those same sides when the button is released.
2. Design Methodology
2.1 Hardware
The hardware setup for the following lab consisted of an Arduino Uno connected to a computer using a USB cable. Then 8 220 Ohm resistors were wired in series with 8 LEDs. Two push buttons were also wired to the breadboard and they were attached to a 5v DC that would activate when the button was pushed. The following is a diagram of the hard ware set up.
Figure 1: Wiring Diagram
We connected 8 jumper cables to connected from the Arduino and wired to the LEDs in order to provide them power, which would light them up when the specific pin was set to HIGH. The ON signal from the Arduino will provide 5v through the 220 Ohm resistor to the LEDs. The purpose of these resistors limit the amount of current being drawn from the digital output pin. The two pushbuttons (PB1 and PB2) are connected to the 5v power supply on the Arduino Uno. Both pushbuttons are also connected to digital pins 12 and 13 to provide the input signal to perform the specific code if the value on that pin is HIGH, with PB1 being connected to digital pin 12 and PB2 connected to digital pin 13. Each pushbutton has its own specific 220 Ohm resistor that was used after the pushbuttons this is used to pull down the value at the pin to 0v till a proper input is provided.
2.2 Software
The software that was used in this program was designed to create two binary counters that will each count from 0-15 when digital input pins 12 or 13 received on “ON†signal. The first few lines of the code simply set variables for the pins. The void setup function initializes the libraries, the pins and sets pins 3-9 as output pins and pins 12 and 13 now known as PB1 and PB2 as the input pins. Next comes the Void loop function which will run the program continuously. At the beginning of the code “digitalWrite†is used to set all the LED pins to 0v this is done to ensure the LEDs do not stay on after the count. If/else statements are used to determine the status of the pushbutton and will complete the code if either PB1 or PB2 are pressed. If PB1 is pressed the function disp(); is performed. The “disp()†function is a function that was made to make the Arduino count from 0-15. The function begins by indicating digital pins 2-5 as low then it will have a 250 milliseconds delay. Then the function will indicate digital pin 2 as “HIGH†since pin 2 is the LSB. The process is continued for each proceeding value to 15 with 250 milliseconds delays in between. After the “disp()†function in the code there is an else/if statement to check if PB2 is pressed, if PB2 is pressed the code in its bracket will initialize. The next code uses a switch/case statement to sequence group 2 LEDs from 0-15. After each case, the variable “var†will be updated so that it will move to the next case. This switch/case function is inside a while loop that has the condition of while “var†is not equal to -1 so at the end of case 15 “var†is set to -1 to exit the loop. In between each case for the group2 LEDs sequence another if statement is ran to check the status of PB1 and has instructions to display group 1 LEDs before proceeding to the next case.
3. Results and Analysis
The program used served to provide events from pushing a pushbutton while giving priority to the sequence associated with group1 proved to be a success. The final result was calculated by first making sure each sequence was initialized by its corresponding button. Afterwards, we began with first pressing PB1, and waited until the sequence ran for 2 seconds. This sequence counted from 0-15 starting from the LSB being connected to pin 2 and the MSB being connected to pin 5. The final pattern in the sequence was “OFF†(0000) since it was set to return to zero once the system finished counting to 15. If PB1 was pressed quickly the program would cycle through 0-15 once. The was a result of the push button being used as a debounced. The initial delay between the counts was 100ms however, we modified the delay to 250ms in order to accurately observe. Next PB2 was pressed, this initialized the second sequence linked to group2 to begin counting from 0-15 with the LSB being pin 6 and the MSB being pin 9. The final sequence after pressing PB2 was “OFF†(0000) as a result of the LEDs being reset to zero at the end of the sequence. When PB2 was pressed twice quickly the Arduino only counted once. This was a result of the pushbutton being debounced. The final objective was to thoroughly test that group1 had priority over group2. In order to test that PB1 had a priority over PB2, PB2 was pressed first, shortly after PB1 was pressed resulting in the sequence associated with group2 halting and then the counting sequence for PB1 beginning. The group1 sequence continues until it finished the group1 sequence and then proceeded to finish up the sequence for group2.
4. Alternative Design
4.1 Hardware
The hardware used in the alternative design is the exact same as the original, however, the placement changes a bit. The new program took advantage of the port registers function. To use these registers we used pins 0-3 for group1 LEDs and pins 4-7 for group 2 LEDs. With the group1 MSB pin 3 and LSB pin 0. The group2 MSB was pin 7 and LSB was pin 4. The new wiring diagram of the circuit is shown in figure 2 below.
Figure 2: Alternative design wiring diagram
The hardware remains the same, consisting of the same amount of LEDs (8) and 220 Ohm resistors with the main difference being that the group1 LEDs would now be powered by pins 0-3 on the Arduino and the group2 pins would be powered by pins 4-7. These new pin locations are located on port register D and byte representations are used to track which LEDs should be on.
4.2 Software
The byte representations of the code would select which pin would get power by its position in the code for instance PORTD = B00000001 would select pin 0 to be lit and all other pins 1-7 to be de-energized. The code will still go through the sequence however, there are some differences due to using port registers. The program will change the value on the digital pins at the same time an example of this is the code PORTD = B011 this will cause pins 0 and 1 to energize at the exact same time. This is different between setting them high milliseconds after each other like with the digitalWrite function. Writing with port registers is faster and uses a lower level of programming that can be used to make your program smaller [1]. The code that was written using port registers was 35% smaller than the one without using them this is shown in figure 3 below.
Figure 3. Size of alternate code
The code above shares a lot with the code that was discussed in the original design. The flow is the same as before however, there are a few differences. In the beginning of the code instead of using pinmode to set the LED pins as outputs the function DDRD is used, this uses binary notion such as B11111111 to set pins 0-7 as output pins. Another major difference between the code is that instead of using the function digitalWrite to change the values of the pins the function PORTD is used and binary notation such as B001 is used to set pin 0 to HIGH and pins 1 and 2 LOW. The last difference between the two codes is how the last values is stored we did this by lowering the last value of group 2 LEDs with the display function that counts group 1 LEDs if pressed.
5. Additional Concerns in the Design Process
This section will describe how public health and safety, economic, and environmental concerns changed the design process.
5.1 Health and Safety
In the experiment, health and safety were maintained by properly following the rules and instructions given to us by the instructor. All resistors were measured before using them, the power was removed from the Arduino. Not many possibilities for injury in this lab
5.2 Ethical Concerns
The IEEE ethical code was adhered to during the completion of this lab. IEEE code 1. states to accept responsibility in making decisions consistent with health and safety [5]. This was demonstrated during the lab as we all worked on the experiment in a safe and professional manner. Health and safety was also given a place in the report to take responsibility for our safe work practices. In addition IEEE code number 5 was used during this lab. IEEE code 5 refers to improving understanding of technology. This was demonstrated in this lab as research was required to learn about port registers as well as improving the group’s ability to program effectively in Arduino code.
6. Broader Impact
6.1 Environmental Impact
The impact of microcontrollers on the environment is significant. One of the largest pollution problems in the world to today is carbon emissions. The Infineon Tri-core Microcontroller for instance is used in over 50 automotive brands and is responsible for making the vehicles exhaust emissions as low as possible [5].
6.2 Social Impact
The invention of the microcontroller has had a major impact on society. A specific example of the microcontroller impacting society is the ability to communicate freely in automobiles. The invention of blue tooth in cars today allows people to communicate safely while driving motor vehicles. Microcontrollers are even making it possible for people who do not know how to drive or may be unable to drive to have the social impact of driving. Many companies such as BMW, Mecedes-Benz, and tesla have either released or are soon to release these self-driving cars[6].
6.3 Economic Impact
Microcontrollers have had a major impact on the world however, this is an example of how the microcontrollers is affecting automobiles. Most well equipped cars now a days have at least 50 separate microcontrollers in it, this is to control many of the additional features that are being added into cars today [7]. This impacts the economy as the semiconductor industry has been growing due to the increased demands from the automobile industry. In 2015 for example the automotive semiconductor market grew to 29 billion [8].
6.4 Global Impact
The Microcontroller has a global impact due to the reduction of emissions. This will limit the amount of greenhouse gasses emitted to the environment and will in turn help combat global warming. The development of microcontrollers is what allows car manufacturers to create hybrid cars and electric cars as they are controlled by microcontroller units [7].
7. Individual Contribution
As always, the work in this lab was distributed by all three of us in a very efficient fashion. We had James working on the code while I built the LEDs and Michael was in charge on taking notes trouble shooting, making sure everything was functioning properly.