cse44742
3 years ago
1 changed files with 32 additions and 65 deletions
@ -1,65 +1,32 @@ |
|||||
#include <OneWire.h> |
#include <OneWire.h> |
||||
#include <DallasTemperature.h> |
#include <DallasTemperature.h> |
||||
#define ONE_WIRE_BUS 2 |
|
||||
OneWire oneWire(ONE_WIRE_BUS); |
#define ONE_WIRE_BUS 2 |
||||
DallasTemperature sensors(&oneWire); |
OneWire oneWire(ONE_WIRE_BUS); |
||||
DeviceAddress insideThermometer; |
DallasTemperature sensors(&oneWire); |
||||
|
void setup(void) |
||||
void setup(void) |
{ |
||||
{ |
Serial.begin(9600); |
||||
Serial.begin(9600); |
Serial.println("SMART WATER IoT (Koutkou-Hidri-Skouloufianakis)\n"); |
||||
Serial.println("Dallas Temperature IC Control Library Demo"); |
sensors.begin(); |
||||
Serial.print("Locating devices..."); |
} |
||||
sensors.begin(); |
void loop(void) |
||||
Serial.print("Found "); |
{ |
||||
Serial.print(sensors.getDeviceCount(), DEC); |
//TEMPERATURE SENSOR
|
||||
Serial.println(" devices."); |
sensors.requestTemperatures(); |
||||
Serial.print("Parasite power is: "); |
Serial.print("Temperature is: "); |
||||
if (sensors.isParasitePowerMode()) Serial.println("ON"); |
Serial.print(sensors.getTempCByIndex(0)); |
||||
else Serial.println("OFF"); |
Serial.println(" °C"); |
||||
|
|
||||
|
//TURBIDITY SENSOR
|
||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); |
int sensorValue = analogRead(A0); |
||||
|
float voltage = sensorValue * (5.0 / 1024.0); |
||||
|
float ntu = -1120.4*square(voltage)+ 5742.3*voltage - 4352.9; |
||||
Serial.print("Device 0 Address: "); |
|
||||
printAddress(insideThermometer); |
Serial.print ("Turbidity is: "); |
||||
Serial.println(); |
Serial.print (voltage); |
||||
sensors.setResolution(insideThermometer, 9); |
Serial.print (" V "); |
||||
|
Serial.print (ntu); |
||||
Serial.print("Device 0 Resolution: "); |
Serial.println (" NTU\n"); |
||||
Serial.print(sensors.getResolution(insideThermometer), DEC); |
delay(1500); |
||||
Serial.println(); |
} |
||||
} |
|
||||
void printTemperature(DeviceAddress deviceAddress) |
|
||||
{ |
|
||||
|
|
||||
float tempC = sensors.getTempC(deviceAddress); |
|
||||
if(tempC == DEVICE_DISCONNECTED_C) |
|
||||
{ |
|
||||
Serial.println("Error: Could not read temperature data"); |
|
||||
return; |
|
||||
} |
|
||||
Serial.print("Temp C: "); |
|
||||
Serial.print(tempC); |
|
||||
Serial.print(" Temp F: "); |
|
||||
Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
|
|
||||
} |
|
||||
|
|
||||
void loop(void) |
|
||||
{ |
|
||||
|
|
||||
Serial.print("Requesting temperatures..."); |
|
||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
|
||||
Serial.println("DONE"); |
|
||||
|
|
||||
printTemperature(insideThermometer); // Use a simple function to print out the data
|
|
||||
} |
|
||||
void printAddress(DeviceAddress deviceAddress) |
|
||||
{ |
|
||||
for (uint8_t i = 0; i < 8; i++) |
|
||||
{ |
|
||||
if (deviceAddress[i] < 16) Serial.print("0"); |
|
||||
Serial.print(deviceAddress[i], HEX); |
|
||||
} |
|
||||
} |
|
||||
|
Loading…
Reference in new issue