user52664: I was trying to use ultrasonic with digispark Attiny85 board and used separate pins for trigger and echo, and used MM5451 led controller as a display, I uploaded the code successfully the problem is if the echo pin is connected to it at startup board stops/freezes I don't know but code doesn't work, and if I connect the echo pin few seconds after the board starts everything works fine.
Below is the code I wrote
#define clock 0
#define data 1
#define trig 2
#define echo 3
byte c[5]={10,11,11,0,12};
long dist=0;
const uint8_t digits[15]={
    B1110111,
    B1000100,
    B1101011,
    B1101110,
    B1011100,
    B0111110,
    B0111111,
    B1100100,
    B1111111,
    B1111110,
    B0111011,
    B0010011,
    B1011101,
    B0111001,
    B0000000
};
void setup()
{
    pinMode(clock,OUTPUT);
    pinMode(data,OUTPUT);
    pinMode(trig,OUTPUT);
    pinMode(echo,INPUT);
    digitalWrite(clock,LOW);
    digitalWrite(data,LOW);
    digitalWrite(trig,LOW);
}
void pulse()
{
    delayMicroseconds(5);
    digitalWrite(clock,HIGH);
    delayMicroseconds(10);
    digitalWrite(clock,LOW);
    delayMicroseconds(5);
}
long ultrasonic(boolean ci)
{
    long distance;
    unsigned long pulsetime;
    digitalWrite(trig,LOW);
    delayMicroseconds(5);
    digitalWrite(trig,HIGH);
    delayMicroseconds(10);
    digitalWrite(trig,LOW);
    pulsetime=pulseIn(echo,HIGH);
    if(ci)
    {
        distance=pulsetime/58;
    }
    else
    {
        distance=pulsetime/148;
    }
    delay(50);
    if((distance<450)&&ci)
    {
        return distance;
    }
    else if((distance<180)&&(!ci))
    {
        return distance;
    }
    else
    {
        return 0;
    } 
}
void show(byte a[5])
{
    delayMicroseconds(5);
    digitalWrite(data,HIGH);
    pulse();
    for(byte x=0;x<5;++x)
    {
        byte data1=digits[a[x]];
        for(byte y=0;y<7;++y)
        {
            if(data1&(1<<y))
            {
              digitalWrite(data,HIGH);
                pulse();
            }
            else
            {
                digitalWrite(data,LOW);
                pulse();
            }
        }
    }
    digitalWrite(data,LOW);
    pulse();
}
void loop()
{
    show(c);
    delay(2000);
    while(1)
    {
        dist=ultrasonic(true);
        if(dist>0)
        {
            byte i=3;
            c[4]=14;
            c[0]=14;
            c[1]=14;
            c[2]=14;
            c[3]=14;
            while(dist>0)
            {
                c[i]=(dist%10);
                if(i==0)
                {
                    i=4;
                }
                dist/=10;
                --i;  
            }
            show(c);
        }
        delay(200);
    }  
}


user2881: Pins 3 and 4 are used for USB (during programming). Try using pin 5 instead. 
Or swap it with one of the clock, data, or trig outputs (i.e. 0,1,2)

52664: <p>I was trying to use ultrasonic with digispark Attiny85 board and used separate pins for trigger and echo, and used MM5451 led controller as a display, I uploaded the code successfully the problem is if the echo pin is connected to it at startup board stops/freezes I don't know but code doesn't work, and if I connect the echo pin few seconds after the board starts everything works fine.</p>

<p>Below is the code I wrote</p>

<pre><code>#define clock 0
#define data 1
#define trig 2
#define echo 3
byte c[5]={10,11,11,0,12};
long dist=0;
const uint8_t digits[15]={
    B1110111,
    B1000100,
    B1101011,
    B1101110,
    B1011100,
    B0111110,
    B0111111,
    B1100100,
    B1111111,
    B1111110,
    B0111011,
    B0010011,
    B1011101,
    B0111001,
    B0000000
};
void setup()
{
    pinMode(clock,OUTPUT);
    pinMode(data,OUTPUT);
    pinMode(trig,OUTPUT);
    pinMode(echo,INPUT);
    digitalWrite(clock,LOW);
    digitalWrite(data,LOW);
    digitalWrite(trig,LOW);
}
void pulse()
{
    delayMicroseconds(5);
    digitalWrite(clock,HIGH);
    delayMicroseconds(10);
    digitalWrite(clock,LOW);
    delayMicroseconds(5);
}
long ultrasonic(boolean ci)
{
    long distance;
    unsigned long pulsetime;
    digitalWrite(trig,LOW);
    delayMicroseconds(5);
    digitalWrite(trig,HIGH);
    delayMicroseconds(10);
    digitalWrite(trig,LOW);
    pulsetime=pulseIn(echo,HIGH);
    if(ci)
    {
        distance=pulsetime/58;
    }
    else
    {
        distance=pulsetime/148;
    }
    delay(50);
    if((distance&lt;450)&amp;&amp;ci)
    {
        return distance;
    }
    else if((distance&lt;180)&amp;&amp;(!ci))
    {
        return distance;
    }
    else
    {
        return 0;
    } 
}
void show(byte a[5])
{
    delayMicroseconds(5);
    digitalWrite(data,HIGH);
    pulse();
    for(byte x=0;x&lt;5;++x)
    {
        byte data1=digits[a[x]];
        for(byte y=0;y&lt;7;++y)
        {
            if(data1&amp;(1&lt;&lt;y))
            {
              digitalWrite(data,HIGH);
                pulse();
            }
            else
            {
                digitalWrite(data,LOW);
                pulse();
            }
        }
    }
    digitalWrite(data,LOW);
    pulse();
}
void loop()
{
    show(c);
    delay(2000);
    while(1)
    {
        dist=ultrasonic(true);
        if(dist&gt;0)
        {
            byte i=3;
            c[4]=14;
            c[0]=14;
            c[1]=14;
            c[2]=14;
            c[3]=14;
            while(dist&gt;0)
            {
                c[i]=(dist%10);
                if(i==0)
                {
                    i=4;
                }
                dist/=10;
                --i;  
            }
            show(c);
        }
        delay(200);
    }  
}
</code></pre>
 2881: <p>Pins 3 and 4 are used for USB (during programming). Try using pin 5 instead. </p>

<p>Or swap it with one of the clock, data, or trig outputs (i.e. 0,1,2)</p>
