I have a student developing a simple project with an ultrasonic sensory to detect if a person is within 1.5m and use a buzzer as an alert and displays distance on an lcd. The student is using Tinkercad Circuit to develop and run code through it's simulator.
Here is a link to a copy of the project:
https://www.tinkercad.com/things/6HoZrWLPQkb-copy-of-final-hopefully-ist-project/editel?sharecode=-DuP-4e8Dw3ZuAGRJSravzEZQiM67JGHKrLkQb7Q4Oc
There are no errors but the code seems to stop on line 44.
Any help would be appreciated. Sorry i've copied and pasted text in but I can't see the '#' tool icon to paste the code to.
#include <LiquidCrystal.h>
#define ECHO 10
#define TRIGGER 9
float time =0;
float distance = 0;
LiquidCrystal lcd(12,11,5,4,3,2);
int num=1;
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 0;
// defines variables
long duration;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Inputer
pinMode (buzzer, OUTPUT); //Makes the buzzer an output
Serial.begin(9600); // Starts the serial communication
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
lcd.begin(16, 2);
lcd.print("COVID");
delay(2000);
lcd.clear();
lcd.print("Social Distance");
delay(2000);
lcd.clear();
lcd.print("1.5 Metres");
delay(2000);
}
void loop() {
lcd.clear();
digitalWrite(TRIGGER, HIGH);
delay(2);
digitalWrite(TRIGGER, LOW);
time = pulseIn(ECHO,HIGH);
distance = 0.01716*time;
Serial.println(time);
lcd.setCursor(5,0);
lcd.print(float(distance/100));
lcd.setCursor(11,0);
lcd.print("m");
delay(1000);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.println(distance);
if (distance < 150)
{
digitalWrite(buzzer, HIGH);
lcd.print("Social Distance! At least 1.5m!!!!");
}
else
{
digitalWrite(buzzer, LOW);
lcd.print("Great work! Stay safe & wear a mask");
}
}