From bb08e9855de2e87a632220292316b00787f95af5 Mon Sep 17 00:00:00 2001 From: cse44742 Date: Sun, 30 Jan 2022 12:43:54 +0000 Subject: [PATCH] Update 'code.ino' --- code.ino | 97 +++++++++++++++++++------------------------------------- 1 file changed, 32 insertions(+), 65 deletions(-) diff --git a/code.ino b/code.ino index 637179f..de9df81 100644 --- a/code.ino +++ b/code.ino @@ -1,65 +1,32 @@ -#include -#include -#define ONE_WIRE_BUS 2 -OneWire oneWire(ONE_WIRE_BUS); -DallasTemperature sensors(&oneWire); -DeviceAddress insideThermometer; - -void setup(void) -{ - Serial.begin(9600); - Serial.println("Dallas Temperature IC Control Library Demo"); - Serial.print("Locating devices..."); - sensors.begin(); - Serial.print("Found "); - Serial.print(sensors.getDeviceCount(), DEC); - Serial.println(" devices."); - Serial.print("Parasite power is: "); - if (sensors.isParasitePowerMode()) Serial.println("ON"); - else Serial.println("OFF"); - - - if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); - - - Serial.print("Device 0 Address: "); - printAddress(insideThermometer); - Serial.println(); - sensors.setResolution(insideThermometer, 9); - - Serial.print("Device 0 Resolution: "); - Serial.print(sensors.getResolution(insideThermometer), DEC); - 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); - } -} \ No newline at end of file +#include +#include + +#define ONE_WIRE_BUS 2 +OneWire oneWire(ONE_WIRE_BUS); +DallasTemperature sensors(&oneWire); +void setup(void) +{ + Serial.begin(9600); + Serial.println("SMART WATER IoT (Koutkou-Hidri-Skouloufianakis)\n"); + sensors.begin(); +} +void loop(void) +{ + //TEMPERATURE SENSOR + sensors.requestTemperatures(); + Serial.print("Temperature is: "); + Serial.print(sensors.getTempCByIndex(0)); + Serial.println(" °C"); + + //TURBIDITY SENSOR + int sensorValue = analogRead(A0); + float voltage = sensorValue * (5.0 / 1024.0); + float ntu = -1120.4*square(voltage)+ 5742.3*voltage - 4352.9; + + Serial.print ("Turbidity is: "); + Serial.print (voltage); + Serial.print (" V "); + Serial.print (ntu); + Serial.println (" NTU\n"); + delay(1500); +}