CAVEDU EducationDFRobotDFRobot Robotics
Published © GPL3+

Open Data Home Automation - Arduino 101 & App Inventor

Get temperature data from a webpage and compare with Arduino 101's LM35 sensor. And turn a fan on/off according to the comparison result.

IntermediateFull instructions provided3 hours2,099
 Open Data Home Automation - Arduino 101 & App Inventor

Things used in this project

Hardware components

Arduino 101 & Genuino 101
Arduino 101 & Genuino 101
×1
DFRobot Gravity: IO Expansion Shield for Arduino V7.1
If you use components not from DFRobot, this item is not required.
×1
DFRobot Gravity: Digital 5A Relay Module
Or use any compatible relay module.
×1
DFRobot Gravity: Analog LM35 Temperature Sensor For Arduino
You can use LM35 component or DHT11 (code modification required).
×1

Software apps and online services

MIT App Inventor
Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit of this project - relay / LM35

001 qwi1gfheoc

Arduino101_relay_lm35

Code

App Inventor .aia

Scratch
No preview (download only).

Arduino 101 code - get opendata parse result from Android phone(App Inventor)

Arduino
#include <CurieBLE.h>

#include <LM35.h>

LM35 temp(A4);
BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService RelayService("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedCharCharacteristic switchCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEUnsignedIntCharacteristic LM35Data( "19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);
const int  RelayPin = 13; // pin to use for the Relay
char control = '0';
int old_data ;

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

  // set Light pin to output mode
  pinMode( RelayPin, OUTPUT);

  // set advertised local name and service UUID:
  blePeripheral.setLocalName("LM35");
  blePeripheral.setAdvertisedServiceUuid( RelayService.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(RelayService);
  blePeripheral.addAttribute(switchCharacteristic);
  blePeripheral.addAttribute(LM35Data);
  // set the initial value for the characeristic:
  switchCharacteristic.setValue(0);

  // begin advertising BLE Relay service:
  blePeripheral.begin();

  Serial.println("BLE Relay service.");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the Light:
      if (switchCharacteristic.written()) {

        control = switchCharacteristic.value();
        Serial.print("value : ");
        Serial.println(control);
        
        if (control == 'O') {      
          Serial.println("Relay on");
          Serial.println(switchCharacteristic.value());
          digitalWrite(13, HIGH);                           // Open relay
        } else if(control == 'C'){ 
          
          Serial.println(F("Relay off"));
          Serial.println(switchCharacteristic.value());
          digitalWrite(13, LOW);                            // Close Relay
        }
        
      }
      int new_data = temp.cel();
      if(old_data != new_data)
      { 
        LM35Data.setValue(new_data);
        Serial.println(new_data);
        old_data = new_data;
        delay(1000);
      }
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

Credits

CAVEDU Education

CAVEDU Education

11 projects • 11 followers
We provide tutorials of robotics, Arduino, Raspberry Pi and IoT topics. http://www.cavedu.com
Contact
DFRobot

DFRobot

8 projects • 33 followers
Contact
DFRobot Robotics

DFRobot Robotics

4 projects • 3 followers
Contact

Comments