BS1 icon BS2 icon BS2e icon BS2sx icon BS2p icon BS2pe icon BS2px icon

SLEEP Example




Syntax: SLEEP Duration


Put the BASIC Stamp into low-power mode for a specified period of time.

* Note: expressions are not allowed as arguments on the BS1.

Quick Facts

  BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
Current Draw

during Run
1 mA 3 mA 25 mA 60 mA 40 mA 15 mA 55 mA
Current Draw

during SLEEP
25 µA 50 µA 200 µA 500 µA 350 µA 36 µA 450 µA
Related Commands END , NAP END, NAP, POLLWAIT
Accuracy of SLEEP ±1% @ 75°F with stable power supply


SLEEP allows the BASIC Stamp to turn itself off, then turn back on after a programmed duration. The length of SLEEP can range from 2.3 seconds to slightly over 18 hours. Power consumption is reduced to the amount described in the table above, assuming no loads are being driven.

Sleep Units vs Sleep Resolution

The units for Duration are 1 second, but the resolution of the SLEEP instruction is 2.304 seconds. SLEEP rounds the specified number of seconds up to the nearest multiple of 2.304. Because of this, Duration values below 10 are not very accurate.

When the Duration value is... 1 2 3 4 5 6 7 8 9 10
Sleep time (in seconds) is approximately... 2.304 2.304 4.608 4.608 6.912 6.912 9.216 9.216 9.216 11.52


To estimate the actual sleeping period for any Duration value, use this equation:

Ceiling of Duration units divided by 2.304, result multiplied by 2.304

The open-bottom square brackets indicate the ceiling function, which essentially means "round up the quantity inside to the next integer."

For example, SLEEP 1 sleeps for 2.304 seconds:

And, SLEEP 10 sleeps for approximately 11.52 seconds:


The Watchdog Timer Improves Sleep Accuracy Automatically

Pins retain their previous I/O directions during SLEEP. However, outputs are interrupted every 2.3 seconds during SLEEP due to the way the chip keeps time. The alarm clock that wakes the BASIC Stamp up is called the watchdog timer. The watchdog is a resistor/capacitor oscillator built into the interpreter chip. During SLEEP, the chip periodically wakes up and adjusts a counter to determine how long it has been asleep. If it isn't time to wake up, the chip "hits the snooze bar" and goes back to sleep.

To ensure accuracy of SLEEP intervals, the BASIC Stamp periodically compares the watchdog timer to the more-accurate resonator time base. It calculates a correction factor that it uses during SLEEP. As a result, longer SLEEP intervals are accurate to approximately ±1 percent.

During execution of power conserving commands (END, NAP, POLLWAIT, and SLEEP), current will occasionally be interrupted on I/O pins for about 18 ms durations (60 µs on the BS2pe). The reason is that the watchdog-timer reset that awakens the BASIC Stamp during these commands also causes all of the pins to switch to input mode for approximately 18 ms (60 µs on the BS2pe). When the interpreter firmware regains control of the processor, it restores the I/O direction dictated by your program.

If you plan to use END, NAP, POLLWAIT, or SLEEP in your programs, make sure that your loads can tolerate these power outages. The simplest solution is often to connect resistors high or low (to +5V or ground) as appropriate to ensure a continuing supply of current during the reset.

The SLEEP Example can be used to demonstrate the effects of this reset with an LED and resistor.

Go to PBASIC Language home page

Open Getting Started with Stamps in Class

Open Connection Troubleshooting

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.