IoT Bluetooth Weather Station

Overview

The goal of this project is to demonstrate extended implementations of sensors and to also give a simple demo for understanding the control and UART capabilities of the Adafruit Bluefruit LE Board. The goal of this project is to bring in four types of atmospheric data and have them sent to one of two phones connected to one of the bluetooth boards. The other phone acts as the controller so data is sent when the controller signals by the user touching buttons on the controller phone device.

Components Needed

  • mBed LPC1768 (1)
  • Adafruit Bluefruit LE Board (2)
  • HTU21D Temperature and Humidity Sensor (1)
  • TMP36 Temperature Sensor (1)
  • Phototransistor Light Sensor (1)
  • SCP1000 Pressure Sensor (1)

Wiring Diagrams

  • HTU21D Wiring Diagram

/media/uploads/hippi345/screen_shot_2016-03-08_at_8.37.00_am.png

  • TMP36

/media/uploads/hippi345/screen_shot_2016-03-08_at_8.39.52_am.png

/media/uploads/hippi345/screen_shot_2016-03-08_at_8.40.07_am.png

  • Phototransistor

/media/uploads/hippi345/screen_shot_2016-03-08_at_8.42.28_am.png

  • SCP1000 Pressure Sensor

/media/uploads/hippi345/screen_shot_2016-03-08_at_8.43.28_am.png

  • Adafruit Bluefruit LE Board

/media/uploads/hippi345/screen_shot_2016-03-08_at_8.44.22_am.png

Import programIoT_Weather_Station

Basic IoT demo of sensor data going to one phone and data push is controlled by another phone.

Code

include the mbed library with this snippet

//Joel Shearon and Van Mang ECE 4180 Mini Project
#include "mbed.h"
#include "HTU21D.h"
#include "TMP36.h"
#include "string"
#include "SCP1000.h"
SCP1000 scp1000(p5,p6,p7,p8);
TMP36 tmp36(p20);
Ticker flipper;
AnalogIn photocell(p15);
string sun;
PwmOut myled(LED1);
RawSerial  dev(p28,p27);
RawSerial ble(p13,p14);
DigitalOut led1(LED3);
DigitalOut led4(LED4);
Serial pc(USBTX, USBRX); 
HTU21D temphumid(p9, p10); // Temp Module || sda, SCL
string options[7] = {"moonless cloudy night \n\r"
,"moonlit night \n\r"
,"dark room\n\r"
,"dark overcast day \n\r"
,"overcast day \n\r"
,"full day \n\r"
,"full sun \n\r"};

void dev_recv()
{
    led1 = !led1;
    while(dev.readable()) {
        pc.putc(dev.getc());
    }
}
 
void pc_recv()
{
    led4 = !led4;
    while(pc.readable()) {
        dev.putc(pc.getc());
    }
}

void flip() {
        float readPhoto = photocell.read()*3.3;
        if (readPhoto < 0.15f)
        { sun = options[0];
         }
        else if (readPhoto < 0.412f)
        { sun = options[1];
         } 
        else if (readPhoto < 1.65f)
        { sun = options[2];
         }
        else if (readPhoto < 1.34f){
            sun = options[3];
        }
        else if (readPhoto < 3.2f)
        { sun = options[4];
         }
        else if (readPhoto < 3.26f)
        { sun = options[5];
         }
        else if (readPhoto >= 3.26f)
        { sun = options[6];
         }  
}
//start of main
 
int main()
{
    char bnum=0;
    char bhit=0;
    pc.baud(9600);
    dev.baud(9600);
    float tempC, tempF;
        pc.attach(&pc_recv, Serial::RxIrq);
        dev.attach(&dev_recv, Serial::RxIrq);
        flipper.attach(&flip, 1); 
    while(1) {
        wait(1);
        //conversion to degrees C - from sensor output voltage per LM61 data sheet
        tempC = tmp36.read();
        //printf("percentage: %3.3f%%\n", tmp36.read());
        //wait(0.5);
        //convert to degrees F
        tempF = tmp36.readFah();
        
        if (ble.getc()=='!') {
            if (ble.getc()=='B') { //button data packet
                bnum = ble.getc(); //button number
                bhit = ble.getc(); //1=hit, 0=release
                if (ble.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
                    myled = bnum - '0'; //current button number will appear on LEDs
                    switch (bnum) {
                        case '1': //number button 1
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("1");
                                tempC = tmp36.read();
                                tempF = tmp36.readFah();
                                dev.printf("%5.2F C %5.2F F \n\r", tempC, tempF);
                            }
                            break;
                        case '2': //number button 2
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("2");
                                dev.printf("Humidity Is: %i %%\n\r", temphumid.sample_humid());
                            }
                            break;
                        case '3': //number button 3
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("3");
                                dev.printf("the sun level is: %s", sun);
                            }
                            break;
                        case '4': //number button 4
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("4");
                                dev.printf("The pressure is %d Pa", scp1000.readPressure());
                            }
                            break;
                        case '5': //button 5 up arrow
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("5");
                                tempC = tmp36.read();
                                tempF = tmp36.readFah();
                                dev.printf("%5.2F C %5.2F F \n\r", tempC, tempF);
                            }
                            break;
                        case '6': //button 6 down arrow
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("6");
                                dev.printf("Humidity Is: %i %%\n\r", temphumid.sample_humid());
                            }
                            break;
                        case '7': //button 7 left arrow
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("7");
                                dev.printf("the sun level is: %s", sun);
                            }
                            break;
                        case '8': //button 8 right arrow
                            if (bhit=='1') {
                                //add hit code here
                            } else {
                                //dev.printf("8");
                                dev.printf("The pressure is %d Pa", scp1000.readPressure());
                            }
                            break;
                        default:
                            break;
                    }
            }
        }
    }
    }
}

Final Results: Pictures and Video

/media/uploads/hippi345/img_2015_-1-.png

/media/uploads/hippi345/img_2016_-1-.jpg

/media/uploads/hippi345/img_2017.png


Please log in to post comments.