Introduction: Intel Edison Simple Distance Sensor With Grove LED Bar Indicator and Buzzer

This is my first and "really" simple project that i made using Intel Edison. This "simple" project will measure distance using ultrasonic sensor and the LED bar will show how far the distance is, and the buzzer will buzz depend on the distance. First time i learn using ultrasonic and buzzer from the tutorial from and in this project, i'm modifying a few code from his project :

This Project by flynn_munroe

Back to the topic, there is The main advantage of using Intel Edison + Breakout Board instead of using Arduino is :

  • Intel Edison ROM's for storing code is relatively big rather than Arduino.
  • When uploading code to Edison, it's so much faster than Arduino.
  • etc

My "simple" project called "Intel Edison Simple Distance Sensor with LED Bar Indicator and Buzzer", this project can be implemented also with Arduino UNO R3. So let's just begin with first step, preparing all the stuff we need.

Step 1: Preparing All the Suffs

Ok, let's prepare the parts we need and there is one parts i received from the Intel Edison IoT Invitational (Thanks to Audrey and Intel). The part is LED Bar, it's not necesarry for us to use the Grove Base Shield, just read the wiki in Here.

Parts :

  1. Intel Edison
  2. HC SR04 Ultrasonic Sensor
  3. Grove LED Bar
  4. Piezzo Buzzer
  5. Breadboard
  6. A few Male-to-male Jumper

Step 2: Let's Assemble Those Stuff

So first of all you need to assemble the sensor, LED bar, buzzer to the Intel Edison's GPIO. The arrangement are :

  • Ultrasonic Sensor :
    • Trigger : Pin : 11
    • Echo : Pin 12
  • Buzzer : Pin 2
  • Grove LED Bar :
    • Clk : Pin 9
    • Dio (Data Pin) : Pin 8

Actually there is 3 pins in Ultrasonic Sensor and Grove LED Bar, the last pin is Vcc, u have to connect it to 5v pin on Intel Edison. I also attached the Schematic Pin, but i'm sorry for the messy image, you just have to follow the line color.

Step 3: Let's Code !

Now is time for the coding section. Open up your Arduino IDE which has a Intel Edison board in the board select menu.

Inside this code, you have to include a LED Bar library which called "Grove_LED_Bar.h" that provided by the awong1900 to make the LED Bar working, because i couldn't find any schematic for Grove LED Bar to use it manually. You can download the library from Here.

If you don't know how to add a new library that downloaded from a Github web, i will show you how :

  1. Click the "Download ZIP" button on the right of the page.
  2. Inside Arduino IDE, just Click Sketch > Include Library > Add .ZIP Library
  3. Your library is Ready.

After u done inserting the library, here we go the code :

Library Section & Defining Pins

#include <Grove_LED_Bar.h> // Include the GROVE LED Bar Library
#define trigPin 11 // Define the trigger pin for the Ultrasonic Sensor #define echoPin 12 // Define the echo pin for the Ultrasonic Sensor #define buzzer 2 // Define Buzzer Pin
Grove_LED_Bar bar(9, 8, 0);  // Clock pin, Data pin, Orientation

Setup Part

void setup() {
Serial.begin (9600); bar.begin(); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); }

Main Program

void loop() {
  long distance, oldDist, duration;
  int nyala, sound;
  
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  // LED Bar calculation
  nyala = distance/3; // a variable to store how many bar will ON in distance
  bar.setLevel(nyala);
  // Buzzer sound calculation
  sound = (140 + (distance/2));
 
  if (distance > 30 || distance <= 0)
  {
    Serial.println("Out of range");
    noTone(buzzer);
  }
  else 
  {
    Serial.print(distance);
    Serial.println(" cm");
    tone(buzzer, sound);
  }
}

Step 4: Voilla ! Try Your "Simple" Project

This is the final step of the "simple" project, a Testing phase. Just get some paper and try to measure the distance you want in front of the Ultrasonic Sensor. The buzzer will buzz with a different note when the distance is change, also the LED bar.

Thank you