First play with an Arduino Uno and an HC-SR04 Ultrasonic Distance Module

Well, I caved.  I've avoided the mass stampede to the Ardiono camp for a long time, because PICs did everything I wanted and I liked them... but I got offered one of these fandangled Uno things to play with - and I've gotta say its actually pretty neat.  

I can really see why they have taken off, given the ease of programming them (although I suspect that some of the 'glossing over' that the Arduino IDE provides will actually create a whole generation of bad embedded programmers - it really lets you get away with murder compared to a standard C implementation).

Here is one of the first programs I wrote (using the NewPing library to support the ultrasonic distance board).

Arduino Uno and HC-SR04 Ultrasonic Distance Module

/*
  Distance-related blink
  
  Uses the NewPing library for HC-SR04 Ultrasonic 
  distance measuring, and the onboard
  LED to flash at a rate proportional to the distance
  measured.
 */
 
#include 

#define TRIGGER_PIN  12  // Pin 12 to 'trigger'
#define ECHO_PIN     11  // Pin 11 to 'echo'
#define MAX_DISTANCE 200 // Maximum distance
#define LED 13           // Onboard LED - pin 13

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); 


void setup() {                
  pinMode(LED, OUTPUT); // Initialize the LED pin as an output.
  Serial.begin(115200); // Serial comms set at 115200 baud. 
}


void loop() {
  delay(50); // Wait 50ms between pings (about 20 pings/sec).
  unsigned int distance = sonar.ping() / US_ROUNDTRIP_CM;
  Serial.println(distance + " cm");
  
  digitalWrite(LED, HIGH);   // Turn the LED on
  delay(distance << 1);      // Wait proportional to distance
  digitalWrite(LED, LOW);    // Turn the LED off
  delay(distance << 1);      // Wait again
}

I'll keep playing with it... because I like it... and wow - the smooth Arduino software makes using a PIC seem like damned hard work.  If the IDE had auto-completion then it would be excellent.

First impressions: its very nice