Another Arduino timer

Another little project, mostly made to learn how to use TIP102 transistors.

The setup is controller an 250 kg electromagnet ([email protected]), and using only one TIP102 to open and close, and one small 1A 12V switch mode power supply. The power supply is connected the the Arduino’s connector for an external power source, and the magnet is then driven through the VIN pin.

I also added a small piezo from a computer to make it able to beep when the timer is started and stopped.

Everything is mounted on a protoshield 4 and looks very clean (both because there aren’t many components, plus no extra supply wires for the load).

I also added a “Start timer” function, where the analog pin 5 is used to determine when the timer should start. The reason for the analog pin is so it can be used for the pressure pads too, and start when enough pressure is reached. The pin is pulled up by an 10k ohm resistor, and will then be pulled towards gnd by the switch, variable resistor, pressure pad, or what else it could be.

Version 1.0

This is with the TIP102 to switch the 12V output on and off, the piezo to give some audio signal, and a blue LED to show that the TIP102 is activated.

BLAH! Hit the blue wire with my soldering iron, but didn’t burn through the isolation.

Version 1.1

This got the same as version 1.0, but here I added screw terminals for the wires, and also feeding the Arduino through the VIN port, as the on-board diode on the Arduino gave up when it had to both pull the relay and the little motor I added to the TIP120. The TIP120 is connected to the PIN6 (pwm) on the Arduino.

//Define the timer (Up to 49 days)
unsigned long seconds     = 0;
unsigned long minutes     = 15;
unsigned long hours       = 0;
unsigned long days        = 0;

int relDelay    = 1000;   //How long delay there will be between the beep and the release of the magnet

//Digital pins
int piezoPin    = 12;    //Where the piezo is connected to
int ledPin      = 13;    //Using the on board LED for visualisation
int relayPin    = 9;     //Where the TIP102 is connected to
int switchPin   = 5;     //The pin with the switch that starts the timer

unsigned long waitTime = 0;
unsigned long startTime = 0;
unsigned long lastBlink = 0;

boolean activated = false;

void beep(int freq, int dur)
{
  digitalWrite(ledPin, HIGH);

  tone(piezoPin, freq, dur);
  delay(dur);

  digitalWrite(ledPin, LOW);
}

void setup()
{
  //Set pin modes
  pinMode(piezoPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);

  //Calculate the waiting time
  waitTime = seconds*1000;
  waitTime += (minutes*1000)*60;
  waitTime += ((hours*1000)*60)*60;
  waitTime += (((days*1000)*60)*60)*24;

  if (waitTime >= 4294967295)
  {
    waitTime = 4294967294;
    beep(150, 1000); //Warn with one long beep about it shortened down
    delay(500);
  }
}

void loop()
{
  if (!activated)
  {
    if (analogRead(switchPin) < 1)
    {
      activated = true;

      for(int i=0; i < 2; i++) //Two beeps to tell the timer has started
      {
        beep(2500, 100);
        delay(80);
      }

      digitalWrite(relayPin, HIGH);
      startTime = millis();
      lastBlink = millis();
    }
  }
  else
  {
    if ((millis() - startTime) + relDelay >= waitTime)
    {
      if (waitTime != 4294967295)
      {
        waitTime = 4294967295; //Yay! You made it, lets set it to max so it won't keep beeping

        for(int i=0; i < 4; i++)
        {
          beep(1000, 100);
          delay(80);
        }

        delay(relDelay); //Release delay to warn about the magnet is about to be released

        //Switch magnet off
        digitalWrite(relayPin, LOW);
      }
    }
    else
    {
      if ((millis() - lastBlink) >= 60000 && waitTime != 4294967295)
      {
        beep(500, 50);
        lastBlink = millis();
      }
    }
  }
}
5 Comments

Add a Comment

Your email address will not be published. Required fields are marked *