I am newbie to thinger.io and I want to connect the arduino to ethernet and send the data from sensor to thinger bucket.
I have arduino UNO Rev3, ethernet shield and the IR sensor E18-D80NK. Currently the combination of arduino + sd card reader + RTC1307 + IR sensor work perfect for me but I want to change it to send all data to thinger database.
My currently code is as follow:
#include “SD.h” // SD card libray
#include “Wire.h” // I2C
#include “Time.h” // Time Manipulation
#include “DS1307RTC.h” // DS1307 RTC
char timedatebuf[65]; // Time and Date string buffer
int year4digit; // 4 digit year
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 10;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 100;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = A0; //the digital pin connected to the PIR sensor’s output
int ledPin = 13;
/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print(“calibrating sensor “);
for(int i = 0; i < calibrationTime; i++){
Serial.print(”.”);
delay(100);
}
Serial.println(" done");
Serial.println(“SENSOR ACTIVE”);
delay(50);
Serial.print(“Initializing SD card…”);
pinMode(10, OUTPUT);
if (!SD.begin(10)) { // check if card is installed
Serial.println(“No SD Card present in module”);
return;
}
Serial.println(“SD Card Ready”);
}
////////////////////////////
//LOOP
void loop(){
tmElements_t tm;
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("—");
Serial.print(“motion detected at “);
Serial.print(millis()/100);
Serial.println(” sec”);
delay(250);
if (RTC.read(tm)) { // Get Time/Date from RTC1307
year4digit = tm.Year + 1970; // 4 digit year variable
// Format Time & Date string in timedatebuf
sprintf(timedatebuf, "Time: %02d:%02d:%02d Date: %02d/%02d/%02d ---->przejscie!!!",tm.Hour, tm.Minute, tm.Second, tm.Day, tm.Month, year4digit);
File dataFile = SD.open("intruder.txt", FILE_WRITE); // Open or Create file
if (dataFile) { // Check if file exist on SD Card
dataFile.println(timedatebuf);
dataFile.close(); // Close file
Serial.println(timedatebuf);
}
else {
Serial.println("error opening intruder.txt"); // if file not on SD Card
}
}
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/100);
Serial.println(" sec");
delay(250);
}
}
}
and now I want to send the sensor data to thinger. I don’t know how to do this. On the google there are several examples but only with temperature sensors.
I understand that there is no need to add RTC module because when the data is send to thinger there is time stamp, am I right?