0
0
Raspberry Piprogramming~10 mins

Email alerts on sensor thresholds in Raspberry Pi - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Email alerts on sensor thresholds
Start Program
Read Sensor Value
Check if Value > Threshold?
NoWait & Repeat
Yes
Send Email Alert
Wait & Repeat
The program reads a sensor value, checks if it passes a set limit, sends an email if it does, then waits before checking again.
Execution Sample
Raspberry Pi
import smtplib
sensor_value = 75
threshold = 70
if sensor_value > threshold:
    send_email_alert()
This code checks if the sensor value is above the threshold and sends an email alert if true.
Execution Table
StepActionSensor ValueThresholdCondition (Value > Threshold)Email Sent
1Read sensor value757075 > 70 = TrueNo
2Check condition7570TrueNo
3Send email alert7570TrueYes
4Wait before next read7570TrueYes
5Read sensor value again657065 > 70 = FalseNo
6Check condition6570FalseNo
7No email sent, wait6570FalseNo
💡 Program runs continuously; stops only if manually terminated.
Variable Tracker
VariableStartAfter Step 1After Step 5Final
sensor_valueNone756565
threshold70707070
email_sentFalseFalseFalseFalse
Key Moments - 2 Insights
Why does the program send an email only when the sensor value is above the threshold?
Because the condition 'sensor_value > threshold' must be True to trigger sending an email, as shown in execution_table rows 2 and 3.
What happens when the sensor value is below the threshold?
No email is sent and the program waits to read the sensor again, as seen in execution_table rows 5 to 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the email alert sent?
AStep 2
BStep 3
CStep 5
DStep 7
💡 Hint
Check the 'Email Sent' column in the execution_table for when it changes to 'Yes'.
At which step does the sensor value fail to exceed the threshold?
AStep 1
BStep 3
CStep 5
DStep 2
💡 Hint
Look at the 'Condition (Value > Threshold)' column for 'False' value.
If the threshold was set to 80, what would happen at step 1?
ANo email sent, condition false
BEmail would be sent
CProgram would crash
DSensor value would change
💡 Hint
Compare sensor_value 75 with new threshold 80 in the condition column.
Concept Snapshot
Read sensor value continuously
Check if value exceeds threshold
If yes, send email alert
Wait before next reading
Repeat forever
Full Transcript
This program reads a sensor value on a Raspberry Pi and compares it to a set threshold. If the sensor value is higher than the threshold, it sends an email alert. Otherwise, it waits and reads the sensor again. This cycle repeats continuously to monitor sensor data and notify when limits are exceeded.