-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeoriaHamfestArduino.ino
120 lines (95 loc) · 3.25 KB
/
PeoriaHamfestArduino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Peoria HamFest Arduino demo by KG9DW 09/2017
// This demo uses a OneWire temperature probe (DS18B20) and 3 LEDs to demonstrate basic concepts.
// When temperature rises above set thresholds, the LEDs will light.
// Code shows the basic If This Then That (IFTT) functionality.
// This code relies on the modified OneWire library from Josh.com.
// See: https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/
#include <OneWire.h>
#include <DallasTemperature.h>
// OneWire data wire is plugged into port 7 on the Arduino
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 9
// Define the LED pins and thresholds
#define RED_LED_PIN 8
#define RED_LED_TEMP 90.0
#define YEL_LED_PIN 9
#define YEL_LED_TEMP 80.0
#define GRE_LED_PIN 10
#define GRE_LED_TEMP 70.0
// Setup oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Setup - runs once
void setup(void)
{
// initialize LEDs as output
pinMode(LED_BUILTIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(YEL_LED_PIN, OUTPUT);
pinMode(GRE_LED_PIN, OUTPUT);
// start serial port
Serial.begin(9600);
Serial.println("Peoria Hamfest Arduino Demo de KG9DW");
// Test the lights
digitalWrite(LED_BUILTIN, HIGH);
delay(750);
digitalWrite(GRE_LED_PIN, HIGH);
delay(750);
digitalWrite(YEL_LED_PIN, HIGH);
delay(750);
digitalWrite(RED_LED_PIN, HIGH);
delay(750);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(YEL_LED_PIN, LOW);
digitalWrite(GRE_LED_PIN, LOW);
delay(750);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(YEL_LED_PIN, HIGH);
digitalWrite(GRE_LED_PIN, HIGH);
delay(1000);
// turn off the lights
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(YEL_LED_PIN, LOW);
digitalWrite(GRE_LED_PIN, LOW);
// initialize the sensor
sensors.begin();
}
// Main loop - runs over and over
void loop(void)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on so we know we're running
// Address of temp sensor found
DeviceAddress tempDeviceAddress;
sensors.requestTemperatures(); // Send the command to get temperatures
// Search the wire for address
if(sensors.getAddress(tempDeviceAddress, 0))
{
float tempC = sensors.getTempC(tempDeviceAddress);
float tempF = DallasTemperature::toFahrenheit(tempC); // Converts tempC to Fahrenheit
Serial.println(tempF);
if (tempF > RED_LED_TEMP) {
Serial.println("Above red temp");
digitalWrite(RED_LED_PIN, HIGH);
} else {
digitalWrite(RED_LED_PIN, LOW);
}
if (tempF > YEL_LED_TEMP) {
Serial.println("Above yellow temp");
digitalWrite(YEL_LED_PIN, HIGH);
} else {
digitalWrite(YEL_LED_PIN, LOW);
}
if (tempF > GRE_LED_TEMP) {
Serial.println("Above green temp");
digitalWrite(GRE_LED_PIN, HIGH);
} else {
digitalWrite(GRE_LED_PIN, LOW);
}
}
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
delay(1500);
}