1 Reply Latest reply on Mar 11, 2015 6:15 PM by CMata_Intel

    Intel Edison + Arduino Breakout Board + Ultrasonic Sensor (HR-SC04)


      Hey all, I'm trying to use the Edison board with the ultrasonic sensor (HR-SC04).


      When I upload the code and test with small distances (4~40cm) everything goes perfect, but when I put my object further (60~150cm) the Edison freezes, stops blinking the LED, stops sending information to the Serial port and stops reading the ultrasonic sensors. I tried three different codes that I found on Internet and still happening the same thing. I also tested the codes on the Arduino MEGA 2560 and it works.

      Does someone know what might be happening?


      I was also curious if exists a library to read Ultrasonic Sensors on the Edison Board like the New_Ping library.



      Thank you!



      The code that I'm trying:

      #define ECHOPIN 7
      #define TRIGGERPIN 6
      #define US_ROUNDTRIP_IN 146     
      #define US_ROUNDTRIP_CM 57      
      #define NewPingConvert(echoTime, conversionFactor) (max((echoTime + conversionFactor / 2) / conversionFactor, (echoTime ? 1 : 0)))
      unsigned long pinStart;
      unsigned long pinEnd;
      void setup()
        pinMode(TRIGGERPIN, OUTPUT);
        pinMode(ECHOPIN, INPUT);
      void loop()
        while(digitalRead(ECHOPIN)==LOW){}; //waiting for the pin to trigger
        pinStart = micros();
        while(digitalRead(ECHOPIN)==HIGH){};//waiting for the pin to go low
        pinEnd = micros();
        unsigned int echoTime = pinEnd - pinStart;
        Serial.println(NewPingConvert(echoTime, US_ROUNDTRIP_IN));
        • 1. Re: Intel Edison + Arduino Breakout Board + Ultrasonic Sensor (HR-SC04)

          Hi martinianodl


          Take a look at the Shield Test Report In there you will find an example with the HR-SC04 sensor, try with that code and let us know the outcome.



          HC-SR04 for Arduino
          Original project from http://www.swanrobotics.com
          This project demonstrates the HC-SR
          The distance presented in the code is in mm, but you can uncomment the line for distance in inches.
          The schematics for this project can be found on http://www.swanrobotics.com
          This example code is in the public domain.
          const int TriggerPin = 8; //Trig pin
          const int EchoPin = 9; //Echo pin
          long Duration = 0;
          void setup(){
          pinMode(TriggerPin,OUTPUT); // Trigger is an output pin
          pinMode(EchoPin,INPUT); // Echo is an input pin
          Serial.begin(9600); // Serial Output
          void loop(){
          digitalWrite(TriggerPin, LOW);
          digitalWrite(TriggerPin, HIGH); // Trigger pin to HIGH
          delayMicroseconds(10); // 10us high
          digitalWrite(TriggerPin, LOW); // Trigger pin to HIGH
          Duration = pulseIn(EchoPin,HIGH); // Waits for the echo pin to get high
          // returns the Duration in microseconds
          long Distance_mm = Distance(Duration); // Use function to calculate the distance
          Serial.print("Distance = "); // Output to serial
          Serial.println(" mm");
          delay(1000); // Wait to do next measurement
          long Distance(long time)
          // Calculates the Distance in mm
          // ((time)*(Speed of sound))/ toward and backward of object) * 10
          long DistanceCalc; // Calculation variable
          DistanceCalc = ((time /2.9) / 2); // Actual calculation in mm
          //DistanceCalc = time / 74 / 2; // Actual calculation in inches
          return DistanceCalc; // return calculated value