Has anyone else had success using the snore library in projects?
My project involves a probe to determine if the water level falls below it and if so to turn on a pump. I want to only check the level occasionally to save power and was hoping the snore function would allow me to do this. The probe and pump work fine but as soon as I introduce the snore function the pump stays on all the time independent of the probe condition.
Sorry I have forgotten how to use codetags. I thought code was preceded by a < and to finish a > but it didn't work.
#include "tinysnore.h" // Include TinySnore Library
// Pin definitions
const uint8_t probePin = 0; // Pin connected to the water level probe
const uint8_t pumpControlPin = 1; // Pin connected to the pump control MOSFET
void setup() {
pinMode(probePin, INPUT); // Probe as input
pinMode(pumpControlPin, OUTPUT); // Output to control the pump
}
void loop() {
delay(10); // Short delay for stability
bool waterIsLow = digitalRead(probePin) == HIGH;
while (waterIsLow)
{
digitalWrite(pumpControlPin, HIGH);
}
digitalWrite(pumpControlPin, LOW);
snore(20000); // Deep sleeps for 20 seconds, (low power) then resumes from here
}
How do you think you'll exit from the while statement ? (and why do you keep setting the pin HIGH every few microseconds, once is enough until you turn it off).
Thanks for the replies.
I have changed the code see below and this works perfectly without the statement
snore(20000); // Deep sleeps for 20 seconds, (low power) then resumes from here.
However when this statement is included, it operates unreliably particularly when a probe state changes during the snore period. At times when the probe state is high, the pump doesn't operate and other times, the pump may operate even when the probe state is low. In each case allowing for any 20 sec snooze time. It is bizarre.
Just reiterating, it works perfectly without the snore code.
#include "tinysnore.h" // Include TinySnore Library
// Pin definitions
const uint8_t probePin = 0; // Pin connected to the water level probe
const uint8_t pumpControlPin = 1; // Pin connected to the pump control MOSFET
void setup() {
pinMode(probePin, INPUT); // Probe as input
pinMode(pumpControlPin, OUTPUT); // Output to control the pump
}
void loop() {
delay(10); // Short delay for stability
if (digitalRead(probePin) == HIGH)
{
digitalWrite(pumpControlPin, HIGH);
}
else
{
digitalWrite(pumpControlPin, LOW);
snore(20000); // Deep sleeps for 20 seconds, (low power) then resumes from here
}
}
This shows the water level controller schematic. There is no need for a pullup resistor as the FET attached to the input probe will supply a high or low to the PB0. This added FET was used so that when the water is quite pure it will respond whereas applying PB0 direct via the probe and including pinMode(probePin, INPUT_PULLUP) would not work with very pure water.
However, using the the unit without the input FET gave the same results. A simple switch was used to leave the probe either open or short circuited for convenience.
I will try and use a sleep method using a watchdog timer to see if I get correct results.
One side of the probe connects to VCC and the P chan FET source whilst the other side connects to the FET gate as well as to a resistor to the negative of the supply. The drain of the FET connects to the PB0 of the ATtiny85. When the probe is open circuited, it turns on the FET and puts Vcc to PB0. When water is applied to the probe and providing it is less than about 2Mohms, the FET is turned off and PB0 is low. I could have used a N chan FET but I didn't want to change the s/w. Note that when the FET is used, the s/w PULLUP is not used.
I have tried many iterations of the software and hardware but although it works for a while eventually I get inconsistencies using "snore". Other people have also experienced similar problems using the "tinysnore.h" library. I quote one such user "I have a really simple script running on a ATtiny85 which turns on a ESP8266 every 30 minutes to sent a temperature reading to domoticz. I am using the tinysnore.h library to make the tiny go into deep sleep. It works for a few hours and then the relay connected to the ESP stays on and drains the battery. I can't seem to figure out what is the problem."
The funny thing is I have used this library to produce very simple timers without any problems. I am at the point of giving up unless someone can point out a possible s/w solution.