Search this site
Embedded Files
Skip to main content
Skip to navigation
TEAM HIRED IF WIRED
HOME
INTRODUCTION
PROBLEM STATEMENT
COMPONENT SELECTION
WHY WIFI ???
COMMUNICATION TECHNOLOGY
IOT CLOUD
EXPERIMENTAL PROCEDURE
CIRCUIT
RESULTS & ANALYSIS
DEMO OF PROTOTYPE
CONCLUSION
REFERENCES
APPENDIX
SOURCE CODE
TEAM HIRED IF WIRED
HOME
INTRODUCTION
PROBLEM STATEMENT
COMPONENT SELECTION
WHY WIFI ???
COMMUNICATION TECHNOLOGY
IOT CLOUD
EXPERIMENTAL PROCEDURE
CIRCUIT
RESULTS & ANALYSIS
DEMO OF PROTOTYPE
CONCLUSION
REFERENCES
APPENDIX
SOURCE CODE
More
HOME
INTRODUCTION
PROBLEM STATEMENT
COMPONENT SELECTION
WHY WIFI ???
COMMUNICATION TECHNOLOGY
IOT CLOUD
EXPERIMENTAL PROCEDURE
CIRCUIT
RESULTS & ANALYSIS
DEMO OF PROTOTYPE
CONCLUSION
REFERENCES
APPENDIX
SOURCE CODE
SOURCE CODE FOR ARDUINO
int RELAY1 = A2;
int RELAY2 = A3;
int delayValue = 1000;
int MusclePulse = analogRead(A0);
#include "Wire.h" // This library allows you to communicate with I2C devices.
const int MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69.
int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; // variables for temperature data
char tmp_str[7]; // temporary variable used in convert function
char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
sprintf(tmp_str, "%6d", i);
return tmp_str;
}
void setup() {
//put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(A0));
// put your main code here, to run repeatedly://
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40]
Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active.
Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers
// "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L)
temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L)
gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L)
gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46 (GYRO_YOUT_L)
gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L)
// print out data
Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));
// the following equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, p.30]
Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53);
Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x));
Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y));
Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z));
Serial.println();
// delay
delay(1000);
if (analogRead(A0) > 13) {
digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, LOW);
delay(500);
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, HIGH);
delay(500);
digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, HIGH);
}
}
SOURCE CODE FOR NODE MCU ESP 8266
/////////////////////////////////
// Generated with a lot of love//
// with TUNIOT FOR ESP8266 //
// Website: Easycoding.tn //
/////////////////////////////////
#include <ESP8266WiFi.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
//#include <BlynkSimpleEsp8266.h>//
#include <SimpleTimer.h>
float data1=D1, data2=D2, data3=0;
String My_String_1;
String My_String_2;
String My_String_3;
WiFiClient client;
String MakerIFTTT_Key ;
;String MakerIFTTT_Event;
char *append_str(char *here, String s) { int i=0; while (*here++ = s[i]){i++;};return here-1;}
char *append_ul(char *here, unsigned long u) { char buf[20]; return append_str(here, ultoa(u, buf, 10));}
char post_rqst[256];char *p;char *content_length_here;char *json_start;int compi;
void setup()
{
My_String_1 = "";
My_String_2 = "";
My_String_3 = "";
Serial.begin(9600);
WiFi.disconnect();
delay(3000);
Serial.println("START");
WiFi.begin("Aaron Lee","19980121");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300);
Serial.print("..");
}
Serial.println("Connected");
Serial.println("Your IP is");
Serial.println((WiFi.localIP().toString()));
}
void loop()
{
data1 = Serial.read(); //Read the serial data and store it
data2 = Serial.read();
data3 = Serial.read();
Serial.println("data1 is : ");
Serial.println(data1);
Serial.println("data2 is : ");
Serial.println(data2);
Serial.println("data3 is : ");
Serial.println(data3);
My_String_1 = data1;
My_String_2 = data2;
My_String_3 = data3;
//delay(100);
Serial.write("");
if (client.connect("maker.ifttt.com",80)) {
MakerIFTTT_Key ="j3VrRe9cjI2kT6rN_Z91olXmLyou53doREGy52PQhD9";
MakerIFTTT_Event ="DCN";
p = post_rqst;
p = append_str(p, "POST /trigger/");
p = append_str(p, MakerIFTTT_Event);
p = append_str(p, "/with/key/");
p = append_str(p, MakerIFTTT_Key);
p = append_str(p, " HTTP/1.1\r\n");
p = append_str(p, "Host: maker.ifttt.com\r\n");
p = append_str(p, "Content-Type: application/json\r\n");
p = append_str(p, "Content-Length: ");
content_length_here = p;
p = append_str(p, "NN\r\n");
p = append_str(p, "\r\n");
json_start = p;
p = append_str(p, "{\"value1\":\"");
p = append_str(p, My_String_1);
p = append_str(p, "\",\"value2\":\"");
p = append_str(p, My_String_2);
p = append_str(p, "\",\"value3\":\"");
p = append_str(p, My_String_3);
p = append_str(p, "\"}");
compi= strlen(json_start);
content_length_here[0] = '0' + (compi/10);
content_length_here[1] = '0' + (compi%10);
client.print(post_rqst);
Serial.println("Value1 sent to google sheets:");
Serial.println(data1);
Serial.println("Value2 sent to google sheets:");
Serial.println(data2);
Serial.println("Value3 sent to google sheets:");
Serial.println(data3);
}
delay(20000);
data1=0;
data2=0;
data3=0;
}
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse