Need help with thinkercad supersonic sensor

hi, i'm trying to get this project to work on thinkercad... GitHub - Abdelrahman1810/People-Counter-Arduino-UltrasonicSensors: This project is a simple people-counting system that uses ultrasonic sensor, an Arduino board, and an LCD display to count the number of people passing through a specific location. The system is designed to be easy to set up and use, making it a great solution for a variety of applications such as retail stores, libraries, museums, and more.

I have connected it like in the project description, but i dont get anything on the lcd screen (im very noob)

Hello @ticsy

Would you post your sketch in text form, inside your message, formatted, using the < CODE > button?

Verify your Arduino is properly powered.

Try using "Serial.println();" to view the data in your serial monitor... and if you see the data in the Serial Monitor, then verify all connections.

here it is: `#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,1);
#define trig 6
#define echo 7
int t_puls = 0, distance = 0, No_people = 0;
int initial_distance = 400;
const int sound_speed = 57; // you can change it depend on the weather

void setup() {
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);

// making puls with width 10µs to Trigger
for(int i=0; i<3; i++)
{
delayMicroseconds(i*5);
digitalWrite(trig, i%2);
}

t_puls = pulseIn(echo, HIGH);
distance = t_puls / sound_speed;
initial_distance = distance;
Serial.println(initial_distance);

lcd.begin(16, 2);
lcd.backlight();

lcd.setCursor(5,0);
lcd.print("Hello");
delay(1500);
lcd.clear();

lcd.setCursor(2,1);
lcd.print("Person passed");
}

void loop() {

// making puls with width 10µs to Trigger
for(int i=0; i<3; i++)
{
delayMicroseconds(i*5);
digitalWrite(trig, i%2);
}
t_puls = pulseIn(echo, HIGH);
distance = t_puls / sound_speed;
delay(100);

if(distance <= initial_distance - 30) // you can change distance 30 depend on the position of the sensor
{
while(distance != initial_distance)
{
for(int i=0; i<3; i++)
{
delayMicroseconds(i*5);
digitalWrite(trig, i%2);
}
t_puls = pulseIn(echo, HIGH);
distance = t_puls / sound_speed;
delay(50);
}
No_people++;
}
lcd.setCursor(8,0);
lcd.print(No_people);
}`

i dont get annything on serial monitor :frowning:

did you click on the sensor to move the 'object' once you started the simulation?
are you sure the LCD you selected is the I2C type?

maybe try this one... its already all wire up and works! :wink:

you can then check what the difference with yours!

hope that helps....

  • why not use the conventional method for generating a pulse
  digitalWrite      (pingPin, HIGH);
  delayMicroseconds (10);
  digitalWrite      (pingPin, LOW);

  duration = pulseIn (pingPin, HIGH);
  distance = duration * 0.034 / 2;
  • don't understand the need for the while loop in your code since loop() is repeatedly called
  • there's a test for distance <= initials_distance but then there's a test for distance != initial_distance that is likely to always be true

since each iteration of loop() measures the distance to the nearest object, why not have a test if the distance is < some threshold and increment the count on each transition from the distance being less than the threshold by keeping track of the previous distance

look this over


const byte  trig = 6;
const byte  echo = 7;

const int Threshold = 60;       // cm
boolean   inRange   = false;

int       count;


void loop ()
{
    // generate pulse
    digitalWrite      (trig, HIGH);
    delayMicroseconds (10);
    digitalWrite      (trig, LOW);

    // compute distance from pulse echo
    long duration = pulseIn (echo, HIGH);
    int  distance = duration * 0.034 / 2;

    // check for something within range
    if (distance < Threshold)  {
        if (! inRange) {
            count++;
            Serial.println (count);
        }
        inRange = true;
    }
    else
        inRange = false;
}


void setup () {
    Serial.begin (9600);

    pinMode (trig, OUTPUT);
    pinMode (echo, INPUT);
}

In your IDE, click the "spyglass" (serial monitor icon) in the upper-right to open the serial monitor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.