Hello all,
It's been many years since I have done anything with Arduino and most of it was pretty simple.
This project is not what I would call simple.
My goal is to have an couple of fans on my enclosure that turn off and on depending on temperature aswell as a servo actuated vent that is controlled via a button press for ABS that also shuts off the fans as well. I only have one relay in the code, I was just going to wire both fans to it.
Also I'm doing this code at work in a text editor and emailing it to myself. I know I'm missing some stuff and probably doing quite a bit wrong and wanted to get some of you Gurus opinions. I saw a few posts pertaining to similar projects but none together that helped.
Please help!
Thanks in advance for taking the time to look over my project!
//3D Printer Enclosure Temp Controlled Fan and Servo Actuated //Vents
#include
#include "DHT.h"
#include <Servo.h>;
// pushbutton pins
const int buttonPin = 8;
// const int buttonpin2 = 9;
// servo pin
const int servoPin = 3;
Servo servo;
int relayPin = 13;
#define DHTPIN 7
#define DHTTYPE DHT22
DHT sensor(DHTPIN, DHTTYPE);
U8GLIB_SH1106_128X64 oled (13, 11, 10, 9, 8);
void setup()
{
pinMode(relayPin, OUTPUT);
sensor.begin();
oled.firstPage();
do
{
oled.setFont(u8g_font_fur14);
//setting the font size
//Printing the data on the OLED
oled.drawStr(20, 15, "G.Tech");
oled.drawStr(40, 40, "Temp");
oled.drawStr(5, 60, "Control Alpha");
}
while( oled.nextPage() );
delay(5000);
}
void loop()
{
// local variable to hold the pushbutton states
int buttonState;
Int buttonState2;
//read the digital state of buttonPin with
//digitalRead() function and store the value in buttonState var
//second button state is placeholder if needed
buttonState = digitalRead(buttonPin);
//buttonState2 = digitalRead(buttonPin2);
float h = sensor.readHumidity();
//Reading the humidityvalue
float t = sensor.readTemperature();
//Reading the temperature value
float fah = sensor.readTemperature(true);
//Reading the temperature in Fahrenheit
if (isnan(h) || isnan(t) || isnan(fah))
{
//Checking if we are receiving the values or not
oled.drawStr(20, 15, "TEMP");
oled.drawStr(40, 40, "READ");
oled.drawStr(5, 60, "FAILURE");
return;
}
Else if(t > desiredt)
{
digitalWrite(relayPin, HIGH);
}
Else if (buttonState == LOW)
{
// check button press
servo.write (180);
oled.drawStr(5, 60, "ABS MODE");
Delay (150);
digitalWrite(relayPin, LOW);
}
}
float heat_index = sensor.computeHeatIndex(fah, h);
//Calculating the heat index in Fahrenheit float heat_indexC = sensor.convertFtoC(heat_index);
//Calculating the heat index in Celsius oled.firstPage();
do
{
oled.setFont(u8g_font_fub11);
//setting the font size
//Printing the data on the OLED oled.drawStr(0, 15, "Temp: "); oled.drawStr(0, 40, "Hum: ");
oled.drawStr(0, 60, "Hi: "); oled.setPrintPos(72, 15);
//setting the dimensions to print the
//temperature
oled.print(t, 0);
oled.println("C");
oled.setPrintPos(72, 40);
//setting the dimensions to print the
//humidity
oled.print(h, 0);
oled.println("%");
oled.setPrintPos(72, 60);
//setting the dimensions to print heat index
oled.print(heat_indexC, 0); oled.println("%");
}
while( oled.nextPage() );
delay(2000);
{