Devices & Components
Arduino Plug and Make Kit
Modulino™ Buzzer
Arduino® UNO R4 WiFi
Modulino™ Thermo
Software & Tools
Arduino IDE
Project description
Code
temperaturesensor
cpp
1#include <Modulino.h> 2 3ModulinoThermo thermo; 4ModulinoButtons buttons; 5ModulinoBuzzer buzzer; 6 7#define BUTTON_A 0 // Button A: °C 8#define BUTTON_B 1 // Button B: °F 9#define BUTTON_C 2 // Button C: K 10 11const float tempThreshold = 30.0; 12 13enum TempUnit { UNIT_C, UNIT_F, UNIT_K }; 14TempUnit tempUnit = UNIT_C; 15 16void setup() { 17 Modulino.begin(); 18 thermo.begin(); 19 buttons.begin(); 20 buzzer.begin(); 21 Serial.begin(9600); 22 Serial.print("Starting Temperature Sensor...\n"); 23} 24 25void loop() { 26 float tempC = thermo.getTemperature(); // Read raw °C 27 float displayTemp = tempC; 28 String label = "°C"; 29 30 // Button handling 31 if (buttons.isPressed(BUTTON_A)) { 32 tempUnit = UNIT_C; 33 buzzer.tone(880, 100); 34 delay(200); 35 } else if (buttons.isPressed(BUTTON_B)) { 36 tempUnit = UNIT_F; 37 buzzer.tone(1000, 100); 38 delay(200); 39 } else if (buttons.isPressed(BUTTON_C)) { 40 tempUnit = UNIT_K; 41 buzzer.tone(1200, 100); 42 delay(200); 43 } 44 45 // Convert based on selected unit 46 switch (tempUnit) { 47 case UNIT_C: 48 displayTemp = tempC; 49 label = "°C"; 50 break; 51 case UNIT_F: 52 displayTemp = tempC * 9.0 / 5.0 + 32; 53 label = "°F"; 54 break; 55 case UNIT_K: 56 displayTemp = tempC + 273.15; 57 label = "K"; 58 break; 59 } 60 61 // Output result 62 Serial.print("Temp: "); 63 Serial.print(displayTemp, 2); 64 Serial.println(" " + label); 65 66 if (displayTemp >= tempThreshold) 67 { 68 Serial.print("TOO HOT: TEMPERATURE IS OR HIGHER THEN 30.00 °C\n"); 69 buzzer.tone(1500, 1000); // Beep if too hot 70 } 71 else 72 { 73 buzzer.noTone(); 74 } 75 delay(1500); 76}
Comments
Only logged in users can leave comments