Sistema Notificação e Monitoramento Ambiental contra Chuvas Fortes e Enchentes via SMS.

Monitoramento e notificação de condição ambiental, em tempo real, via rede celular, serviço de mensagens de texto(SMS), dos espaços urbanos conhecidos por sofrerem com alagamentos e enchentes em decorrência de chuva fortes e tempestades.

Criação de um dispositivo eletrônico programável de alertas via mensagem de texto (SMS), em tempo real, com sensores, baseados na plataforma de Arduino.

Lista de Materiais

1 Arduino Uno

1 Shield GSM para Arduino

2 Sensores de nível d’água

1 Fonte de alimentação 5Volts – 3 Amperes

1 Chip 3G para celular

Créditos para chip celular

1 Estanho para solda

15m Fio elétrico duplo

3m Tubulação eletrica 3/4

10 Abraçadeiras de metal

10 Parafusos e buchas

1 Tubo de silicone

1 Caixa elétrica para área externa

1 Placa Solar com bateria 5V 2A

Ferramentas

Ferro de solda, chave de fenda, alicate, multímetro, furadeira, broca serra copo, escada.

Circuito

Código do Arduino

//SMS Chuvas - 2018
//
// Sistema de Alerta via SMS contra Enchentes
// 
//Arduino UNO, Shield SIM900, 2 water level sensor, LEDs 
//Biblioteca Softaware Serial
//


// Biblioteca Software Serial
#include <SoftwareSerial.h>

// Portas software serial
SoftwareSerial SIM900(7, 8); 

// PORTAS SENSORES
const int buttonPin1 = 4;  // sensor1
const int buttonPin2 = 5;  // sensor2 

//PORTAS LEDS DE STATUS
const int ledPin1 =  10; // amarelo
const int ledPin2 =  11; // vermelho 
const int ledPin3 =  12; // verde

int state1 = 0;
int state2 = 0;


// Estado dos Sensores
//SENSOR 1
int ledState1 = LOW;         
int buttonState1;             
int lastButtonState1 = LOW;   

// SENSOR 2
int ledState2 = LOW;         
int buttonState2;             
int lastButtonState2 = LOW;   

//
int ledState3 = HIGH;         

// 
// DEBOUNCE DOS SENSORES
//
long lastDebounceTime1 = 0;  
long debounceDelay1 = 5000;    

long lastDebounceTime2 = 0;  
long debounceDelay2 = 5000;    



// TELEFONES
char phone1[] = "AT + CMGS = \"999911234\""; // telefone 1
char phone2[] = "AT + CMGS = \"981611299\""; // telefone 2

// MENSAGENS
char msg1[] = "Alerta Amarelo"; // mensagem 1 
char msg2[] = "Alerta Vermelho";//mensagem 2
char msg3[] = "Alerta Verde"; // mensagem3 

void setup() {


  
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);  


  //  LED 1
  pinMode(ledPin1, OUTPUT);   
  
  digitalWrite(ledPin1, ledState1);

  // LED 2
  pinMode(ledPin2, OUTPUT);   
  
  digitalWrite(ledPin2, ledState2);

  // LED 3
  pinMode(ledPin3, OUTPUT);   
  
  digitalWrite(ledPin3, ledState3);

  

}

void loop() { 

  SensorYellow();
  delay(100);
  SensorRed();
  delay(100);
  

}

void SensorYellow() {

  // LEITURA SENSOR AMARELO
  int reading = digitalRead(buttonPin1);

  
  if (reading != lastButtonState1) {
    
    lastDebounceTime1 = millis();
  } 

  if ((millis() - lastDebounceTime1) > debounceDelay1) {
    
    if (reading != buttonState1) {
      buttonState1 = reading;

      if (buttonState1 == HIGH) { 

        turnOnGSM();

        

        sendSMSx(phone1,msg1);
        delay(5000);
        sendSMSx(phone2,msg1);


        ledState1 = !ledState1;
        ledState3 = !ledState3;

        turnOffGSM();

      }     
      //STATUS VERDE
      if (buttonState1 == LOW) {

       

        turnOnGSM();

        
        sendSMSx(phone1,msg3);
        delay(10000);
        sendSMSx(phone2,msg3);
        delay(5000);
        
        ledState1 = !ledState1;
        ledState3 = !ledState3;
        
        turnOffGSM();
      }               
    }
  }

  
  digitalWrite(ledPin1, ledState1);
  digitalWrite(ledPin3, ledState3);

  
  lastButtonState1 = reading;

}

// LEITURA SENSOR VERMELHO

void SensorRed() {

  
  int reading = digitalRead(buttonPin2);

  
  if (reading != lastButtonState2) {
    
    lastDebounceTime2 = millis();
  } 

  if ((millis() - lastDebounceTime2) > debounceDelay2) {
    
    if (reading != buttonState2) {
      buttonState2 = reading;

      
      if (buttonState2 == HIGH) {

       

        turnOnGSM();
        sendSMSx(phone1,msg2);
        delay(5000);
        sendSMSx(phone2,msg2);

        ledState2 = !ledState2;
        turnOffGSM();
        
      }            
      
      if (buttonState2 == LOW) {  
        ledState2 = !ledState2;
      }                        
    }
  }

  
  digitalWrite(ledPin2, ledState2);

  
  lastButtonState2 = reading;

}

//ROTINA ENVIA MENSAGEM
void sendSMSx(char tPhone[], char tMsg[]) {
  // MODO SMS 
  SIM900.print("AT+CMGF=1\r"); 
  delay(100);
  // TELEFONE
  SIM900.println(tPhone);    
  delay(100);
  // MENSAGEM
  SIM900.println(tMsg); 
  delay(100);
  // DESLIGA
  SIM900.println((char)26); 
  delay(100);
  SIM900.println();
  // envio
  delay(5000); 
}

//LIGA GSM
void turnOnGSM(){

  digitalWrite(9, HIGH);   //LIGA GSM
  delay(2000); 
  digitalWrite(9, LOW);
  delay(5000);


  // BAUD RATE 19200
  // 
  SIM900.begin(19200);
  // tempo para conectar
  delay(20000);   


for (int i=0; i<=5 ; i++){

  ledState3 = !ledState3;
  digitalWrite(ledPin3, ledState3);
  delay(500);

}
//DESLIGA GSM

}

void turnOffGSM(){

  digitalWrite(9, HIGH);   //DESLIGA GSM
  delay(2000); 
  digitalWrite(9, LOW);
  delay(5000);

}





Prototipagem

Montagem do Sensor