Arduino atmega328p TIME BOMB movie prop

Hello world! Today i made a standalone Arduino atmega328p TIME BOMB movie prop with a relay. We are going to build our own arduino with this tutorial. This project is somehow more advanced on the electronics side! (You can leave the timer part and build something else to of course!)

AT FIRST:
We need to Burn the bootloader if there is no bootloader on your AtMega328p TIME BOMB movie prop yet!
Then we need to upload the code to the AtMega328p.
Follow this LINK (click) to find out how these 2 steps work.

Schematic:
TIME BOMB movie prop

Datasheet/pinout:
TIME BOMB movie prop

MAKE SURE YOU HAVE THE LIBRARY INSTALLED SevenSeg.h SevenSeg.zip
BEWARE that there are common cathode and common anode displays.< //Only for common cathode 7segments disp.setCommonCathode(); <--- just comment this in the code when using common anode.
Simply wire everything up like the schematic. It should work fine after uploading the code.

Parts list:
Atmega328p Microcontroller
16 Mhz Crystal
220 K resistor
Transistor L7805CV
4 x push button
2x 1 Digit 7 Segment Display
2x Capacitor 10uF
2x Ceramic Capacitor 22pF
Jumper wire Set MM/FF/MF
KY-019 Relay Module
Arduino uno to program your Atmega328p

Good luck building your TIME BOMB movie prop

Code:

/*   Arduino two digit 7 Segment Display Counterdown Timer
  Dev: Michalis Vasilakis // Date: 30/3/2016 // Ver.1
  Find more info at www.ardumotive.com          */

//Library
#include "SevenSeg.h"

//Seven Seg
SevenSeg disp (10,9,8,7,6,11,12); //Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
const int numOfDigits =2;       //number of 7 segments
int digitPins [numOfDigits]={4,5};  //CC(or CA) pins of segment
int relay = A3;
//Constants
const int startBT = 2;
const int changeBT = 3;
const int setBT = 13;
const int dotPoint1=A0; //left digit
const int dotPoint2=A1; //right digit
//Variables
String number="00";
int digit1=0;
int digit2=0;
int start, change, set;
int setPoint=0;
int countdown;
//Useful flags
boolean countFlag=false;

void setup()
{
  pinMode(startBT, INPUT_PULLUP);
  pinMode(changeBT, INPUT_PULLUP);
  pinMode(setBT, INPUT_PULLUP);
  pinMode(dotPoint1, OUTPUT);
  pinMode(dotPoint2, OUTPUT);
  pinMode(relay, OUTPUT);
  //Defines the number of digits to be "numOfDigits" and the digit pins to be the elements of the array "digitPins"
  disp.setDigitPins ( numOfDigits , digitPins );
  //Only for common cathode 7segments
  disp.setCommonCathode();
  //Control brightness (values 0-100);
  disp.setDutyCycle(60);
  disp.setTimer(2);
    disp.startTimer(); 
}

void loop()
{
  //Read buttons state
  start = digitalRead(startBT);
  change = digitalRead(changeBT);
  set = digitalRead(setBT);
  
  
  if (set == LOW && !countFlag){
    delay(500);
    if (setPoint<2){
      setPoint++;
    }
    else{
      setPoint=0;
    }
  }
  
  //Start counting...
  if (start == LOW && setPoint==0
  ){
    delay(500);
    if (!countFlag){
      countFlag=true;
      countdown = number.toInt();
    }
    else{
      countFlag=false;
    }
  }
  if (change == LOW && setPoint == 1 && !countFlag){
    delay(500);
    if (digit1<9){
      digit1++;
    }
    else{
      digit1=0; 
    }
    number=String(digit2) + String(digit1);
  }
  if (change == LOW && setPoint == 2 && !countFlag){
    delay(500);
    if (digit2<9){
      digit2++;
    }
    else{
      digit2=0; 
    }
    number=String(digit2) + String(digit1);
  }
  //Control dot points
  if (setPoint==0){
    digitalWrite(dotPoint1,LOW);
    digitalWrite(dotPoint2,LOW);
  }
  else if (setPoint==1){
    digitalWrite(dotPoint1,HIGH);
    digitalWrite(dotPoint2,LOW);
  }
  else if (setPoint==2){
    digitalWrite(dotPoint1,LOW);
    digitalWrite(dotPoint2,HIGH);
  }
  //////////Counter Control///////////
  if (countFlag){
    if (countdown>0 && countdown<=10){
      countdown--;
      delay(1000);
      disp.write("0"+String(countdown));
    }
    else if (countdown>10){
      countdown--;
      delay(1000);
      disp.write(String(countdown));
    }
    else if (countdown==0){
      disp.write("00");
      delay(500);
      disp.write(" ");
      digitalWrite(relay,HIGH); 
      delay(5000); 
    }
  }
  else{
    disp.write(number);

  }
  
}

ISR( TIMER2_COMPA_vect ){
 disp.interruptAction ();
 }
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

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