Arduino Simple Release code

Selfbondage software and other kinky developments

Moderators: Riddle, Shannon SteelSlave

Post Reply
axl64
*
Posts: 2
Joined: 04 Sep 2013, 07:40

Arduino Simple Release code

Post by axl64 »

Forgive my bad English.
Programmed an arduino with a servo motor to release the key after a certain time without needing to have the computer near or connected. What you need for this tutorial is.
-Arduino UNO or similar and usb cable
-ServoMotor 6g or more
-Battery wall charger or power bank baterry
- Led (Not required);
-Tape
-A box
the code of arduino is this

Code: Select all

#include <Servo.h>

Servo myservo;

#define minuto 60000 // minute in miliseconds
int minutos = 0; // count of minutes

int tiempo = 0; // time to release

void setup() {
  pinMode(13, OUTPUT); // led optional
  Serial.begin(9600); // speed port
  myservo.attach(9); // servo in port 9
  myservo.write(160); // angle of servo initial
  tiempo = 1; // CHANGE THIS INCREASE TIME (IN MINUTES)
 
}

void loop() {
  delay(minuto);
  minutos++;
  analogWrite(13, 255); // turn on led
  apagarled(); // initialize turn off led
  Serial.print(minutos); // print the minutes;
  if(minutos == tiempo){
     myservo.write(0); // angle of servo on the end;
    }
 
  
}

void apagarled(){
  delay (1000);
   analogWrite(13, 0); //turn off led;
  }
You need to put everything in the box and make a small hole for the servomotor and stick the box with the tape on the ceiling (I recommend putting another box where the key falls so that it is not lost)

The servo motor connects to port 9 and the led port in port 13 and turns on when a minute passes (in case you want to count)

Image
Image
User avatar
Riddle
****
Posts: 1135
Joined: 24 Sep 2008, 08:37
Location: Oregon, USA
Contact:

Re: Arduino Simple Release code

Post by Riddle »

Good work.

Have you considered adding buttons to set the bondage time?
Resident timer maker. :hi:
Let’s make timers together!
hog.tied
*
Posts: 19
Joined: 08 Dec 2007, 12:55
Location: Opava, Czech Republic

Re: Arduino Simple Release code

Post by hog.tied »

Hello Axl64,

it's interesting we were both playing with the same arduino setup at the same time :-) Since I don't want to connect arduino board to the computer every time a play with SB, my project includes time setting using buttons (as Riddle pointed out - but don't know if my setup will suite his needs) and some LED lights to indicate time length.

There are 6 LED lights, 3 red and 3 yellow. Red lights indicate hours (0, 1, 2, 3) and yellow LEDs show quarters of hour (0, 15, 30, 45).
So you can set any time between 0h:0m up to 3h:45m. Since my SB sessions are usually hour or two long, this time frame fills my needs.

This project is still under testing (about 20 runs so far and no failure), so I don't have any box or package for it.

Here is the code itself:

Code: Select all

#include <Servo.h>

boolean sessionStarted = false;
int hours = 0;
int MAX_HOURS = 3;
int HOURS_START_PIN = 5;
int minutes = 0;
int MAX_MINUTES = 3;
int MINUTES_START_PIN = 2;
boolean readingHoursInProgress = false;
boolean readingMinutesInProgress = false;
boolean readingSessionBtnInProgress = false;
unsigned long endTime = 0;
unsigned long MINUTES_MULTIPLIER = 60000; // 1000 for seconds, 60000 for minutes
unsigned long HOURS_MULTIPLIER = MINUTES_MULTIPLIER * 60;

Servo servo;

void setup() {
  // put your setup code here, to run once:
  for (int pin = 2; pin <= 7; pin++) {
    pinMode(pin, OUTPUT);
  }
  // SERVO
  servo.attach(9);
  servo.write(0);
  delay(250);
}

void loop() {
  if (!sessionStarted) {
    readMinutes();  
    readHours();
    showCurrentTime();
  } else {
    if (millis() > endTime) {
      finishSession();
    }
  }

  if (sessionStatusChanged()) {
    if (!sessionStarted) {
      startSession();
    } else {
      finishSession();
    }
  }
}

void finishSession() {
  sessionStarted = false;
  servo.write(170);
  fleshLED();
  servo.write(0);
}

void startSession() {
  fleshLED();

  sessionStarted = true;
  endTime = minutes * 15 * MINUTES_MULTIPLIER;
  endTime += hours * HOURS_MULTIPLIER;
  endTime += millis();  
}

void fleshLED() {
  for (int i = 0; i < 5; i++) {
    for (int pin = 2; pin <= 7; pin++) {
      digitalWrite(pin, HIGH);
    }
    delay(500);
    for (int pin = 2; pin <= 7; pin++) {
      digitalWrite(pin, LOW);
    }
    delay(500);
  }
}

boolean sessionStatusChanged() {
  int sessionBtnInput = analogRead(A2);
  
  if (!readingSessionBtnInProgress) {
    if (sessionBtnInput > 1000) {
      readingSessionBtnInProgress = true;
    }
  } else {
    if (sessionBtnInput == 0) {
      readingSessionBtnInProgress = false;
      // react only after user releases button (can be implemented everywhere)
      return true;
    }
  }

  return false;
}

void readMinutes() {
  int minInput = analogRead(A0);
  
  if (!readingMinutesInProgress) {
    if (minInput > 1000) {
      minutes++;
      if (minutes > MAX_MINUTES) {
        minutes = 0;
      }
      readingMinutesInProgress = true;
    }
  } else {
    if (minInput == 0) {
      readingMinutesInProgress = false;
    }
  }
}

void readHours() {
  int hrsInput = analogRead(A1);

  if (!readingHoursInProgress) {
    if (hrsInput > 1000) {
      hours++;
      if (hours > MAX_HOURS) {
        hours = 0;
      }
      readingHoursInProgress = true;
    }
  } else {
    if (hrsInput == 0) {
      readingHoursInProgress = false;
    }
  }
}

void showCurrentTime() {
  // show minutes
  for (int pin = MINUTES_START_PIN; pin < MINUTES_START_PIN + MAX_MINUTES; pin++) {
    digitalWrite(pin, pin < MINUTES_START_PIN + minutes ? HIGH : LOW);    
  }
  // show hours
  for (int pin = HOURS_START_PIN; pin < HOURS_START_PIN + MAX_HOURS; pin++) {
    digitalWrite(pin, pin < HOURS_START_PIN + hours ? HIGH : LOW);
  }
}
LED examples:
Image

Board photos:
Image
Image

Please feel free to comment anything you don't like about this setup.

Happy bondage!!!
Attachments
Board drawing
Board drawing
thatthat21
**
Posts: 149
Joined: 07 Nov 2013, 03:23

Re: Arduino Simple Release code

Post by thatthat21 »

Like the idea and setup.

First question would be what happens on power loss? If the power, be it from the battery or the wall was to drop out?

Not sure what could really happen, unless you worked in a small battery pack into the project so that if the power was to fail, it could run on the battery just for a bit so that it could drop the key early because of the loss in main power source.

Also in the code, I might have missed it, but on power up if you had it drop the key this might also fix it for some one that is using the wall for power, so that when power is restored the key will drop when it resets everything.

Also on the servo arm, might want look at using one that only has one arm and not two like the image shows. This way you could never put it on the wrong side and have the key stuck on top rather than drop.

Just my thoughts looking it over, but really like your setup.
User avatar
Sir Cumference
Moderator
Posts: 1606
Joined: 29 Jan 2012, 22:00
Location: Scandinavia

Re: Arduino Simple Release code

Post by Sir Cumference »

Nice setup.

A small solenoid instead of the servo would make it "fail safe" in case of loss of power.

My take on it is here.
http://forum.boundanna.net/board/viewto ... oid#p61282

Image

If it is about a simple, programmable timer, those can be bought cheap online.
They normally have a relay output, that can be connected to whatever you may want.
~ Leatherworking, blacksmithing , woodworking and programming are the most pervertable skills you can learn! ~
miesvandero
*
Posts: 1
Joined: 19 May 2017, 03:17

Re: Arduino Simple Release code

Post by miesvandero »

I am using the code that you made, as I should start?, with star and then put the minutes or hours or direct start to set the minutes.
Because when I put the board to the arduino all the LEDs flash and the arduino turns, and then opromimo the first yellow led, it turns on but after 15 minutes nothing happens.
What do you recommend me?





hog.tied wrote:Hello Axl64,

it's interesting we were both playing with the same arduino setup at the same time :-) Since I don't want to connect arduino board to the computer every time a play with SB, my project includes time setting using buttons (as Riddle pointed out - but don't know if my setup will suite his needs) and some LED lights to indicate time length.

There are 6 LED lights, 3 red and 3 yellow. Red lights indicate hours (0, 1, 2, 3) and yellow LEDs show quarters of hour (0, 15, 30, 45).
So you can set any time between 0h:0m up to 3h:45m. Since my SB sessions are usually hour or two long, this time frame fills my needs.

This project is still under testing (about 20 runs so far and no failure), so I don't have any box or package for it.

Here is the code itself:

Code: Select all

#include <Servo.h>

boolean sessionStarted = false;
int hours = 0;
int MAX_HOURS = 3;
int HOURS_START_PIN = 5;
int minutes = 0;
int MAX_MINUTES = 3;
int MINUTES_START_PIN = 2;
boolean readingHoursInProgress = false;
boolean readingMinutesInProgress = false;
boolean readingSessionBtnInProgress = false;
unsigned long endTime = 0;
unsigned long MINUTES_MULTIPLIER = 60000; // 1000 for seconds, 60000 for minutes
unsigned long HOURS_MULTIPLIER = MINUTES_MULTIPLIER * 60;

Servo servo;

void setup() {
  // put your setup code here, to run once:
  for (int pin = 2; pin <= 7; pin++) {
    pinMode(pin, OUTPUT);
  }
  // SERVO
  servo.attach(9);
  servo.write(0);
  delay(250);
}

void loop() {
  if (!sessionStarted) {
    readMinutes();  
    readHours();
    showCurrentTime();
  } else {
    if (millis() > endTime) {
      finishSession();
    }
  }

  if (sessionStatusChanged()) {
    if (!sessionStarted) {
      startSession();
    } else {
      finishSession();
    }
  }
}

void finishSession() {
  sessionStarted = false;
  servo.write(170);
  fleshLED();
  servo.write(0);
}

void startSession() {
  fleshLED();

  sessionStarted = true;
  endTime = minutes * 15 * MINUTES_MULTIPLIER;
  endTime += hours * HOURS_MULTIPLIER;
  endTime += millis();  
}

void fleshLED() {
  for (int i = 0; i < 5; i++) {
    for (int pin = 2; pin <= 7; pin++) {
      digitalWrite(pin, HIGH);
    }
    delay(500);
    for (int pin = 2; pin <= 7; pin++) {
      digitalWrite(pin, LOW);
    }
    delay(500);
  }
}

boolean sessionStatusChanged() {
  int sessionBtnInput = analogRead(A2);
  
  if (!readingSessionBtnInProgress) {
    if (sessionBtnInput > 1000) {
      readingSessionBtnInProgress = true;
    }
  } else {
    if (sessionBtnInput == 0) {
      readingSessionBtnInProgress = false;
      // react only after user releases button (can be implemented everywhere)
      return true;
    }
  }

  return false;
}

void readMinutes() {
  int minInput = analogRead(A0);
  
  if (!readingMinutesInProgress) {
    if (minInput > 1000) {
      minutes++;
      if (minutes > MAX_MINUTES) {
        minutes = 0;
      }
      readingMinutesInProgress = true;
    }
  } else {
    if (minInput == 0) {
      readingMinutesInProgress = false;
    }
  }
}

void readHours() {
  int hrsInput = analogRead(A1);

  if (!readingHoursInProgress) {
    if (hrsInput > 1000) {
      hours++;
      if (hours > MAX_HOURS) {
        hours = 0;
      }
      readingHoursInProgress = true;
    }
  } else {
    if (hrsInput == 0) {
      readingHoursInProgress = false;
    }
  }
}

void showCurrentTime() {
  // show minutes
  for (int pin = MINUTES_START_PIN; pin < MINUTES_START_PIN + MAX_MINUTES; pin++) {
    digitalWrite(pin, pin < MINUTES_START_PIN + minutes ? HIGH : LOW);    
  }
  // show hours
  for (int pin = HOURS_START_PIN; pin < HOURS_START_PIN + MAX_HOURS; pin++) {
    digitalWrite(pin, pin < HOURS_START_PIN + hours ? HIGH : LOW);
  }
}
LED examples:
Image

Board photos:
Image
Image

Please feel free to comment anything you don't like about this setup.

Happy bondage!!!
hog.tied
*
Posts: 19
Joined: 08 Dec 2007, 12:55
Location: Opava, Czech Republic

Re: Arduino Simple Release code

Post by hog.tied »

Hi miesvandero,

at first you set up time, then press "Start" button and your session can begin :-)
miesvandero wrote:I am using the code that you made, as I should start?, with star and then put the minutes or hours or direct start to set the minutes.
Because when I put the board to the arduino all the LEDs flash and the arduino turns, and then opromimo the first yellow led, it turns on but after 15 minutes nothing happens.
What do you recommend me?





hog.tied wrote:Hello Axl64,

it's interesting we were both playing with the same arduino setup at the same time :-) Since I don't want to connect arduino board to the computer every time a play with SB, my project includes time setting using buttons (as Riddle pointed out - but don't know if my setup will suite his needs) and some LED lights to indicate time length.

There are 6 LED lights, 3 red and 3 yellow. Red lights indicate hours (0, 1, 2, 3) and yellow LEDs show quarters of hour (0, 15, 30, 45).
So you can set any time between 0h:0m up to 3h:45m. Since my SB sessions are usually hour or two long, this time frame fills my needs.

This project is still under testing (about 20 runs so far and no failure), so I don't have any box or package for it.

Here is the code itself:

Code: Select all

#include <Servo.h>

boolean sessionStarted = false;
int hours = 0;
int MAX_HOURS = 3;
int HOURS_START_PIN = 5;
int minutes = 0;
int MAX_MINUTES = 3;
int MINUTES_START_PIN = 2;
boolean readingHoursInProgress = false;
boolean readingMinutesInProgress = false;
boolean readingSessionBtnInProgress = false;
unsigned long endTime = 0;
unsigned long MINUTES_MULTIPLIER = 60000; // 1000 for seconds, 60000 for minutes
unsigned long HOURS_MULTIPLIER = MINUTES_MULTIPLIER * 60;

Servo servo;

void setup() {
  // put your setup code here, to run once:
  for (int pin = 2; pin <= 7; pin++) {
    pinMode(pin, OUTPUT);
  }
  // SERVO
  servo.attach(9);
  servo.write(0);
  delay(250);
}

void loop() {
  if (!sessionStarted) {
    readMinutes();  
    readHours();
    showCurrentTime();
  } else {
    if (millis() > endTime) {
      finishSession();
    }
  }

  if (sessionStatusChanged()) {
    if (!sessionStarted) {
      startSession();
    } else {
      finishSession();
    }
  }
}

void finishSession() {
  sessionStarted = false;
  servo.write(170);
  fleshLED();
  servo.write(0);
}

void startSession() {
  fleshLED();

  sessionStarted = true;
  endTime = minutes * 15 * MINUTES_MULTIPLIER;
  endTime += hours * HOURS_MULTIPLIER;
  endTime += millis();  
}

void fleshLED() {
  for (int i = 0; i < 5; i++) {
    for (int pin = 2; pin <= 7; pin++) {
      digitalWrite(pin, HIGH);
    }
    delay(500);
    for (int pin = 2; pin <= 7; pin++) {
      digitalWrite(pin, LOW);
    }
    delay(500);
  }
}

boolean sessionStatusChanged() {
  int sessionBtnInput = analogRead(A2);
  
  if (!readingSessionBtnInProgress) {
    if (sessionBtnInput > 1000) {
      readingSessionBtnInProgress = true;
    }
  } else {
    if (sessionBtnInput == 0) {
      readingSessionBtnInProgress = false;
      // react only after user releases button (can be implemented everywhere)
      return true;
    }
  }

  return false;
}

void readMinutes() {
  int minInput = analogRead(A0);
  
  if (!readingMinutesInProgress) {
    if (minInput > 1000) {
      minutes++;
      if (minutes > MAX_MINUTES) {
        minutes = 0;
      }
      readingMinutesInProgress = true;
    }
  } else {
    if (minInput == 0) {
      readingMinutesInProgress = false;
    }
  }
}

void readHours() {
  int hrsInput = analogRead(A1);

  if (!readingHoursInProgress) {
    if (hrsInput > 1000) {
      hours++;
      if (hours > MAX_HOURS) {
        hours = 0;
      }
      readingHoursInProgress = true;
    }
  } else {
    if (hrsInput == 0) {
      readingHoursInProgress = false;
    }
  }
}

void showCurrentTime() {
  // show minutes
  for (int pin = MINUTES_START_PIN; pin < MINUTES_START_PIN + MAX_MINUTES; pin++) {
    digitalWrite(pin, pin < MINUTES_START_PIN + minutes ? HIGH : LOW);    
  }
  // show hours
  for (int pin = HOURS_START_PIN; pin < HOURS_START_PIN + MAX_HOURS; pin++) {
    digitalWrite(pin, pin < HOURS_START_PIN + hours ? HIGH : LOW);
  }
}
LED examples:
Image

Board photos:
Image
Image

Please feel free to comment anything you don't like about this setup.

Happy bondage!!!
Last edited by hog.tied on 19 Aug 2017, 20:31, edited 1 time in total.
hog.tied
*
Posts: 19
Joined: 08 Dec 2007, 12:55
Location: Opava, Czech Republic

Re: Arduino Simple Release code

Post by hog.tied »

yes Sir C., your set up is much better... Aren't you affraid of having the solenoid under constant current for 2 or 3 hours? Is it ok for the batteries as well? I am not an expert at all, so any advice very welcomed.
Sir Cumference wrote:Nice setup.

A small solenoid instead of the servo would make it "fail safe" in case of loss of power.

My take on it is here.
http://forum.boundanna.net/board/viewto ... oid#p61282

Image

If it is about a simple, programmable timer, those can be bought cheap online.
They normally have a relay output, that can be connected to whatever you may want.
User avatar
Sir Cumference
Moderator
Posts: 1606
Joined: 29 Jan 2012, 22:00
Location: Scandinavia

Re: Arduino Simple Release code

Post by Sir Cumference »

It totally depends on the solenoid.

In this case it is from an old relay and has sufficient resistance to never draw more than the 40 mA the arduino can deliver. This also means that the batteries are completely safe.
(But: Remember a free wheeling diode to protect the pin!)

The solenoid is just strong enough to hold the key ring.
When the time runs out, it drops. If the batteries run out, it drops.


Running it on batteries is not a bug, it is a feature :mrgreen:
~ Leatherworking, blacksmithing , woodworking and programming are the most pervertable skills you can learn! ~
User avatar
Sir Cumference
Moderator
Posts: 1606
Joined: 29 Jan 2012, 22:00
Location: Scandinavia

Re: Arduino Simple Release code

Post by Sir Cumference »

Another source for solenoids is printers.

I have torn apart quite a few of them, and in many, you will find this nice little one:
image.jpeg
image.jpeg (21.96 KiB) Viewed 3369 times
The one I measured had a resistance of 140 ohms, meaning that it will draw 35 mA at 5 V.
That's on the high side IMHO, and I would put an extra 100 ohms in front of it.... Just to play it safe.
~ Leatherworking, blacksmithing , woodworking and programming are the most pervertable skills you can learn! ~
Post Reply