I assume for 3 floor Building, I am going listing all components which you need to make smart building.
1. HVAC System : Using LM35 sensor get data of temperature and send data to database.
2. Parking System : Using ultra sonic sensor get data of is parking space is empty or not and send that data to database.
3. Water Plant System : Using Soil moisture sensor get data and send that data to database.
4. Light System : Using LDR sensor get data and send data to database.
5. Water Tank Level : Using ultrasonic sensor, It will detect the depth of water tank and send that data to database.
6. Automatic Street Light : Using LDR, PIR and Relay, When it will detect low light and some motion than and than it will turn on light.
7. Fire Safety : Using MQ5 sensor, When it will detect fire it will automatically turn on water pump and start water lines.
8. Wind Speed : Using wind speed sensor we get data and send that data to database.
Advantage :
1. Lower Cost in electricity
2. Environment Friendly
3. Low Maintains Cost
Let's Get Started.
How to setup first time MKRFOX1200 ?
Step1 : Arduino
1. Install the Arduino IDE
2. Install the MKRFox1200 Arduino core from the "Boards Manager". You can follow this tutorial for help.
3. Now you can select the MKRFox1200 board
4. Install the following libraries (you can use the Arduino Library Manager):
Library :
1. https://github.com/arduino-libraries/SigFox
2. https://github.com/arduino-libraries/ArduinoLowPower
5. Connect your board to your computer and flash the MRKFox1200 example named "FirstConfiguration" or below Code :
#include<SigFox.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while(!Serial);
SigFox.begin();
Serial.print("ID : ");
Serial.println(SigFox.ID());
Serial.print("PAC : ");
Serial.println(SigFox.PAC());
}
void loop() {
// put your main code here, to run repeatedly:
}
6. Open the monitor terminal and write down the ID and PAC
NB: When flashing the MKR, it may be in "deep sleep" which causes a non-detection of the COM port. In order to wake it up, you need to tap twice on the "RST" button and the board will be redetected by your PC.
Step 2 : Sigfox BackendNow that your MKRFox1200 is sending messages, we need to retrieve them and redirect them where we wish to. In order to do this, let's go to the Sigfox Backend service!
1. Go to the Sigfox Backend activation platform
2. Activate your device by selecting Arduino > Your country > Enter the ID and PAC previously written in step 1 part 5.
3. Create an account and validate
It's as simple as that, your MKRFox1200 is now linked to Sigfox Backend.
Step 3 : Check DeviceLet's check if everything is going right. Go back here.
In the "DEVICE" tab click on the Id of your "Arduino Sigfox Kit" (MKRFox1200).
The "MESSAGES" tab shows the messages sent by your board.
If there is at least one message after rebooting your MKRFox1200, consider this step as a success ! ;)
If not, make sure the code is well uploaded on the MKRFox1200 and that you did not mistaken the input of the device ID and PAC. Also, make sure an antenna is plugged in correctly so it can reach a Sigfox base station.
Step 4 : thethings.iO
Now that messages are well sent over the Sigfox network, we need a platform to visualize them accordingly. In this tutorial, we are using thethings.iO Sigfox website. Of course, you may use a different platform (check out the other compatible ones with Sigfox here) but thethings.iO is a quick and easy way to start.
Here I am using only one sensor for sending data to sigfox.
Use as many as sensor and MKRFOX 1200 as wanted in our smart building. This is just prototype to How to get data and how to setup whole modules.
Now we can analyze our building on our desktop.
Automatic Street Light :#include <ArduinoLowPower.h>
#include <SigFox.h>
#include "conversions.h"
int oneshot = true;
typedef struct __attribute__ ((packed)) sigfox_message {
uint8_t status;
int16_t data1;
uint8_t lastMessageStatus;
} SigfoxMessage;
SigfoxMessage msg;
int led = 13; //led as relay (For example use one channel relay)
int sensor = 2;
int state = LOW;
int val = 0;
int ldrPin = A0;
void setup()
{
if (oneshot == true)
{
Serial.begin(115200);
while (!Serial) {}
}
if (!SigFox.begin()) {
reboot();
}
SigFox.end();
if (oneshot == true) {
SigFox.debug();
}
pinMode(led, OUTPUT);
pinMode(sensor, INPUT);
pinMode(ldrPin, INPUT);
Serial.begin(9600);
}
void loop()
{
val = digitalRead(sensor);
int ldrStatus = analogRead(ldrPin);
if (val == HIGH && ldrStatus <= 200)
{
digitalWrite(led, HIGH);
delay(100);
if (state == LOW)
{
Serial.println("Motion detected!");
Serial.print("Its DARK, Turn on the Light");
float status1 = 1.0;
msg.data1 = convertoFloatToUInt16(status1, 2000);
state = HIGH;
}
}
else
{
digitalWrite(led, LOW);
delay(200);
if (state == HIGH)
{
Serial.println("Motion stopped!");
Serial.print("Its BRIGHT, Turn off the Light");
float status1 = 0.0;
msg.data1 = convertoFloatToUInt16(status1, 2000);
state = LOW;
}
}
SigFox.begin();
delay(100);
SigFox.status();
delay(1);
SigFox.beginPacket();
SigFox.write((uint8_t*)&msg, 12);
msg.lastMessageStatus = SigFox.endPacket();
if (oneshot == true) {
Serial.println("Status: " + String(msg.lastMessageStatus));
}
SigFox.end();
if (oneshot == true) {
while (1) {}
}
LowPower.sleep(15 * 60 * 1000);
}
void reboot()
{
NVIC_SystemReset();
while (1);
}
Fire Safety :
#include <ArduinoLowPower.h>
#include <SigFox.h>
#include "conversions.h"
int oneshot = true;
typedef struct __attribute__ ((packed)) sigfox_message {
uint8_t status;
int16_t data1;
uint8_t lastMessageStatus;
} SigfoxMessage;
SigfoxMessage msg;
int sensor=7;
int gas_value;
const int MotorInPin1 = 5;
const int MotorInPin2 = 6;
void setup()
{
if (oneshot == true) {
Serial.begin(115200);
while (!Serial) {}
}
if (!SigFox.begin()) {
reboot();
}
SigFox.end();
if (oneshot == true) {
SigFox.debug();
}
pinMode(MotorInPin1, OUTPUT);
pinMode(MotorInPin2, OUTPUT);
pinMode(sensor,INPUT);
}
void loop()
{
gas_value=digitalRead(sensor);
Serial.println(gas_value);
if(gas_value == 0) // Pump is on
{
float status1 = 1.0;
msg.data1 = convertoFloatToUInt16(status1, 2000);
analogWrite(MotorInPin1, HIGH);
analogWrite(MotorInPin2, LOW);
}
else // Pump is off
{
float status1 = 0.0;
msg.data1 = convertoFloatToUInt16(status1, 2000);
analogWrite(MotorInPin1, LOW);
analogWrite(MotorInPin2, LOW);
}
SigFox.begin();
delay(100);
SigFox.status();
delay(1);
SigFox.beginPacket();
SigFox.write((uint8_t*)&msg, 12);
msg.lastMessageStatus = SigFox.endPacket();
if (oneshot == true) {
Serial.println("Status: " + String(msg.lastMessageStatus));
}
SigFox.end();
if (oneshot == true) {
while (1) {}
}
LowPower.sleep(15 * 60 * 1000);
}
void reboot() {
NVIC_SystemReset();
while (1);
}
Comments