Browse Source

Add distance sensor, Add tests, Add photos

master
Apostolos Fanakis 6 years ago
parent
commit
268a84370b
  1. BIN
      report/res/IMG_20190606_173846.jpg
  2. BIN
      report/res/IMG_20190606_173856.jpg
  3. BIN
      report/res/IMG_20190606_173906.jpg
  4. BIN
      report/res/IMG_20190606_173915.jpg
  5. BIN
      report/res/IMG_20190606_174101.jpg
  6. BIN
      report/res/IMG_20190606_174146.jpg
  7. BIN
      report/res/IMG_20190606_174229.jpg
  8. 37
      tests/test_dht/test_dht.ino
  9. 8
      tests/test_display/test_display.ino
  10. 41
      tests/test_hc_sr04/test_hc_sr04.ino
  11. 13
      todoFindCoolNameForProject/todoFindCoolNameForProject.h
  12. 48
      todoFindCoolNameForProject/todoFindCoolNameForProject.ino

BIN
report/res/IMG_20190606_173846.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

BIN
report/res/IMG_20190606_173856.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 MiB

BIN
report/res/IMG_20190606_173906.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

BIN
report/res/IMG_20190606_173915.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

BIN
report/res/IMG_20190606_174101.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

BIN
report/res/IMG_20190606_174146.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

BIN
report/res/IMG_20190606_174229.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 MiB

37
tests/test_dht/test_dht.ino

@ -0,0 +1,37 @@
/*
* Simple code to test the temperature sensor function and electrical connections.
*/
#include <DHT.h>
// 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);
}

8
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);
}

41
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);
}

13
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

48
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;
}

Loading…
Cancel
Save