saket kulkarni
Published

Smart Home

Using sensors, this device allows you to save energy and maximize security of your household.

IntermediateWork in progress2 hours998
Smart Home

Things used in this project

Hardware components

Grove - Ultrasonic Ranger
Seeed Grove - Ultrasonic Ranger
×1
Grove - Temperature Sensor
Seeed Grove - Temperature Sensor
×1
Grove - Light Sensor
Seeed Grove - Light Sensor
×1

Software apps and online services

Maker service
IFTTT Maker service
Particle Build Web IDE
Particle Build Web IDE
github

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

How the code determines what it will do

Code

Smart Home code version 1.0

C/C++
Particle.io
// This #include statement was automatically added by the Particle IDE.
#include <Grove-Ultrasonic-Ranger.h>
#define CLK D2//pins definitions for TM1637 and can be changed to other ports
#define DIO D3



/***************************************************************************/
//	Function: Measure the distance to obstacles in front and print the distance
//			  value to the serial terminal.The measured distance is from
//			  the range 0 to 400cm(157 inches).
//	Hardware: Grove - Ultrasonic Ranger
//	Arduino IDE: Arduino-1.0
/*****************************************************************************/
//int Ultrasonic = D5;

Ultrasonic ultrasonic(D4);





void setup()
{
	Serial.begin(9600);
}
void loop()
{
    //int range;
	int digit;
    int pos = 3;
	long lastRange;
	//int lastRange;
	long RangeInCentimeters;
	
	Serial.println("The distance to obstacles in front is: ");
	RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
	Serial.print(RangeInCentimeters);//0~400cm
	Serial.println(" cm");
	delay(10000);
	
	if (RangeInCentimeters != lastRange) {
    lastRange = RangeInCentimeters;
    

    // Fill display with zeros
    for (int i = 0; i < 4; i++) {
    }

    // Extract each digit from the range and write it to the display
    while (RangeInCentimeters >= 1) {
    // Get the current digit by performing modulo (%) division on the range
    digit  = RangeInCentimeters % 10;
    // Remove the trailing digit by whole-number division
    RangeInCentimeters /= 10;

}
}
Particle.publish("Someone walked by!!!", "Obstacle noticed at " + String(ultrasonic.MeasureInCentimeters()), PRIVATE);
	
}

Credits

saket kulkarni

saket kulkarni

1 project • 2 followers

Comments

Add projectSign up / Login