Porter MurphyBlake Lilly
Published © GPL3+

Advanced Distance Telemetry System (ADTS)

If your phone, watch, house, and lights can be online, why can't your tape measure? The ADTS provides a wifi enabled measurement system.

IntermediateFull instructions provided78
Advanced Distance Telemetry System (ADTS)

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×2
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
ELEGOO 37-in-1 Sensor Module Kit V1.0
ELEGOO 37-in-1 Sensor Module Kit V1.0
Parts used: Laser Emitter, Ultrasonic Sensor, LCD screen, Button
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Darlington High Power Transistor
Darlington High Power Transistor
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

CAD Drawing of Box

Schematics

Circuit Diagram

Code

LCD/Button Photon Code

C/C++
This code takes the measurement data and displays it on the LCD screen, and takes the inputs from the button and sends them to the other photon to start/stop measurement.
// This #include statement was automatically added by the Particle IDE.
#include "LiquidCrystal/LiquidCrystal.h"

LiquidCrystal lcd(5, 4, 3, 2, 1, 0);
int receivedValue = 0;
int buttonPin = D8;
int buttonState = 0;

void setup() {
    pinMode(buttonPin,INPUT_PULLDOWN);
    lcd.begin(16, 2);
    lcd.clear();
    Particle.variable("buttonState", buttonState);
    Particle.subscribe("sensorData", myHandler, MY_DEVICES);
}

void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == LOW){
    Particle.publish("buttonState",String(1),PRIVATE);
} else { 
    Particle.publish("buttonState",String(0),PRIVATE);
    lcd.clear();
    int receivedValue = 0;
}
    delay(200);
}
    
void myHandler(const char *event, const char *data) {
    receivedValue = atoi(data);

    if (receivedValue == 0){
        lcd.clear();
    } else {
        if (receivedValue <= 3 || receivedValue >= 400){
            lcd.clear();
            lcd.print("Out of Bounds");
            int receivedValue = 0;
        
        } else {
            lcd.setCursor(0, 0);
            lcd.print("Distance: ");
            lcd.print(receivedValue);
            lcd.setCursor(13,0);
            lcd.print("cm");
            int receivedValue = 0;
        }
    delay(700);
    //lcd.clear();
    int receivedValue = 0;
    }
delay(500);
}

Measurement/Sensor Code

C/C++
This code takes the signal from the button to start/stop measurement and takes data from the ultrasonic sensor and sends it to the other photon to be displayed on the LCD screen.
// Define pins for the ultrasonic sensor
const int trigPin = D5;
const int echoPin = D6;
int laser = D0;
//int buttonPin = D8;
int recievedButtonState = 0;

// Variables to store the distance and duration
long duration;
int distance;

void setup() {
    //pinMode(buttonPin,INPUT);
    pinMode(laser,OUTPUT);
    pinMode(D7,OUTPUT);
    Particle.subscribe("buttonState", myButtonHandler, MY_DEVICES);
    Particle.variable("sensorValue", distance);
    
        // Set trigPin as OUTPUT and echoPin as INPUT
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    
        // Initialize serial communication
    Serial.begin(9600);
}   

void myButtonHandler(const char *event, const char *data) {
         recievedButtonState = atoi(data);
    //int buttonState = digitalRead(buttonPin);
    if (recievedButtonState == 1){
        digitalWrite(laser,HIGH);
        digitalWrite(trigPin,LOW);
        delayMicroseconds(2);
        digitalWrite(trigPin,HIGH);
        delayMicroseconds(10);
        digitalWrite(trigPin,LOW);
        
        // Measure the duration of the pulse on the echoPin
        duration = pulseIn(echoPin, HIGH);

        // Calculate the distance based on the speed of sound
        distance = duration * 0.034 / 2;
    
    Particle.variable("sensorValue", distance);
    Particle.publish("sensorData", String(distance), PRIVATE);

    delay(1000);  // Adjust delay as needed
    int recievedButtonState = 0;
    } else if (recievedButtonState == 0){
        digitalWrite(laser,LOW);
    }
    int recievedButtonState = 0;
    delay(500);
}

Credits

Porter Murphy
1 project • 1 follower
Blake Lilly
0 projects • 1 follower

Comments