Days Since Counter

by Rafi-N in Circuits > Microcontrollers

100 Views, 1 Favorites, 0 Comments

Days Since Counter

PXL_20230117_184652639.jpg
PXL_20230125_184455484.jpg
PXL_20230117_184717108.MP.jpg
Accident Counter Resetting
Accident counter Timelapse

This instructable shows how to make a Wheel base counter for the number of days since an event. My example counts the days since the last acident in my kitchen but yours can count whatever you would like.

Supplies

Tools:

  • wire cutter/stripper
  • Hot glue Gun and hot glue
  • Utility Knife
  • Soldering Iron and solder
  • Sharpie

Materials: ($122.50)

  • 2 28byj-48 Stepper Motors with 2 ULN 2003 Motor Controllers (Link)-----5pcs $15
  • 1 Particle Argon Microcontroller (Link-----------------------------------------------$30
  • 1 830 Pin Breadboard (Link)----------------------------------------------------------3Pcs $10
  • 5 Light Neopixel Strip (Link)-----------------------------------------------------------$20 for 16 ft
  • 1 1000 Micro Farad Capacitor (Link)------------------------------------------------10pcs $5
  • 1 button (Link) ----------------------------------------------------------------------------20pcs $10
  • 1 DC barrel Jack adapter for breadboards (Link)--------------------------------$1.5 each
  • 1 5V Wall Wart (Link)--------------------------------------------------------------------$8
  • 3 18in pieces of 22AWG Solid Core wire (Link)-----------------------------------6 spools $16
  • Jumper Wires (Link)---------------------------------------------------------------------120pcs $7

Building the Box and Wheels

PXL_20230125_184350443.jpg
PXL_20230125_184318067.jpg

Cut the Cardboard into the following pieces (measurements in inches)

  • 1 11.5 x 11.5
  • 4 11.5 x 6

Assemble the pieces into a five sided box as shown in the image


Then cut two, 4.25 diameter circles. These will be the counting wheels for each section.


once you have these circles cut use a protrctor to devide each circle into ten equal sections. Number the circles 0-9 moving clockwise

Mount the Steppers

PXL_20230125_184818767.jpg
PXL_20230125_185351010.jpg

draw 2 points on the box 3.75 inches from each side and 5.5 inches from the top on the front of the box. tese will serve at the center point for the steppers.


linning up the center of the stepper pins with the dots, trace arountd the edge of the stepper motor. Once you have donte this for each side use a utility knife to cut around your outlines.

Once you have your outlines cut, you can place the steppers in the holes feeding the wire through first so they come out inside the box.


Now gently push the wiring harnesses from the stepper into the stepper controllers

Neopixel Asembly and Mounting

PXL_20230125_185137507.jpg

Cut a 5 light strip of the neopixel lights

carefully solder 3 wires onto each of the copper pads on the neopixels

Note: Make sure the solder does not connect any of the wires together or they will short


Once the solder has cooled place the lights across the top of the box using double sided tape. cut a hole for the wires to feed into the box.

Set Up the Breadboard

PXL_20230117_184717108.MP.jpg
Screenshot 2023-01-26 204802.png

Wire the components using the imge above for refrence. The stepper motor for the 1s digit gets conncted to controller 1 and the steper for the 10s digit gets connected to controller 2

Set Up the Code

Start by importing the libraries needed for the project:

  • Particle.h
  • neopixel.h
  • Stepper.h
Then add the code bellow:
//includes
  #include "Particle.h"
  #include "neopixel.h"
  #include <Stepper.h>
   

  int day;
  int button = 8;
  int lockout;
  int i;
//stepper values
  int ones = 0;
  int tens = 0;
//stepper values
  const int tenthrev = 204.8;
  const int stepsPerRevolution = 2048;
//define stepper pins
  #define IN1 A5
  #define IN2 A4
  #define IN3 A3
  #define IN4 A2
  #define IN5 D5
  #define IN6 D4
  #define IN7 D3
  #define IN8 D2

//define the steppers
  Stepper Stepper1(stepsPerRevolution, IN1, IN3 , IN2, IN4);
  Stepper Stepper2(stepsPerRevolution, IN5, IN7 , IN6, IN8);
   
// Set pixel COUNT, PIN and TYPE
  #define PIXEL_COUNT 5
  #define PIXEL_PIN D7
  #define PIXEL_TYPE WS2812B
//definie neopixel
  Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() {
// defining variables
  day = Time.day();

//sets loop iterator to 0
  i = 0;

//button pinmode and lockout variable
  pinMode(button, INPUT_PULLUP);
  lockout = 0;

//initialise neopixels and set them blank
  strip.begin();
  strip.show();
  
//stepper stuff
  Stepper1.setSpeed(17);
  Stepper2.setSpeed(17);
  Serial.begin(9600);
}

//this loop runs every secound
void loop() {
  //checks if its the next day every minute and if so increases counter
  if(i = 60) {
    if(Time.day() != day) {
    IterateCounter();
    //sets current day
    day = Time.day();
    }
    i = 0;
  }
   
//checks if button is being pressed
  int btnState = digitalRead(button);
  if((btnState == LOW) && (lockout <= 0)) {
    Emergency(2);
    ZeroCounter();
    Emergency(4);
    lockout = 30;
  }
   
  //lowers the lockout timer on the button
  if(lockout > 0){
    lockout--;
  }
  //iterates counter for day checker 
  i++;
  //makes the loop run every secound
  delay(1000);
}

//increases counter by 1 when called
void IterateCounter() {
  if(ones != 9){
    Stepper1.step(tenthrev);
    ones++;
    return;
  }
  else {
    Stepper1.step(tenthrev);
    ones = 0;
    Stepper2.step(tenthrev);
    tens ++;
    return;
  }
}

//zeros counter when called
void ZeroCounter() {
  for(int i=ones; ones < 10; ones++){
   Stepper1.step(tenthrev);
   delay(500);
 }
 ones = 0;
  
  
 for(int i=tens; tens < 10; tens++){
   Stepper2.step(tenthrev);
   delay(500);
 }
 tens = 0;
}

//flashes neopixels red in a back and forth pattern when triggered
void Emergency(int cycles) {
  for(int Q=0; Q < cycles; Q++) 
  {
  for(int i=0; i<strip.numPixels(); i+=2) {
  strip.setPixelColor(i, 255, 0, 0);
  }
  
  strip.show();
  delay(500);
  strip.clear();
  
  for(int i=1; i<strip.numPixels(); i+=2) {
  strip.setPixelColor(i, 255, 0, 0);
  }
   
  strip.show();
  delay(500);
  strip.clear();   
  }
  strip.clear();
  strip.show();
}

The Sign

PXL_20230125_184814423.jpg

hot glue a 10 x 3.5 piece of cardboard to the top of the project with whatever the project is to be counting

Final Touches

PXL_20230125_184634232.jpg

draw 2 arrows or other markers to indicate which part of the wheen the counter is pointed at. i used the top as you can see in the picture. Each time you power on the project you will have to make sure the dials are set to zero. speaking of which place the dials on the project with the zero at the arrow


TADA

PXL_20230117_184652639.jpg

Add any decorations that you would like and YOU'RE DONE!!