Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: **Fall Detection** - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2025-06-09 05:34:17 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* it wont reset after i pressed cancellation button */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include <EasyButton.h> //https://github.com/evert-arias/EasyButton #include "TinyGPS.h" // Include TinyGPS library #include "SoftwareSerial.h" // Include SoftwareSerial library /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t cancellationbutton_PushButton_PIN_D2 = 2; #define buttonPin 8 // Confirmation button #define cancelButtonPin 7 // Cancellation button /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t myLED_LED_PIN_D3 = 3; #define buzzerPin 6 // Buzzer pin #define ledPin 5 // LED pin /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool myLED_LED_PIN_D3_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float myLED_LED_PIN_D3_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ SoftwareSerial GPRS(2,3); // RX=pin 2, TX=pin 3 SoftwareSerial serial_connection(10, 11); // RX=pin 10, TX=pin 11 TinyGPSPlus gps; // This is the GPS object that will work with the NMEA data // Pins and variables declarations float latitude=0; float longitude=0; String Speed=""; int Contrast=20; // Accelerometer pins #define x A1 #define y A2 #define z A3 // Pulse Sensor pin #define pulseSensorPin A0 // Variables corresponding to accelerometer int xsample=0; int ysample=0; int zsample=0; #define samples 10 // number of sample readings in still case #define fallThreshold 650 // Fall Detection Threshold // Threshold maximum and minimum values of change in acceleration when fall is detected #define minVal -50 #define MaxVal 50 // Variables tracking button state bool isFallDetected = false; bool isFallConfirmed = false; bool isFallCancelled = false; // Assign timing unsigned long fallTime; // when fall is detected unsigned long confirmationTimeout = 5000; // Time wait for confirmation or cancellation button is 5 seconds unsigned long confirmationWaitTime; // Time to wait for confirmation // Pulse sensor variables int pulseValue = 0; unsigned long lastBeatTime = 0; // Last time heartbeat detected unsigned long beatInterval = 0; // Time interval between beats int heartRate = 0; // heart rate in BPM int pulseThreshold = 512; // default threshold for pulse // Function declarations void triggerFallConfirmation(); void sendAlert(); void resetPotentiometer(); void setup(void) { // put your setup code here, to run once: Serial.begin(9600); // Start serial communication serial_connection.begin(9600); // This opens up communications to the GPS Serial.println("successfully Initialized...."); Serial.println("GPS Start"); // Just show to the monitor that the sketch has started // Taking samples in still case for(int i=0; i<samples; i++) { xsample += analogRead(x); ysample += analogRead(y); zsample += analogRead(z); } // Taking average xsample /= samples; ysample /= samples; zsample /= samples; Serial.println(xsample); Serial.println(ysample); Serial.println(zsample); delay(1000); // Set pin mode for button, buzzer and led pinMode(cancellationbutton_PushButton_PIN_D2, INPUT_PULLUP); pinMode(buttonPin, INPUT_PULLUP); // Confirmation button pinMode(cancelButtonPin, INPUT_PULLUP); // Cancellation button pinMode(buzzerPin, OUTPUT); // Buzzer pin pinMode(ledPin, OUTPUT); // LED pin pinMode(pulseSensorPin, INPUT); // Pulse sensor pin } void loop(void) { // put your main code here, to run repeatedly: updateOutputs(); // Refresh output data while(serial_connection.available()) // While there are characters to come from the GPS { gps.encode(serial_connection.read()); // This feeds the serial NMEA data into the library one char at a time } if(gps.location.isUpdated()) { // Get the latest info from the gps object which it derived from the data sent by the GPS unit Serial.println("Satellite Count : "); Serial.println(gps.satellites.value()); Serial.println("Latitude : "); Serial.println(gps.location.lat(), 6); Serial.println("Longitude : "); Serial.println(gps.location.lng(), 6); Serial.println("Speed MPH : "); Serial.println(gps.speed.mph()); Serial.println("Altitude Feet : "); Serial.println(gps.altitude.feet()); Serial.println(""); } int value1 = analogRead(x); int value2 = analogRead(y); int value3 = analogRead(z); int xValue = xsample - value1; int yValue = ysample - value2; int zValue = zsample - value3; Serial.print("x="); Serial.println(xValue); Serial.print("y="); Serial.println(yValue); Serial.print("z="); Serial.println(zValue); // Pulse sensor reading pulseValue = analogRead(pulseSensorPin); // Read value from x axis potentiometer pulseThreshold = map(analogRead(x), 0, 1023, 400, 600); // Adjust threshold range (400-600) Serial.print("Pulse Value : "); Serial.println(pulseValue); Serial.print("Pulse Threshold : "); Serial.println(pulseThreshold); if(pulseValue > pulseThreshold) { if(millis() - lastBeatTime > 500) // Only count a beat every 500ms (roughly 60BPM) { heartRate = 60000 / (millis() - lastBeatTime); // Calculate heart rate in beats per minute lastBeatTime = millis(); Serial.print("Heart Rate : "); Serial.println(heartRate); // Check if heart rate is abnormal if(heartRate < MIN_HEART_RATE || heartRate > MAX_HEART_RATE) { Serial.println("Abnormal heart rate detected. Please confirm if fall has occured."); triggerFallConfirmation(); // Confirm whether there's a fall or not } } } // Condition for Fall Detection if(xValue < minVal || xValue > MaxVal || yValue < minVal || yValue > MaxVal || zValue < minVal || zValue > MaxVal) { // Fall Detected, send SMS to emergency contact Serial.println("Fall Detected, Please press the button to confirm..."); isFallDetected = true; // When fall is detected // Buzzer and LED on when fall is detected digitalWrite(buzzerPin, HIGH); // Buzzer On digitalWrite(ledPin, HIGH); // LED on fallTime = millis(); // Record time when fall is detected confirmationWaitTime = fallTime + confirmationTimeout; // Set timeout time for confirmation // Confirmation button while (!isFallConfirmed && !isFallCancelled && millis() < confirmationWaitTime) { // Wait for confirmation or cancellation button press if (digitalRead(buttonPin) == LOW) // If confirmation button is pressed { isFallConfirmed = true; Serial.println("Fall is confirmed!"); sendAlert(); // Send SMS alert break; // Exit loop once fall is confirmed } if (digitalRead(cancelButtonPin) == LOW) { isFallCancelled = true; // If cancellation button is pressed Serial.println("Fall Detection cancelled"); // Do not reset the state after cancellation digitalWrite(buzzerPin, LOW); // Buzzer off digitalWrite(ledPin, LOW); // LED off break; } } // If no confirmation or cancellation button is pressed, automatically confirm the fall if(!isFallConfirmed && millis() >= confirmationWaitTime) { isFallConfirmed = true; Serial.println("No response, fall Detection is confirmed"); sendAlert(); // send SMS automatically } // After confirmation or cancellation, reset fall detection if (isFallCancelled) { resetPotentiometer(); // Reset Potentiometer values after confirmation isFallDetected = false; isFallConfirmed = false; // Do not reset isFallCancelled to allow for further cancellations Serial.println("Fall Detection reset."); // Reset after cancellation and continue monitoring digitalWrite(buzzerPin, LOW); // Buzzer off digitalWrite(ledPin, LOW); // LED off } } delay(1000); } void updateOutputs() { digitalWrite(myLED_LED_PIN_D3, myLED_LED_PIN_D3_rawData); } // Send SMS alert void sendAlert() { // Initialize GPRS module GPRS.begin(9600); Serial.println("Connecting to network..."); delay(2000); // wait for network connection Serial.println("Should be connected to network by now"); // Send SMS alerts with location GPRS.print("AT+CMGF=1\r"); // set SMS format to text mode delay(1200); GPRS.print("AT+CMGS=\"+01xxxxxxxxx\"\r"); // Set phone number to send alert with (replace with actual number) delay(1200); // Message GPRS.print("Fall Detected!"); GPRS.print("Location:\n"); GPRS.print("Latitude : "); GPRS.print(latitude); GPRS.print("\nLongitude : "); GPRS.print("\nGoogle Maps Link: http://maps.google.com/maps?&z=15&mrt=yp&t=k&q="); GPRS.println(latitude); GPRS.println("+"); GPRS.println(longitude); GPRS.write(26); // Send SMS GPRS.println("SMS Sent!"); } // Function resetting potentiometer void resetPotentiometer() { xsample = 0; ysample = 0; zsample = 0; for(int i = 0; i < samples; i++) { xsample += analogRead(x); ysample += analogRead(y); zsample += analogRead(z); } // Average after reset xsample /= samples; ysample /= samples; zsample /= samples; Serial.println("Potentiometer reset values: "); Serial.println(xsample); Serial.println(ysample); Serial.println(zsample); } // Trigger fall confirmation based on abnormal heart rate void triggerFallConfirmation() { Serial.println("Please press the confirmation button if fall has occured."); } /* END CODE */
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
vertical listview flutter
Dart | 10 min ago | 2.14 KB
horizontal listview flutter
Dart | 14 min ago | 5.37 KB
Untitled
JavaScript | 1 hour ago | 3.00 KB
music
JavaScript | 2 hours ago | 21.51 KB
admin music
JavaScript | 2 hours ago | 2.41 KB
Untitled
JSON | 2 hours ago | 12.82 KB
APK STRATEGI 5
C++ | 2 hours ago | 0.81 KB
Dumps
CSS | 3 hours ago | 0.00 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!