This week I tried to build an alarm clock, that does not wake me up by making anoying sounds, but by vibrating my bed (:D).
A force sensitive resistor is used to change the alarm clock mode. The first press sets the alarm clock in edit time mode. By twisting both potentiometers you can adjust the hours and the minutes. By pressing the FSR again you can set the alarm time, again by twisting both pots. Finally when you press the FSR again the alarm clock goes in active mode and starts counting. When the current time is equal to the set alarm time the motor starts and together with a cork it can make a vibration. Tape it to your bed and you will wake up.
Used parts:
2 x POT
1 x DC motor
1 x Battery pack
1 x Transistor
1 x 220 ohm resistor
1 x 10k resistor
1 x relais
The Code:
int hoursPin = 0; // select the input pin for the potentiometer
int minutesPin = 2;
int motorPin = 9; // select the pin for the Motor
int forcePin = 1;
int valHours = 0;
int valMinutes = 0; // variable to store the value coming from the sensor
int forceVal = 1;
// Time
int hours;
int minutes;
int nHours;
int nMinutes;
int alarmH;
int alarmM;
int nAlarmH;
int nAlarmM;
// Alarm
int clockState = 0;
void setup() {
Serial.begin(9600);
hours = 15;
minutes = 31;
alarmH = 15;
alarmM = 31;
}
void loop() {
// read the value from the sensor, between 0 - 1024
valHours = analogRead(hoursPin);
valMinutes = analogRead(minutesPin);
forceVal = analogRead(forcePin);
if(forceVal > 5) {
String myForce = "f" + String(forceVal);
clockState++;
delay(500);
String myState = "s" + String(clockState);
Serial.println(myState);
}
if(clockState == 1) {
nHours = int(valHours / 42.66);
nMinutes = int(valMinutes / 17.06);
if(hours != nHours || minutes != nMinutes) {
hours = nHours;
minutes = nMinutes;
String time = "t" + String(hours) + ":" + String(minutes);
Serial.println(time);
}
}
else if(clockState == 2) {
nAlarmH = int(valHours / 42.66);
nAlarmM = int(valMinutes / 17);
if(alarmH != nAlarmH || alarmM != nAlarmM) {
alarmH = nAlarmH;
alarmM = nAlarmM;
String alarm = "a" + String(alarmH) + ":" + String(alarmM);
Serial.println(alarm);
}
}
else if(clockState == 3) {
setTime();
delay(1000);
if(hours == alarmH && minutes == alarmM) {
analogWrite(motorPin, 255);
}
}
else if(clockState == 4) {
clockState = 0;
analogWrite(motorPin, 0);
}
}
void setTime() {
minutes++;
if(minutes > 56) {
hours++;
minutes = 0;
if(hours > 23) {
hours = 0;
}
}
String time = "t" + String(hours) + ":" + String(minutes);
Serial.println(time);
}
- Login to post comments