Εμφάνιση ενός μόνο μηνύματος
  #1  
Παλιά 27-06-13, 06:35
Το avatar του χρήστη jimbit22
jimbit22 Ο χρήστης jimbit22 δεν είναι συνδεδεμένος
Senior Member
 
Εγγραφή: 27-05-2011
Περιοχή: Ελληνορώσων
Μηνύματα: 491
Προεπιλογή

Και ναι, ξέρω, είναι λίγο χάος εκεί πάνω αλλά θα βελτιωθεί από 'βδομάδα..
-------------------------
αυτο ειναι το προγραμμα, για οποιον το θελει, οπως τρεχει τωρα για να συλεξω δεδομενα για την θερμοκρασια και την ταχυτητα των ανεμηστηρων..
εχει αρκετα κομματια απο το jarduino aquarium controller v1.1 αλλα λειπει η συναρτηση μου για την ανατολη δυση..
Κώδικας:
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <RTClib.h>
/*
Arduino Controller

Analog Pin 0 = LCD
Analog Pin 1 = LCD
Analog Pin 2 = LCD
Analog Pin 3 = LCD
Analog Pin 4 = LCD
Analog Pin 5 = LCD
Analog Pin 6 =
Analog Pin 7 =

Digital Pin 0 = RX
Digital Pin 1 = TX
Digital Pin 2 = One Wire Bus
Digital Pin 3 = Led Heatshink PWM Fan
Digital Pin 4 = SDA for I2C
Digital Pin 5 = SCL for I2C
Digital Pin 6 = Relay Filter
Digital Pin 7 = 
Digital Pin 8 = Relay Heater
Digital Pin 9 = Led Light Brightness
Digital Pin 10 = Tank PWM Fan
Digital Pin 11 = Moonlight Brightness
Digital Pin 12 = 
Digital Pin 13 =  

*/
#define ONE_WIRE_BUS 2

const int pwm_led_fan = 3;
const int pwm_tank_fan = 10;
const int pwm_ledlight = 9;
const int pwm_moonlight = 11;
const int relay_heater = 8;
const int relay_filter = 6;


OneWire oneWireBus(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWireBus);
DeviceAddress watertherm = {  0x28, 0x61, 0xDC, 0x71, 0x04, 0x00, 0x00, 0x2C  };
DeviceAddress ledtherm = { 0x28, 0xAD, 0x53, 0x77, 0x04, 0x00, 0x00, 0x63 };
DeviceAddress ambienttherm = { 0x28, 0xB7, 0xEF, 0x77, 0x04, 0x00, 0x00, 0x99 };
int v = 0;
float tempW = 0;
float tempL = 0;
float tempA = 0;
float FanOn = 0.2;
float WaterTempInterval = 0;            //Used for PWM Duty calculations
int LedTempInterval = 0;            //Used for PWM Duty calculations
float WaterFanSpeedIncrease = 0;      //Used for PWM Duty calculations
float LedFanSpeedIncrease = 0;      //Used for PWM Duty calculations
float WaterPWM = 0;                   //Used for PWM Duty calculations
float LedPWM = 0;                   //Used for PWM Duty calculations

float settempW = 26.0;
float settempL = 29.0;
float offtemp = 1.5;

float LC = 29.53059;                 //1 Lunar Cycle = 29.53059 days
double AG;


LiquidCrystal lcd( 14, 15, 16, 17, 18, 19);



/******************************** TEMPERATURE FUNCTIONS *******************************/
void checkTempC()
{ 
  sensors.requestTemperatures();   // call sensors.requestTemperatures() to issue a global 
                                   // temperature request to all devices on the bus
  tempW = (sensors.getTempC(watertherm));  //read water temperature
  tempL = (sensors.getTempC(ledtherm));   //read Water's heatsink temperature
  tempA = (sensors.getTempC(ambienttherm));   //read ambient temperature

  if (tempW<(settempW+offtemp) && tempW>(settempW-offtemp))  //turn off heater
      {
       digitalWrite(relay_heater, LOW);
       }
  if (offtemp>0)
    {
     if (tempW<=(settempW-offtemp))             //turn an heater
       {
        digitalWrite(relay_heater, HIGH);
       }
     }    
  //Fan Controller for Water
  WaterTempInterval = (tempW - settempW);   //Sets the interval to start from 0
  WaterFanSpeedIncrease = WaterTempInterval*2;   //Fan's speed increases 200% every degree over set temperature  
  if (tempW < settempW)          //If Temp's less than defined value, leave fan off
    { WaterPWM = 0;
     }
  if ((tempW  >= settempW) && (WaterFanSpeedIncrease < 1))   //For every degree over defined value, increase by 10%
    { WaterPWM = FanOn + WaterFanSpeedIncrease;}
  if (WaterFanSpeedIncrease >= 1)                 //If the temperature is 10 or more degrees C higher than user 
    { WaterPWM = 1;}                              //defined value to start, leave it at 100%
 
  //Fan Controller for Led
  LedTempInterval = (tempL - settempL);   //Sets the interval to start from 0
  LedFanSpeedIncrease = LedTempInterval*0.1;   //Fan's speed increases 10% every degree over set temperature  
  if (tempL < settempL)          //If Temp's less than defined value, leave fan off
    { LedPWM = 0;
     }
  if ((tempL  >= settempL) && (LedFanSpeedIncrease < 1))   //For every degree over defined value, increase by 10%
    { LedPWM = FanOn + LedFanSpeedIncrease;}
  if (LedFanSpeedIncrease >= 1)                 //If the temperature is 10 or more degrees C higher than user 
    { LedPWM = 1;}                              //defined value to start, leave it at 100%   
}
/*************************** END OF TEMPERATURE FUNCTIONS *****************************/

/******************************* LUNAR PHASE FUNCTION *********************************/
float moonPhase(int moonYear, int moonMonth, int moonDay)
{ 
  float phase;
  double IP; 
  long YY, MM, K1, K2, K3, JulianDay; 
  YY = moonYear - floor((12 - moonMonth) / 10); 
  MM = moonMonth + 9;
  if (MM >= 12)
    { MM = MM - 12; }
  K1 = floor(365.25 * (YY + 4712));
  K2 = floor(30.6 * MM + 0.5);
  K3 = floor(floor((YY / 100) + 49) * 0.75) - 38;
  JulianDay = K1 + K2 + moonDay + 59;
  if (JulianDay > 2299160)
    { JulianDay = JulianDay - K3; }
  IP = MyNormalize((JulianDay - 2451550.1) / LC);
  AG = IP*LC;
  phase = 0; 
  
  //Determine the Moon Illumination %
  if ((AG >= 0) && (AG <= LC/2))             //FROM New Moon 0% TO Full Moon 100%
    { phase = (2*AG)/LC; }
  if ((AG > LC/2) && (AG <= LC))             //FROM Full Moon 100% TO New Moon 0%
    { phase = 2*(LC-AG)/LC; }

  return phase; 
}

double MyNormalize(double v) 
{ 
  v = v - floor(v);
  if (v < 0)
    v = v + 1;
  return v;
} 
/**************************** END OF LUNAR PHASE FUNCTION *****************************/

/***************************LED BRIGHTNESS & MOONLIGHT ********************************/




void setup() 
{
  Serial.begin(9600);
  
  /*  Un-comment to set the time
    RTC.stop();
  RTC.set(DS1307_SEC,01);        //set the seconds
  RTC.set(DS1307_MIN,22);     //set the minutes
  RTC.set(DS1307_HR,13);       //set the hours (military)
  RTC.set(DS1307_DOW,2);       //set the day of the week
  RTC.set(DS1307_DATE,17);       //set the date
  RTC.set(DS1307_MTH,3);        //set the month
  RTC.set(DS1307_YR,9);         //set the year
  RTC.start();
*/
   
  
  pinMode (pwm_led_fan, OUTPUT);
  pinMode (pwm_tank_fan, OUTPUT);
  pinMode (pwm_ledlight, OUTPUT);
  pinMode (pwm_moonlight,OUTPUT);
  pinMode (relay_heater, OUTPUT);
  pinMode (relay_filter, OUTPUT);
  
  sensors.begin();
  sensors.setResolution(watertherm, 12);
  sensors.setResolution(ledtherm, 9);
  sensors.setResolution(ambienttherm, 9);
  
  Wire.begin();
 }
  
  
  void loop()
  {
    sensors.requestTemperatures();
    checkTempC();
    float tempC = sensors.getTempC(watertherm);
    if (v = 0)
    {
      Serial.print("Water Temp   PWM level/n");
    }
    else 
    {
      Serial.println("  ");
      Serial.print(tempC);
      Serial.print("    ");
      Serial.print(255 * WaterPWM);
    v = 1;
    }
    delay (500);
    TCCR1B = 0x01;  //  Timer 2: PWM 3 & 11 @ 32 kHz
    //OCR1A = 16000000.0 / (2*25000.0) * WaterPWM;  //"SumpPWM" is the % duty cycle for pin 45
    //OCR1B = 16000000.0 / (2*25000.0) * LedPWM;  //"HoodPWM" is the % duty cycle for pin 44
    //TCCR2B = _BV(CS00); // change the PWM frequencey to 31.25 kHz  - pins 3 & 11 timer 2
    
    analogWrite(pwm_tank_fan, 255 * WaterPWM);
  }
__________________
3dpg.gr/3D Printers Greece

30lit amano-red cherry shrimp
60lit blue pearl shrimp
130lit hi-tech φυτεμένο RIP

Τελευταία επεξεργασία από το χρήστη jimbit22 : 27-06-13 στις 06:35 Αιτία: Automerged Doublepost
Απάντηση με παράθεση
 
Page generated in 0,01271 seconds with 10 queries