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 :
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.
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 :
So first of all you need to assemble the sensor, LED bar, buzzer to the Intel Edison's GPIO. The arrangement are :
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.
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 :
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);
}
}