- Due to the move to our new headquarters, shipments will not be processed on Friday October 3th. Please, for any urgent matters, process your order prior October 2th. -
libelium
  • rss
  • flickr
  • instagram
  • twitter
  • facebook
  • youtube

Example Hack: Ultrasound Parking Sensor

Contents:

Introduction

Cook-Hacker: Marcos Yarza (hardware designer from Libelium Team).

Ingredients:

Difficulty: Medium -medium

Preparation Time: 30 minutes

parking_sensor
 

Steps Index

Steps Index:

  1. The system.
  2. The sensor.
  3. The LEDs.
  4. Communication between Arduinos.
  5. Code.
  6. Photos.

Step 1: The system:

Parking my car is quite more easy now with my Arduino parking sensor.

An ultrasound sensor with Arduino and XBee shield in the back part of the car for measuring the distance from the car to the obstacles. Inside the car another Arduino with XBee shield will get data from the other and displays the distance to the obstacle using an LEDs bar.

Step 2: The sensor:

The sensor I use for measuring the distance is an ultrasound sensor.

We use the analog output of the sensor connected to ANALOG 0 in Arduino.

This sensor is connected to Arduino using three cables:

  • Red => 5V
  • Black => GND
  • White => Signal
parking_sensor parking_sensor

Step 3: The LEDs:

The LEDs bar is made with 5mm LEDs soldered in a prototyping board, the connection to Arduino is made with a 220 ohm resistor (each LED). Each LED is connected to a digital output in Arduino.

parking_sensor parking_sensor

Step 4: Communication between Arduinos:

For the communication between the Arduinos I'm using XBee modules connected to Arduino using the XBee shield. Using the transparent mode we don't have to set-up any parameter of the Xbee's, just to communicate with Arduino using 9600 bps.

parking_sensor

The system is very simple, one of the Arduinos sends data and the other Arduino receives those data and make anything with they.

As you can see in the code, the Arduino with the sensor reads the value of the distance and sends that value each second using the XBee radio to the other Arduino, this one controls the LED's bar according to that value.

This is an example of a simple sensor network using the Xbee module.

NOTE:

The electronic diagrams in this example have been made using Fritzing, an open-source initiative to support designers, artists, researchers and hobbyists to work creatively with interactive electronics.

The Cooking Hacks Team has developed libraries of all our arduino modules (GPS, GPRS, MicroSD, XBee, RFID, Bluetooth, Solar, ...). Fell free to download and use them with Fritzing when developing your own recipes for the Cooking Hacks community!

>> Download Fritzing Libraries for the Cooking Hacks Arduino Modules.

Step 5: Code:

Arduino code:

// Arduino_1_leds

int LED0 = 12;
int LED1 = 11;
int LED2 = 10;
int LED3 = 9;
int LED4 = 8;
int LED5 = 7;
int LED6 = 6;

int blink_state = 0;

void setup(){

Serial.begin(9600);

pinMode(LED0,OUTPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
pinMode(LED5,OUTPUT);
pinMode(LED6,OUTPUT);

delay(2000);
Serial.print("s");
}

int val = 0;
int count = 0;

void loop(){

val = Serial.read();
LED_level(val-48);

if (blink_state == 1){
digitalWrite(LED0,HIGH);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,HIGH);
delay(500);
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
delay(500);
}

delay(5000);
}

void LED_level(int value){
switch (value){
case 0:
digitalWrite(LED0,LOW);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
blink_state = 0;
break;
case 1:
digitalWrite(LED0,HIGH);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
blink_state = 0;
break;
case 2:
digitalWrite(LED0,HIGH);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
blink_state = 0;
break;
case 3:
digitalWrite(LED0,HIGH);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
blink_state = 0;
break;
case 4:
digitalWrite(LED0,HIGH);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
blink_state = 0;
break;
case 5:
digitalWrite(LED0,HIGH);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
blink_state = 0;
break;
case 6:
digitalWrite(LED0,HIGH);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,LOW);
blink_state = 0;
break;
case 7:
digitalWrite(LED0,HIGH);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,HIGH);
blink_state = 0;
break;
case 8:
blink_state = 1;
}
}

// Arduino_2_sensor

int sensor = 0;
int value = 0;
int val = 0;
int meassure = 0;

void setup(){
Serial.begin(9600);
}

void loop(){

while(Serial.available()<0){
}

val = Serial.read();
if (val =='s'){
meassure = 1;
}
if (val == 'q'){
meassure = 0;
}

if (meassure == 1){
value = analogRead(sensor);
if ((value <=140) && (value >= 10)){
if((value > 43)) Serial.print(0);
if((value <=39) && (value > 35)) Serial.print(1);
if((value <=35) && (value > 31)) Serial.print(2);
if((value <=31) && (value > 27)) Serial.print(3);
if((value <=27) && (value > 23)) Serial.print(4);
if((value <=23) && (value > 19)) Serial.print(5);
if((value <=19) && (value > 15)) Serial.print(6);
if((value <=15) && (value > 13)) Serial.print(7);
if((value <=13)) Serial.print(8);

}

delay(1000);
}

}

Step 6: Photos:

Here are some photos of the real hack:

parking_sensor parking_sensor parking_sensor

Links and Documentation

Links and Documentation:

  • Use this section to place your links.

Recipe

Recipe: Filled Potatoes with Vegetable Accompaniment

Ingredients:

  • 4 potatoes.
  • 300g minced meat.
  • 125g chunked bacon.
  • Cheese.
  • Red wine.
  • A handful of raisins.
  • 100gr fillet steak.
  • 2 peppers.
  • 1 1/2 onion.
  • 3 green garlics.
  • Salt.
  • Pepper.

Difficulty: Easy -easy

Preparation Time: 45 minutes

parking_sensor
 
 

Instructions: Cut the vegetables and cook and stir until the onion has softened and turned golden brown about 10 minutes. Then add the filled steak in small slides and add white or black pepper and cook for another 10 minutes.

Wash and boil potatoes in plenty of water for 30 minutes. Meanwhile, chop the onion, garlic and saute with meat and bacon over low heat until the onion is transparent. Season with salt and pepper and a little red wine and leave it cook for 10 minutes more with a lower heat. Allow potatoes to cool and then empty them using a spoon. Fill with meat and vegetable mixture, cover with cheese and au gratin in the oven for 5-7 minutes.

parking_sensor