Biological Engineering


temperature range. If yes, turn on the LED in red and blink it according to how



Yüklə 202,98 Kb.
Pdf görüntüsü
səhifə14/16
tarix07.01.2024
ölçüsü202,98 Kb.
#212070
1   ...   8   9   10   11   12   13   14   15   16
temperature range. If yes, turn on the LED in red and blink it according to how
much the temperature deviated from the optimal range:
else if (tempC > hot) {
// If the temperature is hotter than the optimal temperature range
Serial.println(“It’s hot.”);
// Calculate how much the temperature deviated from the optimal range
if (temp_dif <= 10) {
/* Calculate LED blink interval in milliseconds based on the temperature
deviation from the optimal range; the further the deviation, the faster the LED blinks until
turning into a solid red */
// Blink the LED in red:
digitalWrite(BluePin LOW); // Turn off the blue LED
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
How can we help you?





digitalWrite(BluePin, LOW); // Turn off the blue LED
digitalWrite(GreenPin, LOW); // Turn off the green LED
digitalWrite(RedPin, HIGH); // Turn on the red LED
delay(LED_blink_interval); // Keep this status for certain time in ms
digitalWrite(RedPin, LOW); // Turn off the red LED
delay(LED_blink_interval); // Keep this status for certain time in ms
}
else {
digitalWrite(BluePin, LOW); // Turn off the blue LED
digitalWrite(GreenPin, LOW); // Turn off the green LED
digitalWrite(RedPin, HIGH); // Turn on the red LED
}
Program Part 4.4—If the temperature is within the optimal range, turn on the
LED in green:
else { // Otherwise the temperature should be fine; turn the LED on in solid green
Serial.println(“The temperature is fine.”);
digitalWrite(BluePin, LOW); // Turn off the blue LED
digitalWrite(GreenPin, HIGH); // Turn on the green LED
digitalWrite(RedPin, LOW); // Turn off the red LED
}
delay(10);
}
After the program is written, use the “verify” button in the IDE to compile the code
and debug errors if there are any. If the code has been transcribed accurately, there
should be no syntax errors or bugs. If the IDE indicates errors, it is necessary to work
through each line of code to make sure the program is correct. Be aware that
sometimes the real error indicated by the debugger is in the lines before or after the
location indicated. Some common errors include missing variable definition, missing
braces, wrong spelling for a function, and letter capitalization error. Some other errors,
such as the wrong selection of variable type, often cannot be caught during the
compile stage but we can use the “
Serial print
” function to print the results or
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
How can we help you?





compile stage, but we can use the 
Serial.print
function to print the results or
intermediate results on the serial monitor to see if they look reasonable.
Once the program code has no errors, connect the PC or laptop with the Arduino UNO
board without any wire or pin plug-ins using the USB cable. Check if the selections for
the type of board and port options under “Tools” in the main menu are still right. Use
the “upload” button in the IDE to upload the program code to the Arduino board.
Disconnect the USB cable from the board, and now plug in all the wires and pins. Re-
connect the board and open the “Serial Monitor” from the IDE. The current ambient
temperature should display in the serial monitor, and the LED lights color and blink
accordingly. If any further errors occur, they will show in the message area at the
bottom part of the IDE window. Go back to debugging if this happens. If there are no
errors and everything runs correctly, test how the measurement system works by
changing the temperature around the sensor to see the corresponding response of the
LED color and blinking frequency. This can be done by breathing over the sensor or
placing it close to a cup of iced water or in a fridge for a short time. When the room
temperature is in the set point range (about 18°C to 20°C) the green LED should be
lit. Once the temperature is too high, only the red LED should be lit. When the
temperature is too low, only the blue LED should be lit. If this does not work, check
that you have created different temperatures by using a laboratory thermometer and
then check the program code.

Yüklə 202,98 Kb.

Dostları ilə paylaş:
1   ...   8   9   10   11   12   13   14   15   16




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin