Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
Bruno CunhaB

Bruno Cunha

@Bruno Cunha
About
Posts
12
Topics
6
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Automatic Irrigation (Adjust Hour)
    Bruno CunhaB Bruno Cunha
    #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.
    My Project

  • Timer Help
    Bruno CunhaB Bruno Cunha

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

    Well is something like that

    My Project

  • Timer Help
    Bruno CunhaB Bruno Cunha

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

    My Project

  • Timer Help
    Bruno CunhaB Bruno Cunha
    
    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

    My Project

  • Timer Help
    Bruno CunhaB Bruno Cunha

    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

    My Project

  • Timer (Emergencie)
    Bruno CunhaB Bruno Cunha

    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);
    }
    "

    My Project

  • Irrigation System (LCD Keypad)
    Bruno CunhaB Bruno Cunha

    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

    My Project

  • Irrigation System (LCD Keypad)
    Bruno CunhaB Bruno Cunha

    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.

    My Project

  • Thermostat-Code problem
    Bruno CunhaB Bruno Cunha

    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 :)))

    My Project

  • Thermostat-Code problem
    Bruno CunhaB Bruno Cunha

    celsius1 is the value read by the sensor anda cesliusA is the value regulated by the potenciometer. One question, what is the purpose of the "#define HYSTERESIS 5"?

    My Project

  • Thermostat-Code problem
    Bruno CunhaB Bruno Cunha

    Hi, so im trying to make a a project with the arduino, where i have this:
    -Potenciometer
    -temperature sensor
    -Relay

    So the goal is to read the temperature of something that is heating and turn that off at a certain value that is regulated with the potenciometer.This Is simple , but i want to do something like turn off at 100ºC and only turn that on again at 95ºC. How can you help me? This is the code:

    // Relé ligado ao pino 7

    int porta_rele1 = 7;
    //Relé ligado ao pino 8
    int porta_rele2 = 8;

    float celsius;
    const int porta_sensor1 = A0; // sonda 1 ligada ao pino AO
    const int porta_sensor2 = A2; // sonda 2 ligada ao pino A1
    const int porta_pot1 = A1; // potenciometro 1 ligada ao pino AO
    const int porta_pot2 = A3; // potenciometro 2 ligada ao pino AO

    void setup()
    {
    //Define pinos para o rele como saida
    pinMode(porta_rele1, OUTPUT);
    pinMode(porta_rele2, OUTPUT);
    //Define pinos dos sensores como entrada
    pinMode(porta_pot1, INPUT);
    pinMode(porta_pot2, INPUT);
    pinMode(porta_sensor1, INPUT);
    pinMode(porta_sensor2, INPUT);
    //Estado inicial dos reles - desligados
    digitalWrite(porta_rele1, LOW);
    digitalWrite(porta_rele2, LOW);

    analogReference(INTERNAL);
    Serial.begin(9600);

    Serial.begin(9600);
    pinMode(porta_pot1, INPUT);
    pinMode(porta_sensor1, INPUT);
    pinMode(porta_pot2, OUTPUT);
    pinMode(porta_sensor2, OUTPUT);
    }

    void loop()
    {
    int value1 = analogRead(porta_sensor1); //valor lido na sonda 1
    long celsius1 = value1/9.31;
    int value2 = analogRead(porta_sensor1); //valor lido na sonda 2
    long celsius2 = value2/9.31;
    Serial.print(celsius1);
    Serial.print(celsius2);

    int valueA = analogRead(porta_pot1);
    int valueB = analogRead(porta_pot2);

    long celsiusA = valueA/9.31; // 10 mV por graus C.
    Serial.print(celsiusA);
    long celsiusB = valueB/9.31; // 10 mV por graus C.
    Serial.print(celsiusB);

    if(celsius1 <= celsiusA)
    {

    digitalWrite(porta_sensor1, HIGH); // aquecedor no pino 9

    }
    else
    {

    digitalWrite(porta_sensor1, LOW); // aquecedor no pino 9

    }
    delay(1000);
    }

    My Project
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular