Scott CapehartEsaI Torres-Tarango
Published

Digital Measuring Tape

Our IoT project utilizes ultrasonic sensor technology to create a modern-day measuring tape.

IntermediateWork in progressOver 2 days1,063
Digital Measuring Tape

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Argon
Particle Argon
×2
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Breadboard (generic)
Breadboard (generic)
×1
Light Switch
×1
Wire, Magnet
Wire, Magnet
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Fritzing

Hand tools and fabrication machines

Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires

Story

Read more

Schematics

Ultrasonic Schematic

Switch Schematic

Code

Ultrasonic particle code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Grove-Ultrasonic-Ranger.h>

const int trigPin = A2;
const int echoPin = D5;
int lastSecond = 0;
float inches;
unsigned long duration;
int distanceCm, distanceInch;
Ultrasonic ultrasonic(D4);          // Ultrasonic object constructor

	long RangeInCentimeters; 
void setup()
{
	Serial.begin(9600);             // Begin serial communications
  	Particle.subscribe("status", "on", PUBLIC);
  // Set the trigger pin as an output and the echo pin as an input
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT_PULLDOWN);
}

void loop()
{
	RangeInCentimeters = ultrasonic.MeasureInCentimeters();     // Get the current distance value
	Serial.print(RangeInCentimeters);                           // Out put the value over serial
	Serial.println(" cm"); // use 'particle serial monitor --follow' in the CLI to see serial output
	  digitalWrite(trigPin, LOW);
  delay(2);
  digitalWrite(trigPin, HIGH);
  delay(10);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(100);
	Particle.publish("Distance", String(inches), PUBLIC);
  Serial.print("Distance: ");
  Serial.print(inches);
  Serial.println(" inches");
	delay(1000);                     // small delay, so the sensor has some time to do it's thing
}

Switch Code

C/C++
int switchPin = D2; // switch connected to digital pin 2
int ledPin = D4;   // LED connected to digital pin 4
float inches;
LiquidCrystal_I2C *lcd;

void setup() {
  pinMode(switchPin, INPUT); // set switch pin as input with internal pull-up resistor
  pinMode(ledPin, OUTPUT);          // set LED pin as output
   lcd = new LiquidCrystal_I2C(0x27, 16, 2);
  lcd->init();
  lcd->backlight();
  lcd->clear();
  lcd->print("Distance");
  Particle.subscribe("Distance", String(inches), PUBLIC);
}

void loop() {
    
    lcd->setCursor(0, 1);
  lcd->print("Dist: ");
  lcd->print(inches);
  lcd->print("inch");
	delay(100);
  int switchState = digitalRead(switchPin); // read switch state

  if (switchState == LOW) {    // if switch is pressed
    digitalWrite(ledPin, HIGH); // turn on LED
    Particle.publish("status", "ON",PUBLIC);  //subscribe to this mouse event.
    delay(1000);  //delay to prevent overloading the cloud communication.
  } else {                     // otherwise
    digitalWrite(ledPin, LOW);  // turn off LED
    Particle.publish("status", "OFF",PUBLIC);  //subscribe to this mouse event.
    delay(1000);  //delay to prevent overloading the cloud communication.
    
    
  }
  
}

Credits

Scott Capehart

Scott Capehart

1 project • 0 followers
EsaI Torres-Tarango

EsaI Torres-Tarango

0 projects • 1 follower

Comments