# Boron Sleep Mode

**URL:** <https://community.particle.io/t/boron-sleep-mode/62299>\
**Category:** Libraries\
**Created:** [March 23, 2022, 11:18am UTC](https://community.particle.io/t/boron-sleep-mode/62299 "2022-03-23T11:18:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![majj\_11](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/majj_11/32/21851_2.png) [@majj\_11](https://community.particle.io/u/majj_11)\
**Post date:** [March 23, 2022, 11:18am UTC](https://community.particle.io/t/boron-sleep-mode/62299/1 "2022-03-23T11:18:48Z")

</div>

Hi All,

i am trying to use sleep mode function to my code, but seems it doesn’t like my code, it flashing Magenta after sending data instead of going sleep.  
i want to make the boron to sleep for 10 min then wake send me the signal then back,  
can you please check if i miss something here in the code below? it used to work perfect on particle electron

```cpp
const uint32_t msSAMPLE_INTERVAL = 2500;
const uint32_t msMETRIC_PUBLISH = 5000;

uint32_t msLastMetric;
uint32_t msLastSample;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  Wire.begin(); 
  pinMode(pump_pin, OUTPUT);
}

void loop {
  float duration, inches, cm;

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);

  delayMicroseconds(10);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(15);
  digitalWrite(trigPin, LOW);

  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  xx= cm;
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print("\t");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
 /////////////////////////////////////////////////////////////////
  
  samples.add(xx);
  float l = samples.getLowest();
  float m = samples.getMedian();
  float a = samples.getAverage();
  float h = samples.getHighest();
    
 // lowest =l;
  average = a;
  median = m;
 //////////////////////////////////////////////////////////////
   
  if (millis() - msLastMetric >= msMETRIC_PUBLISH){
    pumpactivator();
    System.sleep(SLEEP_MODE_DEEP,600); 
  }
}

```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 23, 2022, 1:12pm UTC](https://community.particle.io/t/boron-sleep-mode/62299/2 "2022-03-23T13:12:54Z")

</div>

Apart from the suggestions you got about a month ago in another thread but haven't applied yet

> [@Spikes using HC-sr04](https://community.particle.io/t/spikes-using-hc-sr04/62094/2):
>
> You would not need to set the pinMode() each iteration of loop but only once in setup(). You may also want to limit your calculation when microseconds is non-zero as this could indicate the case that no ping was received. You should also be aware that you may well receive stray echoes or even surrounding noise may trigger the input (e.g. my car’s parking sensors sometimes trigger when I’m stood at traffic lights next to a HGV for their noise). Hence you may consider some filtering and some ext…

You may want to have a look at the docs

> **[Device OS API | Reference Documentation](https://docs.particle.io/reference/device-os/firmware/#sleep-classic-api-)**
>
> Reference manual for the C++ API used by user firmware running on Particle IoT devices

Where it states

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/1/5/158f393f715aa45272e4801448c6aecba18c45b4.png)

And at the top of the "classic sleep" reference you also see a link to the _ **modern** _ way of doing it.

> **[Device OS API | Reference Documentation](https://docs.particle.io/reference/device-os/firmware/#sleep-sleep-)**
>
> Reference manual for the C++ API used by user firmware running on Particle IoT devices

We also cannot see what `pumpactivator()` does, so this might also contribute to your issue.

---

<div class="post-metadata">

**Author:** ![majj\_11](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/majj_11/32/21851_2.png) [@majj\_11](https://community.particle.io/u/majj_11)\
**Post date:** [March 24, 2022, 11:20am UTC](https://community.particle.io/t/boron-sleep-mode/62299/3 "2022-03-24T11:20:44Z")

</div>

Thanks a lot, I’ve changed the pinMode() , also the sleeping Mode is working after i added this to the code :

SystemSleepConfiguration config;  
config.mode(SystemSleepMode::STOP)  
.gpio(WKP, RISING)  
.duration(10min);  
System.sleep(config);

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)\
**Post date:** [May 23, 2022, 11:21am UTC](https://community.particle.io/t/boron-sleep-mode/62299/4 "2022-05-23T11:21:22Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
