Created
November 5, 2018 23:44
-
-
Save joaoperez55/f0781c023d980bf2e33c0e884a5547ac to your computer and use it in GitHub Desktop.
Irrigador_Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define F_CPU 16000000UL | |
#include "util/delay.h" | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include "usart.h" | |
#include "defs.h" | |
#include "adc.h" | |
#include "lcd.h" | |
int main(void) | |
{ | |
DDRL = 0b10111111; //definir pinos digitais como OUTPUT | |
//PinoBomba = 42 | |
//PinoLEDReservatorio = 44 | |
//PinoBuzzer = 45 | |
//PinoLEDSoloUmido = 46 | |
//PinoLEDBomba = 47 | |
//PinoLEDSoloSeco = 48 | |
//PinoLEDSoloEncharcado = 49 | |
uint16_t ValorSensorNivel; // armazena o valor do sensor de nivel | |
uint16_t ValorSensorUmidade; // armazena o valor do sensor de umidade | |
DisplayLCD_Init(); | |
DisplayLCD_Cmd(LCD_Clear); | |
DisplayLCD_Out(1,1,"Bem Vindo!"); | |
DisplayLCD_Out(2,1,"Irrigador Planta"); | |
_delay_ms(4000); | |
sei(); //chave global das interrupcoes | |
adc_init(); | |
while (1) | |
{ | |
// ler sensores | |
ValorSensorNivel = adc_read(0); | |
ValorSensorUmidade = adc_read(1); | |
DisplayLCD_Cmd(LCD_Clear); | |
//DisplayLCD_Out(1,1,"Irrigador Planta"); | |
//DisplayLCD_Out(2,1," Sistema Ativo "); | |
// se o nivel de agua estiver baixo, piscar LED reservatorio | |
if(ValorSensorNivel < 200) | |
{ | |
// mensagens no LCD | |
DisplayLCD_Cmd(LCD_Clear); | |
DisplayLCD_Out(1,1,"Nivel tq. baixo"); | |
DisplayLCD_Out(2,1,"Encher reserv. "); | |
// ligar LED nivel reservatorio baixo pino D44 | |
for(int i=0;i<2;i++) | |
{ | |
PORTL ^= 0b00100000; | |
_delay_ms(200); | |
PORTL ^= 0b00000000; | |
_delay_ms(200); | |
} | |
} | |
else | |
{ | |
// verificar intervalo umidade | |
if(ValorSensorUmidade < 300) | |
{ | |
//PORTL ^= 0b00000000; | |
// caso solo esteja encharcado | |
// mensagens no LCD | |
DisplayLCD_Cmd(LCD_Clear); | |
DisplayLCD_Out(1,1,"Solo encharcado"); | |
DisplayLCD_Out(2,1,"Solo encharcado"); | |
// ligar LED solo encharcado pino D49 | |
PORTL ^= 0b00000001; | |
//_delay_ms(100); | |
} | |
if((ValorSensorUmidade >= 300) && (ValorSensorUmidade < 700)) | |
{ | |
//PORTL ^= 0b00000000; | |
// caso solo esteja umido | |
// mensagens no LCD | |
DisplayLCD_Cmd(LCD_Clear); | |
DisplayLCD_Out(1,1,"Solo umido"); | |
DisplayLCD_Out(2,1,"Solo umido"); | |
// ligar LED solo umido pino D46 | |
PORTL ^= 0b00001000; | |
//_delay_ms(250); | |
} | |
if(ValorSensorUmidade >= 700) | |
{ | |
//PORTL ^= 0b00000000; | |
// caso solo esteja seco | |
// mensagens no LCD | |
DisplayLCD_Cmd(LCD_Clear); | |
DisplayLCD_Out(1,1,"Solo Seco"); | |
DisplayLCD_Out(2,1,"Solo Seco"); | |
//ligar LED solo seco pino D48 | |
PORTL ^= 0b00000010; | |
} | |
//_delay_ms(8000); | |
// se o solo estiver seco, liguar bomba durante 10 segundos | |
while (ValorSensorUmidade >= 700) | |
{ | |
//PORTL ^= 0b00000010; | |
// mensagens no LCD | |
DisplayLCD_Cmd(LCD_Clear); | |
DisplayLCD_Out(1,1,"Favor aguardar!"); | |
DisplayLCD_Out(2,1,"Bomba Ativa"); | |
// ligar bomba e LED bomba | |
PORTL ^= 0b10000100; // | |
_delay_ms(10000); | |
// desligar bomba e LED bomba | |
PORTL ^= 0b00000000; | |
// se o solo ainda nao estiver umido | |
// le a umidade do solo novamente | |
ValorSensorUmidade = adc_read(1); | |
_delay_ms(2000); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment