PING With Two 7 Segment LED Displays.

Published

Introduction: PING With Two 7 Segment LED Displays.

About: 18 y/o guy with huge ambitions

Hello Guys!
moxigen here. I got two new 7 segment LED displays, and I was pretty much excited to use them. I decided to multiplex them and use them with parallax ping(HC-SR04).

Step 1: Materials Required

You would require the following:

1. 2 x 7 Segment LED displays(common cathode)

2. 1 x HC-SR04 distance sensor (four pin)

3. Arduino Mega 2560( or any prototype)

4. small breadboard

5. Jumper Wires

Step 2: Assemble It!

remember that you're gonna have to multiplex the two displays, so use normal wires( no matter if they're naked, just make sure they don't touch each other) to connect the two displays and finally to the Arduino.
And I'm really sorry for the untidiness in the drawings.

Step 3: The Code

#include "SevSeg.h" 

SevSeg sevseg; 

int refreshTime = 1000;
int pingPin = 14; //10 
int inPin = 15; //9 
long duration, inches, cm;
int indec, cmdec;
int inchconv = 147; 
int cmconv = 59; 
unsigned long timer;

void setup() {
  sevseg.Begin(0,2,3,4,5,6,7,8,9,10,11,12,13);
  pinMode(pingPin, OUTPUT);
  pinMode(inPin, INPUT);
}

void loop()
{sevseg.PrintOutput(); 
    digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);
  
  duration = pulseIn(inPin, HIGH);
    inches = microsecondsToInches(duration);
  indec = (duration - inches * inchconv) * 10 / inchconv;
  cm = microsecondsToCentimeters(duration);
  cmdec = (duration - cm * cmconv) * 10 / cmconv;
  unsigned long mils=millis(); 
if (mils-timer>=refreshTime) { 
timer=mils; 

sevseg.NewNum(cm,(byte) 2); 
}
}

long microsecondsToInches(long microseconds)
{
  return microseconds / inchconv;
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / cmconv;
}

Step 4: Acknowledgements

Thank you to ya all for viewing this instructable. I'm really open to criticism, so feel free to comment.

please follow my Instagram account if possible: moxigen.

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Clocks Contest

      Clocks Contest
    • Water Contest

      Water Contest

    3 Discussions

    how to connect to arduino?

    OK, so where are the code?

    I mean, I don't exactly need a code.

    But I don't know how to use the multiplexed 7 segment to display different digits on different displays?

    1 reply

    Dude I am so sorry I didn't upload code however I edited it and you can have a look at it now