Hi there,
I'm doing a project whereby I have some solenoids and want to open/close them in correspondence to temperature sensor readings. I'm having trouble getting my head around how this should work. I know I'm close but I have a limited knowledge and would really appreciate some help! The general flow of how it should work is as follows:
Temperature range is to be mapped and constrained from 20-30C for now.
I want to allow the solenoids to let air into a balloon for 1 second for increase in degree, and let it out for 1 second per decrease in degree, again, mapped between 20 and 30C.
- Start up
- Let air in to a certain 'base' point, lets call it 0. (which will be mapped to 20C, and anything below that will be constrained to 20C)
- Get the temp from sensor
- Check if sensor temp is higher than 20, if not do nothing, if so how much higher than 20? (for arguments sake lets say it went up to 23C)
- Let air in for 1 second per each degree above 20 (so 3 seconds)
- Check temp sensor again, if BELOW what it previously was, let air OUT for 1 second per difference in degree. (for arguments sake lets say it went to 22, so 1 second difference)
- if ABOVE what it previously was, let air IN for 1 second per difference in degree.
......and so on and so forth.....
I have two solenoids for each balloon and I have 2 balloons.
My code currently is:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_PIN 3
#define SENSOR_RESOLUTION 12
OneWire oneWire(ONE_WIRE_BUS_PIN); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);
DeviceAddress HS1 = {0x28, 0xFF, 0xDF, 0x1C, 0xA4, 0x16, 0x03, 0x9F};
DeviceAddress HS4 = {0x28, 0xFF, 0x04, 0x19, 0xA5, 0x16, 0x03, 0x9B};
float HSA [2];
int solIn1 = 9;
int solOut1 = 10;
int solIn2 = 7;
int solOut2 = 8;
//-------------------------------------------------------//////////////////////------------------------------------------------------//
void setup() {
// put your setup code here, to run once:
pinMode(solIn1, OUTPUT);
pinMode(solOut1, OUTPUT);
pinMode(solIn2, OUTPUT);
pinMode(solOut2, OUTPUT);
Serial.begin(9600);
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);
sensors.begin();
}
//-------------------------------------------------------//////////////////////------------------------------------------------------//
void printTemperature(DeviceAddress deviceAddress) {
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Error getting temperature ");
}
else
{
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
//-------------------------------------------------------//////////////////////------------------------------------------------------//
void loop() {
// put your main code here, to run repeatedly:
float HS1Temp = sensors.getTempC(HS1);
float HS4Temp = sensors.getTempC(HS4);
HSA [0] = HS1Temp;
HSA [1] = HS4Temp;
Serial.println();
Serial.print("Number of Devices found on bus = ");
Serial.println(sensors.getDeviceCount());
Serial.print("Getting temperatures... ");
Serial.println();
sensors.requestTemperatures();
Serial.print("HS0 temperature is: ");
printTemperature(HS1);
Serial.println();
Serial.print("HS0 array value is: ");
Serial.println(HSA [0], DEC);
Serial.print("HS1 temperature is: ");
printTemperature(HS4);
Serial.println();
Serial.print("HS1 array value is: ");
Serial.println(HSA [1], DEC);
}
Note, I haven't put any code to deal with comparing the values yet as I'm just stumped.... so far I can only think to have some variables like such:
int blowCount = 0
int tempDiff = HS1Temp - OldTemp
delay(blowcount * 1000);
Also, to control my solenoids I am using two, one that lets air in and one out, I made a table which describes the necessary combination of HIGH/LOW signals to let air in and out. they are as follows.
//Let air in to balloon
(solIn1, HIGH);
(solOut1, LOW);
//Let air out of balloon
(solIn1, LOW);
(solOut1, HIGH);
//Hold air in balloon and do nothing
(solIn1, Low);
(solOut1, Low);
//Let air in to balloon
(solIn1, HIGH);
(solOut1, HIGH);
Long message I know.... sorry, I wanted to give all the info. I'm pretty sure it's not that hard an issue to solve, I'm just not that clued up on programming. Any help would be greatly appreciated! Thanks.
Edit: Oh, I should also say, I did have a long look through various other threads, and many similar problems existed, but none that lined up exactly with how I need to control and compare values that I could find.... I had trouble tailoring it to my code with my current skill level anyway.