MDM331AID/Experiment 14
Experiment: Smart Threshold Alerts for Data Minimization using Privacy-by-Design
Aim
To design and implement a Privacy-by-Design IoT system using an LDR sensor and ESP32 that generates an alert only when a predefined threshold is crossed, thereby minimizing unnecessary sensor data transmission.
Objectives
- To understand Privacy-by-Design in an IoT system.
- To understand the concept of data minimization.
- To interface an LDR sensor with ESP32.
- To detect changes in light intensity.
- To define a threshold for detecting darkness.
- To generate a POWER CUT alert when darkness is detected.
- To process raw sensor data locally on the ESP32.
- To avoid continuously transmitting raw LDR readings.
- To transmit or expose only the required alert information.
- To demonstrate data minimization through data inspection.
Components Required
| Sr. No. | Component | Quantity | Purpose |
|---|---|---|---|
| 1 | ESP32 Development Board | 1 | Reads the LDR and hosts the web server |
| 2 | LDR | 1 | Detects light intensity |
| 3 | 10 kOhm Resistor | 1 | Forms the LDR voltage divider |
| 4 | Breadboard | 1 | Circuit connections |
| 5 | Jumper Wires | As required | Electrical connections |
| 6 | Smartphone | 1 | Accesses the ESP32 web page |
| 7 | USB Cable | 1 | Programming and powering ESP32 |
| 8 | Computer with Arduino IDE | 1 | Programming the ESP32 |
Theory
Internet of Things
The Internet of Things, or IoT, is a system in which physical devices use sensors and communication technologies to collect and exchange information.
In a conventional IoT system, sensor readings may be continuously transmitted even when the application does not require all of the readings.
For example, an LDR monitoring system may continuously generate values such as:
3860 3715 3521 3480 3405
If the purpose of the application is only to detect a power cut, the application does not need every individual LDR reading.
The ESP32 can instead process the sensor data locally and generate an alert only when the required condition occurs.
Privacy-by-Design
Privacy-by-Design means that privacy is considered while designing the system rather than being added later.
One important part of Privacy-by-Design is data minimization.
Data minimization means collecting, processing, transmitting, and storing only the information that is necessary for the intended purpose.
In this experiment, the purpose is to detect a possible power cut.
Therefore, the system does not need to continuously expose the exact LDR readings.
The ESP32 processes the readings locally and only generates the required alert when the threshold is crossed.
Smart Threshold Alert
A threshold is a predefined value used to identify a particular condition.
The ESP32 reads the LDR value and compares it with the selected threshold.
The operation is:
LDR reading
|
v
ESP32
|
v
Check threshold
|
+-------------------+
| |
v v
Normal condition Dark condition
| |
v v
No alert POWER CUT
alert
The threshold value depends on the LDR circuit and surrounding lighting conditions.
Therefore, the threshold should be calibrated before performing the experiment.
Data Minimization
In a conventional system, raw LDR readings may be continuously sent to another device or server.
In the proposed system:
LDR reading
|
v
Local processing on ESP32
|
v
Threshold check
|
+------------------+
| |
v v
Normal Dark
| |
v v
No alert POWER CUT
The raw LDR value is used locally for decision making.
Unnecessary raw readings are therefore not continuously exposed outside the device.
Pin Connections
| LDR Circuit | ESP32 | Description |
|---|---|---|
| LDR voltage divider output | GPIO 34 | Analog input |
| Supply | 3.3V | Circuit supply |
| Ground | GND | Common ground |
A typical voltage divider is:
3.3V
|
LDR
|
+-------- GPIO 34
|
10 kOhm
|
GND
The voltage at GPIO 34 changes according to the amount of light falling on the LDR.
Note: Depending on the circuit arrangement, the LDR reading may increase or decrease when the sensor is covered. The actual behavior should be checked during calibration.
Connection Diagram
ESP32
+------------+
| |
3.3V --| |
| |
| GPIO 34 <--|------ LDR Circuit
| |
GND --| |
| |
+------------+
|
|
Wi-Fi Access Point
|
|
Smartphone Browser
|
|
192.168.1.4
Working Principle
The ESP32 works as a Wi-Fi Access Point and hosts a web server.
The smartphone connects directly to the Wi-Fi network created by the ESP32.
The student then opens:
http://192.168.1.4
The ESP32 reads the LDR value.
The value is compared with the threshold.
When sufficient light is present, the system remains in the normal condition.
When the LDR is covered and the reading crosses the threshold, the ESP32 considers the condition to represent a power cut.
The smartphone then displays the POWER CUT alert.
The raw LDR value is processed locally.
Program
The following program avoids embedding HTML source directly into the MediaWiki page.
The web page is constructed using character values so that the program does not contain HTML tags as literal text.
#include <WiFi.h>
#include <WebServer.h>
const int LDR_PIN = 34;
const char* ap_ssid = "ESP32-Power-Monitor";
const char* ap_password = "12345678";
WebServer server(80);
const int LDR_THRESHOLD = 2000;
bool powerCut = false;
void handleRoot()
{
int ldrValue = analogRead(LDR_PIN);
if (ldrValue < LDR_THRESHOLD)
{
powerCut = true;
}
else
{
powerCut = false;
}
String page = "";
char lt = 60;
char gt = 62;
page += lt;
page += "html";
page += gt;
page += lt;
page += "head";
page += gt;
page += lt;
page += "meta name='viewport' content='width=device-width, initial-scale=1'";
page += gt;
page += lt;
page += "title";
page += gt;
page += "Smart Power Monitor";
page += lt;
page += "/title";
page += gt;
page += lt;
page += "/head";
page += gt;
page += lt;
page += "body";
page += gt;
page += lt;
page += "h1";
page += gt;
page += "Smart Power Monitor";
page += lt;
page += "/h1";
page += gt;
if (powerCut)
{
page += lt;
page += "h2";
page += gt;
page += "POWER CUT";
page += lt;
page += "/h2";
page += gt;
page += lt;
page += "p";
page += gt;
page += "Dark condition detected.";
page += lt;
page += "/p";
page += gt;
}
else
{
page += lt;
page += "h2";
page += gt;
page += "NORMAL";
page += lt;
page += "/h2";
page += gt;
page += lt;
page += "p";
page += gt;
page += "No power cut detected.";
page += lt;
page += "/p";
page += gt;
}
page += lt;
page += "/body";
page += gt;
page += lt;
page += "/html";
page += gt;
server.send(200, "text/html", page);
}
void setup()
{
Serial.begin(115200);
pinMode(LDR_PIN, INPUT);
WiFi.softAPConfig(
IPAddress(192,168,1,4),
IPAddress(192,168,1,1),
IPAddress(255,255,255,0)
);
WiFi.softAP(ap_ssid, ap_password);
Serial.println("ESP32 Access Point started");
Serial.print("IP Address: ");
Serial.println(WiFi.softAPIP());
server.on("/", handleRoot);
server.begin();
Serial.println("Web server started");
}
void loop()
{
server.handleClient();
}
Code Explanation
| Code or Function | Explanation |
|---|---|
| WiFi.h | Provides ESP32 Wi-Fi functionality. |
| WebServer.h | Provides the web server functionality. |
| LDR_PIN | Defines GPIO 34 as the LDR analog input. |
| WiFi.softAP | Creates a Wi-Fi Access Point using the ESP32. |
| WiFi.softAPConfig | Sets the Access Point IP address to 192.168.1.4. |
| WebServer server(80) | Creates an HTTP web server on port 80. |
| LDR_THRESHOLD | Defines the value used to detect the dark condition. |
| analogRead | Reads the analog value from the LDR circuit. |
| powerCut | Stores whether a dark condition has been detected. |
| handleRoot | Generates the web page displayed on the smartphone. |
| server.send | Sends the web page to the browser. |
| server.handleClient | Processes browser requests. |
Access Point
The ESP32 creates its own Wi-Fi network.
The network name is:
ESP32-Power-Monitor
The IP address is:
192.168.1.4
The smartphone can therefore access the web page using:
http://192.168.1.4
Threshold Detection
The ESP32 reads the LDR using:
int ldrValue = analogRead(LDR_PIN);
The value is compared with the threshold:
if (ldrValue < LDR_THRESHOLD)
{
powerCut = true;
}
If the condition is satisfied, the ESP32 generates the POWER CUT alert.
Calibration of LDR Threshold
The threshold should be calibrated before the experiment.
- Upload the program to the ESP32.
- Open the Arduino IDE Serial Monitor.
- Observe the LDR readings under normal light.
- Cover the LDR with a finger.
- Observe the LDR readings again.
- Compare the readings for bright and dark conditions.
- Select a suitable threshold between the two conditions.
- Change the LDR_THRESHOLD value in the program.
- Upload the program again.
- Test the system.
For example, the readings may be:
Normal light: 3000 to 3800 LDR covered: 500 to 1200
In such a case, a threshold somewhere between these ranges can be selected.
The above values are examples only. Actual values depend on the LDR circuit and lighting conditions.
Procedure
- Connect the LDR and resistor as a voltage divider.
- Connect the output of the voltage divider to GPIO 34.
- Connect the circuit to 3.3V and GND.
- Connect the ESP32 to the computer.
- Open Arduino IDE.
- Select the appropriate ESP32 board.
- Select the appropriate COM port.
- Upload the program.
- Open the Serial Monitor.
- Verify that the ESP32 Access Point has started.
- Connect the smartphone to ESP32-Power-Monitor.
- Open the smartphone browser.
- Enter http://192.168.1.4.
- Observe the NORMAL status.
- Keep the LDR exposed to light.
- Cover the LDR using a finger.
- Observe the POWER CUT alert.
- Remove the finger.
- Verify that the normal condition is restored.
- Perform the data inspection demonstration.
Observations and Output
Normal Condition
When the LDR is exposed to sufficient light:
LDR Condition : Bright System Status : NORMAL Alert : None
No power-cut alert is generated.
Dark Condition
When the LDR is covered with a finger:
LDR Condition : Dark System Status : ALERT Alert : POWER CUT
The ESP32 detects the threshold crossing and generates the alert.
Smartphone Output
Normal condition:
SMART POWER MONITOR NORMAL No power cut detected.
Dark condition:
SMART POWER MONITOR POWER CUT Dark condition detected.
Demonstration of Data Minimization
The main purpose of this experiment is to demonstrate that unnecessary raw sensor data does not need to be transmitted.
Conventional System
In a conventional IoT system, the server may receive raw LDR readings continuously.
For example:
LDR value: 3860 LDR value: 3715 LDR value: 3521 LDR value: 3480
The server therefore receives detailed sensor information.
Privacy-by-Design System
In the proposed system, the ESP32 processes the LDR reading locally.
During normal conditions:
LDR reading
|
v
Local threshold check
|
v
Normal condition
|
v
No alert
When the threshold is crossed:
LDR reading
|
v
Local threshold check
|
v
Dark condition
|
v
POWER CUT
The application only needs to expose the required event.
The raw LDR measurement does not need to be exposed.
Data Inspection Demonstration
The data inspection demonstration is used to compare the amount of information exposed by two system designs.
The demonstration is educational and is intended to show the effect of data minimization.
Conventional Design
A conventional system may expose information such as:
LDR value: 3860 LDR value: 3715 LDR value: 3521 LDR value: 1200
An observer can therefore obtain detailed information about the sensor readings.
Privacy-by-Design Design
The Privacy-by-Design system processes the raw value locally.
When there is no threshold event:
No alert
When darkness is detected:
POWER CUT
The application therefore exposes only the information needed for the intended purpose.
The raw LDR values are not required by the application.
Demonstration Steps
- Connect the smartphone to the ESP32 Access Point.
- Open the ESP32 web page.
- Observe the normal condition.
- Cover the LDR with a finger.
- Observe the POWER CUT alert.
- Inspect the application data using an appropriate network inspection or server logging method.
- Observe that the useful application information is the alert rather than a continuous stream of raw LDR values.
- Explain that the raw reading was processed locally before the alert was generated.
Note: This demonstration is about data minimization. It does not claim that HTTP communication is encrypted or completely secure.
Conventional System vs Privacy-by-Design System
| Feature | Conventional System | Privacy-by-Design System |
|---|---|---|
| Sensor processing | May be performed at server | Performed locally on ESP32 |
| Raw LDR readings | May be continuously transmitted | Processed locally |
| Normal readings | May be transmitted | No unnecessary transmission |
| Threshold detection | May be performed at server | Performed on ESP32 |
| Alert | May contain sensor information | Only required alert is exposed |
| Data volume | Higher | Lower |
| Data exposure | Higher | Minimized |
Why This is Privacy-by-Design
The experiment demonstrates Privacy-by-Design through the following design decisions:
- Local Processing: Raw LDR readings are processed on the ESP32.
- Data Minimization: Continuous raw readings are not unnecessarily transmitted.
- Purpose Limitation: The system only needs to detect a possible power-cut condition.
- Smart Thresholding: An alert is generated only when the threshold is crossed.
- Reduced Data Exposure: Unnecessary sensor information is not exposed.
- Privacy by Default: The system is designed to minimize data exposure from the beginning.
The main principle demonstrated is:
Do not transmit unnecessary information when the application does not require it.
Advantages
- Reduces unnecessary data transmission.
- Reduces the amount of sensor information exposed outside the device.
- Reduces network traffic.
- Allows fast local decision making.
- Demonstrates data minimization clearly.
- Does not require an external cloud server.
- Can be demonstrated easily using a smartphone.
- Can be extended to other IoT alert applications.
Limitations
- The LDR provides an indirect indication of a power cut.
- Changes in environmental lighting can also trigger the alert.
- The threshold must be calibrated.
- The HTTP communication used in this experiment is not encrypted.
- This experiment demonstrates data minimization and not complete IoT security.
- A real power monitoring system would use an appropriate electrical sensing method.
Result
The smart threshold alert system was successfully implemented using an LDR sensor and ESP32.
The ESP32 locally processed the LDR readings and detected a dark condition using a predefined threshold.
When the threshold was crossed, the smartphone displayed a POWER CUT alert through the ESP32 web server.
The ESP32 used the IP address:
192.168.1.4
The experiment demonstrated that raw LDR readings do not need to be continuously exposed when the application only requires an event notification.
Thus, the experiment demonstrated data minimization through local processing and smart threshold alerts as a practical Privacy-by-Design approach.
Viva Questions
Q1. What is Privacy-by-Design?
Ans: Privacy-by-Design means incorporating privacy considerations into the design of a system from the beginning.
Q2. What is data minimization?
Ans: Data minimization means collecting, processing, transmitting, and storing only the data required for the intended purpose.
Q3. Why is an LDR used?
Ans: An LDR is used because its light-sensitive behavior makes it easy to manually generate a threshold event by covering it with a finger.
Q4. What does darkness represent in this experiment?
Ans: Darkness is treated as an indication of a possible power cut.
Q5. Why is the raw LDR value not continuously transmitted?
Ans: The application only needs to know whether the threshold has been crossed. Therefore, continuous transmission of the raw value is unnecessary.
Q6. Where is the threshold checked?
Ans: The threshold is checked locally on the ESP32.
Q7. What happens when the threshold is not crossed?
Ans: No power-cut alert is generated and unnecessary sensor data is not exposed.
Q8. What happens when the threshold is crossed?
Ans: The ESP32 detects the dark condition and generates the POWER CUT alert.
Q9. What is the purpose of the data inspection demonstration?
Ans: It demonstrates how much sensor information is exposed and how data minimization reduces unnecessary information.
Q10. What information is required when the threshold is crossed?
Ans: The required information is the POWER CUT alert.
Q11. Is the system completely secure?
Ans: No. The main purpose is to demonstrate data minimization and Privacy-by-Design. HTTP communication is not encrypted.
Q12. Does data minimization mean that no data is transmitted?
Ans: No. It means that only the data necessary for the intended purpose should be transmitted or exposed.
Q13. Why is local processing useful?
Ans: Local processing allows the ESP32 to make decisions using raw sensor data without unnecessarily exposing that raw data.
Q14. What is a smart threshold alert?
Ans: A smart threshold alert is generated when a sensor reading crosses a predefined threshold representing a meaningful condition.
Q15. What is the main principle demonstrated by this experiment?
Ans: The main principle is data minimization. Raw sensor information is processed locally and only the required alert is exposed.