Hello, I've been dabbling with Arduino for a little bit now, this is my most advanced project to date.
Project Goal: 2 DS18b20 sensor's reading 2 temperatures controlling a dual relay module. This is to control a seedling propagation environment by maintaining temperature via a heat mat controlled by Arduino relay. Also include bluetooth so that I can monitor temperatures remotely.
What works:
I can successfully bluetooth the values of two separate DS18B20's on the same bus wire to my phone and read them Individually (See screenshot attached)
What Doesn't work:
The Relay is being really strange. Initially, if I plug the Relay Power and ground into the same Ground Rail as the Bluetooth and Temperature Sensors, then the temp reading goes to 185.00 on both and sticks there until I reflash a sketch. Pulling the power doesn't release it.
I figure I'm overloading it, so I've gotten around that temporarily by using an arduino nano on its own breadboard, and just plugging the Relay into that +/- rail. So now I can get correct Temperature readings out of both, with relay connected.
See code below, this is the best I can get. This somehow turns the relay on for a little bit, less than a minute....and its independent of what the Water Temperature probe's if statement for > 85.
// Coded by theratdude64 to maintain an ideal seedling/cutting propagation environment
// Hardware setup:
// BT module Arduino
// GND ------- GND
// VCC ------- 5V
// TX ------ RX
// RX ------ TX
// OneWire Temperature sensor pin 2 (a 4.7K resistor is necessary)
#include <OneWire.h>
#include <DallasTemperature.h>
const int levelSensor = 2; // Water Level Float Sensor
const int lowLED = 4; // Low Water Blue LED -
const int led1Pin = 5; //Too Cold Red LED
const int led2Pin = 6; //Too Hot Green LED
const int relay1Pin = 7; //Top Outlet
const int relay2Pin = 8; // Bottom Outlet
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup Bluetooth
#define bluetooth Serial
// 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 unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress waterTemp = { 0x28, 0xFF, 0xC8, 0x36, 0xC4, 0x17, 0x04, 0x3B };
DeviceAddress domeTemp = { 0x28, 0xFF, 0x05, 0x3C, 0xC4, 0x17, 0x04, 0xEE };
void setup(void)
{
// start serial port
Serial.begin(9600);
bluetooth.begin(9600);
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(waterTemp, 10);
sensors.setResolution(domeTemp, 10);
}
void printWater()
{
float tempC = sensors.getTempC(waterTemp);
if (tempC == -127.00) {
Serial.print("Error getting Water temperature");
} else {
// Serial.print("C: ");
// Serial.print(tempC);
// Serial.print("Water Temp: ");
// Serial.print(DallasTemperature::toFahrenheit(tempC));
Serial.print("\n\r");
Serial.println( (String)"Water Temp: " + DallasTemperature::toFahrenheit(tempC) + "\n" );
bluetooth.print( (String)"Water Temp: " + DallasTemperature::toFahrenheit(tempC) + "\n" );
}
// if (DallasTemperature::toFahrenheit(tempC) > 85){ digitalWrite(relay2Pin, HIGH); }
}
void printDome()
{
float tempC = sensors.getTempC(domeTemp);
if (tempC == -127.00) {
Serial.print("Error getting Dome temperature");
} else {
//Serial.print("Dome Temp: ");
// Serial.print(DallasTemperature::toFahrenheit(tempC));
Serial.print("\n\r");
Serial.println( (String)"Dome Temp: " + DallasTemperature::toFahrenheit(tempC) + "\n" );
bluetooth.print( (String)"Dome Temp: " + DallasTemperature::toFahrenheit(tempC) + "\n" );
}
}
int waterValue(DeviceAddress)
{
float tempC = sensors.getTempC(waterTemp);
float waterF = DallasTemperature::toFahrenheit(tempC);
return waterF;
}
void loop(void)
{
int waterMat = waterValue(waterTemp);
delay(1000);
//Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
// Serial.print("Water temperature is: ");
printWater();
// Serial.print("\n\r");
// Serial.print("Dome temperature is: ");
printDome();
// Serial.print("\n\r\n\r");
Serial.println(waterMat);
if (waterValue(waterTemp) > 85){
digitalWrite(relay1Pin, HIGH);
digitalWrite(relay2Pin, HIGH);
}
}


