Rafa Juárez
Published © CC0

Arduino YUN IoT for Home monitoring using dweet.io

Practicing with IoT using dweet.io service from YUN.

BeginnerProtip2 hours4,373
Arduino YUN IoT for Home monitoring using dweet.io

Things used in this project

Hardware components

Arduino Yun
Arduino Yun
×1
http://dweet.io/
×1
LM35
×1
Resistor 10k ohm
Resistor 10k ohm
×1
LDR
×1

Story

Read more

Schematics

Preliminary reading before go to the project.

This PDF shows preliminary Reading and actions that I did before do the final Project. It can be interesting for begginers.

Code

Room monitoring, temperature and light just using the component LM35 and one LDR divider

Arduino
The input from theLM35 sensor is connected to the Analog input A1, its value is multipled by 0.4689455791989076 to convert it in ºC and proper calibration. One 10KOhm resistor from this point to the GND is needed to stabilize the Reading.
The center point from the divider of 10kOhm resitor and the LDR is connecte to the Analog input A0, its value is mapped from its min and max values meassured with min and max lighting to scale it into a range from 0 to 100, like of the 0 - 100% of the room lighting values.
The Timestamp of the readying is also added.
#include <Bridge.h>
#include <HttpClient.h>
int analogIn = A0; int analogVal = 0; int analogIn1 = A1; int analogVal1 = 0;int light = 0;
float temp;
void setup() {
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);
}

void loop() {
// Initialize the client library
String dataString;
  analogVal = analogRead(analogIn);analogVal1 = analogRead(analogIn1);
  light=map(analogVal,0,1024,0,100);// To convert Analog values to % of luminosity
  temp=analogVal1*0.4689455791989076; //Sensor Calibration
  HttpClient client;
  dataString += getTimeStamp(); // CAll routine to obtain current timestamp from the linino side of the YUN
  // Make a HTTP request:To send analog input values of A0 and A1
  client.get("http://www.dweet.io/dweet/for/YUN_ANALOG_IN_DWEETING?A0_Home_Light="+String(light)+"&A1_Home_Temp="+String(temp)+"&TimeStamp="+String(dataString)+"&Visit=https://www.hackster.io/Rjuarez7");
  delay(1000); // To give time to the server for answering
}

String getTimeStamp() {
   String result;
   Process time;
   time.begin("date");
   time.addParameter("+%D-%T");  
   time.run(); 
   while(time.available()>0) {
     char c = time.read();
     if(c != '\n')
       result += c;
   }
   return result;
}

Credits

Rafa Juárez

Rafa Juárez

18 projects • 39 followers
Very interested in prototyping of new ideas. 30 years experience in electronics.

Comments