SlideShare a Scribd company logo
1 of 19
ANTISLEEP
ALARM
Under the guidance of :-
Dr. Sudhansu Kumar Samal
Centurion
Unive r sit y
GROUPMEMBERS:
2
UNDERTHEGUIDANCEOF:
04
03
01
02
Introduction
Components Used
Circuit Diagram
Code
Content:
Introduction
╸ In modern-times, owing to hectic schedules it becomes very difficult to remain active allthe
4
time. Imagine a situation where a person is driving home from work, dead tired after facing all
the challenges of the day. His hands are on the wheel and foot on the pedal but suddenly he
starts feeling drowsy, his eyes start shutting and his vision blurs and before he knows it, he’s
asleep. Falling asleep on the wheel can lead to serious consequences, there may beaccidents
and people may even lose their lives. This situation is much more common then we notice and
hence, it is very important to counter this problem. So to address this issue, we have come up
with a Driver Anti-sleep Alarm ⏰ .
╸ ThissystemStopstheuser'scarif he/shefallsasleepatthewheelthereby,avoidingaccidents
andsavinglives.Thissystemis useful,especiallyfor peoplewhotravellongdistancesandpeople
whoaredrivinglateatnight🌃.
COMPONENTSUSED:
╸ Eye blinksensor
╸ Eye glass 👓
╸ Relaymodule
╸ Arduino nano
╸ 9Vbattery🔋
╸ Toy carremote
╸ Capacitor
╸ Wires
5
COMPONENTSUSED:
╸ Plyboard
╸ Gearmotorwithtwotires
╸ Lock andkey🗝
╸ Remote controlcar
╸ 5Vrelay
╸ 18650 battery🔋
6
CIRCUITDIAGRAM:
Transmitter:
7
CIRCUITDIAGRAM:
Receiver:
8
9
CODE:
#define Relay 13
#define buzzer A0
static const int sensorPin = 10;
// sensor input pin
int SensorStatePrevious = LOW;
// previousstate of the sensor
unsigned long minSensorDuration = 3000; // Time we
//
//
wait before the sensor active as long
unsigned long minSensorDuration2 = 4000;
unsigned long SensorLongMillis;
Time in ms when the sensor was active
bool SensorStateLongTime = false;
True if it is a long active
const int intervalSensor = 50;
// Time between two readings sensor state
unsigned long previousSensorMillis;
// Timestamp of the latest reading
//
1
0
unsigned long SensorOutDuration;
Time the sensor is active in ms
//// GENERAL ////
unsigned long currentMillis; // Variabele to
store the number of milleseconds since the Arduino has
started
// Initialise
void setup() {
Serial.begin(9600);
the serial monitor
// set sensorPin
pinMode(sensorPin, INPUT);
as input
Serial.println("Press button");
pinMode(Relay,OUTPUT);
pinMode(buzzer,OUTPUT);
}
// Function for reading the sensor state
void readSensorState() {
// If the difference in time between the previous reading
is larger than intervalsensor
if(currentMillis - previousSensorMillis >
intervalSensor) {
// Read the digital value of the sensor (LOW/HIGH)
int SensorState = digitalRead(sensorPin);
// If the button has been active AND
// If the sensor wasn't activated before AND
// IF there was not already a measurement running to
determine how long the sensor has been activated
if (SensorState == LOW && SensorStatePrevious == HIGH
&& !SensorStateLongTime) {
SensorLongMillis = currentMillis;
SensorStatePrevious = LOW;
Serial.println("Button pressed");
}
// Calculate how long the sensor has been activated
1
1
SensorOutDuration = currentMillis - SensorLongMillis;
// If the button is active AND
// If there is no measurement running to
determine how long the sensor is active AND
// If the time the sensor has been activated is
larger or equal to the time needed for a long active
if (SensorState == HIGH && !SensorStateLongTime
&& SensorOutDuration >= minSensorDuration) {
SensorStateLongTime = true;
digitalWrite(Relay,HIGH);
Serial.println("Button long pressed");
}
if (SensorState == HIGH && SensorStateLongTime &&
SensorOutDuration >= minSensorDuration2) {
SensorStateLongTime = true;
digitalWrite(buzzer,HIGH);
delay(1000);
Serial.println("Button long pressed");
}
1
2
// If the sensor is released AND
// If the sensor was activated before
if (SensorState == HIGH && SensorStatePrevious ==
LOW) {
SensorStatePrevious = HIGH;
SensorStateLongTime = false;
digitalWrite(Relay,LOW);
digitalWrite(buzzer,LOW);
Serial.println("Button released");
if(digitalRead(sensor)==0)
{
digitalWrite(13,LOW);
digitalWrite(motor,HIGH);
}
else
{
delay(3000);
digitalWrite(a0
,HIGH);
digitalWrite(motor,LOW);
1
3
}
// store the current timestamp in
previousSensorMillis
previousSensorMillis = currentMillis;
}
}
void loop() {
1
4
// store the current
currentMillis = millis();
time
readSensorState(); // read the sensor state
}
PROJECTOVERVIEW
1
5
PROJECTOVERVIEW
1
6
PROJECTOVERVIEW
1
7
PROJECTOVERVIEW
1
8
1
9

More Related Content

Similar to antisleepalarm-230417034941-79209def (1).pptx

Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
josnihmurni2907
 
Darma Sleep Solution
Darma Sleep SolutionDarma Sleep Solution
Darma Sleep Solution
Pippen Zeng
 
White Paper on Security Systems for residential installations - Version 2.0 -...
White Paper on Security Systems for residential installations - Version 2.0 -...White Paper on Security Systems for residential installations - Version 2.0 -...
White Paper on Security Systems for residential installations - Version 2.0 -...
Ritesh Nagpal
 

Similar to antisleepalarm-230417034941-79209def (1).pptx (20)

IRJET- Intelligent Security System for Women by using Arduino
IRJET- Intelligent Security System for Women by using ArduinoIRJET- Intelligent Security System for Women by using Arduino
IRJET- Intelligent Security System for Women by using Arduino
 
New Microsoft PowerPoint Presentation_033815.pptx
New Microsoft PowerPoint Presentation_033815.pptxNew Microsoft PowerPoint Presentation_033815.pptx
New Microsoft PowerPoint Presentation_033815.pptx
 
Geriatrics preventing falls in elderly - technology [IIT Bombay Techfest Win...
Geriatrics  preventing falls in elderly - technology [IIT Bombay Techfest Win...Geriatrics  preventing falls in elderly - technology [IIT Bombay Techfest Win...
Geriatrics preventing falls in elderly - technology [IIT Bombay Techfest Win...
 
Iot based health monitoring system
Iot based health monitoring systemIot based health monitoring system
Iot based health monitoring system
 
FINGUER TIP OXIMETER
FINGUER TIP OXIMETERFINGUER TIP OXIMETER
FINGUER TIP OXIMETER
 
Bontrager node en
Bontrager node enBontrager node en
Bontrager node en
 
UEE PPT.pptx
UEE PPT.pptxUEE PPT.pptx
UEE PPT.pptx
 
Ph psm02-zipato-multisensor-quad-user-manual-v1.4
Ph psm02-zipato-multisensor-quad-user-manual-v1.4Ph psm02-zipato-multisensor-quad-user-manual-v1.4
Ph psm02-zipato-multisensor-quad-user-manual-v1.4
 
Ph psm02-zipato-multisensor-quad-user-manual-v1.4
Ph psm02-zipato-multisensor-quad-user-manual-v1.4Ph psm02-zipato-multisensor-quad-user-manual-v1.4
Ph psm02-zipato-multisensor-quad-user-manual-v1.4
 
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
 
Darma Sleep Solution
Darma Sleep SolutionDarma Sleep Solution
Darma Sleep Solution
 
Intelligent fatigue detection and automatic vehicle control system
Intelligent fatigue detection and automatic vehicle control systemIntelligent fatigue detection and automatic vehicle control system
Intelligent fatigue detection and automatic vehicle control system
 
Top Peak Electronics Co.,limited hot gps tracker user manual
Top Peak Electronics Co.,limited hot gps tracker user manualTop Peak Electronics Co.,limited hot gps tracker user manual
Top Peak Electronics Co.,limited hot gps tracker user manual
 
Top Peak Electronics Co.,limited hot gps tracker user manual
Top Peak Electronics Co.,limited hot gps tracker user manualTop Peak Electronics Co.,limited hot gps tracker user manual
Top Peak Electronics Co.,limited hot gps tracker user manual
 
White Paper on Security Systems for residential installations - Version 2.0 -...
White Paper on Security Systems for residential installations - Version 2.0 -...White Paper on Security Systems for residential installations - Version 2.0 -...
White Paper on Security Systems for residential installations - Version 2.0 -...
 
Fall detector
Fall detectorFall detector
Fall detector
 
Manual acc
Manual accManual acc
Manual acc
 
Smart digital and analogue ambience control and
Smart digital and analogue ambience control andSmart digital and analogue ambience control and
Smart digital and analogue ambience control and
 
Location identifier
Location identifierLocation identifier
Location identifier
 
APS48Z Owners Guide Rev. 0_11.13.19.pdf
APS48Z Owners Guide Rev. 0_11.13.19.pdfAPS48Z Owners Guide Rev. 0_11.13.19.pdf
APS48Z Owners Guide Rev. 0_11.13.19.pdf
 

Recently uploaded

CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...
amitlee9823
 
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...
amitlee9823
 
Abortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get CytotecAbortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
drmarathore
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
amitlee9823
 
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...
Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...
Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...
gajnagarg
 
CHEAP Call Girls in Hauz Quazi (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Hauz Quazi  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Hauz Quazi  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Hauz Quazi (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
uodye
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
tufbav
 

Recently uploaded (20)

CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Kalyan Call On 9920725232 With Body to body massage wit...
 
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...
 
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
 
Abortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get CytotecAbortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get Cytotec
 
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
 
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006
 
Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Call Girls Chickpet ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...
Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...
Just Call Vip call girls daman Escorts ☎️9352988975 Two shot with one girl (d...
 
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
 
CHEAP Call Girls in Hauz Quazi (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Hauz Quazi  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Hauz Quazi  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Hauz Quazi (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
HLH PPT.ppt very important topic to discuss
HLH PPT.ppt very important topic to discussHLH PPT.ppt very important topic to discuss
HLH PPT.ppt very important topic to discuss
 
(ISHITA) Call Girls Service Aurangabad Call Now 8617697112 Aurangabad Escorts...
(ISHITA) Call Girls Service Aurangabad Call Now 8617697112 Aurangabad Escorts...(ISHITA) Call Girls Service Aurangabad Call Now 8617697112 Aurangabad Escorts...
(ISHITA) Call Girls Service Aurangabad Call Now 8617697112 Aurangabad Escorts...
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
 

antisleepalarm-230417034941-79209def (1).pptx

  • 1. ANTISLEEP ALARM Under the guidance of :- Dr. Sudhansu Kumar Samal Centurion Unive r sit y
  • 4. Introduction ╸ In modern-times, owing to hectic schedules it becomes very difficult to remain active allthe 4 time. Imagine a situation where a person is driving home from work, dead tired after facing all the challenges of the day. His hands are on the wheel and foot on the pedal but suddenly he starts feeling drowsy, his eyes start shutting and his vision blurs and before he knows it, he’s asleep. Falling asleep on the wheel can lead to serious consequences, there may beaccidents and people may even lose their lives. This situation is much more common then we notice and hence, it is very important to counter this problem. So to address this issue, we have come up with a Driver Anti-sleep Alarm ⏰ . ╸ ThissystemStopstheuser'scarif he/shefallsasleepatthewheelthereby,avoidingaccidents andsavinglives.Thissystemis useful,especiallyfor peoplewhotravellongdistancesandpeople whoaredrivinglateatnight🌃.
  • 5. COMPONENTSUSED: ╸ Eye blinksensor ╸ Eye glass 👓 ╸ Relaymodule ╸ Arduino nano ╸ 9Vbattery🔋 ╸ Toy carremote ╸ Capacitor ╸ Wires 5
  • 6. COMPONENTSUSED: ╸ Plyboard ╸ Gearmotorwithtwotires ╸ Lock andkey🗝 ╸ Remote controlcar ╸ 5Vrelay ╸ 18650 battery🔋 6
  • 9. 9 CODE: #define Relay 13 #define buzzer A0 static const int sensorPin = 10; // sensor input pin int SensorStatePrevious = LOW; // previousstate of the sensor unsigned long minSensorDuration = 3000; // Time we // // wait before the sensor active as long unsigned long minSensorDuration2 = 4000; unsigned long SensorLongMillis; Time in ms when the sensor was active bool SensorStateLongTime = false; True if it is a long active const int intervalSensor = 50; // Time between two readings sensor state unsigned long previousSensorMillis; // Timestamp of the latest reading
  • 10. // 1 0 unsigned long SensorOutDuration; Time the sensor is active in ms //// GENERAL //// unsigned long currentMillis; // Variabele to store the number of milleseconds since the Arduino has started // Initialise void setup() { Serial.begin(9600); the serial monitor // set sensorPin pinMode(sensorPin, INPUT); as input Serial.println("Press button"); pinMode(Relay,OUTPUT); pinMode(buzzer,OUTPUT); } // Function for reading the sensor state void readSensorState() {
  • 11. // If the difference in time between the previous reading is larger than intervalsensor if(currentMillis - previousSensorMillis > intervalSensor) { // Read the digital value of the sensor (LOW/HIGH) int SensorState = digitalRead(sensorPin); // If the button has been active AND // If the sensor wasn't activated before AND // IF there was not already a measurement running to determine how long the sensor has been activated if (SensorState == LOW && SensorStatePrevious == HIGH && !SensorStateLongTime) { SensorLongMillis = currentMillis; SensorStatePrevious = LOW; Serial.println("Button pressed"); } // Calculate how long the sensor has been activated 1 1
  • 12. SensorOutDuration = currentMillis - SensorLongMillis; // If the button is active AND // If there is no measurement running to determine how long the sensor is active AND // If the time the sensor has been activated is larger or equal to the time needed for a long active if (SensorState == HIGH && !SensorStateLongTime && SensorOutDuration >= minSensorDuration) { SensorStateLongTime = true; digitalWrite(Relay,HIGH); Serial.println("Button long pressed"); } if (SensorState == HIGH && SensorStateLongTime && SensorOutDuration >= minSensorDuration2) { SensorStateLongTime = true; digitalWrite(buzzer,HIGH); delay(1000); Serial.println("Button long pressed"); } 1 2
  • 13. // If the sensor is released AND // If the sensor was activated before if (SensorState == HIGH && SensorStatePrevious == LOW) { SensorStatePrevious = HIGH; SensorStateLongTime = false; digitalWrite(Relay,LOW); digitalWrite(buzzer,LOW); Serial.println("Button released"); if(digitalRead(sensor)==0) { digitalWrite(13,LOW); digitalWrite(motor,HIGH); } else { delay(3000); digitalWrite(a0 ,HIGH); digitalWrite(motor,LOW); 1 3
  • 14. } // store the current timestamp in previousSensorMillis previousSensorMillis = currentMillis; } } void loop() { 1 4 // store the current currentMillis = millis(); time readSensorState(); // read the sensor state }
  • 19. 1 9