mindfulness vibrating bracelet with random time

Wearable electronics: boards, conductive materials, and projects from Adafruit!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

mindfulness vibrating bracelet with random time

Post by bozzaglia »

Hi,
I am completely new and would like to build a wearable circuit that I can program to vibrate at random time within a certain interval (i.e. one randomly timed vibration every 30 minutes interval.
I have seen a similar project based on the GEMMA platform, but it didn't have the random time function.
Can you point out the easiest way to do it?
Thanks in advance!
Angelo

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: mindfulness vibrating bracelet with random time

Post by adafruit_support_bill »

There is a random function in the Arduino library. It works on the Gemma too: https://www.arduino.cc/reference/en/lan ... rs/random/

User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

Re: mindfulness vibrating bracelet with random time

Post by bozzaglia »

Thanks! Forgive my ignorance: I understand the GEMMA comes preloaded with CircuitPython, so I would have to wipe it to use Arduino?
Another thing: I see the “random” function provides numbers, how can I turn it to times?
Thanks!!

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: mindfulness vibrating bracelet with random time

Post by adafruit_support_bill »

Thanks! Forgive my ignorance: I understand the GEMMA comes preloaded with CircuitPython, so I would have to wipe it to use Arduino?
CircuitPython has a random function also: https://docs.circuitpython.org/en/lates ... index.html
Another thing: I see the “random” function provides numbers, how can I turn it to times?
Time is just numbers too. The Python code from that project defines "on_time" as 2 seconds. You can substitute a random number for the "2";

https://learn.adafruit.com/buzzing-mind ... ython-code

Code: Select all

on_time = 2     # Vibration motor run time, in seconds

User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

Re: mindfulness vibrating bracelet with random time

Post by bozzaglia »

Ok, I think with the help you are providing I can just use the existing bracelet project and tweak the code to do what I need.
Please let me know if I am abusing of your kindness: the current code is:

on_time = 2 # Vibration motor run time, in seconds
interval = 60 # Time between reminders, in seconds

I think I need to keep the 2, as it is the vibration duration, and change the 60 into a random number.
However I want to have ONE random motor run EVERY 30 minutes, so I guess the code becomes a little more complicated, because the interval needs to vary randomly but looking at an active window between 07:00 and 23:00 I only want to get 2 alarms every hour. I post a screenshot of the app I currently use on my iPhone.
Any idea about how to code it?
It would save me hours of research...
Attachments
1D19BEB1-1C17-4369-A7DA-19EBF77E7444.jpeg
1D19BEB1-1C17-4369-A7DA-19EBF77E7444.jpeg (78.78 KiB) Viewed 241 times
22AB01AD-CEFE-4BC0-BCF3-BFD768EEA286.png
22AB01AD-CEFE-4BC0-BCF3-BFD768EEA286.png (360.36 KiB) Viewed 241 times

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: mindfulness vibrating bracelet with random time

Post by adafruit_support_bill »

I'm not much of a Python programmer. But I think a reasonable approach would be to set your interval to 30 minutes. When the interval passes, instead of starting the buzzer, generate a random delay between 0 and 30 minutes. When that delay expires, you can start the buzzer.

User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

Re: mindfulness vibrating bracelet with random time

Post by bozzaglia »

Thanks again! I was able to get some code also from the stackoverflow forum. I'll post it at the end in case it helps somebody else.
I was wandering if this would also work on the Trinket, which I understand is slightly smaller than the Gemma.


import datetime
from random import randint

begin = datetime.datetime.strptime("07:00", "%H:%M")
end = datetime.datetime.strptime("23:00", "%H:%M")
delta = datetime.timedelta(minutes=30)
r = []

while begin <= end:
r.append(begin + datetime.timedelta(seconds=randint(0, 1800)))
begin = begin + delta
print(r)

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: mindfulness vibrating bracelet with random time

Post by adafruit_support_bill »

The Trinket & Gemma are essentially identical circuits. The Trinket is designed for minimum size. The Gemma has a larger form-factor to accommodate the larger holes needed for use with conductive thread on wearable projects.

User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

Re: mindfulness vibrating bracelet with random time

Post by bozzaglia »

Ok great! Now I am looking at the battery.. what is the smallest coin battery holder that I can accommodate in a small case with the trinket or Gemma? (I saw the 3D printable cases)...

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: mindfulness vibrating bracelet with random time

Post by adafruit_support_bill »

We have a 12mm holder: https://www.adafruit.com/product/1868
The one with a built-in switch is a bit larger: https://www.adafruit.com/product/1867

User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

Re: mindfulness vibrating bracelet with random time

Post by bozzaglia »

Great! For some reason I hadn’t been able to find those on your website.
Is there a tutorial showing how to connect them to the GEMMA/TRINKET?
I’d like to position it on the top or bottom, in order to gain only a little thickness but no length or width, so I can put everything in a small case.

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: mindfulness vibrating bracelet with random time

Post by adafruit_support_bill »

Connect the "-" pin to "GND". And connect the "+" pin to "BAT" on the Trinket or "VOUT" on the Gemma.

User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

Re: mindfulness vibrating bracelet with random time

Post by bozzaglia »

Ok and these connections can be done through the pitch breakout pins provided with the battery card or I have to solder wires?

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: mindfulness vibrating bracelet with random time

Post by adafruit_support_bill »

You would need to solder some wires.

User avatar
bozzaglia
 
Posts: 131
Joined: Mon Aug 01, 2022 6:14 am

Re: mindfulness vibrating bracelet with random time

Post by bozzaglia »

Got it! Finally I am buying the components. The only one I am having trouble with is the “~220-1K ohm resistor”. It’s not on your website and if I look it up I get both 220 ohm and 1k ohm resistors. Which one is it?

Locked
Please be positive and constructive with your questions and comments.

Return to “Wearables”