I am writing a code for a self contain soil moisture sensor box using Arduino Nano. I am a completely armature at Arduino and have been coasting though my previous project with Youtube videos and Wokwi publicly available projects
The gist is that I am trying the Arduino IDE keeps giving me errors saying that TIMER1_0N is not recognized by the library even if I copied the text straight from the library repository.
I am stuck because this project needs the TIMER function to be on in the sleep. To wake up the Arduino every hour to take sensor readings.
I know the code us extremely messy and probably is full of errors but at this moment I really need the TIMER function to work so please if anyone have any advice they can give I will be very grateful.
Thank you for your time in advance
this is the error message
Soil_Moisture_fulltest.ino: In function 'void goToSleep()':
Soil_Moisture_fulltest.ino:95:65: error: no matching function for call to 'LowPowerClass::powerDown(period_t, adc_t, bod_t, timer1_t)'
LowPower.powerDown(SLEEP_FOREVER, ADC_ON, BOD_OFF, TIMER1_ON);
^
In file included from T:\Arduino Proj\Soil_Moisture_fulltest\Soil_Moisture_fulltest.ino:1:0:
LowPower.h:151:9: note: candidate: void LowPowerClass::powerDown(period_t, adc_t, bod_t)
void powerDown(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
^~~~~~~~~
LowPower.h:151:9: note: candidate expects 3 arguments, 4 provided
Soil_Moisture_fulltest.ino:97:66: error: no matching function for call to 'LowPowerClass::powerDown(period_t, adc_t, bod_t, timer1_t)'
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF, TIMER1_ON);
^
In file included fromSoil_Moisture_fulltest.ino:1:0:
LowPower.h:151:9: note: candidate: void LowPowerClass::powerDown(period_t, adc_t, bod_t)
void powerDown(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
^~~~~~~~~
#include <LowPower.h>
#include <TimerOne.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int moistSensorPin = A0;
const int knockSensorPin = 4;
const int ledPin = 2;
const unsigned long awakeMoistInterval = 500;
unsigned long awakeMoistLastReading = 0;
unsigned long lastKnockTime = 0;
int moistValue = 0;
int moistPercentValue = 0;
volatile bool knockDetected = false;
volatile bool lowMoisture = false;
volatile bool blinkState = false;
void setup() {
pinMode(knockSensorPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(knockSensorPin), knockInterrupt, FALLING);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Awake! (^w^)b");
delay(1000);
lcd.clear();
// Initialize Timer1 for blinking
Timer1.initialize(500); // 0.5 seconds
Timer1.attachInterrupt(blinkLED);
}
void loop() {
if (knockDetected) {
knockDetected = false;
lastKnockTime = millis();
lcd.backlight();
wakeUp();
}
if(lowMoisture == true){
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
if (millis() - awakeMoistLastReading >= awakeMoistInterval) {
awakeMoistLastReading = millis();
String msg = moistPercentValue < 30 ? "Dry" : moistPercentValue > 70 ? "WET" : "OK";
lcd.setCursor(0, 0);
lcd.print(" Soil : ");
lcd.print(msg);
lcd.setCursor(7, 1);
int moistValue = analogRead(moistSensorPin);
int moistPercentValue = map(moistValue, 478, 288, 0, 100);
lcd.print(moistPercentValue);
lcd.print("%");
if (moistPercentValue <= 30) {
lowMoisture = true;
}
else {
lowMoisture = false;
Timer1.detachInterrupt();
}
Serial.println(moistPercentValue);
}
if (millis() - lastKnockTime > 300000) {
goToSleep();
}
}
void goToSleep(){
// Set timer to wake up every hour
Timer1.initialize(3600000);
Timer1.attachInterrupt(wakeUp);
if (lowMoisture == true) {
LowPower.powerDown(SLEEP_FOREVER, ADC_ON, BOD_OFF, TIMER1_ON);
} else {
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF, TIMER1_ON);
}
}
void wakeUp() {
lcd.backlight();
int moistValue = analogRead(moistSensorPin);
int moistPercentValue = map(moistValue, 478, 288, 0, 100);
if (moistPercentValue <= 30) {
lowMoisture = true;
Timer1.attachInterrupt(blinkLED);
}
else {
lowMoisture = false;
Timer1.detachInterrupt();
}
// Take sensor reading and go back to sleep
Serial.println(moistPercentValue);
goToSleep();
}
void knockInterrupt() {
knockDetected = true;
wakeUp(); // Wake up from deep sleep
}
void blinkLED() {
digitalWrite(ledPin, blinkState);
blinkState = !blinkState;
}