Skip to content

Commit 888d8bd

Browse files
author
brentru
committed
adding Adafruit IO Home - Lights and Temperature
1 parent ff67a72 commit 888d8bd

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/************************ Adafruit IO Config *******************************/
2+
3+
// visit io.adafruit.com if you need to create an account,
4+
// or if you need your Adafruit IO key.
5+
#define IO_USERNAME "YOUR_IO_USERNAME"
6+
#define IO_KEY "YOUR_IO_PASSWORD"
7+
8+
/******************************* WIFI **************************************/
9+
10+
// the AdafruitIO_WiFi client will work with the following boards:
11+
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
12+
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
13+
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
14+
// - Feather WICED -> https://www.adafruit.com/products/3056
15+
16+
#define WIFI_SSID "YOUR_WIFI_SSID"
17+
#define WIFI_PASS "YOUR_WIFI_PASSWORD"
18+
19+
// comment out the following two lines if you are using fona or ethernet
20+
#include "AdafruitIO_WiFi.h"
21+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
22+
23+
24+
/******************************* FONA **************************************/
25+
26+
// the AdafruitIO_FONA client will work with the following boards:
27+
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
28+
29+
// uncomment the following two lines for 32u4 FONA,
30+
// and comment out the AdafruitIO_WiFi client in the WIFI section
31+
// #include "AdafruitIO_FONA.h"
32+
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
33+
34+
35+
/**************************** ETHERNET ************************************/
36+
37+
// the AdafruitIO_Ethernet client will work with the following boards:
38+
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
39+
40+
// uncomment the following two lines for ethernet,
41+
// and comment out the AdafruitIO_WiFi client in the WIFI section
42+
// #include "AdafruitIO_Ethernet.h"
43+
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// Adafruit IO House: Lights and Temperature
2+
//
3+
// Learn Guide: https://learn.adafruit.com/adafruit-io-house-lights-and-temperature
4+
//
5+
// Adafruit invests time and resources providing this open source code.
6+
// Please support Adafruit and open source hardware by purchasing
7+
// products from Adafruit!
8+
//
9+
// Written by Brent Rubell for Adafruit Industries
10+
// Copyright (c) 2018 Adafruit Industries
11+
// Licensed under the MIT license.
12+
//
13+
// All text above must be included in any redistribution.
14+
15+
/************************** Configuration ***********************************/
16+
17+
// edit the config.h tab and enter your Adafruit IO credentials
18+
// and any additional configuration needed for WiFi, cellular,
19+
// or ethernet clients.
20+
#include "config.h"
21+
22+
// include the NeoPixel library
23+
#include "Adafruit_NeoPixel.h"
24+
25+
// include the si7021 library
26+
#include "Adafruit_Si7021.h"
27+
/************************ Example Starts Here *******************************/
28+
29+
// pin the NeoPixel strip is connected to
30+
#define STRIP_PIN 12
31+
// pin the NeoPixel Jewel is connected to
32+
#define JEWEL_PIN 2
33+
34+
// amount of neopixels on the NeoPixel strip
35+
#define STRIP_PIXEL_COUNT 34
36+
// amount of neopixels on the NeoPixel jewel
37+
#define JEWEL_PIXEL_COUNT 7
38+
39+
// type of neopixels used by the NeoPixel strip and jewel.
40+
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
41+
42+
// main loop() delay, in seconds
43+
#define TEMP_DELAY 7
44+
45+
// Temperature and Humidity: Si7021 Sensor
46+
int temperatureData;
47+
int humidityData;
48+
49+
// initalize neopixel strip
50+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, STRIP_PIN, PIXEL_TYPE);
51+
// initalize neopixel jewel
52+
Adafruit_NeoPixel jewel = Adafruit_NeoPixel(JEWEL_PIXEL_COUNT, JEWEL_PIN, PIXEL_TYPE);
53+
54+
// initalize the sensor object
55+
Adafruit_Si7021 sensor = Adafruit_Si7021();
56+
57+
// set up the Adafruit IO House Group
58+
AdafruitIO_Group *houseGroup = io.group("io-house");
59+
60+
void setup() {
61+
62+
// start the serial connection
63+
Serial.begin(115200);
64+
65+
// wait for serial monitor to open
66+
while(! Serial);
67+
68+
// connect to io.adafruit.com
69+
Serial.print("Connecting to Adafruit IO");
70+
io.connect();
71+
72+
// subscribe to lighting feeds and register message handlers
73+
houseGroup->onMessage("indoor-lights", indoorLightHandler);
74+
houseGroup->onMessage("outside-lights", outdoorLightHandler);
75+
76+
// wait for a connection
77+
while(io.status() < AIO_CONNECTED) {
78+
Serial.print(".");
79+
delay(500);
80+
}
81+
82+
// we are connected
83+
Serial.println();
84+
Serial.println(io.statusText());
85+
86+
// initalize the Si7021 sensor
87+
if (!sensor.begin()) {
88+
Serial.println("Did not find Si7021 sensor!");
89+
while (true);
90+
}
91+
Serial.println("Si7021 sensor set up!");
92+
93+
// initalize the neopixel strip and jewel.
94+
strip.begin();
95+
jewel.begin();
96+
97+
// set all neopixels on the strip and jewel to `off`.
98+
strip.show();
99+
jewel.show();
100+
}
101+
102+
void loop() {
103+
// io.run(); is required for all sketches.
104+
// it should always be present at the top of your loop
105+
// function. it keeps the client connected to
106+
// io.adafruit.com, and processes any incoming data.
107+
io.run();
108+
109+
temperatureData = sensor.readTemperature() * 1.8 + 32;
110+
humidityData = sensor.readHumidity();
111+
112+
113+
Serial.print("-> Sending Temperature to Adafruit IO: ");
114+
Serial.println(temperatureData);
115+
Serial.print("-> Sending Humidity to Adafruit IO: ");
116+
Serial.println(humidityData);
117+
118+
// set feeds to temperature and humidity data
119+
houseGroup->set("humidity", temperatureData);
120+
houseGroup->set("temperature", humidityData);
121+
// send these values to Adafruit IO
122+
houseGroup->save();
123+
124+
// delay the loop to avoid flooding Adafruit IO
125+
delay(1000*TEMP_DELAY);
126+
127+
}
128+
129+
void indoorLightHandler(AdafruitIO_Data *data) {
130+
Serial.print("-> indoor light HEX: ");
131+
Serial.println(data->value());
132+
133+
long color = data->toNeoPixel();
134+
135+
// set the color of each NeoPixel in the jewel
136+
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
137+
jewel.setPixelColor(i, color);
138+
}
139+
// 'set' the neopixel jewel to the new color
140+
jewel.show();
141+
}
142+
143+
void outdoorLightHandler(AdafruitIO_Data *data) {
144+
Serial.print("-> outdoor light HEX: ");
145+
Serial.println(data->value());
146+
147+
long color = data->toNeoPixel();
148+
149+
// set the color of each NeoPixel in the strip
150+
for(int i=0; i<STRIP_PIXEL_COUNT; ++i) {
151+
strip.setPixelColor(i, color);
152+
}
153+
// 'set' the neopixel strip to the new color
154+
strip.show();
155+
}
156+
157+
Binary file not shown.

0 commit comments

Comments
 (0)