Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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?

Respuestas (1)

Chetan
Chetan el 27 de Feb. de 2024
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

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by