Hello LMRians,
After finishing as runner-ups in the line following section of the Yantra 2.0 Robotics Competition, the organizers provided the team a Roboduino, an Arduino Diecimila Clone. I already had one, and did not want another, as it had taken me a whole day to shake hands between my computer and this board, with a lot of driver and serial port issues. So, i requested them an alternative instead.
I had never tried my hands on an LCD, therefore got my self a big-version 20 x 4 LCD.
The Model Number says JHD 204A and has 16 pins on either side (top and bottom) for ease of use.
So, what has this LCD to do with Dist-Bot? As the stupid name suggests, it simply measures the distances using ultrasonic waves emitted by an HC-SR04 sensor, and displays the corresponding results on the LCD.
For Dist-Bot, i used a Spider Controller as it was nearly the same size as the LCD board and it neatly stacked on top of it using appropriate standoffs. Furthermore, the innumerable pins on the Spider made it relatively easier to connect the respective pins.
Next on the list, was the ever popular Ulrasonic Sensors Module, the HS-SR04.
And afer some soldering, some wiring, some screw-driving, this is what Dist-Bot looked like at the end.
At the moment, it's tasks are simply straightforward, the HC-SR04 produces the ultrasonic waves, the distance in centimetres is measured and is displayed on the LCD. If there's an object within a range of 200 cm, it responds along with the distance from the object.
In this case, it spotted the camera while a picture was being taken. It's fine to take a pic, but those HC-SR04s will glare at you!
When it's out of range, it'll respond to that as well, as per the program, in this case it just says, " I see nothing".
Upgrades might come along the way, to make use of more devices and do something more than just plain old measurement! For now, that's all about Dist-Bot.
Below is the code I used. To get things working right away, i used the NewPing Library. Feel free to make changes, if you are trying to make something similar. You can also control the TRIG and ECHO outputs of the HCSR04 manually to get the readings.
#include <NewPing.h>#include <LiquidCrystal.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 13 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum uS / US_ROUNDTRIP_CM we want to ping for (in centimeters). Maximum sensor uS / US_ROUNDTRIP_CM is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN,MAX_DISTANCE); // NewPing setup of pins and maximum uS / US_ROUNDTRIP_CM.
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(38, 39, 30, 31, 32, 33, 34, 35, 36, 37); //RS pin, Enable pin, Digital pins
void setup(){
<span style="color: #888888;">// set up the LCD's number of columns and rows: </span>
lcd.begin(20, 4);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
delay(50); // Wait 50ms between pings .
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to uS / US_ROUNDTRIP_CM in cm and print result (0 = outside set uS / US_ROUNDTRIP_CM range)
Serial.println(“cm”);
<span style="color: #008800; font-weight: bold;">if</span> (uS <span style="color: #333333;">/</span> US_ROUNDTRIP_CM <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">200</span> <span style="color: #333333;">||</span> uS <span style="color: #333333;">/</span> US_ROUNDTRIP_CM <span style="color: #333333;"><=</span> <span style="color: #0000dd; font-weight: bold;">0</span>){ <span style="color: #888888;">// If there's no object within 200cm or if the distance equals zero</span> lcd.clear(); lcd.setCursor(<span style="color: #0000dd; font-weight: bold;">3</span>,<span style="color: #0000dd; font-weight: bold;">1</span>); <span style="color: #888888;">// Go to this position. (3,1) implies 3 units towards posiive X-axis and 1 units towards negative Y-axis. We start at (0,0)</span> lcd.print(<span style="background-color: #fff0f0;">"I see nothing!!"</span>); <span style="color: #888888;">// Notify that no object is spotted within the 200 cm range</span>
}
else { // but if there’s an object within 200 cm
lcd.clear(); lcd.setCursor(<span style="color: #0000dd; font-weight: bold;">2</span>,<span style="color: #0000dd; font-weight: bold;">0</span>); <span style="color: #888888;">// Go to this position</span> lcd.print(<span style="background-color: #fff0f0;">"Object Spotted!!"</span>); <span style="color: #888888;">// Notify that there's an object</span> lcd.setCursor(<span style="color: #0000dd; font-weight: bold;">2</span>,<span style="color: #0000dd; font-weight: bold;">2</span>); lcd.print(<span style="background-color: #fff0f0;">"It's"</span>); lcd.setCursor(<span style="color: #0000dd; font-weight: bold;">7</span>,<span style="color: #0000dd; font-weight: bold;">2</span>); lcd.print(uS <span style="color: #333333;">/</span> US_ROUNDTRIP_CM); <span style="color: #888888;">// the distance between Dist-Bot and the object</span> lcd.setCursor(<span style="color: #0000dd; font-weight: bold;">10</span>,<span style="color: #0000dd; font-weight: bold;">2</span>); lcd.print(<span style="background-color: #fff0f0;">" Cm"</span>); lcd.setCursor(<span style="color: #0000dd; font-weight: bold;">14</span>,<span style="color: #0000dd; font-weight: bold;">2</span>); lcd.print(<span style="background-color: #fff0f0;">"far"</span>);
}
delay(500); // a delay between the corresponding outputs
}
Thanks for reading! Let me know your thoughts.
Ashim
Calculates the distance and reports to an LCD
- Actuators / output devices: 20X4 LCD
- Control method: autonomous
- CPU: Arduino Mega (Spider controller)
- Power source: 7.2 V LI-ION 1500 mAh battery
- Programming language: Arduino C
- Sensors / input devices: Ultrasonic sensors
- Target environment: Anywhere in range
This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/dist-bot