Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
cstram
Published © GPL3+

Smart Arduino Digital Meter with HC-SR04 and TM1637

There are quite a few distant meters made with Arduino, but this is special as it gives you in real time the delta between two positions!

IntermediateFull instructions provided1,581
Smart Arduino Digital Meter with HC-SR04 and TM1637

Things used in this project

Hardware components

ATmega328
Microchip ATmega328
×1
16 MHz Crystal
16 MHz Crystal
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED (generic)
LED (generic)
×1
Display 4 digits I2C TM1637
×1
Capacitor 100 nF
Capacitor 100 nF
×1
Capacitor 22pF
×2
SparkFun USB to Serial Breakout - FT232RL
SparkFun USB to Serial Breakout - FT232RL
×1
6-pin Header & Gender Changer (5-pack)
Digilent 6-pin Header & Gender Changer (5-pack)
×1
Push button normally open
×1
Resistor 100k ohm
Resistor 100k ohm
×1
Double Side PCB board 3x7 CM
×1
Battery Holder AAA
×1
Batteries AAA
×4
Case 6x10x3 CM
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Drill / Driver, Cordless
Drill / Driver, Cordless

Story

Read more

Schematics

Smart Digital Meeter

Code

Smart Arduino Digital Meter

Arduino
Smart Arduino Digital Meter Sketch
#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);
} 

Credits

cstram
16 projects • 22 followers
Passionate about IT, Electronics and DIY. Strong believer in Raspberry and Arduino devices. Experience in digital television and security.
Contact

Comments

Please log in or sign up to comment.