Advertisement
RuiViana

Liga_Rele_Botao_Desliga_temperatura

May 9th, 2017
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #define redPin 4 //pin
  2. #define greenPin 6 //pin
  3. //#define bluePin 5 //pin
  4. ///////////
  5. int TORBINE;
  6. int Calc;
  7. int HSensor = 2; //pin
  8. ///////////
  9.  
  10.  
  11. ///////////////////////
  12. #define RELAY1  3  //pin                      
  13. #define RELAY2  7  //pin
  14. ////////////////////////
  15. int analogInput = A1;//pin
  16. float vout = 0.0;
  17. float vin = 0.0;
  18. float R1 = 30000.0; //
  19. float R2 = 7500.0; //
  20. int value = 0;
  21.  
  22. int vlt = 2.00; // 3volts  valores para criar a limpeza e inicio do flow
  23. /// simulaçao quando o valor for 3v o flow
  24. ////esta inativo quando for 0v esta activo
  25. //////////////////////////////////////////////////
  26. const int buttonPin = A2;
  27. int buttonState = 0;
  28. const int ledPin =  12;
  29.  
  30. //---------------------------------------------------------------
  31. void rpm ()
  32. {
  33.   TORBINE++;
  34. }
  35. //---------------------------------------------------------------
  36. const int buttonPin1 = A3; //para afunçao de activar depois de bloquado
  37. #define Leitura A1                  // Port para leitura analogica
  38. byte Status = 0;
  39. int corte = 600; //e como se fosse a tmp
  40. //---------------------------------------------------------------
  41. void setup()
  42. {
  43.   pinMode(analogInput, INPUT);
  44.   Serial.begin(9600);
  45.   //Serial.print("DC VOLTMETER");
  46.  
  47.   pinMode(RELAY1, OUTPUT);
  48.   pinMode(RELAY2, OUTPUT);
  49.  
  50.   pinMode(HSensor, INPUT);
  51.   attachInterrupt(0, rpm, RISING);
  52.  
  53.   pinMode(redPin, OUTPUT);
  54.   pinMode(greenPin, OUTPUT);
  55.   //pinMode(bluePin, OUTPUT);
  56.  
  57.   pinMode(buttonPin, INPUT);
  58.   pinMode(ledPin, OUTPUT);
  59.  
  60.   pinMode(buttonPin1, INPUT);
  61. //---------------------------------------------------------------
  62. }
  63. void loop() {
  64.   TORBINE = 0;
  65.   sei();
  66.   delay (1000);
  67.   cli();
  68.   Calc = (TORBINE * 60 / 7.5);
  69.   Serial.print(Calc, DEC);
  70.   Serial.print(" L/hour\r\n");
  71.   //////////////////////////////////////////////////////////////////////////////////////////
  72.   Serial.print("buttonPin1 ");Serial.println(digitalRead(buttonPin1));
  73.   Serial.print("Leitura ");Serial.println(analogRead(Leitura));
  74.   Serial.print("Status ");Serial.println(Status);
  75.   if (digitalRead(buttonPin1) == 1)                   // Botao pressionado
  76.   {
  77.     delay(50);                                    // Debouncing
  78.     if (digitalRead(buttonPin1) == 1)                 // Se botao continua pressionado
  79.     {
  80.       Status = 1;                                 // Liga rele
  81.     }
  82.   }
  83.   if (analogRead(Leitura) >= corte)                 // Se ultrapasou a temperatura
  84.   {
  85.     Status = 0;                                   // Informa rele desligado
  86.   }
  87.   if (Status == 0)                                // Se rele esta desligado
  88.   {
  89.     digitalWrite(RELAY1, LOW);                    // Desliga rele  port 7 (Fio Verde)
  90.     digitalWrite(greenPin, LOW);                  // Apaga Led verde Port 5 (Fio lilas)
  91.     digitalWrite(redPin, HIGH);                   // Acende Led vermelho Port 4 Fio preto)
  92.   }
  93.   if (Status == 1)                                // Se rele esta ligado
  94.   {
  95.     digitalWrite(RELAY1, HIGH);                   // Liga rele
  96.     digitalWrite(greenPin, HIGH);                 // Apaga Led verde
  97.     digitalWrite(redPin, LOW);                    // Apaga Led vermelho
  98.   }
  99.  
  100.   //////////////////////////////////////////////////////////////////////////////////////////////
  101.   value = analogRead(analogInput);
  102.   vout = (value * 5.0) / 1024.0;
  103.   vin = vout / (R2 / (R1 + R2));
  104.   Serial.print("INPUT V= ");
  105.   Serial.println(vin, 2);
  106.   if (vin < vlt)
  107.     digitalWrite(RELAY2, HIGH);
  108.   else
  109.     digitalWrite(RELAY2, LOW);
  110.  
  111.   int button = digitalRead(buttonPin);
  112.   if (button == HIGH)
  113.   {
  114.     digitalWrite(ledPin, LOW);
  115.   }
  116.   else
  117.   {
  118.     digitalWrite(ledPin, HIGH);
  119.   }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement