![]() ![]() The output is a comma-separated list of values where the first value represents the current temperature in degree Celsius, and the second is the distance to the nearest object measured in centimeters. If you upload the program to your Arduino and play around with your hand in front of the sensor, you’ll see an output similar to the following: On the receiving side, you have to divide it by 100 again. This is done by the scaled_value function, which rounds a float value to two decimal digits and converts it into a long value by multiplying it by 100. We no longer transfer the sensor data as floating-point numbers on the serial port, but instead use scaled integer values.If yes, we measure the current temperature again. From lines 15 to 19, we check whether more than a second has passed since the last measurement. We use millis in line 7 to determine the number of milliseconds that have passed since the Arduino started. Because the current temperature usually won’t change often or rapidly, we don’t measure it permanently, but only once a second.The constant MICROSECONDS_PER_CM has been replaced by the microseconds_per_cm function, which determines the microseconds sound needs to travel 1 centimeter dynamically, depending on the current temperature.The code is nearly a perfect merge of the programs we used to get the PING))) and the TMP36 sensors working. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |