Hi Folks,
History and Project Description
I am a Honeybee Beekeeper and I have started a winter project of creating a sun tracking solar wax melter, to melt beeswax from my bee hives. My current wax melter I have to manually re-position every half-hour to hour throughout the day to take advantage of the suns rays and heat to melt the wax.
I am looking at using a Arduino Uno to monitor and control several funtions:
1)LDR's & Horizontal Mounted Servo, to track and rotate the wax melter as the sun moves (most likely update in 15 minute intervals)
2)DHT22 Temperature/Humidity sensor with a small PWM cooling fan to (well try to anyway) maintain 140F-155F inside the melter.
3)LCD to Display Temperature Humidity and Fan Speed 0-100% (real time)
4)Save Temperature Humidity & Fan Speed data to a SD Shield in something like 5-15 minute intervals to review later(added just for kicks)
I have a little background in basic old school electronic circuits, but am limited in the scope of micro processing and coding.
I have written some code for:
1) LDR's & Horizontal mount servo... a little buggy and still working out trying to incorporate some sort of tolerance feature so not to constantly fight between the Left & Right LDR's, not having much luck with this...but I have been able to track a flash light. Also Looking to-re code this with the VarSpeedServo Library I came across for speed control
2) DHT22 & Fan circuit is built/coded out and seems to be working 100%
3) LCD Display is coded out and working but makes the Servo motion Jitter/Stutter...even more so when I have serial monitor enabled. Not sure how to reduce the Jitter/Stutter this feature is putting on the servo motion.
4) SD Shield haven't attempt incorporating this yet
5) Haven't looked into the 5-15 minute intervals i would like to add to certain areas...for now keeping it somewhat real time for testing/troubleshooting purposes.
Any suggestions to fix/streamline some of this would be greatly appreciated...again this is a winter project so I am not in a big hurry to get it up and running. I made a mock test platform to work on and plan to get the circuit working first on the bench...then build the full scale rotating enclosure.
Here is my code so far...please excuse the mess it is in...again my skills are poor (which I know is a understatement).
Moderator edit: added code tags
History and Project Description
I am a Honeybee Beekeeper and I have started a winter project of creating a sun tracking solar wax melter, to melt beeswax from my bee hives. My current wax melter I have to manually re-position every half-hour to hour throughout the day to take advantage of the suns rays and heat to melt the wax.
I am looking at using a Arduino Uno to monitor and control several funtions:
1)LDR's & Horizontal Mounted Servo, to track and rotate the wax melter as the sun moves (most likely update in 15 minute intervals)
2)DHT22 Temperature/Humidity sensor with a small PWM cooling fan to (well try to anyway) maintain 140F-155F inside the melter.
3)LCD to Display Temperature Humidity and Fan Speed 0-100% (real time)
4)Save Temperature Humidity & Fan Speed data to a SD Shield in something like 5-15 minute intervals to review later(added just for kicks)
I have a little background in basic old school electronic circuits, but am limited in the scope of micro processing and coding.
I have written some code for:
1) LDR's & Horizontal mount servo... a little buggy and still working out trying to incorporate some sort of tolerance feature so not to constantly fight between the Left & Right LDR's, not having much luck with this...but I have been able to track a flash light. Also Looking to-re code this with the VarSpeedServo Library I came across for speed control
2) DHT22 & Fan circuit is built/coded out and seems to be working 100%
3) LCD Display is coded out and working but makes the Servo motion Jitter/Stutter...even more so when I have serial monitor enabled. Not sure how to reduce the Jitter/Stutter this feature is putting on the servo motion.
4) SD Shield haven't attempt incorporating this yet
5) Haven't looked into the 5-15 minute intervals i would like to add to certain areas...for now keeping it somewhat real time for testing/troubleshooting purposes.
Any suggestions to fix/streamline some of this would be greatly appreciated...again this is a winter project so I am not in a big hurry to get it up and running. I made a mock test platform to work on and plan to get the circuit working first on the bench...then build the full scale rotating enclosure.
Here is my code so far...please excuse the mess it is in...again my skills are poor (which I know is a understatement).
Code:
//********************** Interrupt Service Routine - Soft E-Stop **************************
boolean start = true;
volatile boolean e_stop = false;
//*********************** Liquid Crystal-I2C ******************************************************
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // <<- Add your address here.
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
//*********************** Temp-Fan ******************************************************
#include <DHT.h> // add DHT library
#define DHTPIN A0 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); // set DHT condition
#define fan 10 // fan Pin 10
//int humMin = 40; // min humindy set point
//int humMax = 100; // max humindy set point
int tempMin = 70; // min Temperature "degrees F" set point
int tempMax = 80; // max Temperature "Degrees F" set point
int fanSpeed;
int fanLCD;
//********************** Servo/LDR Sun Tracking ***********************************************
#include <Servo.h>
Servo servo1; // create servo object to control a servo
int pos = 90; // initial position
int LLDR = A1; // LRD1 pin1
int RLDR = A2; // LDR2 pin2
int tolerance = 3; // <<- Set LDR Tolerance set point
//******************************************************************************************************************
//************************* SETUP *****************************************************************************
//******************************************************************************************************************
void setup(){
Serial.begin(9600); // begin writing to the serial monitior
attachInterrupt(0, e_stop_ISR ,RISING); // add interrupt for soft e_stop feature
lcd.begin (20,4); // <<-- our LCD is a 20x4, change for your LCD if needed
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); // set backlight condition
lcd.setBacklight(HIGH); // turn backlight on
lcd.home (); // go home on LCD
lcd.print("Wax Melter v1.0"); // print to LCD
dht.begin(); // initializes the inerface with the DHT22 Sensor
pinMode(fan, OUTPUT); // Set Fan as a OUTPUT Signal
servo1.attach(9); // attaches the servo on pin 9 to the servo object
servo1.write(90); // Move servo1 to 90 degree position
pinMode(LLDR, INPUT); // Set leftLDR as INPUT signal
pinMode(RLDR, INPUT); // Set rightLDR as INPUT signal
delay(2000); // a 2 second delay while we position the solar wax melter
}
//***************************************************************************************************
//*********************** LOOP *****************************************************************
//***************************************************************************************************
void loop(){
//********************* Interrupt Service Routine - Soft E-Stop *******************************
if(start == true){
if(e_stop == false){
//********************* Temp-Fan ***************************************************************
float h = dht.readHumidity(); // read Humidity
float t = dht.readTemperature(); // read temperature as Celsius
int f = (t * 1.8 + 32); // convert to Farenheit
if( t < tempMin){ // if temperature is lower than minimum temperature
fanSpeed = 0; // fan = off
digitalWrite(fan, LOW); // turn fan off
}
if((f > tempMin) && ( f <= tempMax)){ // if temperatureis >= Min and <= Max setpoint
fanSpeed = map(f, tempMin, tempMax, 32, 255); // map fan speed
fanLCD = map(f, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
//********************* Servo/LDR Sun Tracking *******************************************************
int pos = servo1.read(); // read the value of Left LDR
int leftLDR = analogRead(LLDR); // read the value of Right LDR
int rightLDR = analogRead(RLDR); // read the value of Left LDR
if((abs(leftLDR - rightLDR) < tolerance) || (abs(rightLDR - leftLDR) < tolerance)){}
// do nothing if the diff. between values is within the tolerance limit
else{
if(leftLDR > rightLDR){ // if leftLDR value is greater than rightLDR value
pos = --pos; // move servo in the negitive direction
delay(100); // wait time to move servo
}
if(leftLDR < rightLDR){ // if leftLDR value is less than rightLDR value
pos = ++pos; // move servo in the positive direction
delay(100); // wait time to move servo
}
}
if(pos > 180){ // reset to 170 if it goes higher
pos = 170; // move servo to 170 degrees
servo1.write(pos); // write the position to servo
//delay(1000); // wait time to move servo
}
if(pos < 0){ // reset to 10 degrees if it goes lower
pos = 10; // move servo to 10 degrees
servo1.write(pos); // write the position to servo
//delay(1000); // wait time to move servo
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.println("%\t");
Serial.print("Temperature: ");
Serial.print(f);
Serial.println("F");
Serial.println();
Serial.print("LeftLDR: ");
Serial.println(leftLDR);
Serial.print("RightLDR Value: ");
Serial.println(rightLDR);
Serial.println();
lcd.setCursor(0,0);
lcd.print("TEMPERATURE: ");
lcd.print(f); // display the temperature
lcd.print("F");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(h); // display the Humidity
lcd.print("%");
lcd.setCursor(0,2);
lcd.print("FANS: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
}
}
else{
start = false;
}
}
//********************* Interrupt Service Routine - Soft E-Stop ******************************************
void e_stop_ISR(void){
detachInterrupt(0);
e_stop = !e_stop;
}