aardweeno
Created February 1, 2018 © CC0

Om: meditation timer

How to program an ATTiny85 as a 30 minute timer from an Arduino. It beeps every 5 seconds until the time is up, and then it beeps faster.

BeginnerFull instructions provided505

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
If you want to make it permanent
×1
Buzzer
Buzzer
Use an active buzzer
×1
Slide Switch
Slide Switch
If you want to make it permanent, and have on-off control
×1
IC socket stamped contacts
If you want to make it permanent.
×1
Coin Cell Battery Holder
Coin Cell Battery Holder
I improvised a coin cell battery holder, but I recommend you use a proper one.
×1
Matrix Board
If you want to make it permanent
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit_3uGlbkjgTe.png

Code

om.ino

C/C++
/*
 * Started 20-Jan-2018
 * 
 * Meditation timer
 * 
 * You probably need the clock running at 8MHz

 */
 
#define F_CPU 8000000L

unsigned long startTime;
constexpr int buzzer = 1;
constexpr unsigned long mins30 = 30L * 60L * 1000L; // 30 minutes
enum state {RUNNING, TIMES_UP} the_state;

void setup()
{
  startTime = millis();
  the_state = RUNNING;
  pinMode(buzzer, OUTPUT);
}

void beep(int postDelay)
{
  analogWrite(buzzer, 210); // about the right volume. 150 is too low. 
  delay(500);
  digitalWrite(buzzer, LOW);
  delay(postDelay);
}
void beepbeep(int postDelay)
{
  beep(500);
  beep(postDelay); 
}

void loop()
{
	unsigned long timeNow = millis();
	switch(the_state) {
		case RUNNING:
			beepbeep(5000);
			if(timeNow >= startTime + mins30) the_state = TIMES_UP;
			break;
		case TIMES_UP:
			beepbeep(750);
			break;
	}

}

Credits

aardweeno
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.