Goodnight Bowl

Description

This bowl acts as a night-light and glows red when picked up while it is dark. Upon being set down, it plays “Twinkle, Twinkle Little Star” and the light slowly fades. During the day when there is light, it appears to be just a bowl of cotton balls. In this way, it acts as an object that will put the user to sleep at the end of their day.

I used a force-sensitive resistor on the bottom of the bowl to measure when it is set down, and I used a light sensor on the bowl to measure whether it is dark around the bowl. A piezo speaker plays music.

Materials

  • 1 ceramic bowl
  • 1 force-sensitive resistor
  • masking tape
  • 1 Arduino
  • cotton balls
  • 1 red LED
  • 1 light sensor
  • 1 piezo speaker
  • 1 22 KΩ resistor
  • 3 10 KΩ resistors
  • wires

Images

Goodnight Bowl

Goodnight Bowl

Code

int ledPin = 9; // select the output pin for LED
int speakerPin = 7; // select the output pin for speaker
int lightSensorPin = A0; // select input for light sensor
int forceSensorPin = A2; // select input for force sensor

int forceValue = 0; // variable to store force value
int lightValue = 0; // variable to store light value
int wasHeld = 0; // boolean for if force was very low in last loop

byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1351, 1275, 1136, 1014, 956}; // f was changed to f sharp (370 Hz)
byte melody[] = "7d1p7d1p7a1p7a1p7b1p7b1p8a6a2p7g1p7g1p7f1p7f1p7e1p7e1p8d6d2p";
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int LIGHT_THRESHOLD = 200;
int FORCE_THRESHOLD = 100;

void setup() {
// put your setup code here, to run once:
pinMode(speakerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
int max_subloops;
// put your main code here, to run repeatedly:
lightValue = analogRead(lightSensorPin);
// turn the ledPin on, convert from 0-1023 scale to 0-255
//analogWrite(ledPin, (lightValue - 300) / 4); //forceValue / 4 +

forceValue = analogRead(forceSensorPin);
if (forceValue >= FORCE_THRESHOLD && wasHeld && lightValue < LIGHT_THRESHOLD) { wasHeld = 0; digitalWrite(speakerPin, LOW); max_subloops = sizeof(melody) / 2; for (count = 0; count < max_subloops; count++) { analogWrite(ledPin, 255 * (max_subloops - count - 1) / max_subloops); // 48 converts from byte to int // 30 is length of time for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) { for (count2=0;count2<8;count2++) { // 8 is the size of names if (names[count2] == melody[count*2 + 1]) { digitalWrite(speakerPin,HIGH); delayMicroseconds(tones[count2]); digitalWrite(speakerPin, LOW); delayMicroseconds(tones[count2]); } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size digitalWrite(speakerPin, 0); delayMicroseconds(500); } } } } } else if (forceValue < FORCE_THRESHOLD) { if (lightValue < LIGHT_THRESHOLD) { digitalWrite(ledPin, HIGH); } wasHeld = 1; } else { wasHeld = 0; } Serial.print(lightValue); Serial.println(); }

Leave a Reply