Dear Smart People,
My name is Aaron Funderburg, I am new to the electronics field all in general. I have been spending the last couple of months studying general electronics and basic Arduino. I finally feel confident enough to start my own project. I want to build a robot more than anything else, but i am always open for ideas. I have an Arduino Uno, Mega, Ultrasonic distance sensor, Motor shield, a camera shield and tons of electronic components and sensors. Where do i even begin? Do I have to follow certain guidlines? Does anyone just have some useful information on how to begin a project and how to take advantage of Arduinos helpful sources?
2 steps that you might have taken the first, which is "a doozy".
-
Learn basic C code. Do tutorials and read and more tutorials. Practice or you will never get it. Save the big C++ improvements for later, microcontrollers are small environments. Be sure to include the IDE example Blink Without Delay, you will need it in time.
-
Get the ultrasonic sensor working, see what real data looks like.
Ok Thanks! I just have issues with understanding how to use some of the arduino commands. Right now i struggle the most with understanding serial communication like sending bytes and stuff like that.
As I did in my time. One step at a time. But learn a few steps before you try and pull so many pieces together and coordinate them, which it seems you have started to do already.
Maybe you are ready for step 2.
Here is the code I used to make sure the ultrasonic modules I bought do work.
I stress that it's not perfect, has room for optimizing and maybe I start counting micros() too soon as the accuracy I got was far less than should be. But it's a start.
// this code is to test LC Tech Ultrasonic Range module with Arduino
// wiring module to Arduino: (I used a Teensy++ 2.0 but a pin is a pin.)
// GND to GND, VCC to 5V, ECHO to pin 10, TRIG to pin 11
#define ECHO 10
#define TRIGGER 11
// DZ is to slow down the rate of serial prints, it is the difference
// in usecs that must be from one read to the next before print is made
#define DZ 33
unsigned long mikros, lastEcho = 0UL; // lastEcho is needed for DZ to work
unsigned long echo; // I just like data when I test, compare to micros
void setup( void )
{
Serial.begin( 9600 );
digitalWrite( ECHO, LOW );
pinMode( ECHO, INPUT );
digitalWrite( TRIGGER, LOW );
pinMode( TRIGGER, OUTPUT );
}
void loop( void )
{
// Operation of the ultrasonic module:
// First, trigger must be held HIGH at least 10 usecs then made LOW
// For a short period, ECHO pin will read LOW. This must be passed.
// I begin counting usecs after the ECHO pin changes to read HIGH.
// Then ECHO pin will read HIGH until the echo is done, but which
// echo pulse? There are 8 pulses sent out.
// Also the temperature here is colder that Atmosphere Standard.
// Beware with speed of sound based formula, the speed changes
// with temperature.
// Under ideal conditions with ideal objects you may get 2mm accurate
// but just point around a room or at people gives much less.
digitalWrite( TRIGGER, HIGH );
delayMicroseconds( 20 );
digitalWrite( TRIGGER, LOW );
while ( !( digitalRead( ECHO )));
mikros = micros();
// Test distance = (high level time * sound velocity (340M/S) / 2)
echo = 0UL;
while ( ( digitalRead( ECHO )))
{
echo++;
if ( echo > 1000000UL )
{
echo = 0UL;
break;
}
}
mikros = micros() - mikros;
if ( echo )
{
if (( mikros - lastEcho > DZ ) && ( lastEcho - mikros > DZ ))
{
Serial.print( "loops = " );
Serial.print( echo );
Serial.print( " -- range = " );
Serial.print( mikros * 170 / 1000 );
Serial.println( "mm" );
}
lastEcho = mikros;
}
else
{
Serial.println( "No echo." );
lastEcho = 0UL;
}
delay( 10 ); // this seems to help settle readings
}