first working prototype.
This commit is contained in:
parent
50cd264db3
commit
fb83761487
2 changed files with 77 additions and 13 deletions
6
main/adresses.txt
Normal file
6
main/adresses.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
Found 2 devices.
|
||||
|
||||
Printing addresses...
|
||||
black : 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD1, 0xB1, 0x75
|
||||
red : 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD7, 0xDA, 0x9A
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
/* References:
|
||||
* https://lastminuteengineers.com/multiple-ds18b20-arduino-tutorial/
|
||||
*/
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
#include <OneWire.h>
|
||||
|
@ -6,25 +8,34 @@
|
|||
|
||||
// Data wire is conntec to the Arduino digital pin 4
|
||||
#define ONE_WIRE_BUS 2
|
||||
#define MOSFET 3
|
||||
#define MOSFET1 3
|
||||
#define MOSFET2 4
|
||||
// Setup a oneWire instance to communicate with any OneWire devices
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature sensor
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
|
||||
DeviceAddress Thermometer;
|
||||
int deviceCount = 0;
|
||||
|
||||
int analogPin = 2;
|
||||
int data = 0;
|
||||
char userInput;
|
||||
char* commandVer;
|
||||
// temperature values in °C
|
||||
float tempSensor1;
|
||||
float tempSensor2;
|
||||
// HighTemp - when to turn on the power
|
||||
float HTemp1 = 12.0;
|
||||
float HTemp2;
|
||||
float HTemp2 = 16.0;
|
||||
// LowTemp - when to turn of the power
|
||||
float LTemp1 = 10.0;
|
||||
float LTemp2;
|
||||
float LTemp2 = 14.0;
|
||||
|
||||
uint8_t addrSensor1[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD1, 0xB1, 0x75 };
|
||||
uint8_t addrSensor2[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD7, 0xDA, 0x9A };
|
||||
/*
|
||||
|
||||
// countLowTemp
|
||||
int cLTemp1 = 0;
|
||||
int cLTemp2 = 0;
|
||||
|
@ -34,12 +45,34 @@ int cHTemp2 = 0;
|
|||
// loops to count temp before switching state
|
||||
int cTemp = 5;
|
||||
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(MOSFET, OUTPUT);
|
||||
pinMode(MOSFET1, OUTPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
sensors.begin();
|
||||
|
||||
|
||||
|
||||
// locate devices on the bus
|
||||
Serial.println("Locating devices...");
|
||||
Serial.print("Found ");
|
||||
deviceCount = sensors.getDeviceCount();
|
||||
Serial.print(deviceCount, DEC);
|
||||
Serial.println(" devices.");
|
||||
Serial.println("");
|
||||
|
||||
Serial.println("Printing addresses...");
|
||||
for (int i = 0; i < deviceCount; i++)
|
||||
{
|
||||
Serial.print("Sensor ");
|
||||
Serial.print(i+1);
|
||||
Serial.print(" : ");
|
||||
sensors.getAddress(Thermometer, i);
|
||||
printAddress(Thermometer);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -51,17 +84,30 @@ void loop() {
|
|||
Serial.print("Sens 1 ");
|
||||
Serial.print("Celsius temperature: ");
|
||||
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
|
||||
Serial.print(sensors.getTempCByIndex(0));
|
||||
Serial.print(sensors.getTempC(addrSensor1));
|
||||
Serial.print(" - Fahrenheit temperature: ");
|
||||
Serial.println(sensors.getTempFByIndex(0));
|
||||
Serial.println(sensors.getTempF(addrSensor1));
|
||||
|
||||
tempSensor1 = sensors.getTempCByIndex(0);
|
||||
Serial.print("Sens 2 ");
|
||||
Serial.print("Celsius temperature: ");
|
||||
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
|
||||
Serial.print(sensors.getTempC(addrSensor2));
|
||||
Serial.print(" - Fahrenheit temperature: ");
|
||||
Serial.println(sensors.getTempF(addrSensor2));
|
||||
|
||||
tempSensor1 = sensors.getTempC(addrSensor1);
|
||||
if(tempSensor1 > HTemp1) {
|
||||
digitalWrite(MOSFET, HIGH);
|
||||
digitalWrite(MOSFET1, HIGH);
|
||||
} else if(tempSensor1 < LTemp1) {
|
||||
digitalWrite(MOSFET, LOW);
|
||||
digitalWrite(MOSFET1, LOW);
|
||||
}
|
||||
|
||||
tempSensor2 = sensors.getTempC(addrSensor2);
|
||||
if(tempSensor2 > HTemp2) {
|
||||
digitalWrite(MOSFET2, HIGH);
|
||||
} else if(tempSensor1 < LTemp1) {
|
||||
digitalWrite(MOSFET2, LOW);
|
||||
}
|
||||
|
||||
/*
|
||||
digitalWrite(MOSFET, HIGH);
|
||||
|
@ -73,3 +119,15 @@ void loop() {
|
|||
// }
|
||||
|
||||
}
|
||||
|
||||
void printAddress(DeviceAddress deviceAddress)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
Serial.print("0x");
|
||||
if (deviceAddress[i] < 0x10) Serial.print("0");
|
||||
Serial.print(deviceAddress[i], HEX);
|
||||
if (i < 7) Serial.print(", ");
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue