Build3-4

pdf

School

University of Florida *

*We aren’t endorsed by this school

Course

3003

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

7

Uploaded by CorporalGalaxy13875

Report
EEL 3003 Arduino Builds 3 & 4 Notes: There are multiple parts to some questions, insert pictures as required, save as a PDF, and upload into Canvas before the due date/time! Leave the question statements in your document, insert your answers/pictures, etc. after each individual question. Include your UF ID in all photos and videos First Name: Carolina Last Name: Horey UF-ID Number: 17990517 Read the instructions carefully, and then answer the questions below. Build 3 1) Read pages 42-51 in your Arduino Book and watch the lecture video “Arduino Build 3” 2) Before building the circuit review the following: a. If you are using the temperature sensor TMP36 from the former kit used in this class, please follow these instructions. Alternatively, if you are using the new ELEGOO Kit, proceed to part b. Replace the ground wire on the temperature sensor. In most circuits a good ground connection is critical. In the build 3 circuit, the temperature sensor is very sensitive to ground. If you connect the circuit as shown in the Arduino book, when one of the LEDs illuminates it can affect the sensor and your temperature readings will instantly change. If you connect the sensors ground directly to the Arduino board by replacing the black wire with the orange wire, you will fix this potential problem. IMPORTANT! Make sure you insert the temperature sensor correctly. If you wire it backward, it will get very hot, very fast and you will probably destroy it (and you won't be able to complete the assignment). If you notice the sensor getting hot, pull it out of the board immediately and check your wiring. b. If you are using the DHT11 Temperature and Humidity Sensor temperature sensor (from the ELEEGOO Kit) follow these instructions: Connect the top prong of the temperature sensor to the pin A0, the middle prong of the temp sensor to the positive breadboard terminal, and the bottom prong to ground the Arduino board. Also please make sure that your LEDs cathode/anode are correctly placed in the breadboard and you are using the correct resistors. Your build should look something like this:
Install the DHT sensor library by Adafruit before running the code into your board. Here's a quick guide on how to add the DHT library to your Arduino project: Using the Library Manager (Recommended) Open the Arduino IDE on your computer. Click on "Sketch" in the top menu bar, then navigate to "Include Library" and select "Manage Libraries." In the Library Manager, type "DHT" into the search bar. Look for the "DHT sensor library" by Adafruit, and click the "Install" button next to it. The library will be downloaded and installed automatically. You will see a confirmation message when the installation is complete. Copy and paste the following code into your Arduino IDE *************************************BEGINNING OF CODE*************************************** //adding the dht library #include <DHT.h> #define dht_apin A0 // Analog Pin sensor is connected to #define DHTTYPE DHT11 // DHT TYPE11 DHT dht(dht_apin, DHTTYPE); // declaring dht function // named constant for the pin the sensor is connected to const int sensorPin = A0;
// room temperature in Celsius const float baselineTemp = 20.0; void setup() { dht.begin(); // open a serial connection to display values Serial.begin(9600); // set the LED pins as outputs // the for() loop saves some extra coding for (int pinNumber = 2; pinNumber < 5; pinNumber++) { pinMode(pinNumber, OUTPUT); digitalWrite(pinNumber, LOW); } } void loop() { // read the value on AnalogIn pin 0 and store it in a variable int sensorVal = analogRead(sensorPin); // send the 10-bit sensor value out the serial port Serial.print("sensor Value: "); Serial.print(sensorVal); // convert the ADC reading to voltage float voltage = (sensorVal / 1024.0) * 5.0; // Send the voltage level out the Serial port Serial.print(", Volts: "); Serial.print(voltage); // convert the voltage to temperature in degrees C // the sensor changes 10 mV per degree // the datasheet says there's a 500 mV offset // ((voltage - 500 mV) times 100) Serial.print(", degrees C: "); //float temperature = (voltage - .5) * 100;replace this with: float temperature = dht.readTemperature(); Serial.println(temperature); // if the current temperature is lower than the baseline turn off all LEDs if (temperature < baselineTemp + 2) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); } // if the temperature rises 2-4 degrees, turn an LED on else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) {
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); } // if the temperature rises 4-6 degrees, turn a second LED on else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); } // if the temperature rises more than 6 degrees, turn all LEDs on else if (temperature >= baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); } delay(1); } ************************************ END OF CODE ************************************** 3) Be sure to open the serial monitor and observe the readings. 4) IMPORTANT! Notice the baseline in the code is set to 20. You may need to adjust this value to get the LEDs to light in a reasonable fashion. The LEDs should light slowly, perhaps taking 2 - 10 seconds to advance to the next one. If they all light immediately go back to the first bullet and wire the circuit as described above. If your temperature readings are too high, try changing some of the threshold values in the code to make it less/more sensitive. 5) You can raise the temperature by pinching the sensor or by blowing on it. 6) [2] In a few sentences describe what the circuit does. This is a very high-level description as if you were describing it to a non-technical person. This circuit takes in information from the code provided to output results. The temperature sensor used here inputs information regarding its surrounding temperature which is then read by the code and interpreted to provide a certain output. A baseline temperature is determined at the beginning and is compared to the temperature input by the sensor. The inputs from the temperature sensor are converted into usable values that we see on the serial monitor; these are the constantly updated sensor values, volts, and temperatures. With the degrees Celsius displayed on the serial monitor, we can take this value and compare it to our baseline temperature in different ways to obtain an output (LED lighting up). There are 4 outcomes in which none of the LEDs are on, the first one is on, the first two are on, or all of them are on. 7) Short answers a. [2] How does the following line of code (line 11 in the book, line 38 in the Arduino IDE), int sensorVal = analogRead(sensorPin); differ from digitalRead() that was used in last week's build 2? Last week we worked with digital values that only consider 2 outcomes: either on or off. We saw this with the switches as they were pressed (on) or not (off). This build deals with analog values which consider a range of values. For example, the temperature sensor will detect a range of temperatures; this is what will determine if our LED lights turn on. b. [2] How many millivolts change on the temperature sensor is equivalent to 1 degree Celsius? The code tells us there is a 10mV change on the temperature sensor per degree Celsius. c. [2] Why is there a 1ms delay in the loop? The delay allows us to properly see a change in the outputs according to the changes in temperature.
8) [5] Include a screenshot of the serial monitor and a brief description of the information provided by it. With the serial monitor, you can see the constant values of the sensor, voltage, and degrees Celsius. With my board connections, we know the voltage source is 5V, the code provides an equation to determine this value (float voltage = (sensorVal/1024.0) * 5.0). Since we know the voltage is 5V the sensor value is 1024 or close to it; in this case, it is 1023. Then the degrees C shows us our temperature as detected by the sensor. 9) [20] Download and complete the flowchart template of the code from file Build3 Flowchart.pdf , and include it in this report. You will be using this flowchart in the video described in part 7. 10) [25] Record a video of your working circuit. In your video refer to the flowchart you completed in part 6 while you describe how you circuit works. Be sure to include your UF ID in the video. *Video attached 11) [2] Describe your observations (challenges, thought process, anything interesting that occurred, etc.) At first, I was having issues with the temperature sensor but then realized this was due to issues with my connections. The flow chart was very helpful in understanding what exactly was happening, especially in interpreting the code. I could understand the if statements clearly, but the serial inputs confused me a bit in terms of interpreting the data. With the flow chart, I could understand that the information is taken in from the temperature sensor and then converted with the equations within the code to display on the serial monitor.
Build 4 DO NOT BUILD THE CIRCUIT IN THE BOOK!!! 1) Read pages 52-60 in your Arduino Book and watch the lecture video “Arduino Build 4 2) Build the circuit below. DO NOT BUILD THE CIRCUIT IN THE BOOK! This circuit is only a subset of the one in the Arduino book. Do not include the photo- resistor circuit. Typically in RGB LEDs, the green LED is not as bright as the red and blue. In order to show white (if you see pink then do this), you may need to replace the 220Ω resistor on the green LED with a wire. Refer to the book to determine which resistor to replace with a wire. 3) Be sure to open the serial monitor and observe the readings. 4) [2] In a few sentences describe what the circuit does. This is a very high-level description as if you were describing it to a non-technical person. Each yellow pin is connected to a different point on the RGB LED light. The code defines the red light being connected to the pin at 9, the green pin at 10, and the blue pin at 11. Within the code, signals are sent to each of these pins (or multiple) to output a color on our LED. Using Pulse Width Modulation (PWM), certain colors may be turned on at the same time to create a new color; for example, blue and red are turned on to create purple. The code itself is programmed for the lights to flash certain colors and then fade these colors into a rainbow. 5) Short answers: a. [2] What colors did you observe? At first, I saw flashes of colors including red, green, blue, yellow, light blue (cyan), purple, and white. Then the color would flash red again and fade into the different colors of the rainbow (red, yellow, green, blue, purple) and finally fade back into red. b. [5] What is Pulse Width Modulation (PWM)? PWM is a technique used to control analog devices via a digital signal. In this case, the RGB LED is an analog device because it can produce a range of colors (outputs) from the input (signal) is it given. Digital values are used to control these outputs by displaying different colors or a mix of them.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
c. [2] Which pins on the Arduino support PWM? All the pins support PWM as they can be mixed to create new colors on the RGB LED. These are pins 9, 10, and 11. d. [2] From the code copy a line that uses PWM? Serial . println ( "Purple (Red and Blue)" ) ; digitalWrite ( RED_PIN, HIGH ) ; digitalWrite ( GREEN_PIN, LOW ) ; digitalWrite ( BLUE_PIN, HIGH ) ; The output of the color purple is an analog value. Digital inputs are used to produce this color by instructing certain pins to turn on and off. In the code above, we see purple is being output, so with digital values we tell red and blue to turn on and green to stay off. 6) [25] Record a video of your working circuit. Be sure to include your UF ID in the video. *Video attached 7) [2] Describe your observations (challenges, thought process, anything interesting that occurred, etc.) At first, I connected my pins as shown in the diagram; however, I realized that this configuration did not correlate to the initialization by the code. I switched around my pins at 9, 10, and 11 to correspond to the correct color on the RGB LED as indicated by the code and this gave me an accurate output. After this change, it was easier to understand what was happening within the circuit.