Smart Arduino Digital Meter with HC-SR04 and TM1637

1 37638 Medium

I made this project a few months ago and I wanted to share it with DFRobot friends.

 

There are quite a few distant meters made with Arduino, but this is a special one. Two reasons why this is special: First because it's made with a 328P chip with boot loader; Second because it has a push button that allows to give you in real time the delta distance of a measure.

 

Let me explain how it works:

 

- When switched on, the meter measures the centimeters distance from the meter to the front obstacle.

- At that point, pressing the push button, the meter does a reset to zero and moving it from the obstacle it measures the delta distance.

- The distance can be positive or negative depending if you move the meter closer of farer to the obstacle.

- The push button can be pressed at any time to reset the delta measure.

 

This function is handy for several applications. One of them is the measure of your height. I've applied to the device an old swipe card to the bottom that can be used to fix the device to the door frame. Look at the video for an example.

HARDWARE LIST
1 atmega328 chip
1 16Mhz Crystal
1 HC-SR04
1 4 Digit Display I2C TM1637
1 Capacitor 100nF
1 Led
1 Capacitor 22pF
1 FT232RL
1 Push Button normally open
1 Resistor 100k Ohm
1 Double side PCB board
1 4 battery holder AAA
4 AAA batteries
1 Case 6x10x3 CM
CODE
#include <NewPing.h>
#include <TM1637.h>
#include "OneButton.h"

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

// Instantiation and pins configurations
// Pin 3 - > DIO
// Pin 2 - > CLK
TM1637 tm(2, 3);
int i = 0;
int delta = 0;
int misura = 0;
OneButton button(A1, true);

void setup() {
  tm.init();
  button.attachClick(clicka);
  button.attachDoubleClick(doubleclick);
}

void loop() {
  button.tick();
  delay(50);                     
  delta = sonar.ping_cm();
  misura = i - delta;
  if (i > 0)
    tm.display (misura);
  else
    tm.display (delta);
  
}

void clicka() {
  i = delta;
//  tm.display (misura);
} 

void doubleclick()
{
  i = 0;
//  tm.display (0);
} 
projectImage
License
All Rights
Reserved
licensBg
1