Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Bruno Cunha
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Bruno Cunha

    @Bruno Cunha

    0
    Reputation
    12
    Posts
    350
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Bruno Cunha Follow

    Best posts made by Bruno Cunha

    This user hasn't posted anything yet.

    Latest posts made by Bruno Cunha

    • Automatic Irrigation (Adjust Hour)
      #include <string.h>
      #include <Wire.h>
      #include <DS1307.h>
      #include <avr/wdt.h>
      #include <EEPROM.h>
      #include <LiquidCrystal.h>
      #include <TimerOne.h>
      char dateTime[20];
      int RTCValues[7];
      char acertahora[8];
      
      int programas[21];
      LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
      const int analogS = 0; // Sensor connected to Analog 0
      const int relay1 =12; // Led connected at pin 13 ( Dry ON- Wet OFF)
      const int led2= 13; // Led connectected at pin 12(Dry OFF - Wet ON)
      const int relay2 = 11; // Realay connected at pin 8
      
      
      boolean up = 8;
      boolean sete = 9;
      boolean dow = 10;
      
      
      
      
      int i = 0;
      int p = 0;
      byte z = 0;
      byte h = 0;
      byte db = 0;
      boolean m = 0;
      boolean o = 0;
      int d = 0;
      int d1 = 0;
      byte menu = 0;
      byte program =0;
      int humidad = 0;
      int reading = 0;
      byte estouro = 0;
      int deslbomba = 0;
      int deslbomba2 = 0;
      
      
      void setup() {
        
        Serial.begin(9600);// initialize serial communications at 9600 bps
        DS1307.begin();
        lcd.begin(16, 2);
        
         Timer1.initialize(500000);
         Timer1.attachInterrupt(interrup);
        
        pinMode(relay1, OUTPUT);// declare the ledPin as an OUTPUT:
        pinMode(relay2, OUTPUT); // Declare relay as Output
        pinMode(led2, OUTPUT); //  
        pinMode(up, INPUT);
        digitalWrite(up, HIGH);
        pinMode(dow, INPUT);
        digitalWrite(dow, HIGH);
        pinMode(sete, INPUT);
        digitalWrite(sete, HIGH);
        digitalWrite(relay1, LOW); // Led off at start up
        
        humidad = EEPROM.read(50);
        o = EEPROM.read(51);
        for (int x=0; x<10; x++){programas[x] = EEPROM.read(x);}
        
        *((char*)&deslbomba) = EEPROM.read(52);
        *((char*)&deslbomba + 1) = EEPROM.read(53);
        
        
      }
      
      void interrup()
      {
      
        d1 = d1++;
        if(!menu == 0){estouro = estouro++;}
        if(!p == 0){estouro = estouro++;}
        if(!db == 0){estouro = estouro++;}
        if(!h == 0){estouro = estouro++;}
        if(!i == 0){estouro = estouro++;}
        if(m == 1){estouro = estouro++;}
        if(o == 1 && digitalRead(relay2)==HIGH && (reading > humidad)){deslbomba2 = deslbomba2++;}
        if(o == 0 && digitalRead(relay2)==HIGH && reading >= humidad){deslbomba2 = deslbomba2++;}
        // ou seja a bomba vai ligar ate atingir a humidade necessaria, quando a humidade for atingida ela conta um tempo que é o delay off bomba e depois desliga.
      }
      
      void acertartc()// COMANDO PARA ACERTAR A DATA E A HORA.
      {
       wdt_disable(); // DESABILITA A FUNÇÃO WDT NESTA PARTE DO PROGRAMA.
       delay(1000);
      
           while( i> 0 && i<8)
              {
                lcd.clear();
                lcd.setCursor(0,0);
                if(i==1){lcd.print(" Entre com Ano  ");}
                if(i==2){lcd.print(" Entre com Mes  ");}
                if(i==3){lcd.print(" Entre com Dia  ");}
                if(i==4){lcd.print(" Entre cm Semana");}
                if(i==5){lcd.print(" Entre com Hora ");}
                if(i==6){lcd.print(" Entre com Minut");}
                if(i==7){lcd.print(" Entre com Segun");}              
                if(digitalRead(up) == LOW){acertahora[i]++;estouro = 0;}
                if(digitalRead(dow) == LOW && acertahora[i] >= 0){acertahora[i]--;estouro = 0;}
                if(digitalRead(sete) == LOW){i ++;estouro = 0;}
                if(acertahora[1] < 1 ){acertahora[1] = 13;}
                if(acertahora[2] > 12){acertahora[2] = 1;}
                if(acertahora[2] == 0){acertahora[2] = 12;}
                if(acertahora[3] > 31){acertahora[3] = 1;}
                if(acertahora[3] == 0){acertahora[3] = 31;}
                if(acertahora[4] > 7){acertahora[4] = 1;}
                if(acertahora[4] == 0){acertahora[4] = 7;}
                if(acertahora[5] > 23){acertahora[5] = 0;}
                if(acertahora[5] == -1){acertahora[5] = 23;}
                if(acertahora[6] > 59){acertahora[6] = 0;}
                if(acertahora[6] == -1){acertahora[6] = 59;}
                if(acertahora[7] > 59){acertahora[7] = 0;}
                if(acertahora[7] == -1){acertahora[7] = 59;}
                lcd.setCursor(9, 1);
                lcd.print(acertahora[i], DEC);
                if(estouro == 20){ i = 0 ; estouro = 0;}
                delay(200);
              }
      
          DS1307.setDate(acertahora[1], acertahora[2], acertahora[3], acertahora[4], acertahora[5], acertahora[6], acertahora[7]); // AQUI ENVIAMOS OS DADOS DEFINIDOS PARA O REAL TIME CLOK
          lcd.clear();
            
      }
      
      void menus()
      {  
         wdt_disable();
         delay(1000);
         lcd.clear();
         while(menu > 0)
         {
            lcd.setCursor(0,0);
            if(menu==1){lcd.print("Definir Horarios"); if(digitalRead(sete)==LOW){p=1; menu=0; programa();}}
            if(menu==2){lcd.print("Definir Umidade "); if(digitalRead(sete)==LOW){h = 1; menu=0; humidade();}}
            if(menu==3){lcd.print("Acerta dt e a Hr"); if(digitalRead(sete)==LOW){i=1; menu=0; acertartc();}}
            if(menu==4){lcd.print("delay off bomba "); if(digitalRead(sete)==LOW){db=1; menu=0; offbomba();}}
            if(menu==5){lcd.print("Zerar programas "); if(digitalRead(sete)==LOW){z=1; menu=0; zera();}} 
            if(menu==6){lcd.print("Modo de Operacao"); if(digitalRead(sete)==LOW){m=1; menu=0; operacao();}}   
            if(digitalRead(up)==LOW && menu < 6){menu++;estouro = 0;}
            if(digitalRead(dow)==LOW && menu > 0){menu--;estouro = 0;}
            if(estouro == 20){ menu = 0 ; estouro = 0;}
            delay(400);
         }
         lcd.clear();
      }
      
      void programa()
      {
         wdt_disable();
         delay(1000);
         lcd.clear(); 
              while( p> 0 && p<7)
              {
                lcd.clear();
                lcd.setCursor(0,0);
                if(p==1 || p==2){lcd.print("   Programa 1   "); lcd.setCursor(2, 1);lcd.print(programas[1], DEC);lcd.print(':');lcd.print(programas[2]);lcd.print(" horas");}
                if(p==3 || p==4){lcd.print("   Programa 2   "); lcd.setCursor(2, 1);lcd.print(programas[3], DEC);lcd.print(':');lcd.print(programas[4]);lcd.print(" horas");}
                if(p==5 || p==6){lcd.print("   Programa 3   "); lcd.setCursor(2, 1);lcd.print(programas[5], DEC);lcd.print(':');lcd.print(programas[6]);lcd.print(" horas");}
      
                    
                if(digitalRead(up) == LOW ){programas[p]++;estouro = 0;}
                if(digitalRead(dow) == LOW && programas[p] >= 0 ){programas[p]--;estouro = 0;}
                if(digitalRead(sete) == LOW){p ++;estouro = 0;}
                if(estouro == 30){ p = 0 ; estouro = 0;}
                if(programas[1] > 23){programas[1] = 0; }
                if(programas[1] < 0){programas[1] = 23; }
                if(programas[3] > 23){programas[3] = 0; }
                if(programas[3] < 0){programas[3] = 23; }
                if(programas[5] > 23){programas[5] = 0; }
                if(programas[5] < 0){programas[5] = 23; }
                if(programas[2] > 59){programas[2] = 0; }
                if(programas[2] < 0){programas[2] = 59; }
                if(programas[4] > 59){programas[4] = 0; }
                if(programas[4] < 0){programas[4] = 59; }
                if(programas[6] > 59){programas[6] = 0; }
                if(programas[6] < 0){programas[6] = 59; }
      
                delay(400);
              }
      for (int x=0; x<10; x++)
      {
      EEPROM.write(x, programas[x]);
      }
      for(int x = 0; x < 16; x++) {delay(90);lcd.setCursor(x,1);lcd.write(B11111111);}
      lcd.clear(); 
      p = 0;
      }
      
      void humidade()
      { 
        wdt_disable();
        delay(1000);
        lcd.clear();
        while(h > 0)
        {
          lcd.setCursor(0,0); lcd.print("Definir Umidade ");
          if(digitalRead(up) == LOW && humidad < 100 ){humidad ++;estouro = 0;}
          if(digitalRead(dow) == LOW && humidad > 0){humidad --;estouro = 0;}
          if(digitalRead(sete) == LOW){h = 0;estouro = 0;}
          lcd.setCursor(5, 1);lcd.print(humidad);lcd.print("%   ");
          if(estouro == 20){ h = 0 ; estouro = 0;}
          delay(150);
        }
      EEPROM.write(50, humidad);
      for(int x = 0; x < 16; x++) {delay(90);lcd.setCursor(x,1);lcd.write(B11111111);}
      lcd.clear(); 
      }
      
      void offbomba()
      {
       { 
        wdt_disable();
        delay(1000);
        lcd.clear();
        while(db > 0)
        {
          lcd.setCursor(0,0); lcd.print("Delay off bomba");
          if(digitalRead(up) == LOW){deslbomba ++;estouro = 0;}
          if(digitalRead(dow) == LOW && deslbomba > 0){deslbomba --;estouro = 0;}
          if(digitalRead(sete) == LOW){db = 0;estouro = 0;}
          lcd.setCursor(5, 1);lcd.print(deslbomba);lcd.print(" Segundos");
          delay(150);
          if(estouro == 30){ db = 0 ; estouro = 0;}
        }
      EEPROM.write(52,*((char*)&deslbomba ));
      EEPROM.write(53, *((char*)&deslbomba + 1));
      } 
      for(int x = 0; x < 16; x++) {delay(90);lcd.setCursor(x,1);lcd.write(B11111111);}
      lcd.clear(); 
      }
        
      void zera()
      {
        lcd.setCursor(4, 0);
        lcd.clear();
        lcd.print("Zerando");
      
       for (int x=0; x<10; x++)
      {
      EEPROM.write(x, 0);
      } 
      for (int x=0; x<10; x++){programas[x] = EEPROM.read(x);}
      for(int x = 0; x < 16; x++) {delay(90);lcd.setCursor(x,1);lcd.write(B11111111);}
      lcd.clear();
      }
      
      void operacao()
      {
        wdt_disable();
        delay(500);
        lcd.clear();
        while(m > 0)
        {
          lcd.setCursor(0,0); lcd.print("Modo de Controle");
          lcd.setCursor(0,1); lcd.print("Dow = Um Up = Pr");
          if(digitalRead(up) == LOW){o = 0;digitalWrite(relay2, LOW); m = 0 ;}
          if(digitalRead(dow) == LOW){ o = 1; m = 0 ;}
          if(estouro == 30){ m = 0 ; estouro = 0;}
        }
      EEPROM.write(51, o); 
      for(int x = 0; x < 16; x++) {delay(90);lcd.setCursor(x,1);lcd.write(B11111111);}
      lcd.clear(); 
      }
         
      void mostrahora()
      {
         DS1307.getDate(RTCValues);
         sprintf(dateTime, "%02d:%02d:%02d   %02d/%02d", RTCValues[4], RTCValues[5], RTCValues[6], RTCValues[2], RTCValues[1]);
         delay(50);
         lcd.setCursor(0,0); lcd.print(dateTime);
         delay(50);
      }
      
      void teste()
      {
        if(programas[1] == RTCValues[4] && programas[2] == RTCValues[5] && RTCValues[6] == 0 && reading < humidad){ digitalWrite(relay2, HIGH);}
        if(programas[3] == RTCValues[4] && programas[4] == RTCValues[5] && RTCValues[6] == 0 && reading < humidad){ digitalWrite(relay2, HIGH);}
        if(programas[5] == RTCValues[4] && programas[6] == RTCValues[5] && RTCValues[6] == 0 && reading < humidad){ digitalWrite(relay2, HIGH);}
        if(o == 1 && reading < humidad){ digitalWrite(relay2, HIGH);}else{if(o == 1 && (deslbomba2/2) >= deslbomba){digitalWrite(relay2, LOW);}}// Caso queira que a bomba não desligue imediatamente coloque aqui seu delay.
      
        
        if(RTCValues[4] == 0 && RTCValues[5] == 0 && RTCValues[6] == 0) { digitalWrite(relay2, LOW);}
       
      }
      
      void informa()
      {
                  if(d1<= 10){lcd.setCursor(0,1);lcd.print("Setpoint. ");lcd.print(humidad);lcd.print("%             ");}
                  if(d1>10 && d1<=15){lcd.setCursor(0,1);lcd.print("Sensor ");lcd.print(reading);lcd.print("%             ");}
                  if(d1>15 && d1<=20){lcd.setCursor(0,1);if(digitalRead(relay2)==HIGH){lcd.print("> Bomba ligada <");}else{lcd.print("Bomba Desligada ");}}
                  if(d1>20 && d1<=25){lcd.setCursor(0,1);if(reading < humidad){lcd.print("Umidade Baixa!!!");}else{lcd.print(" Umidade Normal ");}}
                  if(d1>25 && d1<=30){lcd.setCursor(0,1);lcd.print("Irrigador Autom.");}
                  if(d1>=30){d1=0;}
           
      }
      
      void Nivel()
      {
        int nivelMax =  analogRead(1); 
        int nivelMini = analogRead(2); 
        if(nivelMax < 10) {digitalWrite(relay1 , LOW);}
        if(nivelMini < 10 && nivelMax > 500) {digitalWrite(relay1 , HIGH);}
      }
        void loop()
      {
       
          if(digitalRead(sete)==LOW){menu =1; menus();}
          reading = map(analogRead(analogS),0, 1023, 0, 100);
          mostrahora();
          informa();
          teste();
          Nivel();
          
          if(digitalRead(relay2)==HIGH && (deslbomba2/2) >= deslbomba){digitalWrite(relay2, LOW);deslbomba2 = 0;}
          if(reading < humidad){ digitalWrite(led2, HIGH);}else{digitalWrite(led2, LOW);
      }
      
      
         //for (int b=0; b<21; b++){
       // Serial.println(programas[b]);}
        //Serial.println(humidad , DEC);
      }
      I know i should learn and make myself the code, but i need this working by the end of this month, so, i pray for anyone that could look to the code and change it to work the same way but with a LCDkeypas instead of a typical LCD, it would really help me guys, and i promise i will learn when i got time.
      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • RE: Timer Help

      https://circuits.io/circuits/4669781-the-unnamed-circuit

      Well is something like that

      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • RE: Timer Help

      Well that remains a problem, the relay keeps turning in and off even if i dont press the button...

      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • RE: Timer Help
      
      int potPin = A1;
      const int buttonPin = A2;
      
      void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT);
      
      pinMode(buttonPin, INPUT);
      
      }
      
      void loop()
      {
      int buttonState = digitalRead(buttonPin);
      
      int val = analogRead(potPin);
      long tempo = (val*19.550342131);
      Serial.print(tempo);
      Serial.print("tempo:");
      
      // read the value from the sensor
      if (buttonState==HIGH) {
      
      digitalWrite(ledPin, HIGH);
      delay(tempo);
      digitalWrite(ledPin, LOW);
      } else {}; // turn the ledPin off
      
      delay(500);
      }
      
      

      Like this

      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • Timer Help

      Hi,´
      I have this timer, where when a button is pressed it activates a relay for some time, the duration is regulated by a potenciometer.

      int potPin = A1;
      const int buttonPin = A2;

      void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT);

      pinMode(buttonPin, INPUT);

      }

      void loop()
      {
      int buttonState = digitalRead(buttonPin);

      int val = analogRead(potPin);
      long tempo = (val*19.550342131);
      Serial.print(tempo);
      Serial.print("tempo:");

      // read the value from the sensor
      if (buttonState==HIGH) {

      digitalWrite(ledPin, HIGH);
      delay(tempo);
      digitalWrite(ledPin, LOW);
      } else {}; // turn the ledPin off

      delay(500);
      }

      Thats the code, my problem is that when i press de button, the arduino stops reading the code while it is counting, can anyone show me a way to keep running the code, but counting the time?
      Thank you

      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • Timer (Emergencie)

      Hi, i have this project where i control the the time (0-20 s) that a relay is actuated, i have a button to turn the relay and i want another button to turn off the relay in any moment, like a emergencie button. I though about running a parallel program but i dont know if it possible, here is the code.

      "
      int potPin = A0;
      int ledPin = 13;
      const int buttonPin = 2;

      void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT);

      pinMode(buttonPin, INPUT);

      }

      void loop()
      {
      int buttonState = digitalRead(buttonPin);

      int val = analogRead(potPin);
      long tempo = (val*19.550342131);
      Serial.print(val);
      Serial.print("tempo:");

      // read the value from the sensor
      if (buttonState==HIGH) {

      digitalWrite(ledPin, HIGH);
      delay(tempo);
      digitalWrite(ledPin, LOW);
      } else {}; // turn the ledPin off

      delay(500);
      }
      "

      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • RE: Irrigation System (LCD Keypad)

      Well i need to finish this Project until the end of this month so o dont have time to learn, im learning arduino but slower, i dont want a magic code just nisto way of programing the switch buttons to change the time, or where tofind

      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • Irrigation System (LCD Keypad)

      Hi,
      I´m on a irrigation system and i´m using a ds3132 module and a LCD keypad, well i searched a lot and i didnt find a way to change de hour using the switch buttons, for example, i have de lcd showing 6 am as the time it start to irrigate i want to be able to change that hour, so i dont need to disturb the code. I dont really know programing so that´s my problem, please help, thank you for your time.

      posted in My Project
      Bruno Cunha
      Bruno Cunha
    • RE: Thermostat-Code problem

      Yes it worked, i tried something similar before but i did "celsiusA -5" i didnt know i need a variable.I think its solved, thank you very much :)))

      posted in My Project
      Bruno Cunha
      Bruno Cunha