필터 지우기
필터 지우기

how to take TMP36 measurements once every 2 seconds for an indefinite duration Arduino

조회 수: 2 (최근 30일)
clear
a=arduino;
voltage=readVoltage(a,'A0');
if (voltage>=0.76)
playTone(a,'D9',500,10)
end
I have a buzzer set up to sound if the temperature goes reaches or goes over 80 deg F, or if voltage >=0.76. How can I make the buzzer sound as long as the temperature is over 80 and not just for 10 seconds? How can I program the arduino to take continuous measurements every two seconds?

답변 (1개)

Chetan
Chetan 2024년 2월 27일
Based on your requirements:
  • You want the buzzer to sound continuously when the temperature is 80°F or above.
  • You need the Arduino to take temperature readings every two seconds.
As a solution you can
  • Utilize a `while` loop for continuous temperature monitoring.
  • Use `playTone` within an `if` statement to sound the buzzer for 2 seconds when the threshold is met.
  • Implement `pause(2)` to set the measurement interval.
Here is the sample code for the same:
clear
a = arduino;
% Buzzer settings
buzzerPin = 'D9';
frequency = 500;
% Monitoring loop
while true
voltage = readVoltage(a, 'A0');
if voltage >= 0.76
playTone(a, buzzerPin, frequency, 2);
end
pause(2);
end
You can refer to the following MathWorks documentation for details regarding Arduino functions
Best regards,
Chetan Verma

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by