How 2 Get A Table Lamp to Always Understand "On" and "OFF" and "Dim" - Page 1
Forum section: electronics / general

author: martys
author_rank: Regular Contributor
timestamp: July 18, 2017, 12:43:37 pm
content: If they can do it on Star Trek, why can't I?I have succeeded in making the ultimate kitchen timer for my girlfriend, now is no time to rest on my laurels! My next project is to take sound control of a table lamp.I don't want to use any stink'n pre-fab speech recog or synth IC's. I will use a mike, op-amps, active filters made with discrete components, etc. butthis is a software challenge.(1)What would be the best choice for a minimal MCU able to handle this SW task written in C code?(2)How do I approach the software challenge of writing code that can interpret these simple spoken commands?(3)If the lamp can understand the command clearly, it should say, "Ok" and perform the requested action.(4)No Rasberry Pi, no room for this,has to be small and low-poweredly green enoughto fit comfortably in the base of a small table lamp.(5)This makes an idiot lamp a moron robot, but it doesn't have to respond immediately, it can take a few number-crunching seconds to exact a reply or else say, and only then if it is only just reasonably sure, "Huh?"(6)At the same time, it must clearly understand me, my girlfriend, or a even her <=7 year old child and not falsely respond.(7)Idon't want wireless connectivityto Google AI or to any PC equip to augment operation. Should work in nowhereville without any internet connection or wireless link to a PC.

author: CJay
author_rank: Super Contributor
timestamp: July 18, 2017, 01:13:46 pm
content: No Pi you say but Pi Zero W with Google AIY kit would do this in small physical size.if you really don't want to go that way there were/are dedicated single chip solutions for it.Software speech recognition is not trivial and requires a good amount of CPU power, might be possible with a Teensy or similar but then you're upping the physical size again.

author: martys
author_rank: Regular Contributor
timestamp: July 18, 2017, 01:28:55 pm
content: http://www.raspberrypi-spy.co.uk/2017/05/the-magpi-issue-57-comes-with-google-voice-interaction-kit/This is a bigger box that is too smart, need something small, to work at all.Having trouble finding the exact power specs for the Pi Zero W.

author: CJay
author_rank: Super Contributor
timestamp: July 18, 2017, 02:00:27 pm
content: You only need the microphone part of the AIY unless you want it to talk back at you and that board is tiny, much smaller than the Pi Zero W

author: rstofer
author_rank: Super Contributor
timestamp: July 18, 2017, 03:33:42 pm
content: That MagPi board is an add-on board to a Raspberry PI so the combined boards are probably too large for the base of a lamp. I would do it anyway... Even if I had to sit the cardboard box along side the lamp..There have been some Hackaday projects:http://hackaday.com/2010/07/11/adding-speach-recognition-to-your-embedded-platform/Speech recognition is hard! The fact that Google gets it nearly right is due to the enormous servers they have parsing the stuff.

author: CJay
author_rank: Super Contributor
timestamp: July 18, 2017, 03:48:06 pm
content: Quote from: rstofer on July 18, 2017, 03:33:42 pmIt is, Apple and Amazon too have data centres to handle this stuff and it can create laughable mistakes.I have anecdotal evidence from a colleague that the AIY kit works with a Raspberry Pi Zero W and I *think* you'd only need the microphone board, it talks I2S directly so I think it's 'just' a matter of getting the data to Google to parse and then processing the returned data.It's a good reason for me to build the AIY kit that's been hiding under my table since two days after it was released.

author: Richard Crowley
author_rank: Super Contributor
timestamp: July 18, 2017, 04:09:26 pm
content: There are dozens of enormous server farms which comprise "Alexa" and "Siri" and all those speech-recognition features. There is no way that kind of sophisticated speech recognition is implemented inside the little gadget at the user end of the transaction.I heard an interesting news story last week on the radio. Some woman was being attacked by a thug who broke into her home and he shouted "You didn't call the sheriff, did you?" The little Amazon gadget in the kitchen picked up the thug's question and dutifully called the sheriff.

author: nfmax
author_rank: Super Contributor
timestamp: July 18, 2017, 04:39:23 pm
content: OTOH the Echo Dot can recognise the word 'Alexa' (or one of the other magic words) all by itself, independent of the speaker, and with background noise such as music & speech, using only just over a watt. And it's small enough to fit into a lamp base.What the OP is asking for is probably not impossible, just very difficult.

author: Zero999
author_rank: Super Contributor
timestamp: July 18, 2017, 04:47:05 pm
content: Quote from: nfmax on July 18, 2017, 04:39:23 pmProbably blissfully unaware of how difficult it is.Just for a start. Record several uncompressed .wav files of each of the voice commands, by several different people: male, female and with different accents. Now write a program to differentiate between them. Now hopefully you'll see how difficult it really is. You'll need to experiment a lot, just to get something which works most of the time.

author: rstofer
author_rank: Super Contributor
timestamp: July 18, 2017, 06:54:45 pm
content: Way back in the '54, Popular Electronics had an article about voice control of a model railroad. I was 9 years old, I certainly didn't understand how it worked... It only recognized "Stop" and "Go" but I believe it did it with filters to detect high frequency components. Or maybe it recognized the time between "sssss" and "TOP versus "GUH" and "oh".So, I suppose a very limited vocabulary could be created with analog circuits.Found a reference for Popular Electronics Volume 1 No. 3 - December 1954http://www.smecc.org/popular_electronics.htmAnd then I went on eBay and found:http://www.ebay.com/itm/272729262971And bought it... I have no idea why...My long term memory works a lot better than my short term memory. I remember reading the volume while riding in our car. I looked like a cool project!

author: martys
author_rank: Regular Contributor
timestamp: July 18, 2017, 06:58:31 pm
content: I never said it wasn't hard to accomplish this project goal, but that I like the idea and I am willing to accept the challenge. I like to accomplish what is called difficult. There is some feeling of achievement to learn and develop, improve and maybe perfect something that is called difficult to do.My goal is to get this idea to work well, even if it may never be perfected by me due to the multitudes of issues that could cause me to finally give up such as excess time spent on this project or having waning interest.I would consider this idea has been successful even if it only worked in a reasonably quiet room(exactly the target environment) and may only recognize one or two commands or one or two special command speakers.Here's my first primitive software and hardware strategy to accomplish this.(1)Pick up the sound and amplify and filter the sound pickup to filter out everything but a portion of the human voice spectrum.(2)Sample this mike pickup and convert into digital data and store in RAM for later analysis.(3)Try to identify the length and characteristics of vowels and consonants by some software means.(4)Maybe with (3) using FFT to analyze the frequency spectrum of a sample.(5)Help identify a spoken command by the length of the command. A spoken command would have to fit into a time window.If the sound stream is too long or too short it is ignored. Only spoken commands fitting into the time window would be analyzed(6) The time between accented consonants or length of vowels are also important clues to be weighed by the software.For instance, "ON" has a soft consonant ending following a duplicating vowel "Ah" sound, while "OFF" has a distinctive "FFFF" brown noise like structure completing the sound bytes sample and would also last slightly longer.The software would weight comparisons to expected results and assign a figure of merit of match to help make a command decision.As far as replying to commands with a voice response, this has already been easily accomplished by me playing back PCM recordings stored in a SEEPROM.Whacha think?

author: rstofer
author_rank: Super Contributor
timestamp: July 18, 2017, 07:05:58 pm
content: Quote from: nfmax on July 18, 2017, 04:39:23 pmDoes "Alexa" have to be pronounced in some particular way? Like with the emphasis on the second syllable or can I prononce it "AL" "exa". I wonder how discriminating it really is. Does "LEX" "us" work? That kind of thing.Do we know it works "standalone" or could it be sending "Alexa" to the big server farm?We're not going to buy one but I will admit to being intrigued.BTW, Microsoft Kinect does speech recognition and there is a development kit but I'm not sure this is the least bit helpful.

author: rstofer
author_rank: Super Contributor
timestamp: July 18, 2017, 07:13:04 pm
content: Google might be your friend!Search for 'speech recognition ARM' and there are several links like:http://www.ti.com/tool/TIDEP0066

author: BrianHG
author_rank: Super Contributor
timestamp: July 18, 2017, 07:29:47 pm
content: Since you want only a few words, as long as there is no background noise, with a little smart diligence, you could do it with a 16bit PIC which has a built in fast enough 12 bit or more ADC and some smart coding & tables. It has certainly been done with much slower MCUs and 1 bit ADC in the past as seen here in Dave's video.You should be able to outperform this old 80's 1 bit ADC piece of junk easily today.With the MIC amp, I would do some of the filtering already at that stage, all too easy with the OPAMPs you will be using to amplify the MIC anyways, to lower CPU processing.

author: Richard Crowley
author_rank: Super Contributor
timestamp: July 18, 2017, 08:41:32 pm
content: Quote from: rstofer on July 18, 2017, 06:54:45 pmIt worked by detecting the number of syllables. It was a pretty primitive peak detector controlling a relay.Ref:http://www.americanradiohistory.com/Archive-Poptronics/50s/54/Pop-1954-12.pdfpage 17

author: martys
author_rank: Regular Contributor
timestamp: July 18, 2017, 08:57:10 pm
content: Thanks BrianHG, the idea of using a midrange 16-bit PICC looks like a first choice for a simple low-power solution with micro-power standby.I also watched Dave's video on an amazingly simple but unreliable HW approach and I certainly think I can make something to work many times better.Any other comments on my strategy?

author: BrianHG
author_rank: Super Contributor
timestamp: July 19, 2017, 08:11:17 pm
content: One thing I can recommend, tune you audio amp filter and ADC sample rate to match something close to a phone line. Something like and audio bandwidth close to flat from 400Hz to 3KHz, meaning audio should begin around 200hz and roll off out around 6khz, sample at around 12khz. This should be readily understandable for MCU speech decoding and anything else would just be excess noise you need to process around.There do exist cheap tricks to achieve a fast cheap quality spectrum analysts of the source audio using integer math only, basically many multiply adds in a pipe, but I suspect to get the quality you want, you will just need to go with a pic which has the maximum ram and instruction ram so you aren't left squeezing code in at the last minute for trying to save 2-3$ on a single PIC. That 1 bit input motorola MCU probably sampled at 1khz for 1.5 seconds, my guess looking at Dave's video, the sift through that 1 bit pattern, 187 bytes of ram, probably all they could muster on an MCU at the time. You'll be operating at, say 8 bit, 2 seconds sampled at 8Khz is 16k. If you do a real-time cheap FFT, and retain 50samp/second 64 bands, at 8 bit each, you are talking 7kb for 2 seconds. Take a look at this guy, I chose it because it's in a DIP package, easy for testing:http://www.microchip.com/wwwproducts/en/PIC24EP512GP202512k flash, 48k ram.It also has 2x built in opamps which may be good enough for your MIC, + wired to it's internal comparators to wake up the MCU from sleep when there is sufficient noise. An all in 1 solution. Though, if you enable the internal op-amps and comparators, I cant say how little power the device will consume during sleep.Also, remember, you most likely need to keep the MIC continuously powered as well.

author: BrianHG
author_rank: Super Contributor
timestamp: July 19, 2017, 09:02:01 pm
content: Use this PIC if you want to use floating point processing:http://www.microchip.com/wwwproducts/en/dsPIC33EP512GM706It also has hardware multiple accumulate used in FFT decoding. But, judging that even a 7MHz Amiga can do a realtime FFT in integer with a 68000, this 70mips, single clock/multiply/add, floating point monster (by comparison) will leave you with mips to spare...

author: Kjelt
author_rank: Super Contributor
timestamp: July 19, 2017, 10:10:32 pm
content: Yeah voice recognitionYoutube search on voice recognition failCars with VR that fail, MS Cortana fail, those are systems with millions of R&D and they are mediocre at best.Good luck.https://youtu.be/NmWRhhvf60Y

author: rstofer
author_rank: Super Contributor
timestamp: July 20, 2017, 12:06:52 am
content: Quote from: Richard Crowley on July 18, 2017, 08:41:32 pmAnd it relied on Lionel's remote control scheme which embedded a stepper relay in the locomotive. All the box is doing is recognizing a syllable and pulsing the track power which steps the stepper.Did you notice how casually they treated 115V back in the day? I remember my father telling me he would rather I didn't work on line operated projects on his test bench. So, sure thing, the next day I was working on line voltage stuff.Two prong power cord...

author: dferyance
author_rank: Regular Contributor
timestamp: July 20, 2017, 04:09:52 pm
content: You may want to consider getting speech recognition working on a PC first before running it on a MCU. This comes with some risks of having difficulty porting your code over or performance tuning after-the-fact but it also helps mitigate some of your risks. You will have better dev tools available on a PC and it let's you concentrate on tuning your algorithm or at least getting the basics working. Getting it all working on a MCU to start has both the risks of your algorithm not working along with the limitations of embedded tools and hardware all at once.QuoteSo it is harder to develop it on a PC if you want to be designing input filters as your connection to a PC will be different than on a MCU. However the "this is a software challenge" will be greatly helped by not having to deal with cross-compile, downloading to target, debugger and breakpoint limitations and such. Also if you manage to fail at getting speech recognition working reliably, at least you didn't waste extra time on these other problems that you didn't need to solve yet.

author: Alex Eisenhut
author_rank: Super Contributor
timestamp: July 20, 2017, 11:49:02 pm
content: http://www.ebay.ca/itm/ASR-Speech-Recognition-LD3320-Professional-SP-Voice-Recognition-Voice-Module-/331748869120?hash=item4d3dc60400:g:VmEAAOSwcUBYVQhu

author: rstofer
author_rank: Super Contributor
timestamp: July 21, 2017, 02:53:09 pm
content: Quote from: dferyance on July 20, 2017, 04:09:52 pmI wonder if a PC sound card plays into this. It is possible to model the filtering done by the card, an external microphone can be added and pre-filtering can be easily done. At some level, it should be pretty easy to capture the input. After all, sound card oscilloscopes are still around so code is out there somewhere.Among others:http://www.analog.com/en/analog-dialogue/articles/turning-pc-sound-card-into-sampling-oscilloscope.htmlThen there is Matlab! Is there anything this tool can't do?https://www.mathworks.com/company/newsletters/articles/developing-an-isolated-word-recognition-system-in-matlab.htmlSure, you can't bundle up Matlab in the base of a lamp but there must be something to learn. Not surprisingly, Matlab has a data aquisition toolbox that is aimed straight at this kind of thing.Google 'Yule Walker' and read on... Many of the links head back to Matlab (or Mathworks) but there is a lot of information out there. Who knew that speech recognition is an exercise in truly ugly math? Looks like a good place to play with Fortran to me!

author: martys
author_rank: Regular Contributor
timestamp: July 22, 2017, 01:10:30 am
content: Thanks again rstofer and also dferyance for your good advice.I have been using a music editor program on my PC called "Cool Edit Pro" which records and displays the waveform of spoken words in great detail and has analytical tools, FFT and filters, effects, etc. and this helps me quite a bit to understand speech issues and with visual graphical feedback to get asound understandingof the nuances and complexity of speech. This does help me a lot to know how to write the code to get a MCU to recognize a few words.

author: martys
author_rank: Regular Contributor
timestamp: July 22, 2017, 01:24:35 am
content: Thanks again, BrianHG, your help is much appreciated and will help me organize my path to achieve my goals. I am carefully looking over the spec sheet for the PICC MCUs you recommend.I can easily see how this project can stay green by allowing the CPU to wake up from ULP sleep a few times each second to take a listen.I get the idea of adding a trigger word to be said before a command to be used to waken the MCU(such as the word "lamp" that needn't be fully recognized, but can cause the MCU to make a waking decision based just on the length window of the sound heard by the MCU.)

author: martys
author_rank: Regular Contributor
timestamp: July 22, 2017, 01:53:11 am
content: "And then I went on eBay and found:http://www.ebay.com/itm/272729262971"rstofer please note, you can download any or all issues of Popular Electronics and other similar magazines for free on the web.

author: BrianHG
author_rank: Super Contributor
timestamp: July 22, 2017, 03:14:55 am
content: Quote from: martys on July 22, 2017, 01:24:35 amRemember, you need not run those PICs at the full 70 mips. Espicially the DSPIC as the main grouped multiply adds you will be doing for your DCT has a hardware DSP unit implementation cutting down CPU clock cycles/transform something like 5 fold, even another 10x more if you wanted to process everything in floating point.Also, looking at CoolEdit96/Pro/2K, the spectrum display you see there is 5x or more defined that what you need for good speect recognition. Only analyzing a selection of bands between 400hz and 4Khz, ignoring the rest, and only responding to the to 4-9 strongest peaks in that range will give you excellent performance. Do not try to trace out and follow every minor peak in the waveform as some phonetics as you have seen can have even more that 30 between 40hz and 15Khz. You will become so precise that you software will only respond to 1 person...

author: CJay
author_rank: Super Contributor
timestamp: July 22, 2017, 08:59:13 am
content: This got very silly very fast, there are off the shelf speech recognition chips out there.If you want to do software speech recognition then be prepared for a steep uphill struggle, this is at least an order of magnitude more difficult than a simple kitchen timer.Even 'the big boys' struggle to get this right, Dragon dictate, Google, Apple, all have prolems, every speech recognition device i've ever used was less than perfect (often much less) so it won't be simple even with only a few words.One amusing aside though, I built a computer for a born again Christian friend and put Win XP on it (was current at the time), a few weeks or months later I got a phone call from him telling me he no longer wanted it and I should come and remove it immediately.Obviously i was curious why, so after a little questioning he told me he believed it to be possessed by evil spirits.Apparently it was typing satanic messages whenever he had MS Word open (Hi, you seem to be writing a black mass, would you like some demons to help with that?)Turns out he and his wife have a bit of a thing for schlock TV like CSI and other such rubbish.Their recent purchase of a webcam had enables Win XP speech to text, which was merrily transcribing portions of the script from said TV programs into open MS Word documents with rather remarkable accuracy given it hadn't been trained.

author: martys
author_rank: Regular Contributor
timestamp: July 22, 2017, 10:38:42 am
content: Thanks again for the hints, BrianHG.Would I have to deal with the expense of buying a compiler license to work with these DSP chips?The PIC24EP512GP202-I/SP looks very attractive, cheap enough, and I like it especially since it is available in SDIP and so can be breadboarded easily!I would have to deal with my unfamiliarity and accept a learning curve to deal with the newness and increased complexity of these chips. So far I have only learned to be very skilled with 18F PICC chips which are much more math compromised and slower.On the very plus side, learning to use these chips gives me a potential ability to use higher MIPS in future projects.Your ideas of voice spectrum limiting and only analyzing peak voice burst intervals of the data stored sounds like sound advice.As far as running these chips at highest MIPS, wouldn't the idea of finishing the Voice Rec processing as quick as possible when a valid trigger word occurs be the fastest way to minimize MCU on time power use? A quick burst of MIPS power usage would give the quickest result.I don't know how long it will take learning about DSP to get to a place where I understand how to design code using the features available with a DSP MCU.However, I must yet convince myself that switching to DSP is the simplest approach sufficient to apply to what now seems be an immodest goal.(OMG! My Demons!)

author: martys
author_rank: Regular Contributor
timestamp: July 22, 2017, 10:42:16 am
content: Thanks Clay for your funny story about voice rec. Luckily, the only demons I have to deal with in getting this idea to work are my own, and I am enthusiastic about this project but not religious about it!The big boys may have had trouble getting voice rec. to work, but a small chance at perfect may be achievable because I have a very tiny vocab goal.In terms of enlightenment, a word to the wise is sufficient.

author: Kjelt
author_rank: Super Contributor
timestamp: July 22, 2017, 12:25:47 pm
content: Ok since you are still going on with it, another few hints:You're device will be listening 24/7 so you have to trigger it with a start word that is not often used, that word will be the trigger for the software to analyze the following spoken words.A good word might be Light or Lamp or whatever you want.Then the second problem arises, the verbs On and Off are almost identical sounding at least the start. That might not be the wisest decision.Do you only want one dimlevel? Otherwise you might have to mark two words DimUp and DimDown.

author: BrianHG
author_rank: Super Contributor
timestamp: July 22, 2017, 02:46:36 pm
content: Quote from: Kjelt on July 22, 2017, 12:25:47 pmThis isn't too terrible. You will already be using 2 words to begin with and you just need to give the lamp a little intelligence. If the lamp has been OFF for over a minute or 2 and your speech decode has given a 50/50 +/- 10% possibility of 'Lamp On' vs 'Lam Off', just assume the command was 'Lamp On'. Just reverse this logic is the lamp has been ON for over a minute or so. If it has been less than a minute either way since the last command, only respond when the lamp has a better, clearer recognition of these 2 main commands.

author: BrianHG
author_rank: Super Contributor
timestamp: July 22, 2017, 03:07:05 pm
content: martys, a few things. On your PCB, make sure you wire up the RS232 com ports so that you can connect the PIC to a PC, with a little PC software, monitor plot and log your spectrum decoder + other variables during debugging. Also, add a ceramic beeper or speaker to one or 2 of the PWM outputs so your lamp controller can make acknowledgement sounds.The next step is how are your math programming skills?Are you expecting to use someone-elses code, or, are you going to process the raw ADC yourself?How are you powering this thing?Note that even in ultra low power sleep, powering the electric MIC actually consumes more power than a sleeping MCU will use.Having enabled at least 1 of the PIC's op-amps, 1 comparator and an internal voltage reference to have the MCU awake on a degree of noise thresh-hold will raise the power consumption from the high nA range to the mid uA range. Doing some careful data sheet reading and tests, you may not want to use the deep sleep or comparator, just run the MCU at 32khz with ADC running at tight loop around 1khz waiting for the beginning of a spoken word, then jumping to high speed xx mips mode to process, then back to slow mode. In any event, I would expect this method to consume power in the 100-50uA range. (not good for 2xAAA batteries power supply, but fine for 2xC or 2xD batteries) Your gonna need to decide how much power is appropriate VS code and responsiveness. Powering up and down the MIC opamp and MIC itself might introduce effects you will need to work out. External ultra-low power op-amps exist which may run at lower power than the ones in the PIC, but, then have very low bandwidths.

author: martys
author_rank: Regular Contributor
timestamp: July 23, 2017, 11:36:19 am
content: Thanks Alex Eisenhut, I didn't know there was a cheap pre-fab board available before you sent me a link,but my intention was to try to get my own code to accomplish this goal,and the power requirements of this board and its size are also a bit big since a MCU and some kind of P/S and the on/off/dim triac type lamp power control must also be fit into a tight space in a table lamp.I am sure this suggestion would work, and would be a good idea to add to any decent-sized robot, but I am trying to find my own minimalist way to make sense out of only a few words and learn about solving such a significant software/hardware challenge.

author: martys
author_rank: Regular Contributor
timestamp: July 23, 2017, 11:52:36 am
content: Very helpful advice on power, BrianHG, "Note that even in ultra low power sleep, powering the electric MIC actually consumes more power than a sleeping MCU will use"My concept now on how green my mike machine will be means that it shouldn't use more than a watt or so when on and considerably less when idle and waiting for a trigger spoken word.My yet to be realized idea is that the MCU would be mostly a lounge lizard, to be mostly in a snooze, standby or idle state and when periodically awoken by a WDT for a sample of sound, it would strobe on the power to the Mic and the required associated circuits for signal conditioning.I plan to power my circuit with a small valued 250VAC RMS rated capacitor feeding a bridge directly from the mains, since I don't like the idea that the lamp would have to be taken apart to replace batteries and even a small power transformer would be much bigger. Of course, while breadboarding this project, I would use a wall wart feeding a LM317 type regulator so no shock hazards. When finally getting to the point of shoving my hardware into the base, I must also be sure there can not be any shock hazards.

author: martys
author_rank: Regular Contributor
timestamp: July 23, 2017, 12:12:16 pm
content: Kjelt, I didn't have room in the post title to add Un-Dim, but of course, what lights up, must lights down.

author: Kjelt
author_rank: Super Contributor
timestamp: July 23, 2017, 01:24:35 pm
content: Ok so full dimrange it is. Then another suggestion: add scene command(s).A lightscene is a fixed setting (usually for more then one lamp but hey you have to start somewhere) which creates the wanted ambience for a certain activity such as eating, watching tv, reading, etc.So if you for instance can determine a few of these activities with the desired lightsetting than you could add the commands for instance "Light Reading" for the dimsetting required to read a book.There are so many other possibilities, like Colourtemperature, mix 2700K and 6000K white leds with two seperate full dimmable drivers and you have tunable white lightsource.Now to take it even a step further, if you replace the lightbulbs with "inteligent" tunable white ledbulbs such as the PhilipsHue that are Zigbee controllable from a single source (the bridge) you only have to build one voice controller that interacts with that bridge and the possibilities become endless and the benefit is that you have more room for your VC electronics.So that are enough project ideas to keep you busy for awhile

author: BrianHG
author_rank: Super Contributor
timestamp: July 23, 2017, 02:08:44 pm
content: Quote from: martys on July 23, 2017, 11:52:36 amThe battery example I gave was telling you how long you can power your circuit for 1 year straight before the 2 batteries would be dead. Powering the mic means drawing 0.5ma. Running your processor continuously at 32khz instead of deep sleep with adc running to monitor the sound before switching to high speed means drawing another 0.1ma. You sort of see why deep sleep doesn't help much for power consumption unless you go to a 0 power coil magnetic type mic, which requires much more gain on your op-amp and is very sensitive to 60/50hz noise from the AC mains.As for turning on and off the lamp, you can use a logic-level input mosfet & diode bridge rectifier. This will draw 0 power to turn on of off your lamp, though some care will be needed to protect the PIC's io driving the gate and how you power the pic. Your other choice is to use a opto-triac (draws a few ma to keep turned on) and freely power the PIC anyway you like with anonymity. You can aslo use a latching relay, with a large enough cap of the PIC's power supply to pulse the relay on and off, still only requiring a low power PSP for the pic.