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.
Dostları ilə paylaş: