Embedded

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <dht.

h>

#define dht_pin 7

dht Dht;
void setup(){
  Serial.begin(9600);
  delay(500);
  pinMode(6, OUTPUT); // kipas
  pinMode(4,OUTPUT); // spray
  Serial.println("DHT11 Sensor");
  delay(1000);
   
}

void loop(){
  //dht11
  Dht.read11(dht_pin);
  int suhu = Dht.temperature;
  int kelembaban = Dht.humidity;

  if (suhu>35.00)
  {
    Serial.println("suhu tinggi Kipas menyala, spray menyala");
    digitalWrite(6, HIGH); //kipas on
    digitalWrite(4, HIGH);//spray on

  }
  if (suhu < 35.00 && kelembaban > 65)
    {
      Serial.println("kelembapan tinggi, kipas menyala");
      digitalWrite(6, HIGH); // kipas on
      digitalWrite(4, LOW); // spray off
    }
   if (suhu < 35.00 && kelembaban < 65.00){
    Serial.println("suhu standart");
    Serial.println("kipas dan spray mati");
    digitalWrite(6, LOW);
    digitalWrite(4, LOW);
//    digitalWrite(13, LOW);
   }
 
  //display
  Serial.print("humidity = "); Serial.print(Dht.humidity);Serial.println(" %");
  Serial.print("suhu = "); Serial.print(Dht.temperature);Serial.println("C");

  delay(500);
}
#include <LiquidCrystal_I2C.h>
//(address, kolom, baris)
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {

lcd.begin(16, 2); //jumlah kolom dan baris


lcd.clear(); //menghapus layar

void loop() {

int data = analogRead(A2); //mendefinisikan variable data untuk membaca input


analog pada pin A2
int suhu = map(data, 0,1023, 0, 500); //mendefinisikan variable suhu untuk
menimpan map suhu
lcd.setCursor(3,0); //setCursor pada kolom 3 baris 0
lcd.print("suhu : "); //menulis huruf
lcd.print(suhu);//menulis variable suhu pada layar
lcd.print("C");

}
#include <Servo.h>
Servo myServo;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);

//servo
myServo.attach(9);
}

void loop() {
  int adc = analogRead(A0);
  float pwm = map(adc, 0, 1023, 0,255);

  float pwm2 = map(adc, 0,1023, 0,180);

  Serial.print("Adc = ");
  Serial.print(adc);
  Serial.print(", pwm = ");
  Serial.print(pwm);
  Serial.print(" , pwm2 = ");
  Serial.println(pwm2);

  digitalWrite(2, HIGH);
  digitalWrite(4, LOW);

  analogWrite(3, pwm);
  delay(1000);
  //PWM --> Sudut putar
  myServo.write(pwm2);
  delay(1000);
}

You might also like