Published

# Summer Bridge AK

I'm learning IoT over a week long period. I have learned how to use a Temp gage, LED lights.

BeginnerFull instructions providedOver 1 day20

## Things used in this project

### Hardware components

 Particle Argon
×1
 Seeed Studio Base Shield V2
×1
 Seeed Studio Grove - Light Sensor
×1
 Seeed Studio Grove - 6-Axis Accelerometer&Gyroscope (BMI088)
×1
 Seeed Studio Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680)
×1
 Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1

### Software apps and online services

 Microsoft VS Code

## Code

### Motion.ino

C/C++
```/*
* Project Motion
* Description: Learn to use accelerometer
* Author:
* Date:
*/

int x, y, z;
float ax, ay, az;
float pitch, roll;

SYSTEM_MODE(SEMI_AUTOMATIC);

void setup() {
Serial.begin(9600);
}

void loop() {
//read the accelerometer values and store them in variables  x,y,z
Serial.printf("values of X = %i, Y = %i, Z = %i\n",x,y,z);

// Get acceleration in g's
double xyz[3];
ax = xyz[0];
ay = xyz[1];
az = xyz[2];
pitch = asin(ay)*(306/(2*M_PI));

Serial.printf("values of X = %0.2f, Y = %0.2f, Z = %0.2f, pitch = %0.2, roll = %0.2f\n",ax,ay,az,pitch,roll);

delay(500);

}
```

### Nopixel

C/C++
```/*
* Project newo
* Description:
* Author:
* Date:
*/

#include "neopixel.h"
#include "colors.h"
#include "math.h"

#define PIXEL_PIN A2
#define PIXEL_COUNT 14
#define PIXEL_TYPE WS2812B

int i, pixelNum, color;
bool buttonState;
float bright, t, freq;

SYSTEM_MODE(SEMI_AUTOMATIC);

// setup() runs once, when the device is first turned on.
void setup() {
// Put initilization like pinMode and begin functions here.
pinMode(D10,INPUT);
freq = 1/3.0;
pixel.begin();
pixel.setPixelColor(5,red);
pixel.show();
i = 0;
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.

while(buttonState == true){
t = millis() / 1000.0;
bright = 127.5 * sin(2* M_PI * freq * t) + 127.5;
pixel.setBrightness(bright);
i++;
pixelNum = i % 14;
//color should be 6
color = i % 3;
pixel.setPixelColor(pixelNum,cool[color]);
pixel.show();
delay(15);
}

}
```

### The Cloud

C/C++
```/*
* Project TheCloud
* Description: Starter Code for Adafruit.io
* Author: Brian Rashap
* Date: 6-Aug-2020
*/

// Need to install library Adafruit_MQTT

// We will create credentials.h using the below
#include "credentials.h"

/************ Global State (you don't need to change this!) ***   ***************/
TCPClient TheClient;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.

/****************************** Feeds ***************************************/
// Setup Feeds to publish or subscribe

/************Declare Variables*************/
unsigned long last, lastTime;
float h,t,f;
int light;
int ledOn;

#include <Grove_Temperature_And_Humidity_Sensor.h>

#define DHTPIN D2     //set pin

DHT dht(DHTPIN);

SYSTEM_MODE(SEMI_AUTOMATIC);

void setup() {
waitFor(Serial.isConnected, 15000); //wait for Serial Monitor to startup
Serial.begin(9600);
Serial.printf("DHTII Begin!!!\n");

//Connect to WiFi without going to Particle Cloud
WiFi.connect();
while(WiFi.connecting()) {
Serial.printf(".");

}
pinMode(A0,INPUT);
pinMode(D4,OUTPUT);

// Setup MQTT subscription for onoff feed.
mqtt.subscribe(&mqttLED);
}

void loop() {
// Validate connected to MQTT Broker
MQTT_connect();
h = dht.getHumidity();
t = dht.getTempCelcius();
f = dht.getTempFarenheit();

// Ping MQTT Broker every 2 minutes to keep connection alive
if ((millis()-last)>120000) {
Serial.printf("Pinging MQTT \n");
if(! mqtt.ping()) {
Serial.printf("Disconnecting \n");
mqtt.disconnect();
}
last = millis();
}

// publish to cloud every 30 seconds
delay(5000);
h = dht.getHumidity();
t = dht.getTempCelcius();
f = dht.getTempFarenheit();

if (isnan(h) || isnan(t) || isnan(f)) {
Serial.printf("Failed to read from DHTII sensor!\n");
return;
}
Serial.printf("Temp(C): %0.2f, Temp (F): %0.2f, Humid: %0.2f\n",t,f,h);

if((millis()-lastTime > 10000)) {
if(mqtt.Update()) {
mqttTemp.publish(f);
mqttHum.publish(h);
mqttLight.publish(light);
Serial.printf("Publishing %0.2f \n",f);
}
lastTime = millis();
}

// this is our 'wait for incoming subscription packets' busy subloop
if (subscription == &mqttLED) {
analogWrite(D4,ledOn);
}
}
}

// Function to connect and reconnect as necessary to the MQTT server.
void MQTT_connect() {
int8_t ret;

if (mqtt.connected()) {
return;
}

Serial.print("Connecting to MQTT... ");

while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.printf("%s\n",(char *)mqtt.connectErrorString(ret));
Serial.printf("Retrying MQTT connection in 5 seconds..\n");
mqtt.disconnect();
delay(5000);  // wait 5 seconds
}
Serial.printf("MQTT Connected!\n");
}
```

## Credits

### Aaron Kieling

1 project • 2 followers