To sleep, it's nice for a room to be really dark--no glowing leds and nightlights, but a little light would be useful for nocturnal bathroom breaks. Ghosty supplies some light only when you need it.
Ghosty will detect day and night using a photocell inside the 3d printed structure. An ultrasonic transducer is always watching for someone to pass by. If it's dark and you pass by, the ghost will illuminate. Ghosty will stay illuminated until 10 seconds after your next appearance (he wants you to make it back to bed), then he shuts off so you can sleep.
My wife, Annelle, molded the ghost using polymer clay. I scanned it and created necessary holes using a MakerBot scanner and TinkerCad.
My video camera doesn't have the same characteristics as my eyeballs, but here's Ghosty from a camera's perspective.
I did a little "thumbnail" analysis to see how practical (or not) it would be to produce Ghosty. For the prototype, major bits included Ping ($30.), Arduino ($25.) a 9 volt wall wart ($7.) and 100 grams of PLA filament ($2.50)--plus minor bits for a total of $64.50, not counting labor. Ouch!
A little searching on the internet showed that the ATTINY85 (I think I can replace the Arduino with this) can be had for $0.90 at digikey. The HC-SR04 (Ping replacement) can be found for $1.19. A 5 volt wall wart can be had for $2.12. The plastic should be $0.50 or less if made by a method other than 3d printing. This gets us to less than $5.00 for most material. So . . . maybe there is some potential for the project.
So how did yesterday's software change work? GREAT!
Ghosty never skipped a beat and responded correctly to every approach. The green light on the Ping transducer was activating the photocell and that was causing the odd responses on previous days.
Another night with Ghosty, but he still performed erratically. Sometimes he would turn on when I walked by--sometimes not. If I went slowly, he would always work. What's going on? My suspicions centered around the little green light on the Ping transducer.
What if that light somehow convinces the photocell that it is daytime?
The hardware side of me wanted to pull the Ping out of Ghosty's head and crush the led with a pair of wire snippers! The software side (knowing that it's up against an adrenal filled "do something" junkie) protested.
"You might destroy the Ping and have to wire in a new one. You really don't know if that's the problem--let's at least prove it before you go on your destructive rampage."
Barely succumbing to the logic, I agreed to give it a little thought and one or two tests. In software I ask, "Is it dark? If it's dark, is anyone passing by? If no one is passing by, repeat." The "Is anyone passing by?" question fires up the Ping and lights the little green light. If this is done enough times, the inside of Ghosty's head gets fairly green and the photocell thinks it's daytime.
"So what?" argues my hardware side. The light is off when the "Is it dark?" question is asked. Our photocell friend, however, is what you might call, "a little slow." By placing a .2 second delay before reading the photocell the problem is solved.
At least, it's solved in my test room. Tonight, we'll find out for sure!
I tried Ghosty last night and he was a bit on the insensitive side (I had to get close to the counter to be reliably recognized). I increased the range in the Arduino sketch (available on this site). You can make software changes on Ghosty through the Arduino usb port (reachable through Ghosty's base).
The good news is that the single led (drawing 18 mA) provides enough light to see without shocking you into wakefulness.
I added a circular base plug (which can be tacked in with putty) to provide a more finished look.
I need to use a photocell for day/night detection. Ghosty does not need to activate if I am standing in front of him brushing my teeth. My 3d printed structure is porous, but how much light gets through? Do I need a hole through the surface for a photocell? I ran a test and my photocell (inside the structure) measures about 14K with daylight in the room.
In the dark (if it gets too dark, I can't read the meter), the resistance goes to over 100K (flash from the camera starts bringing the number down in the photo below).
This is good news, meaning that the photocell can be hidden inside the structure.
Before you rip out the LED for testing you could easily cover it with some black tape. Is the ultrasonic motion detector better than a PIR detector, or even a microwave motion detector?
There are countless similar lights with some LEDs, a PIR sensor and a photo-resistor. Normally battery operated, 3 AAAs last quite a while, obviously the PIR sensor needs nearly no power. They use a special chip, which is made for this purpose. These lights cost a few dollars and do basically the same as yours, except the nice ghost. Perhaps one can put the "guts" of it into the ghost.
Using an ultrasonic motion detector allows more control over the sensing range (set it for whatever distance within reason that you like). The PIR detector is more or less fixed (maybe two ranges) and probably will detect me thrashing in bed (depending on where the night light is set). I'm not familiar with microwave detectors, but would be interested in learning more about them.
I'm not aware of any commercial nightlights that turn on when you pass and stay on until a time delay after the next pass--not that it couldn't be done with a special chip.
Both the PIR and the ultrasonic detectors can be confused by clothing (PIR doesn't sense changes through cloth and ultrasonic sound doesn't bounce well on cloth--stealth pajamas--though I've had better luck with ultrasonic).
Of course, the PIR sensor would give me a one eyed ghost, but who's to say how many eyes a ghost needs :)
Before you rip out the LED for testing you could easily cover it with some black tape. Is the ultrasonic motion detector better than a PIR detector, or even a microwave motion detector?
There are countless similar lights with some LEDs, a PIR sensor and a photo-resistor. Normally battery operated, 3 AAAs last quite a while, obviously the PIR sensor needs nearly no power. They use a special chip, which is made for this purpose. These lights cost a few dollars and do basically the same as yours, except the nice ghost. Perhaps one can put the "guts" of it into the ghost.