Halo semuanya, kembali lagi denan admin disini, pada kesempatan kali ini admin akan memberikan sefruit tutorial membuat alarm suhu di Arduino Uno
Alat yang kalian perlu persiapkan adalah aplikasi yang mensupport arduino uno seperti Arduino IDE, atau kalian bisa coding online di wokwi
nahhh, berikut adalah code yang bisa kalian coba untuk membuat alarm kalian sendiri, kalian juga bisa memodifikasi sesuai kebutuhan kalian
#include <Adafruit_LiquidCrystal.h>
Adafruit_LiquidCrystal lcd(0);
unsigned long previousMillis = 0;
const long interval = 1000;
const int ledPins[] = {1, 2, 4}; // Array of LED pins
const int numLeds = 3;
void setup()
{
Serial.begin(9600);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(" SENSOR SUHU");
delay(1000);
lcd.clear();
}
void loop()
{
String message;
long frequency;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
float tegangan, degC, input,degF;
input = (analogRead(A3) - 20) * 3.04;
tegangan = input* 5/1024;
degF= (degC*1.8)+32;
degC = map(input, 0, 1023, -40, 125);
//lcd.clear();
int value = map(analogRead(A3), 0, 1023, 0, 1000);
int activeLedIndex;
if (degC<15) {
activeLedIndex = 0;
message = "SUHU DINGIN";
;
} else if (degC >= 15 && degC <= 25) {
activeLedIndex = 0;
message = "SUHU SEJUK ";
} else if (degC >= 26 && degC <= 40) {
activeLedIndex = 1;
message = "SUHU PANAS ";
} else if (degC >= 41 && degC <= 55) {
activeLedIndex = 2;
message = "SUHU SNGT PANAS ";
} else {
activeLedIndex = 2;
message = "AWAS KEBAKARAN ";
}
// Turn on the appropriate LED and turn off all others
for (int i = 0; i <numLeds; i++) {
digitalWrite(ledPins[i], i == activeLedIndex ? HIGH : LOW);
}
lcd.setCursor(0,0);
lcd.print(message);
lcd.setCursor(0,1);
lcd.print(degC);
lcd.print(" \xB0\C/");
lcd.print(degF);
lcd.print(" \xB0\F");
}
}