|
DIY . Φτιάχτο μόνος σου Ο τίτλος τα λέει όλα. |
![]() |
|
Εργαλεία Θεμάτων | Τρόποι εμφάνισης |
#1
|
|||
|
|||
![]()
Υπάρχει κανένας να βοηθήσει με τον κώδικα για έναν Controller με βάση το Arduino η βασική ιδέα είναι να ελέγχει:
-Θερμοκρασία -PH -TDS -Dosing Pumps -Φώτα -Αυτόματη αναπλήρωση Μέχρι τώρα έχω καταφέρει να φτιάξω τον Controller να μετράω Θερμοκρασία και να έχω ενδείξεις σε μια οθόνη LCD 20x4. έχω κολήσει όμως και δεν μπορώ να κάνω τα ρελέ να ανοιγοκλείνουν οπότε μια βοήθεια θα μου ήταν σωτήρια γιατί αλλίως θα αναγκαστώ να εγκαταλείψω... ![]() ![]() |
#2
|
||||
|
||||
![]()
Καλησπέρα. Μια free έκδοση κωδικα ειναι ο jarduino όπου ελέγχει θερμοκρασίες κ φώτα (στο μέλλον θα μπουν κ αλλα παρελκομενα).
Στο reefcentral αν ψαχτεις εχει διάφορες κατασκευές arduino. Αν καταφέρεις να βάλεις το ferduino κ να κατασκευάσεις όλο αυτά που εχουν φτιάξει σίγουρα θα ειναι μεγαλο κατόρθωμα. Ο κώδικας κ εδώ ειναι free αλλα αν θέλεις μπορεις να τα πάρεις όλα έτοιμα γύρω στα 120Ε. Κ ο ελληνικός poseidon ειναι πολλή καλός αλλα δεν εχει όλα αυτά που θες. |
#3
|
||||
|
||||
![]() Παράθεση:
Κώδικας:
san afto
__________________
3dpg.gr/3D Printers Greece 30lit amano-red cherry shrimp 60lit blue pearl shrimp 130lit hi-tech φυτεμένο RIP |
#4
|
|||
|
|||
![]()
Δημήτρη Καλησπέρα τί κάνεις σου είχα στείλει και ΠΜ ρίξε μια ματιά μπάς και ξοκολήσω λίγο γιατί είναι κρύμα τόσος κόπος και τόσα λεφτά να τα πετάξω.
Κώδικας:
#include <LiquidCrystal.h> #include <math.h> #include "RTClib.h" #include <Time.h> #include <Wire.h> #include <OneWire.h> #include <DallasTemperature.h> // Data wire is plugged into pin 3 on the Arduino #define ONE_WIRE_BUS 3 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Assign the addresses of your 1-Wire temp sensors. DeviceAddress WaterTemperature = { 0x28, 0x62, 0x30, 0xCA, 0x03, 0x00, 0x00, 0xF1 }; DeviceAddress DeviceTemperature = { 0x10, 0x9A, 0x3E, 0x84, 0x02, 0x08, 0x00, 0x4D }; DeviceAddress RoomTemperature = { 0x10, 0xA1, 0xFE, 0x83, 0x02, 0x08, 0x00, 0xFC }; /* LCD Connections: rs (LCD pin 4) to Arduino pin 12 rw (LCD pin 5) to Arduino pin 11 enable (LCD pin 6) to Arduino pin 10 LCD pin 15 to Arduino pin 13 LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2 */ LiquidCrystal lcd(12, 11, 4, 5, 6, 7); RTC_DS1307 RTC; long previousLCDMillis = 0; // for LCD screen update long lcdInterval = 20000; // screen to show int screen = 0; int screenMax = 2; bool screenChanged = true; // initially we have a new screen, by definition // defines of the screens to show #define SCREEN1 0 #define SCREEN2 1 #define SCREEN3 2 int ledPinFilter1 = 26; // LED connected to digital pin 28 (Filter 1) int ledPinFilter2 = 27; // LED connected to digital pin 31 (Filter 2) int ledPinHeater = 29; // LED connected to digital pin 27 (Heater) int ledPinFan = 28; int RelayPinHeater = 24; int RelayPinFan = 25; void setup(void) { pinMode(ledPinFilter1, OUTPUT); // sets the digital pin as output pinMode(ledPinFilter2, OUTPUT); pinMode(ledPinHeater, OUTPUT); pinMode(ledPinFan, OUTPUT); pinMode(RelayPinHeater, OUTPUT); pinMode(RelayPinFan, OUTPUT); digitalWrite(RelayPinHeater, LOW); // Set the Heater to LOW (off) // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) sensors.setResolution(WaterTemperature, 11); sensors.setResolution(RoomTemperature, 11); sensors.setResolution(DeviceTemperature, 11); Serial.begin(9600); Wire.begin(); RTC.begin(); lcd.begin(20, 4); pinMode(8,OUTPUT); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } lcd.begin(20, 4); // rows, columns. use 16,2 for a 16x2 LCD, etc. showWelcome(); delay(4000); // to show message on screen} } void showWelcome() { lcd.clear(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(3, 1); lcd.print("initialising..."); lcd.setCursor(1, 2); lcd.print("Aquarium Controler"); } void showScreen1() { lcd.clear(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); lcd.print("Water Temp:"); printTemperature(WaterTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 2); lcd.print("PH: 6.8"); lcd.setCursor(0, 3); lcd.print("TDS: 150"); lcd.setCursor(9, 3); lcd.print("ms"); } void showScreen2() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.year(), DEC); lcd.setCursor(12, 1); if (now.hour()<10) lcd.print('0'); lcd.print(now.hour(), DEC); lcd.print(':'); if (now.minute()<10) lcd.print('0'); lcd.print(now.minute(), DEC); lcd.print(':'); if (now.second()<10) lcd.print('0'); lcd.print(now.second(), DEC); lcd.setCursor(0, 2); lcd.print("Room Temp:"); printTemperature(RoomTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("PH: 6.8"); lcd.setCursor(8, 3); lcd.print("TDS: 150"); lcd.setCursor(16, 3); lcd.print("ms"); } void showScreen3() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(6, 1); if (now.hour()<10) lcd.print('0'); lcd.print(now.hour(), DEC); lcd.print(':'); if (now.minute()<10) lcd.print('0'); lcd.print(now.minute(), DEC); lcd.print(':'); if (now.second()<10) lcd.print('0'); lcd.print(now.second(), DEC); lcd.setCursor(0, 2); lcd.print("Water Temp:"); printTemperature(WaterTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("Device Temp:"); printTemperature(DeviceTemperature); lcd.print((char)223); lcd.print("C"); } void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); if (tempC == -127.00) { lcd.print("Error"); } else { lcd.print(tempC, 1); } } void loop(void) { unsigned long currentLCDMillis = millis(); // MUST WE SWITCH SCREEN? if(currentLCDMillis - previousLCDMillis > lcdInterval) // save the last time you changed the display { previousLCDMillis = currentLCDMillis; screen++; if (screen > screenMax) screen = 0; // all screens done? => start over screenChanged = true; } // debug Serial.println(screen); // DISPLAY CURRENT SCREEN { screenChanged = false; // reset for next iteration switch(screen) { case SCREEN1: showScreen1(); break; case SCREEN2: showScreen2(); break; case SCREEN3: showScreen3(); break; default: // cannot happen -> showError() ? break; } const int TurnHeaterOnTemperature = 27.8; // The Temperature that sets the Heater on const int TurnHeaterOffTemperature = 28.0; // The Temperature that sets the Heater off const int TurnFanOnTemperature = 27.2; // The Temperature that sets the Fan on const int TurnFanOffTemperature = 27.0; // The Temperature that sets the Fan off sensors.requestTemperatures(); { if('WaterTemperature' <= 'TurnHeaterOnTemperature'){ digitalWrite(RelayPinHeater,HIGH); // sets the Heater on } delay(1000); }}} |
#5
|
||||
|
||||
![]()
ο κωδικας σου μονο ανοιγει το ρελε
εχεις πολλα { } που δεν χρειαζονται.. κοιτα εαν τωρα δουλευει Κώδικας:
#include <LiquidCrystal.h> #include <math.h> #include "RTClib.h" #include <Time.h> #include <Wire.h> #include <OneWire.h> #include <DallasTemperature.h> #define SCREEN1 0 #define SCREEN2 1 #define SCREEN3 2 // Data wire is plugged into pin 3 on the Arduino #define ONE_WIRE_BUS 3 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Assign the addresses of your 1-Wire temp sensors. DeviceAddress WaterTemperature = { 0x28, 0x62, 0x30, 0xCA, 0x03, 0x00, 0x00, 0xF1 }; DeviceAddress DeviceTemperature = { 0x10, 0x9A, 0x3E, 0x84, 0x02, 0x08, 0x00, 0x4D }; DeviceAddress RoomTemperature = { 0x10, 0xA1, 0xFE, 0x83, 0x02, 0x08, 0x00, 0xFC }; const int TurnHeaterOnTemperature = 27.8; // The Temperature that sets the Heater on const int TurnHeaterOffTemperature = 28.0; // The Temperature that sets the Heater off const int TurnFanOnTemperature = 27.2; // The Temperature that sets the Fan on const int TurnFanOffTemperature = 27.0; // The Temperature that sets the Fan off /* LCD Connections: rs (LCD pin 4) to Arduino pin 12 rw (LCD pin 5) to Arduino pin 11 enable (LCD pin 6) to Arduino pin 10 LCD pin 15 to Arduino pin 13 LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2 */ LiquidCrystal lcd(12, 11, 4, 5, 6, 7); RTC_DS1307 RTC; long previousLCDMillis = 0; // for LCD screen update long lcdInterval = 20000; // screen to show int screen = 0; int screenMax = 2; bool screenChanged = true; // initially we have a new screen, by definition // defines of the screens to show int ledPinFilter1 = 26; // LED connected to digital pin 28 (Filter 1) int ledPinFilter2 = 27; // LED connected to digital pin 31 (Filter 2) int ledPinHeater = 29; // LED connected to digital pin 27 (Heater) int ledPinFan = 28; int RelayPinHeater = 24; int RelayPinFan = 25; void setup(void) { pinMode(ledPinFilter1, OUTPUT); // sets the digital pin as output pinMode(ledPinFilter2, OUTPUT); pinMode(ledPinHeater, OUTPUT); pinMode(ledPinFan, OUTPUT); pinMode(RelayPinHeater, OUTPUT); pinMode(RelayPinFan, OUTPUT); digitalWrite(RelayPinHeater, LOW); // Set the Heater to LOW (off) // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) sensors.setResolution(WaterTemperature, 11); sensors.setResolution(RoomTemperature, 11); sensors.setResolution(DeviceTemperature, 11); Serial.begin(9600); Wire.begin(); RTC.begin(); lcd.begin(20, 4); pinMode(8,OUTPUT); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } lcd.begin(20, 4); // rows, columns. use 16,2 for a 16x2 LCD, etc. showWelcome(); delay(4000); // to show message on screen} } void showWelcome() { lcd.clear(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(3, 1); lcd.print("initialising..."); lcd.setCursor(1, 2); lcd.print("Aquarium Controler"); } void showScreen1() { lcd.clear(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); lcd.print("Water Temp:"); printTemperature(WaterTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 2); lcd.print("PH: 6.8"); lcd.setCursor(0, 3); lcd.print("TDS: 150"); lcd.setCursor(9, 3); lcd.print("ms"); } void showScreen2() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.year(), DEC); lcd.setCursor(12, 1); if (now.hour()<10) lcd.print('0'); lcd.print(now.hour(), DEC); lcd.print(':'); if (now.minute()<10) lcd.print('0'); lcd.print(now.minute(), DEC); lcd.print(':'); if (now.second()<10) lcd.print('0'); lcd.print(now.second(), DEC); lcd.setCursor(0, 2); lcd.print("Room Temp:"); printTemperature(RoomTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("PH: 6.8"); lcd.setCursor(8, 3); lcd.print("TDS: 150"); lcd.setCursor(16, 3); lcd.print("ms"); } void showScreen3() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(6, 1); if (now.hour()<10) lcd.print('0'); lcd.print(now.hour(), DEC); lcd.print(':'); if (now.minute()<10) lcd.print('0'); lcd.print(now.minute(), DEC); lcd.print(':'); if (now.second()<10) lcd.print('0'); lcd.print(now.second(), DEC); lcd.setCursor(0, 2); lcd.print("Water Temp:"); printTemperature(WaterTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("Device Temp:"); printTemperature(DeviceTemperature); lcd.print((char)223); lcd.print("C"); } void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); if (tempC == -127.00) { lcd.print("Error"); } else { lcd.print(tempC, 1); } } void loop(void) { unsigned long currentLCDMillis = millis(); sensors.requestTemperatures(); if('WaterTemperature' <= 'TurnHeaterOnTemperature') { digitalWrite(RelayPinHeater,HIGH); // sets the Heater on delay(1000); } // MUST WE SWITCH SCREEN? if(currentLCDMillis - previousLCDMillis > lcdInterval) // save the last time you changed the display { previousLCDMillis = currentLCDMillis; screen++; if (screen > screenMax) screen = 0; // all screens done? => start over screenChanged = true; } screenChanged = false; // reset for next iteration switch(screen) { case SCREEN1: showScreen1(); break; case SCREEN2: showScreen2(); break; case SCREEN3: showScreen3(); break; default: // cannot happen -> showError() ? break; } } AΑυτο το προγραμμα: Κώδικας:
#include <LiquidCrystal.h> #include <MenuBackend.h> #include <avr/pgmspace.h> /* Analog Pin 0 = Button Up Analog Pin 1 = Button Down Analog Pin 2 = Button Mode Analog Pin 3 = Button Select Analog Pin 4 = Analog Pin 5 = Analog Pin 6 = Thermistor Analog Pin 7 = Digital Pin 0 = Digital Pin 1 = Digital Pin 2 = LCD Digital Pin 3 = LCD Digital Pin 4 = LCD Digital Pin 5 = LCD Digital Pin 6 = LCD Digital Pin 7 = SDA Digital Pin 8 = SCL Digital Pin 9 = Heater Digital Pin 10 = Motor Digital Pin 11 = LED temp_ok Digital Pin 12 = LCD Digital Pin 13 = */ const int temp_ok PROGMEM = 11; const int heater PROGMEM = 9; const int buttonPinLeft PROGMEM = A1; const int buttonPinRight PROGMEM = A0; const int buttonPinEsc PROGMEM = A2; const int buttonPinEnter PROGMEM = A3; const int motor PROGMEM = 10; const int thermistor PROGMEM = A6; const int numReadings PROGMEM = 10; // defines accuracy of the temp average int settemp; // holds the set target temperature int pwmheater; // current heater PWM value int index = 0; // the index of the current reading int tempok; // returns the temperature status for the motor to start int motorspeed; // holds the set motor speed 0-255 int lastButtonPushed = 0; int lastButtonEnterState = LOW; // the previous reading from the Enter input pin int lastButtonEscState = LOW; // the previous reading from the Esc input pin int lastButtonLeftState = LOW; // the previous reading from the Left input pin int lastButtonRightState = LOW; // the previous reading from the Right input pin int counter = 0; //variable that will store the count int hours = 0; //stores the running hours int minutes = 0; //stores the running minutes char buffer[16]; //stores sprintf data before lcd.print long lastEnterDebounceTime = 0; // the last time the output pin was toggled long lastEscDebounceTime = 0; // the last time the output pin was toggled long lastLeftDebounceTime = 0; // the last time the output pin was toggled long lastRightDebounceTime = 0; // the last time the output pin was toggled long debounceDelay PROGMEM = 180; // the debounce time float readings[numReadings]; // the readings from the thermistor input float total = 0; // the running total float average = 0; // the average float tempC; // holds the current temp value #define NUMTEMPS 20 short temptable[NUMTEMPS][2] PROGMEM = { {1, 929}, {54, 266}, {107, 217}, {160, 190}, {213, 172}, {266, 158}, {319, 146}, {372, 136}, {425, 127}, {478, 119}, {531, 111}, {584, 103}, {637, 96}, {690, 88}, {743, 80}, {796, 71}, {849, 62}, {902, 50}, {955, 34}, {1008, 2} }; byte degree[8] PROGMEM = { 0b00110, 0b01001, 0b01001, 0b00110, 0b00000, 0b00000, 0b00000, 0b00000 }; LiquidCrystal lcd( 2, 3, 4, 5, 6, 12); //Menu variables MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent); //beneath is list of menu items needed to build the menu MenuItem settings = MenuItem("Settings"); MenuItem runtime = MenuItem("Run Time"); MenuItem material = MenuItem("Material"); MenuItem pla = MenuItem("PLA"); MenuItem absa = MenuItem("ABS"); MenuItem rpm = MenuItem("RPM"); MenuItem temp = MenuItem("Temperature"); int freeRam () { extern int __heap_start, *__brkval; int v; return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); } /******************************** Menu Functions **************************************/ void circularList_incrementBy(int *value, int minimun, int maximun, int incrementBy) { if (incrementBy>0) { if (*value+incrementBy > maximun) *value = minimun; else *value = *value+incrementBy; } else { if ( (*value < minimun) || (*value < (incrementBy*(-1)) )) *value = maximun; else *value = *value+incrementBy; } } void menuUseEvent(MenuUseEvent used) { if (used.item == "Run Time") { lcd.setCursor(0, 0); lcd.print(F("Set Run Time:")); lcd.setCursor(0, 1); sprintf(buffer, "%02d:%02d", hours, minutes); lcd.print(buffer); for(boolean exit = false;!exit;) { readButtons(); if(lastButtonPushed==buttonPinLeft) { circularList_incrementBy(&counter, 0, 24, -1); sprintf(buffer, "%02d:%02d", counter, minutes); lcd.setCursor(0, 1); lcd.print(buffer); lcd.print(" "); } if(lastButtonPushed==buttonPinRight) { circularList_incrementBy(&counter, 0, 24, 1); sprintf(buffer, "%02d:%02d", counter, minutes); lcd.setCursor(0, 1); lcd.print(buffer); lcd.print(" "); } if(lastButtonPushed==buttonPinEnter) { hours = counter; exit = true; counter = 0; } if(lastButtonPushed==buttonPinEsc) { exit = true; counter = 0; } } for(boolean exit = false;!exit;) { readButtons(); if(lastButtonPushed==buttonPinLeft) { circularList_incrementBy(&counter, 0, 60, -1); sprintf(buffer, "%02d:%02d", hours, counter); lcd.setCursor(0, 1); lcd.print(buffer); lcd.print(" "); } if(lastButtonPushed==buttonPinRight) { circularList_incrementBy(&counter, 0, 60, 1); sprintf(buffer, "%02d:%02d", hours, counter); lcd.setCursor(0, 1); lcd.print(buffer); lcd.print(" "); } if(lastButtonPushed==buttonPinEnter) { minutes = counter; exit = true; counter = 0; } if(lastButtonPushed==buttonPinEsc) { exit = true; counter = 0; } } } else if (used.item == "ABS") { settemp = 230; lcd.clear(); } else if (used.item == "PLS") { settemp = 180; lcd.clear(); } else if (used.item == "RPM") { lcd.setCursor(0, 0); lcd.print(F("Set RPM:")); lcd.setCursor(0, 14); lcd.print(" "); for(boolean exit = false;!exit;) { readButtons(); if(lastButtonPushed==buttonPinLeft) { circularList_incrementBy(&counter, 0, 255, -1); lcd.setCursor(0, 1); lcd.print(counter); lcd.print(" "); } if(lastButtonPushed==buttonPinRight) { circularList_incrementBy(&counter, 0, 255, 1); lcd.setCursor(0, 1); lcd.print(counter); lcd.print(" "); } if(lastButtonPushed==buttonPinEnter) { motorspeed = counter; exit = true; counter = 0; } if(lastButtonPushed==buttonPinEsc) { exit = true; counter = 0; } } } else if (used.item == "Temperature") { lcd.setCursor(0, 0); lcd.print(F("Set Temperature:")); lcd.setCursor(0, 13); lcd.print(" "); for(boolean exit = false;!exit;) { readButtons(); if(lastButtonPushed==buttonPinLeft) { circularList_incrementBy(&counter, 0, 300, -1); lcd.setCursor(0, 1); lcd.print(counter); lcd.print(" "); } if(lastButtonPushed==buttonPinRight) { circularList_incrementBy(&counter, 0, 300, 1); lcd.setCursor(0, 1); lcd.print(counter); lcd.print(" "); } if(lastButtonPushed==buttonPinEnter) { settemp = counter; exit = true; counter = 0; } if(lastButtonPushed==buttonPinEsc) { exit = true; counter = 0; } } } lcd.setCursor(0,0); lcd.clear(); lcd.print(F("Saved")); delay(1500); lcd.clear(); } void menuChangeEvent(MenuChangeEvent changed) { MenuItem newMenuItem=changed.to; //get the destination menu lcd.setCursor(0,1); //set the start position for lcd printing to the second row if(newMenuItem.getName() == menu.getRoot()) { lcd.print(F("Settings ")); } else if(newMenuItem.getName()=="Run Time") { lcd.print(F("Run Time ")); } else if(newMenuItem.getName()=="Material") { lcd.print(F("Material ")); } else if(newMenuItem.getName()=="PLA") { lcd.print(F("PLA ")); } else if(newMenuItem.getName()=="ABS") { lcd.print(F("ABS ")); } else if (newMenuItem.getName()=="RPM") { lcd.print(F("RPM ")); } else if(newMenuItem.getName()=="Temperature") { lcd.print(F("Temperature ")); } } void readButtons(){ //read buttons status int reading; int buttonEnterState=LOW; // the current reading from the Enter input pin int buttonEscState=LOW; // the current reading from the input pin int buttonLeftState=LOW; // the current reading from the input pin int buttonRightState=LOW; // the current reading from the input pin //Enter button // read the state of the switch into a local variable: reading = digitalRead(buttonPinEnter); // check to see if you just pressed the enter button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonEnterState) { // reset the debouncing timer lastEnterDebounceTime = millis(); } if ((millis() - lastEnterDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: buttonEnterState=reading; lastEnterDebounceTime=millis(); } // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonEnterState = reading; //Esc button // read the state of the switch into a local variable: reading = digitalRead(buttonPinEsc); // check to see if you just pressed the Down button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonEscState) { // reset the debouncing timer lastEscDebounceTime = millis(); } if ((millis() - lastEscDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: buttonEscState = reading; lastEscDebounceTime=millis(); } // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonEscState = reading; //Down button // read the state of the switch into a local variable: reading = digitalRead(buttonPinRight); // check to see if you just pressed the Down button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonRightState) { // reset the debouncing timer lastRightDebounceTime = millis(); } if ((millis() - lastRightDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: buttonRightState = reading; lastRightDebounceTime =millis(); } // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonRightState = reading; //Up button // read the state of the switch into a local variable: reading = digitalRead(buttonPinLeft); // check to see if you just pressed the Down button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonLeftState) { // reset the debouncing timer lastLeftDebounceTime = millis(); } if ((millis() - lastLeftDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: buttonLeftState = reading; lastLeftDebounceTime=millis();; } // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonLeftState = reading; //records which button has been pressed if (buttonEnterState==HIGH){ lastButtonPushed=buttonPinEnter; }else if(buttonEscState==HIGH){ lastButtonPushed=buttonPinEsc; }else if(buttonRightState==HIGH){ lastButtonPushed=buttonPinRight; }else if(buttonLeftState==HIGH){ lastButtonPushed=buttonPinLeft; }else{ lastButtonPushed=0; } } void navigateMenus() { MenuItem currentMenu=menu.getCurrent(); switch (lastButtonPushed){ case buttonPinEnter: if(!(currentMenu.moveDown())){ //if the current menu has a child and has been pressed enter then menu navigate to item below menu.use(); }else{ //otherwise, if menu has no child and has been pressed enter the current menu is used menu.moveDown(); } break; case buttonPinEsc: menu.toRoot(); //back to main break; case buttonPinRight: menu.moveRight(); break; case buttonPinLeft: menu.moveLeft(); break; } lastButtonPushed=0; //reset the lastButtonPushed variable } /***************************** END Menu Functions *************************************/ /******************************** TEMPERATURE FUNCTIONS *******************************/ int read_temp() { int rawtemp = analogRead(thermistor); int current_celsius = 0; byte i; for (i=1; i<NUMTEMPS; i++) { if (temptable[i][0] > rawtemp) { int realtemp = temptable[i-1][1] + (rawtemp - temptable[i-1][0]) * (temptable[i][1] - temptable[i-1][1]) / (temptable[i][0] - temptable[i-1][0]); if (realtemp > 255) realtemp = 255; current_celsius = realtemp; break; } } // Overflow: We just clamp to 0 degrees celsius if (i == NUMTEMPS) current_celsius = 0; return current_celsius; } void checkTempC() { float TempInterval; float HeatingIncrease; // subtract the last reading: total= total - readings[index]; // read from the sensor: readings[index] = read_temp(); // add the reading to the total: total= total + readings[index]; // advance to the next position in the array: index++ ; // if we're at the end of the array... if (index >= numReadings) // ...wrap around to the beginning: index = 0; // calculate the average: average = total / numReadings; tempC = average; //Controller for Heater TempInterval = (settemp - tempC); //Sets the interval to start from 0 HeatingIncrease = TempInterval*0.1; //Heating increases 10% every degree lower than set temperature if (tempC > settemp) //If Temp's more than defined value, turn heater off { pwmheater = 0; tempok = 1; } if ((tempC <= settemp) && (HeatingIncrease < 1)) //For every degree lower than defined value, increase heating by 10% { pwmheater = HeatingIncrease;} if (HeatingIncrease >= 1) //If the temperature is 10 or more degrees C higher than user { pwmheater = 1;} //defined value to start, leave it at 100% } /*************************** END OF TEMPERATURE FUNCTIONS *****************************/ /********************************* MOTOR FUNCTIONS ************************************/ void motorsts() { if ((tempok = 1) && (tempC >= 150)) { analogWrite(motor, motorspeed); } } /****************************** END OF MOTOR FUNCTIONS ********************************/ /*********************************** LCD FUNCTIONS ************************************/ void welcome_screen() { lcd.clear(); lcd.setCursor(3, 0); lcd.print(F("FILAMENT")); delay(2000); lcd.setCursor(3, 1); lcd.print(F("FACTORY")); delay(2000); lcd.clear(); lcd.setCursor(0,0); lcd.print(F("LOADING")); delay(500); lcd.setCursor(8,0); lcd.print(F(".")); delay(500); lcd.setCursor(9,0); lcd.print(F(".")); delay(500); lcd.setCursor(10,0); lcd.print(F(".")); delay(1000); lcd.clear(); } /******************************* END OF LCD FUNCTIONS *********************************/ void setup() { Serial.begin(9600); pinMode(temp_ok, OUTPUT); pinMode (heater, OUTPUT); pinMode (motor, OUTPUT); pinMode (buttonPinLeft, INPUT); pinMode (buttonPinRight, INPUT); pinMode (buttonPinEsc, INPUT); pinMode (buttonPinEnter, INPUT); pinMode (thermistor, INPUT); Serial.begin(9600); lcd.begin(16, 2); checkTempC(); welcome_screen(); motorsts(); menu.getRoot().add(settings); settings.add(runtime).addRight(material).addRight(rpm).addRight(temp); material.add(absa).addRight(pla); menu.toRoot(); } void loop() { readButtons(); navigateMenus(); Serial.println(freeRam()); checkTempC(); motorsts(); delay(500); } πχ εαν θες να εμφανιζεις ενα νουμερο ως 0# (δυο χαρακτηρες) οταν ειναι <10 το κανεισ με charbuffer kai sprinf κ οχι με if.. και οταν αλλαζεις σελιδα στη οθονη πρεπει να κανεις clear η να γραψεις κενα εκει που ανανεωνεις..
__________________
3dpg.gr/3D Printers Greece 30lit amano-red cherry shrimp 60lit blue pearl shrimp 130lit hi-tech φυτεμένο RIP Τελευταία επεξεργασία από το χρήστη jimbit22 : 04-12-14 στις 17:41 Αιτία: Automerged Doublepost |
#6
|
||||
|
||||
![]() Κώδικας:
#include <LiquidCrystal.h> #include <math.h> #include "RTClib.h" #include <Time.h> #include <Wire.h> #include <OneWire.h> #include <DallasTemperature.h> #define SCREEN1 0 #define SCREEN2 1 #define SCREEN3 2 // Data wire is plugged into pin 3 on the Arduino #define ONE_WIRE_BUS 3 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Assign the addresses of your 1-Wire temp sensors. DeviceAddress WaterTemperature = { 0x28, 0x62, 0x30, 0xCA, 0x03, 0x00, 0x00, 0xF1 }; DeviceAddress DeviceTemperature = { 0x10, 0x9A, 0x3E, 0x84, 0x02, 0x08, 0x00, 0x4D }; DeviceAddress RoomTemperature = { 0x10, 0xA1, 0xFE, 0x83, 0x02, 0x08, 0x00, 0xFC }; const int TurnHeaterOnTemperature = 27.8; // The Temperature that sets the Heater on const int TurnHeaterOffTemperature = 28.0; // The Temperature that sets the Heater off const int TurnFanOnTemperature = 27.2; // The Temperature that sets the Fan on const int TurnFanOffTemperature = 27.0; // The Temperature that sets the Fan off uint16_t relayHeatInterval = 4000; byte degree[8] PROGMEM = { 0b00110, 0b01001, 0b01001, 0b00110, 0b00000, 0b00000, 0b00000, 0b00000 }; char buffer[20]; //stores sprintf data before lcd.print /* LCD Connections: rs (LCD pin 4) to Arduino pin 12 rw (LCD pin 5) to Arduino pin 11 enable (LCD pin 6) to Arduino pin 10 LCD pin 15 to Arduino pin 13 LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2 */ LiquidCrystal lcd(12, 11, 4, 5, 6, 7); RTC_DS1307 RTC; long lcdInterval = 20000; long previousLCDMillis = 0; long previousRelayMillis = 0; // screen to show int screen = 0; int screenMax = 2; bool screenChanged = true; // initially we have a new screen, by definition // defines of the screens to show int ledPinFilter1 = 26; // LED connected to digital pin 28 (Filter 1) int ledPinFilter2 = 27; // LED connected to digital pin 31 (Filter 2) int ledPinHeater = 29; // LED connected to digital pin 27 (Heater) int ledPinFan = 28; int RelayPinHeater = 24; int RelayPinFan = 25; /*------------------------- SCREEN FUNCTIONS ---------------------------*/ void showWelcome() { lcd.clear(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(3, 1); lcd.print("initialising..."); lcd.setCursor(1, 2); lcd.print("Aquarium Controler"); delay(4000); // to show message on screen} } void showScreen1() { lcd.clear(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); lcd.print("Water Temp:"); printTemperature(WaterTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 2); lcd.print("PH: 6.8"); lcd.setCursor(0, 3); lcd.print("TDS: 150"); lcd.setCursor(9, 3); lcd.print("ms"); } void showScreen2() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); sprintf(buffer, "%02d/%02d/%02d %02d:%02d:%02d" , now.day(),now.month(),now.year(),now.hour(),now.minute(),now.second()); lcd.print(buffer); lcd.setCursor(0, 2); lcd.print("Room Temp:"); printTemperature(RoomTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("PH: 6.8"); lcd.setCursor(8, 3); lcd.print("TDS: 150"); lcd.setCursor(16, 3); lcd.print("ms"); } void showScreen3() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); sprintf(buffer, " %02d:%02d:%02d" , now.hour(),now.minute(),now.second()); lcd.print(buffer); lcd.setCursor(0, 2); lcd.print("Water Temp:"); printTemperature(WaterTemperature); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("Device Temp:"); printTemperature(DeviceTemperature); lcd.print((char)223); lcd.print("C"); } void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); if (tempC == -127.00) lcd.print("Error"); else lcd.print(tempC, 1); } /*------------------------- END SCREEN FUNCTIONS ---------------------------*/ void setup(void) { pinMode(ledPinFilter1, OUTPUT); // sets the digital pin as output pinMode(ledPinFilter2, OUTPUT); pinMode(ledPinHeater, OUTPUT); pinMode(ledPinFan, OUTPUT); pinMode(RelayPinHeater, OUTPUT); pinMode(RelayPinFan, OUTPUT); pinMode(8,OUTPUT); digitalWrite(RelayPinHeater, LOW); // Set the Heater to LOW (off) // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) sensors.setResolution(WaterTemperature, 11); sensors.setResolution(RoomTemperature, 11); sensors.setResolution(DeviceTemperature, 11); lcd.createChar (0, degree); lcd.begin(20, 4); previousLCDMillis = millis(); previousRelayMillis = millis(); if (! RTC.isrunning()){ Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } Serial.begin(9600); Wire.begin(); RTC.begin(); showWelcome(); } void loop(void) { if ((millis() - previousRelayMillis) > relayHeatInterval){ sensors.requestTemperatures(); if('WaterTemperature' <= 'TurnHeaterOnTemperature') digitalWrite(RelayPinHeater,HIGH); // sets the Heater on else digitalWrite(RelayPinHeater,LOW); } // MUST WE SWITCH SCREEN? if((millis() - previousLCDMillis) > lcdInterval) // save the last time you changed the display { previousLCDMillis = millis(); screen++; if (screen > screenMax) screen = 0; // all screens done? => start over screenChanged = true; } if (screenChanged){ switch(screen){ case SCREEN1: showScreen1(); break; case SCREEN2: showScreen2(); break; case SCREEN3: showScreen3(); break; } } screenChanged = false; // reset for next iteration }
__________________
3dpg.gr/3D Printers Greece 30lit amano-red cherry shrimp 60lit blue pearl shrimp 130lit hi-tech φυτεμένο RIP |
#7
|
|||
|
|||
![]()
Λοιπόν τα κατάφερα και το έκανα και δούλεψε, ανοιγοκλείνουν τα Ρελέ μια χαρά βρήκα που είχα κάνει λάθος άλλαξα και λιγάκι τον κώδικα και είναι οκ.
Κώδικας:
#include <LiquidCrystal.h> #include <math.h> #include "RTClib.h" #include <Time.h> #include <Wire.h> #include <OneWire.h> #include <DallasTemperature.h> // Data wire is plugged into pin 3 on the Arduino #define ONE_WIRE_BUS 3 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Assign the addresses of your 1-Wire temp sensors. DeviceAddress WaterTemperatureSensor = { 0x28, 0x62, 0x30, 0xCA, 0x03, 0x00, 0x00, 0xF1 }; DeviceAddress DeviceTemperatureSensor = { 0x10, 0x9A, 0x3E, 0x84, 0x02, 0x08, 0x00, 0x4D }; DeviceAddress RoomTemperatureSensor = { 0x10, 0xA1, 0xFE, 0x83, 0x02, 0x08, 0x00, 0xFC }; float WaterTemperature = 0; float DeviceTemperature = 0; float RoomTemperature = 0; /* LCD Connections: rs (LCD pin 4) to Arduino pin 12 rw (LCD pin 5) to Arduino pin 11 enable (LCD pin 6) to Arduino pin 10 LCD pin 15 to Arduino pin 13 LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2 */ LiquidCrystal lcd(12, 11, 4, 5, 6, 7); RTC_DS1307 RTC; long previousLCDMillis = 0; // for LCD screen update long lcdInterval = 20000; // screen to show int screen = 0; int screenMax = 2; bool screenChanged = true; // initially we have a new screen, by definition // defines of the screens to show #define SCREEN1 0 #define SCREEN2 1 #define SCREEN3 2 int ledPinFilter1 = 26; // LED connected to digital pin 28 (Filter 1) int ledPinFilter2 = 27; // LED connected to digital pin 31 (Filter 2) int ledPinHeater = 29; // LED connected to digital pin 27 (Heater) int ledPinFan = 28; int RelayPinHeater = 24; int RelayPinFan = 25; void setup(void) { //-------( Initialize Pins so relays are inactive at reset)---- digitalWrite(RelayPinHeater, HIGH); // Set the Heater to HIGH (off) //---( THEN set pins as outputs )---- pinMode(ledPinFilter1, OUTPUT); // sets the digital pin as output pinMode(ledPinFilter2, OUTPUT); pinMode(ledPinHeater, OUTPUT); pinMode(ledPinFan, OUTPUT); pinMode(RelayPinHeater, OUTPUT); pinMode(RelayPinFan, OUTPUT); delay(4000); //Check that all relays are inactive at Reset // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) sensors.setResolution(WaterTemperatureSensor, 12); sensors.setResolution(RoomTemperatureSensor, 11); sensors.setResolution(DeviceTemperatureSensor, 11); Serial.begin(9600); Wire.begin(); RTC.begin(); lcd.begin(20, 4); pinMode(8,OUTPUT); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } lcd.begin(20, 4); // rows, columns. use 16,2 for a 16x2 LCD, etc. showWelcome(); delay(4000); // to show message on screen} } void showWelcome() { lcd.clear(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(3, 1); lcd.print("initialising..."); lcd.setCursor(1, 2); lcd.print("Aquarium Controler"); } void showScreen1() { lcd.clear(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); lcd.print("Water Temp:"); printTemperature(WaterTemperatureSensor); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 2); lcd.print("PH: 6.8"); lcd.setCursor(0, 3); lcd.print("TDS: 150"); lcd.setCursor(9, 3); lcd.print("ms"); } void showScreen2() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0); lcd.print("My Amazon Aquarium"); lcd.setCursor(0, 1); lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.year(), DEC); lcd.setCursor(12, 1); if (now.hour()<10) lcd.print('0'); lcd.print(now.hour(), DEC); lcd.print(':'); if (now.minute()<10) lcd.print('0'); lcd.print(now.minute(), DEC); lcd.print(':'); if (now.second()<10) lcd.print('0'); lcd.print(now.second(), DEC); lcd.setCursor(0, 2); lcd.print("Room Temp:"); printTemperature(RoomTemperatureSensor); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("PH: 6.8"); lcd.setCursor(8, 3); lcd.print("TDS: 150"); lcd.setCursor(16, 3); lcd.print("ms"); } void showScreen3() { lcd.clear(); DateTime now = RTC.now(); lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row) lcd.print("My Amazon Aquarium"); lcd.setCursor(6, 1); if (now.hour()<10) lcd.print('0'); lcd.print(now.hour(), DEC); lcd.print(':'); if (now.minute()<10) lcd.print('0'); lcd.print(now.minute(), DEC); lcd.print(':'); if (now.second()<10) lcd.print('0'); lcd.print(now.second(), DEC); lcd.setCursor(0, 2); lcd.print("Water Temp:"); printTemperature(WaterTemperatureSensor); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 3); lcd.print("Device Temp:"); printTemperature(DeviceTemperatureSensor); lcd.print((char)223); lcd.print("C"); } void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); float WaterTemperaturetempC = sensors.getTempC(WaterTemperatureSensor); float DeviceTemperaturetempC = sensors.getTempC(DeviceTemperatureSensor); float RoomTemperaturetempC = sensors.getTempC(RoomTemperatureSensor); if (tempC == -127.00) { lcd.print("Error"); } else { //lcd.print(tempC, 1); WaterTemperature = (WaterTemperaturetempC); DeviceTemperature = (DeviceTemperaturetempC); RoomTemperature = (RoomTemperaturetempC); lcd.print(tempC, 1); } } void loop(void) { unsigned long currentLCDMillis = millis(); // MUST WE SWITCH SCREEN? if(currentLCDMillis - previousLCDMillis > lcdInterval) // save the last time you changed the display { previousLCDMillis = currentLCDMillis; screen++; if (screen > screenMax) screen = 0; // all screens done? => start over screenChanged = true; } // debug Serial.println(screen); // DISPLAY CURRENT SCREEN { screenChanged = false; // reset for next iteration switch(screen) { case SCREEN1: showScreen1(); break; case SCREEN2: showScreen2(); break; case SCREEN3: showScreen3(); break; default: // cannot happen -> showError() ? break; } sensors.requestTemperatures(); if(WaterTemperature <= 27.8) { digitalWrite(RelayPinHeater, LOW); // sets the Heater on } if(WaterTemperature >= 28.0) { digitalWrite(RelayPinHeater, HIGH); // sets the Heater off } delay(500); } if(digitalRead(RelayPinHeater) == LOW) { digitalWrite(ledPinHeater, HIGH); // sets the LED on } else{ digitalWrite(ledPinHeater, LOW); // sets the LED off } } To be Continued......... |
#8
|
||||
|
||||
![]()
σου τις εχω κανει τις διορθωσεις στο τελευταιο μ ποστ και μειωσα τον κωδικα κατα 40 γραμμες και προσθεσα πραγματα.
__________________
3dpg.gr/3D Printers Greece 30lit amano-red cherry shrimp 60lit blue pearl shrimp 130lit hi-tech φυτεμένο RIP |
#9
|
|||
|
|||
![]() Παράθεση:
![]() ![]() ![]() |
![]() |
Συνδεδεμένοι χρήστες που διαβάζουν αυτό το θέμα: 1 (0 μέλη και 1 επισκέπτες) | |
|
|
![]() |
||||
Θέμα | Δημιουργός | Forum | Απαντήσεις | Τελευταίο Μήνυμα |
arduino controller | ikaria_jim | DIY . Φτιάχτο μόνος σου | 5 | 09-02-14 16:21 |
GHL Profilux aquarium controller | aquarius | Λοιπός εξοπλισμός | 83 | 12-11-10 18:06 |
dimming controller με Arduino board | aquaman | DIY . Φτιάχτο μόνος σου | 12 | 07-04-10 07:39 |
Arduino aquarium controller | chris the trik | DIY . Φτιάχτο μόνος σου | 33 | 06-04-10 20:23 |
Aquarium Controller | mitas | Εξοπλισμός - Τεχνολογία Γλυκού νερού | 16 | 15-10-03 01:01 |