A Lonely Lamp
A Lonely Lamp is a lamp that alludes to people in the metropolis. People will feel lonely if there is no noise around them or no one talking to them. Just like that, this lonely lamp also needs people's attentions. People have to pick up the telephone receiver then this lamp will turn to face to people. If people talk to this lamp through that telephone receiver, this lamp will turn on and change the brightness based on the volume. If there is no noise for 5 seconds, this lamp will turn back.
Materials
The things you need :
1. Arduino Nano
3. Adafruit 12-Key Capacitive Touch Sensor Breakout
4.Electret Microphone Amplifier
8.Container
9.Glue gun
10. Jumper wires
Circuit
Code
<p>#include <servo.h><br>#include <wire.h> #include "Adafruit_MPR121.h"</wire.h></servo.h></p><p>Adafruit_MPR121 cap = Adafruit_MPR121();</p><p>int pos = 0; Servo myservo;</p><p>const int ledPin1 = 13; const int ledPin2 = 11; bool greenOn = false;</p><p>uint16_t lasttouched = 0; uint16_t currtouched = 0;</p><p>int soundSensorPin = A0; int soundReading = 0;</p><p>unsigned long lastEvent = 0; boolean ledOn = false; unsigned long lastTalkTime = 0;</p><p>void setup() { // put your setup code here, to run once: Serial.begin(9600); myservo.attach(9); pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT);</p><p> while (!Serial) { // needed to keep leonardo/micro from starting too fast! delay(10); }</p><p> if (!cap.begin(0x5A)) { Serial.println("MPR121 not found, check wiring?"); while (1); } }</p><p>void loop() { // put your main code here, to run repeatedly: currtouched = cap.touched(); // Serial.println(currtouched);</p><p> for (uint8_t i=0; i<12; i++) { // it if *is* touched and *wasnt* touched before, alert! if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { Serial.print(i); Serial.println(" touched"); Serial.println(millis()-lastEvent); if (millis() - lastEvent > 50) { //toggle LED and set the output ledOn = true; lastTalkTime = millis(); digitalWrite(ledPin1, ledOn ? HIGH : LOW); } lastEvent = millis(); } // if it *was* touched and now *isnt*, alert! if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { Serial.print(i); Serial.println(" released"); lastEvent = 0; ledOn = false; } } lasttouched = currtouched; if (ledOn){ pos = 180; myservo.write(pos); soundReading = analogRead(soundSensorPin); // Serial.println(soundReading);</p><p> if (pos = 180 && soundReading > 800) { lastTalkTime = millis(); greenOn = true; } if (millis() - lastTalkTime > 8000) { ledOn = false; } else if (millis() - lastTalkTime > 800) { greenOn = false; } // Serial.println(ledOn); } else { pos = 0; greenOn = false; myservo.write(pos); digitalWrite(ledPin1, LOW); } // Serial.print(greenOn); Serial.println(soundReading); if(greenOn){ int outputValue = map(soundReading, 800, 1023, 0, 255); analogWrite(ledPin2,outputValue); } else{ digitalWrite(ledPin2, greenOn); } delay(100); }</p>
Downloads
Wrap It Up
Put Arduino at the bottom.
Make a second solid layer to glue servo motor stably.
I made a telephone handset.
I put the sound sensor and jumper wires that connect with touch sensor inside of handset. Then I soldered jumper wires with conductive tapes on the handset.
Then I used woolen yarn to decorate wires.