***ARDUINO SHOCKING
ALARM***
***WRIST WATCH***
REQUIRED MATERIALS:-
PIECES PRICE
1) Arduino nano. = 1 pcs. ₹500
2) OLED 128×32 12c display. = 1 pcs. ₹300
3) NPN Transistor. = 2 pcs. ₹
4) Tactile push Button. = 3 pcs. ₹50/3. + 70 (D)
5) Shocking module. = 1 pcs. ₹
6) Mini 5v Buzzer. = 1 pcs. ₹50
7) 3.7v LI-PO Battery. = 1 pcs. ₹350
8) Battery shield V1.2.0 = 1 pcs. ₹350
9) Thin wires
10) Glue gun ₹250
CIRCUIT DIAGRAMS :-
.
FUNCTIONS OF WATCH :-
Clock and Time Management: It can serve as a clock with time,
minute, and second display. Users can set and manage the time in
12-hour format (AM/PM).
Alarm Functionality: Allows users to set an alarm time,
indicated by a buzzer sound. Additionally, it seems to have a shock
feature that activates after a certain delay post-alarm time.
Settings Configuration: Through the use of buttons, users can
navigate and configure settings such as hour, minute, and AM/PM
settings for both the current time and the alarm.
Battery Indicator: Provides a visual indicator of battery status
based on voltage readings.Shock Feature: Appears to have a
function to administer a shock for a configurable duration after a
certain time post-alarm.
Shock Feature: Appears to have a function to administer a shock
for a configurable duration after a certain time post-alarm.
SKETCH FOR WATCH :-
// Adafruit GFX Library – Version: 1.2.9
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <Wire.h>
// JC_Button – Version: Latest
#include <JC_Button.h>
// Adafruit GFX Library – Version: Latest
#include <Adafruit_GFX.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL
pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino
reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
&Wire, OLED_RESET);
//Set the time of now
Unsigned int hour = 8;
Unsigned int minute = 2;
Unsigned int second = 50;
String AMorPM = “PM”;
//Set the alaram variables
Unsigned int Al_hour = 8;
Unsigned int Al_minute = 1;
String Al_AMorPM = “PM”;
// Editing mode
Bool editHH;
Bool editMM;
Bool editAmPm;
Bool settingsMode;
Bool alarmMode;
Bool shockMode;
Bool editShockP;
Bool editShockT;
Bool oledOn = true;
Unsigned int modeBtnCount = 1;
Bool modeBtnPressed = false;
// Declare for how much time u want shock in seconds
Unsigned int shockTime = 20;
Float batteryVoltage;
Float ledVoltage;
//use millis to increase second
Unsigned long TpreviousMillis = 0;
Unsigned long DpreviousMillis = 0;
Const long Tinterval = 983;
Const long Dinterval = 10000;
// adjust according to your hardware
// Button Pins
Button DecreaseBtn(5);
Button ModeBtn(6);
Button IncreaseBtn(7);
// Shock pin and buzzer pin
#define buzzerPin 11
#define shockPin 10
// Battery bitmaps
// Battery charging
Const unsigned char BatteryCharging [] PROGMEM = {
0x7f, 0xff, 0xf8, 0x80, 0x00, 0x06, 0x80, 0x00, 0x02, 0x80, 0x00,
0x06, 0x80, 0x30, 0x03, 0x86,
0x3c, 0x03, 0x83, 0xff, 0x03, 0x80, 0xff, 0x83, 0x80, 0x30, 0x03,
0x80, 0x00, 0x06, 0x80, 0x00,
0x02, 0x80, 0x00, 0x06, 0x7f, 0xff, 0xfc
};
// ‘battery full’, 24x13px
Const unsigned char BatteryFull [] PROGMEM = {
0x7f, 0xff, 0xf8, 0xf9, 0xef, 0x3c, 0xf9, 0xef, 0x3c, 0xf9, 0xef, 0x3c,
0xf9, 0xef, 0x3f, 0xf9,
0xef, 0x3f, 0xf9, 0xef, 0x3f, 0xf9, 0xef, 0x3f, 0xf9, 0xef, 0x3f, 0xf9,
0xef, 0x3c, 0xf9, 0xef,
0x3c, 0xf9, 0xef, 0x3c, 0x7f, 0xff, 0xf8
};
// ‘battery down’, 24x13px
Const unsigned char BatteryDown [] PROGMEM = {
0x7f, 0xff, 0xf8, 0x80, 0x00, 0x06, 0x80, 0x00, 0x02, 0x80, 0x00,
0x06, 0x80, 0x00, 0x03, 0x80,
0x00, 0x03, 0x80, 0x00, 0x03, 0x80, 0x00, 0x03, 0x80, 0x00, 0x03,
0x80, 0x00, 0x06, 0x80, 0x00,
0x02, 0x80, 0x00, 0x06, 0x7f, 0xff, 0xfc
};
Void setup() {
Serial.begin(115200);
// SSD1306_SWITCHCAPVCC = generate display voltage from
3.3V internally
If (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address
0x3C for 128x32
Serial.println(F(“SSD1306 allocation failed”));
For (;;); // Don’t proceed, loop forever
}
// Initialize the buttons
DecreaseBtn.begin();
ModeBtn.begin();
IncreaseBtn.begin();
// Set buzzer pin and shock pin mode to output
pinMode(buzzerPin, OUTPUT);
pinMode(shockPin, OUTPUT);
// alaram function
Void setAlaram() {
If (Al_minute > 60) {
Al_minute = 59;
}
If (Al_minute > 59) {
Al_minute = 0;
If (Al_hour > 12) {
Al_hour = 1;
}
If (Al_hour < 1) {
Hour = 12;
}
String Al_time = String(Al_hour) + “:” + String(Al_minute) + “ “ +
String(Al_AMorPM);
If (Al_minute < 10) {
Al_time = String(Al_hour) + “:” + “0” + String(Al_minute) + “ “ +
String(Al_AMorPM);
}
Display.clearDisplay();
Display.setTextSize(2);
Display.setTextColor(WHITE);
Display.setCursor(10, 0);
Display.println(Al_time);
Display.setTextSize(1);
Display.setCursor(25, 20);
Display.println(“Set Alaram”);
If (editHH) {
Display.setCursor(10, 10);
} else if (editMM) {
Display.setCursor(50, 10);
}
Else if (editAmPm) {
Display.setCursor(80, 10);
}
Display.println(“__”);
Display.display();
Void openSettings() {
Display.setTextSize(1);
Display.setCursor(35, 20);
Display.println(“Set Time”);
}
// function to show and maintain the time
Void showTime() {
If (minute > 60) {
Minute = 59;
}
If (minute > 59) {
Minute = 0;
If (hour > 12) {
Hour = 1;
}
If (hour < 1) {
Hour = 12;
}
String time = String(hour) + “:” + String(minute) + “:” +
String(second);
If (minute < 10) {
Time = String(hour) + “:” + “0” + String(minute) + “:” +
String(second);
}
If (second < 10) {
Time = String(hour) + “:” + String(minute) + “:” + “0” +
String(second);
}
If (second < 10 && minute < 10) {
Time = String(hour) + “:” + “0” + String(minute) + “:” + “0” +
String(second);
}
Display.clearDisplay();
Display.setTextSize(2);
Display.setTextColor(WHITE);
If (hour < 10) {
Display.setCursor(5, 0);
} else {
Display.setCursor(0, 0);
}
Display.println(time);
Display.setCursor(100, 0);
Display.println(AMorPM);
If (settingsMode) {
openSettings();
}
If (settingsMode) {
If (editHH) {
Display.setCursor(1, 10);
} else if (editMM) {
Display.setCursor(40, 10);
}
Else if (editAmPm) {
Display.setCursor(100, 10);
}
Display.println(“__”);
}
If (!settingsMode) {
If (ledVoltage > 3.5) {
Display.drawBitmap(5, 19, BatteryCharging, 24, 13, WHITE);
}
Else if (batteryVoltage > 4) {
Display.drawBitmap(5, 19, BatteryFull, 24, 13, WHITE);
} else if (batteryVoltage < 3.7) {
Display.drawBitmap(5, 19, BatteryDown, 24, 13, WHITE);
}
}
Display.display();
}
// increase time every second
Void increaseTime() {
// Store the currentMillis
Unsigned long TcurrentMillis = millis();
If (TcurrentMillis – TpreviousMillis >= Tinterval) {
// save the last time
TpreviousMillis = TcurrentMillis;
Second++;
If (second > 59) {
Second = 0;
Minute++;
If (minute > 59) {
Minute = 0;
Hour++;
If (hour == 12) {
If (AMorPM == “PM”) {
AMorPM = “AM”;
} else if (AMorPM == “AM”) {
AMorPM = “PM”;
}
}
}
}
// define function to show shock settings
Void shockSettings() {
If (editShockT) {
If (DecreaseBtn.wasPressed()) {
shockTime -= 10;
}
If (IncreaseBtn.wasPressed()) {
shockTime += 10;
}
}
If (shockTime > 50) {
shockTime = 0;
}
// make shock strings
String shockTimeStr = “Time “ + String(shockTime) + “s”;
Display.clearDisplay();
Display.setTextSize(2);
Display.setTextColor(WHITE);
Display.setCursor(0, 0);
Display.println(shockTimeStr);
Display.display();
}
// this is the loop
Void loop() {
increaseTime();
// calling increaseTime every time
//read the button states
DecreaseBtn.read();
ModeBtn.read();
IncreaseBtn.read();
// check if settings mode is on and inscrease according to button
pressed
If (settingsMode) {
If (editHH) {
If (DecreaseBtn.wasPressed()) {
Hour--;
}
If (IncreaseBtn.wasPressed()) {
Hour++;
}
}
Else if (editMM) {
If (DecreaseBtn.wasPressed()) {
Minute--;
}
If (IncreaseBtn.wasPressed()) {
Minute++;
}
}
Else if (editAmPm) {
If (DecreaseBtn.wasPressed()) {
If (AMorPM == “PM”) {
AMorPM = “AM”;
} else if (AMorPM = “AM”) {
AMorPM = “PM”;
}
}
If (IncreaseBtn.wasPressed()) {
If (AMorPM == “PM”) {
AMorPM = “AM”;
} else if (AMorPM = “AM”) {
AMorPM = “PM”;
}
}
}
If (alarmMode) {
If (editHH) {
If (DecreaseBtn.wasPressed()) {
Al_hour--;
}
If (IncreaseBtn.wasPressed()) {
Al_hour++;
}
}
Else if (editMM) {
If (DecreaseBtn.wasPressed()) {
Al_minute--;
}
If (IncreaseBtn.wasPressed()) {
Al_minute++;
}
} else if (editAmPm) {
If (DecreaseBtn.wasPressed()) {
If (Al_AMorPM == “PM”) {
Al_AMorPM = “AM”;
} else if (Al_AMorPM = “AM”) {
Al_AMorPM = “PM”;
}
}
If (IncreaseBtn.wasPressed()) {
If (Al_AMorPM == “PM”) {
Al_AMorPM = “AM”;
} else if (Al_AMorPM == “AM”) {
Al_AMorPM = “PM”;
}
}
}
}
// open settings mode if btn pressed for 1 sec
If ( ModeBtn.pressedFor(1000) && !settingsMode ) {
modeBtnPressed = true;
settingsMode = true;
If ( ModeBtn.wasPressed() && settingsMode) {
modeBtnCount++;
}
// we are using switch cases to toggle between hour minute &
AmPm
If (settingsMode) {
Switch (modeBtnCount) {
Case 1:
editHH = true;
break;
case 2:
editHH = false;
editMM = true;
break;
case 3:
editMM = false;
editAmPm = true;
break;
case 4:
editAmPm = false;
settingsMode = false;
alarmMode = true;
modeBtnCount = 0;
}
}
If (ModeBtn.wasPressed() && alarmMode) {
modeBtnCount++;
If (!alarmMode && !shockMode && oledOn) {
showTime();
}
Unsigned long DcurrentMillis = millis();
// if any button pressed turn on the display
If ( ModeBtn.wasPressed() || IncreaseBtn.wasPressed() ||
DecreaseBtn.wasPressed() && !oledOn) {
oledOn = true;
DpreviousMillis = DcurrentMillis;
}
// turn off oled after 5 seconds
If (DcurrentMillis – DpreviousMillis >= Dinterval && oledOn && !
settingsMode) {
DpreviousMillis = DcurrentMillis;
oledOn = false;
display.clearDisplay();
display.display();
};
If (alarmMode) {
Switch (modeBtnCount) {
Case 1:
editHH = true;
break;
case 2:
editHH = false;
editMM = true;
break;
case 3:
editMM = false;
editAmPm = true;
break;
case 4:
editAmPm = false;
settingsMode = false;
alarmMode = false;
shockMode = true;
modeBtnCount = 0;
}
setAlaram();
}
If (ModeBtn.wasPressed() && shockMode) {
modeBtnCount++;
If (shockMode) {
Switch (modeBtnCount) {
Case 1:
editShockT = true;
break;
case 2:
editShockT = false;
shockMode = false;
modeBtnCount = 1;
break;
}
}
If (shockMode) {
shockSettings();
}
// ring the alaram if it matches with the Time
If (Al_hour == hour && Al_minute == minute && second < 10) {
digitalWrite(buzzerPin, HIGH);
} else {
digitalWrite(buzzerPin, LOW);
}
// give shock every sec after 10 sec of alaram beeping
If (Al_hour == hour && Al_minute == minute && second <
shockTime + 10 && second > 10 && second % 2 == 0) {
digitalWrite(shockPin, HIGH);
} else {
digitalWrite(shockPin, LOW);
// reading battery voltages to show battery indicator
// read the input on analog pin 0:
Int batteryValue = analogRead(A0);
// Convert the analog reading (which goes from 0 – 1023) to a
voltage (0 – 5V):
// I noticed increase in voltage reading so I decreased .3
batteryVoltage = ((batteryValue * 5.0) / 1023.0 ) – 0.3;
// read the input on analog pin 0:
// print out the value you read
// Serial.println(batteryVoltage);
Int ledValue = analogRead(A1);
ledVoltage = ((ledValue * 5.0) / 1023.0 ) – 0.3;
// Serial.println(“LED voltage here”);
// print out the value you read
// Serial.println(ledVoltage);
delay(50);