Quantcast
Viewing all articles
Browse latest Browse all 4

Sociable Objects: a nap doorbell

Nap doorbells are designed for nappers. They will not actually ring and wake you up unless it is a real emergency. This project is developed in collaboration with Adi and Asli.

Doorbell for insistent visitors from My Journey on Vimeo.

Switch Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
int BUTTON = 2;
int GREEN = 12;
int RED = 13;

void setup()
{
 pinMode(BUTTON, INPUT);
 pinMode(GREEN, OUTPUT);
 pinMode(RED, OUTPUT);
 Serial.begin(9600);
}

void loop()
{
 if (digitalRead(BUTTON) == HIGH)
 {
   Serial.print('D');
   delay(10);
 }

 if (Serial.available() > 0)
 {
   char r = Serial.read();
   if (r == 'G')
   {
     digitalWrite(GREEN, HIGH);
   }
   else if (r == 'R')
   {
     digitalWrite(RED, HIGH);
   }
 }
 else
 {
   digitalWrite(GREEN, LOW);
   digitalWrite(RED, LOW);
 }
}

Buzzer Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
int BELL = 5;
long lastReleased = -1;
long lastPressed = -1;
int counter = 0;
int offcounter = 0;

boolean pressed = false;

void setup()
{
  pinMode (BELL, OUTPUT);
  Serial.begin(9600);  
}

void loop()
{
  if((Serial.available() > 0))  
  {
    if (Serial.read() == 'D') // look for a capital D over the serial port and ring the bell if found
    {
      //Serial.println("ON");
      if (!pressed)
      {
        lastPressed = millis();
        pressed = true;
        long interval = lastPressed - lastReleased;
       
        //Serial.print("+");
        //Serial.println(counter, DEC);
        //Serial.println(interval);

        if (interval < 1000) // if this one is pressed soon enough, increase the counter
        {
          counter++;
        }
        else
        {
          counter = 0;
        }
      }

      //send feedback that message was recieved
      if (counter >= 5)
      {
        Serial.print('G');
        //ring the bell briefly
        digitalWrite(BELL, HIGH);
        delay(10);
        digitalWrite(BELL, LOW);
      }
      else
      {
        Serial.print('R');
      }
     
      offcounter = 0;
    }

  }
  else
  {
    //Serial.println("OFF");
    offcounter++;
    if (pressed && offcounter > 5000)
    {
      pressed = false;
      Serial.print("-");
      lastReleased = millis();
      offcounter = 0;
    }
  }
}

Viewing all articles
Browse latest Browse all 4

Trending Articles