Search code examples
attiny

How to deep sleep an Attiny until an analog value of a photoresistor changes?


for a battery powered project I would like to put an Attiny85 into deep sleep mode immediately after program start and let it wake up only when a sensor value (in this case a photo resistor) changes. Unfortunately I could only find examples for interrupts by a button and not for photo resistors in the internet. Does anyone have an idea how I could implement it, or if it is impossible?


Solution

  • Turn out that this is probably a software question.

    Probably to lowest power and simplest way to implement this would be to...

    1. Connect the analog sensor value to any one of the analog input pins on the ATTINY.
    2. Make sure you disable the digital buffer on that pin.
    3. Set up the ADC to point to the pin and set other relevant values like precaller.
    4. Set up a watchdog timer to fire a periodic interrupt.
    5. Go into deep sleep and wait for the watchdog timer to fire.

    Each time the watchdog fires...

    1. Enable the the ADC.
    2. Take a sample.
    3. Jump to main code if the value has changed more than your threshold.
    4. Disable ADC.
    5. Go back to deep sleep.

    How power efficient this will be really depends on how often the timer interrupt fires - the less often the better. If your application can live with only checking the sensor, say, once per second then I bet power usage will be single digits of microamps or less.

    If you really need very low latency when that sensor values changes, then you could instead use the build in analog comparitor... enter image description here .. to generate an interrupt when the input voltage goes above or below a threshold value, but this will likely use much more power since just the analog comparitor itself uses ~30ua while on, and you will also need to generate the voltage that you are comparing to either with the internal 1.1 voltage reference or an external resistor bridge or buffer capacitor.