I'm trying to figure out how to wake up and put to sleep the Arduino Nano 33 BLE. I have seen a few post about it but absolutely nothing I can understand or implement. I'm attaching a subset of the code below because the whole thing is 20 pages. But the declarations, setup and loop show what I'm trying to do. The first if statement in the loop is where I would like to put the code to wake it up. The second If statement is where I would like to put the Arduino to sleep. I can provide the rest of the code if needed but its really 20 pages of functions that all work without issue.
Any help would be appreciated.
// Note this program uses a watchdog timmer.// It is required to reset the Arduino by two presses of the reset button and setting available com ports prior to upload.// After upload the com port needs to be reset.// Define Global Constants /////////////////////////////////////////////////////////////////// constants thet are desirable to adjust during debugging.const bool SerialStatus = true; // Set to true to hold serial printing until the serial printer is started. Set to false to release hold for stand alone use const bool WDTStatus = false; // Set to true to activate the Watch Dog Timmer, Set to false to deactivate for debuggingconst unsigned long WDT = 30; // Watch Dog Timer max time seconds This must be greater than the time requird to complete a cycle// Constant for voltage sensingconst unsigned long Resistor1 = 33000L; // Voltage divider resistor #1const unsigned long Resistor2 = 3300L; // Voltage divider resistor #2const float BoardV = 3.3; // Board operating voltageconst float VMult = BoardV*((Resistor1 + Resistor2)/Resistor2)/1023L; // Voltage multiplier to get voltage from analogread pin "VsnPin"const float EngineOnVoltage = 13.2; // Voltage at which the engine is considered to be runningconst float KeyOnVoltage = 12; // Voltage at which the key is considered to be onconst long PostRunInterval = 30; // Time the fan will run after engine shut down// Constanst for program controlconst int frequency = 10.0; // Set fan frequencyconst int NumberOfSamples = 20; // Sent number of data samples for averaging.const int BlinkTimeOnTest = 2000; // Blink time on period for initial circuit testconst int BlinkTimeOn = 500; // Blink time on periodconst int BlinkTimeOff = 500; // Blink time off period// Constants for Arduino board configurationconst int VsnPin = A0; // Circuite 15 Voltage level sensing pinconst int RadPin = A1; // Radiator Input Thermisterconst int CndPin = A2; // Condenser Input Thermisterconst int AuxPin = A3; // Auxilary Input const int FanPin = D9; // Set Fan pinconst int LED1Pin = D4; // Set Cooling Fan LEDconst int LED2Pin = D3; // Set Condenser Fan LEDconst int LED3Pin = D2; // Set Aux Fan LED////////////////////////////////////////////////////////////////////////////////////void setup() { // put your setup code here, to run once: pinMode(VsnPin, INPUT); pinMode(RadPin, INPUT); pinMode(CndPin, INPUT); pinMode(AuxPin, INPUT); pinMode(LED1Pin, OUTPUT); pinMode(LED2Pin, OUTPUT); pinMode(LED3Pin, OUTPUT); pinMode(FanPin, OUTPUT); pinMode(LED_BUILTIN, OUTPUT); ////////////////////////////////////////////////////////////////////////////////////void loop() { if (VMult*analogRead(VsnPin) > EngineOnVoltage) { // Wake Nano 33 BLE } if (RunFan() == false) { //Put Nano 33 BLE to sleep } if (RunFan() == true) // Run the fan if apropriate { // wait for a Bluetooth® Low Energy central BLEDevice central = BLE.central(); // if a central is connected to the peripheral:- If your MCU is in sleep mode, it won't execute the
ifstatement to read the analog input. You need to either set up a timer to wake up periodically or with a hardware comparator with the analog input as the input and compare to a threshold reference voltage to generate a trigger signal to wake up the MCU.hcheung– hcheung2024-11-12 13:24:35 +00:00CommentedNov 12, 2024 at 13:24 - Also posted inforum.arduino.cc/t/…hcheung– hcheung2024-11-12 13:29:45 +00:00CommentedNov 12, 2024 at 13:29
- your sketch has a lot of irrelevant code linesjsotola– jsotola2024-11-12 22:05:35 +00:00CommentedNov 12, 2024 at 22:05
- I guess my first priority is to figure out how to get it in and out of sleep mode. Then I can look into what runs or doesn't when its asleep. I certainly expect that to be a hurdle.MB107– MB1072024-11-14 02:09:56 +00:00CommentedNov 14, 2024 at 2:09
- I see three closing brackets are missing from the code that you shared. The setup function has no closing bracket. So don't the loop function and the last if loop.liaifat85– liaifat852025-01-18 14:12:10 +00:00CommentedJan 18 at 14:12