Cod Arduino

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

#include <IRremote.

h>

#include "DHT.h"

#include <LiquidCrystal.h>

#define DHTPIN 0

#define relay A1

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(8,9,4,5,6,7);

const int buzzer = 3;

const int led_rosu = 2;

const int led_verde = 1;

const int relay_pin_bec = A3;

int i=0;

volatile int v=28;

int receiver = A2;

//senzor ultrasonic

int trigPin = A5; ; //ultrasonic trig pin

int echoPin = A4; ; //ultrasonic echo pin

long duration, cm, inches;

IRrecv irrecv(receiver);

decode_results results;

unsigned long key_value = 0;

void setup(void) {
lcd.begin(16, 2);

lcd.print("Citire senzor");

dht.begin();

//pentru releu

pinMode(relay, OUTPUT);

digitalWrite(relay, HIGH);

pinMode(led_rosu, OUTPUT); // rosu

pinMode(led_verde , OUTPUT); // verde

pinMode(buzzer, OUTPUT);

//senzor ultrasonic

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(relay_pin_bec,OUTPUT); // pentru releul becului

irrecv.enableIRIn();

void translateIR(){

switch(results.value)

case 0xFFA25D: //lcd.print("1");

v = v + 1;

lcd.print(v);

break;

case 0xFF629D: //lcd.print("2");

v = v - 1;

lcd.print(v);

break;
case 0xFFE21D: //lcd.print("3");

lcd.setCursor(0,0);

lcd.clear();

lcd.print("Oprire Sistem!");

digitalWrite(relay, HIGH);

digitalWrite(relay_pin_bec,HIGH);

delay(20000);

break;

case 0xFFFFFFFF: lcd.print("Tasta- REPETA");break;

default:

Serial.println("Semnal necunoscut");

void loop() {

float temperature, humidity;

humidity = dht.readHumidity();

temperature = dht.readTemperature();

lcd.clear();
char tempF[6];

char humF[6];

dtostrf(temperature, 5, 1, tempF);

dtostrf(humidity, 2, 0, humF);

// comenzi senzor ultrasonic

digitalWrite(trigPin, LOW);

delayMicroseconds(5);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);

duration = pulseIn(echoPin, HIGH);

cm = (duration/2) / 29.1;

if( cm < 3){

lcd.clear();

lcd.print("ATENTIE!!! ");

lcd.setCursor(0, 1);

lcd.print("Prea aproape!");

digitalWrite(relay, HIGH);

delay(55000);

if (temperature> v){

digitalWrite(relay, LOW);

digitalWrite(relay_pin_bec,HIGH); //pornire bec

digitalWrite(led_rosu,HIGH);

delay(200);
digitalWrite(led_verde ,LOW);

delay(200);

if (temperature <= v){

digitalWrite(relay, HIGH);

digitalWrite(relay_pin_bec,LOW); //oprire bec

digitalWrite(led_verde ,HIGH);

delay(200);

digitalWrite(led_rosu,LOW);

delay(200);

lcd.print("T:");

lcd.print(tempF);

lcd.print((char)223);

lcd.print("C ");

lcd.print("H: ");

lcd.print(humF);

lcd.print("%");

lcd.setCursor(0, 1);

lcd.print("Temp setata:");

lcd.print(v);

//telecomanda

if (irrecv.decode(&results)){

translateIR();

irrecv.resume();

}
// sistem alarma - buzzer

if(temperature> 30){

lcd.clear();

lcd.print("ATENTIE!!! ");

lcd.setCursor(0, 1);

lcd.print("Temp Ridicata!");

tone(buzzer, 1000);

delay(10000);

noTone(buzzer);

delay(1000);

delay(1000);

You might also like