0% found this document useful (0 votes)
14 views2 pages

Iot Ir

Object detection using ESP

Uploaded by

vijayprasathme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Iot Ir

Object detection using ESP

Uploaded by

vijayprasathme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

Sketch generated by the Arduino IoT Cloud Thing "Untitled"


https://create.arduino.cc/cloud/things/08b7f64a-600c-4d44-b2cd-32d2e557b4ee

Arduino IoT Cloud Variables description

The following variables are automatically generated and updated when changes are
made to the Thing

String oBJECT_DETECTION;

Variables which are marked as READ/WRITE in the Cloud Thing will also have
functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

// Pin connected to OUT pin of CA023 Smart Sensor Module


const int obstaclePin = D5;

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if
none is found
delay(1500);

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud


ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();

// Set up the obstacle pin


pinMode(obstaclePin, INPUT);
}

void loop() {
ArduinoCloud.update();
// Your code here

// Read obstacle detection status


bool obstacleDetected = digitalRead(obstaclePin) == HIGH;

// Update obstacle detection status property in IoT Cloud


if (obstacleDetected) {
oBJECT_DETECTION = "Detected";
} else {
oBJECT_DETECTION = "Not Detected";
}

// Print status to Serial Monitor for debugging


Serial.print("Object Detection status: ");
Serial.println(oBJECT_DETECTION);

delay(1000); // Adjust delay as needed


}

/*
Since OBJECTDETECTION is READ_WRITE variable, onOBJECTDETECTIONChange() is
executed every time a new value is received from IoT Cloud.
*/
void onOBJECTDETECTIONChange() {
// Add your code here to act upon OBJECTDETECTION change
Serial.print("Object Detection status changed to: ");
Serial.println(oBJECT_DETECTION);
}

You might also like