diff --git a/report/res/IMG_20190606_173846.jpg b/report/res/IMG_20190606_173846.jpg new file mode 100644 index 0000000..efb7eb1 Binary files /dev/null and b/report/res/IMG_20190606_173846.jpg differ diff --git a/report/res/IMG_20190606_173856.jpg b/report/res/IMG_20190606_173856.jpg new file mode 100644 index 0000000..1f8e884 Binary files /dev/null and b/report/res/IMG_20190606_173856.jpg differ diff --git a/report/res/IMG_20190606_173906.jpg b/report/res/IMG_20190606_173906.jpg new file mode 100644 index 0000000..e7d616f Binary files /dev/null and b/report/res/IMG_20190606_173906.jpg differ diff --git a/report/res/IMG_20190606_173915.jpg b/report/res/IMG_20190606_173915.jpg new file mode 100644 index 0000000..178d2f4 Binary files /dev/null and b/report/res/IMG_20190606_173915.jpg differ diff --git a/report/res/IMG_20190606_174101.jpg b/report/res/IMG_20190606_174101.jpg new file mode 100644 index 0000000..b1fc655 Binary files /dev/null and b/report/res/IMG_20190606_174101.jpg differ diff --git a/report/res/IMG_20190606_174146.jpg b/report/res/IMG_20190606_174146.jpg new file mode 100644 index 0000000..1e3faa8 Binary files /dev/null and b/report/res/IMG_20190606_174146.jpg differ diff --git a/report/res/IMG_20190606_174229.jpg b/report/res/IMG_20190606_174229.jpg new file mode 100644 index 0000000..8648d28 Binary files /dev/null and b/report/res/IMG_20190606_174229.jpg differ diff --git a/tests/test_dht/test_dht.ino b/tests/test_dht/test_dht.ino new file mode 100644 index 0000000..6f2665d --- /dev/null +++ b/tests/test_dht/test_dht.ino @@ -0,0 +1,37 @@ +/* + * Simple code to test the temperature sensor function and electrical connections. +*/ +#include + +// Type of DHT sensor used is 11 +#define DHTTYPE DHT11 +#define DHTPIN 2 + +// Initializes DHT sensor +DHT dht(DHTPIN, DHTTYPE); + +/* ===== SETUP AND LOOP ===== */ +void setup() { + // Starts the serial com with PC + Serial.begin(9600); + Serial.println("Running setup function"); + + dht.begin(); +} + +void loop() { + // Reads temperature as Celsius + float temperature = dht.readTemperature(); + + // Checks if the read failed and handles the failure + if (isnan(temperature)) { + Serial.print(F("Failed to read from DHT sensor!")); + } + + Serial.print(F("Temperature: ")); + Serial.print(temperature); + Serial.println(F("°C ")); + + // Waits a few seconds between measurements. + delay(1000); +} diff --git a/tests/test_display/test_display.ino b/tests/test_display/test_display.ino index 769fe9c..8fd9d97 100644 --- a/tests/test_display/test_display.ino +++ b/tests/test_display/test_display.ino @@ -9,19 +9,19 @@ SevSeg sevseg; void setup() { byte numDigits = 4; byte digitPins[] = {14, 17, 18, 12}; - byte segmentPins[] = {15, 19, 7, 9, 6, 16, 8}; + byte segmentPins[] = {15, 19, 7, 8, 9, 16, 6, 13}; bool resistorsOnSegments = false; byte hardwareConfig = COMMON_CATHODE; bool updateWithDelays = false; bool leadingZeros = false; - bool disableDecPoint = true; + bool disableDecPoint = false; sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint); } void loop() { - sevseg.setNumber(555,0); // Displays '3.141' + sevseg.setNumber(567, 1); sevseg.refreshDisplay(); - sevseg.setBrightness(100); + sevseg.setBrightness(120); } diff --git a/tests/test_hc_sr04/test_hc_sr04.ino b/tests/test_hc_sr04/test_hc_sr04.ino new file mode 100644 index 0000000..c7168aa --- /dev/null +++ b/tests/test_hc_sr04/test_hc_sr04.ino @@ -0,0 +1,41 @@ +/* + * Simple code to test the distance sensor function and electrical connections. +*/ +int DIST_ECHO_PIN = 10; +int DIST_TRIG_PIN = 11; +long duration, cm; + +void setup() { + // Starts the serial com with PC + Serial.begin(9600); + Serial.println("Running setup function"); + + //Defines inputs and outputs + pinMode(DIST_TRIG_PIN, OUTPUT); + pinMode(DIST_ECHO_PIN, INPUT); +} + +void loop() { + // The sensor is triggered by a HIGH pulse of 10 or more microseconds. + // Gives a short LOW pulse beforehand to ensure a clean HIGH pulse: + digitalWrite(DIST_TRIG_PIN, LOW); + delayMicroseconds(5); + digitalWrite(DIST_TRIG_PIN, HIGH); + delayMicroseconds(10); + digitalWrite(DIST_TRIG_PIN, LOW); + + // Reads the signal from the sensor: a HIGH pulse whose + // duration is the time (in microseconds) from the sending + // of the ping to the reception of its echo off of an object. + //pinMode(DIST_ECHO_PIN, INPUT); + duration = pulseIn(DIST_ECHO_PIN, HIGH); + + // Converts the time into a distance + cm = (duration/2) / 29.1; + + Serial.print(cm); + Serial.print("cm"); + Serial.println(); + + delay(1000); +} \ No newline at end of file diff --git a/todoFindCoolNameForProject/todoFindCoolNameForProject.h b/todoFindCoolNameForProject/todoFindCoolNameForProject.h index 9c7528e..f139866 100644 --- a/todoFindCoolNameForProject/todoFindCoolNameForProject.h +++ b/todoFindCoolNameForProject/todoFindCoolNameForProject.h @@ -18,6 +18,8 @@ #define NUMBER_OF_DIGITS 4 // Pin layout #define DHTPIN 2 +#define DIST_ECHO_PIN 10 +#define DIST_TRIG_PIN 11 #define LOW_TEMP_LED_PIN 3 #define HIGH_TEMP_LED_PIN 4 #define RELAY_PIN 5 @@ -28,14 +30,16 @@ #define SEGMENT_A_PIN 15 #define SEGMENT_B_PIN 19 #define SEGMENT_C_PIN 7 -#define SEGMENT_D_PIN 9 -#define SEGMENT_E_PIN 6 +#define SEGMENT_D_PIN 8 +#define SEGMENT_E_PIN 9 #define SEGMENT_F_PIN 16 -#define SEGMENT_G_PIN 8 +#define SEGMENT_G_PIN 6 #define DECIMAL_POINT_PIN 13 // Temperature thresholds #define LOW_TEMP 28 #define HIGH_TEMP 28 +// Distance threshold +#define DIST_THRESHOLD 10 /* ===== GLOBAL VARIABLES AND INITIALIZATIONS ===== */ @@ -46,11 +50,12 @@ SevSeg sevseg; int temperatureReadingsCounter; float temperatures[BUFFER_SIZE]; float averageTemp = 0; -unsigned long displayTimeStart = 0; +unsigned long lastReading = 0, displayTimeStart = 0; /* ===== FUNCTION DEFINITIONS ===== */ void getNewSamples(); float getNewTemp(); float calcAverageTempAndReset(); +float getDistance(); #endif //TODO_FIND_COOL_NAME_FOR_PROJECT_H diff --git a/todoFindCoolNameForProject/todoFindCoolNameForProject.ino b/todoFindCoolNameForProject/todoFindCoolNameForProject.ino index 7a7e480..c19024d 100644 --- a/todoFindCoolNameForProject/todoFindCoolNameForProject.ino +++ b/todoFindCoolNameForProject/todoFindCoolNameForProject.ino @@ -16,6 +16,9 @@ void setup() { pinMode(HIGH_TEMP_LED_PIN, OUTPUT); pinMode(RELAY_PIN, OUTPUT); + pinMode(DIST_TRIG_PIN, OUTPUT); + pinMode(DIST_ECHO_PIN, INPUT); + byte numDigits = NUMBER_OF_DIGITS; byte digitPins[] = {DIGIT_1_PIN, DIGIT_2_PIN, DIGIT_3_PIN, DIGIT_4_PIN}; byte segmentPins[] = {SEGMENT_A_PIN, SEGMENT_B_PIN, SEGMENT_C_PIN, SEGMENT_D_PIN, SEGMENT_E_PIN, @@ -33,24 +36,25 @@ void setup() { void loop() { // Gets new readings - getNewSamples(); - Serial.println(temperatureReadingsCounter); + if (!lastReading || millis() - lastReading > SLEEP_INTERVAL) { + getNewSamples(); + Serial.println(temperatureReadingsCounter); + lastReading = millis(); + } - bool getAnotherSample = true; - while ((millis() - displayTimeStart) < TEMPERATURE_DISPLAY_DURATION) { - // Should display the average temperature for ten seconds + float distance = getDistance(); + + if (distance < DIST_THRESHOLD || (millis() - displayTimeStart) < TEMPERATURE_DISPLAY_DURATION) { + // Should display the average temperature sevseg.setNumber(averageTemp, 1); sevseg.refreshDisplay(); - if ((getAnotherSample && millis() - displayTimeStart) >= (TEMPERATURE_DISPLAY_DURATION/2)){ - getNewSamples(); - getAnotherSample = false; - } + } else { + sevseg.blank(); + sevseg.refreshDisplay(); } - sevseg.blank(); - sevseg.refreshDisplay(); // Waits a few seconds between measurements. - delay(SLEEP_INTERVAL); + //delay(SLEEP_INTERVAL); } /* ===== FUNCTION IMPLEMENTATIONS ===== */ @@ -126,3 +130,23 @@ float calcAverageTempAndReset() { return sum/BUFFER_SIZE; } + +float getDistance() { + // The sensor is triggered by a HIGH pulse of 10 or more microseconds. + // Gives a short LOW pulse beforehand to ensure a clean HIGH pulse: + digitalWrite(DIST_TRIG_PIN, LOW); + delayMicroseconds(5); + digitalWrite(DIST_TRIG_PIN, HIGH); + delayMicroseconds(10); + digitalWrite(DIST_TRIG_PIN, LOW); + + // Reads the signal from the sensor: a HIGH pulse whose + // duration is the time (in microseconds) from the sending + // of the ping to the reception of its echo off of an object. + pinMode(DIST_ECHO_PIN, INPUT); + unsigned long duration = pulseIn(DIST_ECHO_PIN, HIGH); + + // Converts the time into a distance + float distance = (duration/2) / 29.1; + return distance; +}