Pages: [1] 2   Go Down
Author Topic: First real project (in class). need guidance for last few details  (Read 1596 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm currently learning a whole lot about arduino language and how to use my Arduino UNO. However, I'm struggling on how to wire and use three ultrasonic proximity sensor like the one referred to in the Pint tutorial here, http://arduino.cc/en/Tutorial/Ping, to control the speeds at which a servo and a LED pattern cycles through.

So far, I have made a layout in fritzing of how the wiring would look like and have figured that I could possibly use min(x,y) to get the lowest variable of any of the three sensors and thus use that lowest variable to control the three set speed for the LED and Servo with "if else". However, I'm still learning about the Ohm's Law and aren't sure how much resistance I should put in the resistor for the 8 LED row. There will be an 8x8 layout with it but it will only be controlled rows by rows to preserves on pins.

I've had played around with the Ping's code but I always seemed to really mess things up whenever I add codes to the Ping's code. I'm not sure where in the code I should put all of my "If else" portions?

I will be posting a code sample up on here to see whether you guys could use to offers me advices. In the meantime, I wonder if I could have some info for the below questions?

1) how much resistance I should put in the resistor for the 8 LED row?

2) Where can I put my "If else" block of code in this Ping's code?  (http://arduino.cc/en/Tutorial/Ping)

3)is there any books or tutorials out there that focus more on teaching the language than the hardware portion of Arduino? Cause I'm finding the coding to be my weak point in this area.

Any info would be much appreciated. thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, forgot to post the image too.

 smiley-red


project_bb by deafcyclist, on Flickr
« Last Edit: March 06, 2011, 06:47:36 pm by lostearstudio » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 75
Posts: 7269
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Depending on how bright you want the LEDs, you can go anywhere between like 100 and 1,000 Ohms. If you have not made the actual circuit yet, get a kit of lots of resistance values and try them out. Although you need some calculation to find out the suggested value of resistance, you can also play by ear and start with a large value like 1K, then step down the resistance. Make sure you know how to use an ammeter to make sure the current doesn't exceed either 20mA for arduino pins or LED's suggested current value.
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 75
Posts: 7269
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest you do one sensor with one if, then find out if your scenario works or not. I am a bit concerned if there's no object in front of the sensor, you may get zero depending on what code you cut and paste. So get one sensor to work first would be best.

For learning the language, you can start with arduino programming notebook. Just google it. Then find some basic c programming book. A good master of coding is essential in moving forward.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest you do one sensor with one if, then find out if your scenario works or not. I am a bit concerned if there's no object in front of the sensor, you may get zero depending on what code you cut and paste. So get one sensor to work first would be best.

For learning the language, you can start with arduino programming notebook. Just google it. Then find some basic c programming book. A good master of coding is essential in moving forward.

thank you  smiley-grin

my problem is that i need to sense a wider range than one sensor can give me. maybe if I use the syntax, constraint, I could have the code to automatically reject anything below like 2 inches since that means the viewers are coming too close to the sensor than they should anyway?

doing constrain in this way would have the system automatically ignore any non-functionally sensor and still works with the remaining sensors?  I had thought to use the boolean 'or' function "||" but this would basically do the same as min(x,y,z) but the min one have cleaner code, i think?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

to clarify, I found out the exact name and model of the sensor I'm using (couldn't get to the sensor earlier). It's a Parallax PING))) Ultrasonic sensor.

http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/CategoryID/51/List/0/SortField/0/Level/a/ProductID/92/Default.aspx

would I be able to code this as a potentiometer and calibrate it? would this be easier to use/code this way?
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 75
Posts: 7269
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure you can use all three. I was just suggesting the path of least resistance to get to a partial goal. You're a good planner (diagram is pretty good) so maybe your first stop is your final goal!

So get the sensors, play with them a bit. Type up some code and post back here for critique!

The parallax ping is a very popular sensor. It is not like a potentiometer. You need to talk to it to start the measurement, then listen on the same pin you talked to it for a pulse. The width of the pulse tells you distance (round trip).

Here, take a look at my codes for this car reverse obstacle sensor project:
http://liudr.wordpress.com/2011/02/12/arduino-parking-sensor/

It's got an intro to the sensor.

When you download my code, do the nutshell first. It's easy to read through and understand what I do. The full version has interactive features you don't need for your project (at least at this stage).

Let me know if you have questions!
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The deadline for this project have been postponed for another two weeks so I now have an excess of time to catch up on everything cause of the spring break next week! so I'll be taking a little more times between posting to be sure than I'm learning what I can before spamming this thread :-)

@ luidr, thank you for referring to that arduino programming book! I've printed out two copies and stapled/bound them up to give the extra one to my teacher so he can look it over and share it with the rest of the class. that resource is going to be extremely useful for us deaf students as we like to see a clear concise explanation of specific components like the syntaxes :-D thanks!

Sure you can use all three. I was just suggesting the path of least resistance to get to a partial goal. You're a good planner (diagram is pretty good) so maybe your first stop is your final goal!

So get the sensors, play with them a bit. Type up some code and post back here for critique!

The parallax ping is a very popular sensor. It is not like a potentiometer. You need to talk to it to start the measurement, then listen on the same pin you talked to it for a pulse. The width of the pulse tells you distance (round trip).

Here, take a look at my codes for this car reverse obstacle sensor project:
http://liudr.wordpress.com/2011/02/12/arduino-parking-sensor/

It's got an intro to the sensor.

When you download my code, do the nutshell first. It's easy to read through and understand what I do. The full version has interactive features you don't need for your project (at least at this stage).

Let me know if you have questions!


Thank you! looking over your codes :-) I'll get back here later on in the week when the classes are finishing up before the spring break :-)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm stuck. I'm having problems understanding the power requirement of all of the components. I found out that a 9v battery can only light 3 LED in a series so I can't rewire all of the LED in time for a 16x3 LED.

I'm forced to abandon the LED grid for the moment and just focus on simply controlling one servo and one RGB LED with three ultrasonic rangefinder. I will post my codes here later on for constructive criticsm so I can fix it up and use it for my class.

see updated pic attached for more simpler circuit. (yes, I noticed that the RGB LED ground is connected to power)


* project_bb1.png (59.01 KB, 483x610 - viewed 8 times.)
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 75
Posts: 7269
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't have 3 LEDs in series. The matrix should have rows and columns and turns on one LED at a time. You will take 33% time to turn on each one of the 3 LEDs if you want to have 3 LEDs on together. If you do it fast enough, you will think several LEDs are turned on simultaneously.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah, that would require the MAX7217 chips that I have? the problem is, I don't really have time to learn how to do that overnight. so I'm reducing my workload some and focusing on getting the bare minimum functional.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, finally figured out how to find out the lowest value of any of three ultrasonic rangefinder to control the LED. However, I'm trying to look up the codes to get my continuous rotation servo running without delaying the rangefinder (the current servo portion of the code caused very jerky action with the servo and a massive delay in between cycles for the rangefinder to detect distance).

Any insight on how to get the servo to change speed without delaying the rangefinders?

I want the servo to continuously rotates but do change speed.

default speed for distance of over 5 feet
a little faster speed for between 2.5 to 5 feet
fast speed for less than 2 feet.

you get the concept?

Thanks

Code:
#include <Servo.h>
Servo myservo;
int pos = 0;
int pingPin = 8;
int pingPin1 = 9;
int pingPin2 = 10;
const int ledPin = 5;
const int ledPin1 = 6;
const int ledPin2 = 7;


void setup()
{
 Serial.begin(9600);
 pinMode (ledPin, OUTPUT);
 pinMode (ledPin1, OUTPUT);
 pinMode (ledPin2, OUTPUT);
 myservo.attach(4);
}


void loop()
{
 long duration, cm, duration1, cm1, duration2, cm2, minone, minimumsensor;

 pinMode(pingPin, OUTPUT);
 digitalWrite(pingPin, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin, LOW);

 pinMode(pingPin, INPUT);
 duration = pulseIn(pingPin, HIGH);

 cm = microsecondsToCentimeters(duration);
 
 delay(15);

 pinMode(pingPin1, OUTPUT);
 digitalWrite(pingPin1, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin1, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin1, LOW);

 pinMode(pingPin1, INPUT);
 duration1 = pulseIn(pingPin1, HIGH);

 cm1 = microsecondsToCentimeters(duration1);
 
 delay(15);
 
 pinMode(pingPin2, OUTPUT);
 digitalWrite(pingPin2, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin2, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin2, LOW);

 pinMode(pingPin2, INPUT);
 duration2 = pulseIn(pingPin2, HIGH);

 cm2 = microsecondsToCentimeters(duration2);
 
 delay(15);
 
 minone = min(cm, cm1);
 minimumsensor = min(cm2, minone);
 
 if (minimumsensor <= 30) {
   digitalWrite (ledPin, HIGH);
   digitalWrite (ledPin1, LOW);
   digitalWrite (ledPin2, LOW);
   pos=45;
   myservo.write(pos);
   
 Serial.print(cm);
 Serial.print(", ");
 Serial.print(cm1);
 Serial.print(", ");
 Serial.print(cm2);
 Serial.print(", ");
 Serial.println();
 Serial.print(minimumsensor);
 Serial.print(". out of range.");
 Serial.println();
 Serial.println();
 }
 else if (minimumsensor >=60) {
   digitalWrite (ledPin, LOW);
   digitalWrite (ledPin1, HIGH);
   digitalWrite (ledPin2, LOW);
   pos=135;
   myservo.write(pos);

 Serial.print(cm);
 Serial.print(", ");
 Serial.print(cm1);
 Serial.print(", ");
 Serial.print(cm2);
 Serial.print(", ");
 Serial.println();
 Serial.print(minimumsensor);
 Serial.print(". in sight.");
 Serial.println();
 Serial.println();
 }
 else {
   digitalWrite (ledPin, LOW);
   digitalWrite (ledPin1, LOW);
   digitalWrite (ledPin2, HIGH);
   pos=90;
   myservo.write(pos);
 Serial.print(cm);
 Serial.print(", ");
 Serial.print(cm1);
 Serial.print(", ");
 Serial.print(cm2);
 Serial.print(", ");
 Serial.println();
 Serial.print(minimumsensor);
 Serial.print(". too close!");
 Serial.println();
 Serial.println();
 }

}

long microsecondsToCentimeters(long microseconds)
{
 return microseconds / 29 / 2;
}

long microsecondsToCentimeters1(long microseconds)
{
 return microseconds / 29 / 2;
}

long microsecondsToCentimeters2(long microseconds)
{
 return microseconds / 29 / 2;
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Finally gotten pretty much everything in the code the way I need it to except for the servo's POS code. I keep having conflicting behaviors and it weirdly alternated between some of the if else statement for no reason (the sensors report 0 value at every other turn and seems to only happens with the current servo if else codes).

Any advices would be much appreciated as this is the very last item to do before class tomorrow night. thanks

Code:
#include <Servo.h>
Servo myservo;
int pos = 0;
int pos1 = 0;
int pos2 = 0;
int pingPin = 8;
int pingPin1 = 9;
int pingPin2 = 10;
const int ledPin = 5;
const int ledPin1 = 6;
const int ledPin2 = 7;


void setup()
{
 Serial.begin(9600);
 pinMode (ledPin, OUTPUT);
 pinMode (ledPin1, OUTPUT);
 pinMode (ledPin2, OUTPUT);
myservo.attach(4);
}


void loop()
{
 long duration, cm, duration1, cm1, duration2, cm2, minone, minimumsensor;

 pinMode(pingPin, OUTPUT);
 digitalWrite(pingPin, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin, LOW);

 pinMode(pingPin, INPUT);
 duration = pulseIn(pingPin, HIGH);

 cm = microsecondsToCentimeters(duration);
 
 delay(5);

 pinMode(pingPin1, OUTPUT);
 digitalWrite(pingPin1, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin1, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin1, LOW);

 pinMode(pingPin1, INPUT);
 duration1 = pulseIn(pingPin1, HIGH);

 cm1 = microsecondsToCentimeters1(duration1);
 
 delay(5);
 
 pinMode(pingPin2, OUTPUT);
 digitalWrite(pingPin2, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin2, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin2, LOW);

 pinMode(pingPin2, INPUT);
 duration2 = pulseIn(pingPin2, HIGH);

 cm2 = microsecondsToCentimeters2(duration2);
 
 delay(5);
 
 minone = min(cm, cm1);
 minimumsensor = min(cm2, minone);
 
 if (minimumsensor >=60) {
   digitalWrite (ledPin, HIGH);
   digitalWrite (ledPin1, LOW);
   digitalWrite (ledPin2, LOW); 
   for(pos = 180; pos < 180; pos -=1)
   
 myservo.write(pos);
 delayMicroseconds(1);
 

 Serial.print(cm);
 Serial.print(", ");
 Serial.print(cm1);
 Serial.print(", ");
 Serial.print(cm2);
 Serial.println();
 }
 else if (minimumsensor <= 30) {
   digitalWrite (ledPin, LOW);
   digitalWrite (ledPin1, LOW);
   digitalWrite (ledPin2, HIGH);
   for(pos1 = 0; pos1 > 180; pos1 -=10)
 myservo.write(pos1);
 delayMicroseconds(1);
 

 Serial.print(cm);
 Serial.print(", ");
 Serial.print(cm1);
 Serial.print(", ");
 Serial.print(cm2);
 Serial.println();
 }
 
 else {
   digitalWrite (ledPin, LOW);
   digitalWrite (ledPin1, HIGH);
   digitalWrite (ledPin2, LOW);
   for(pos2 = 360; pos2 < 180; pos2 -=1)
   
 myservo.write(pos2);
 delayMicroseconds(1);
 

 Serial.print(cm);
 Serial.print(", ");
 Serial.print(cm1);
 Serial.print(", ");
 Serial.print(cm2);
 Serial.println();
 }

}

long microsecondsToCentimeters(long microseconds)
{
 return microseconds / 29 / 2;
}

long microsecondsToCentimeters1(long microseconds1)
{
 return microseconds1 / 29 / 2;
}

long microsecondsToCentimeters2(long microseconds2)
{
 return microseconds2 / 29 / 2;
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you see how this:
Code:
pinMode(pingPin, OUTPUT);
 digitalWrite(pingPin, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin, LOW);

 pinMode(pingPin, INPUT);
 duration = pulseIn(pingPin, HIGH);

 cm = microsecondsToCentimeters(duration);
 
looks a lot like this:
Code:
pinMode(pingPin1, OUTPUT);
 digitalWrite(pingPin1, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin1, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin1, LOW);

 pinMode(pingPin1, INPUT);
 duration1 = pulseIn(pingPin1, HIGH);
?

We programmers are a lazy bunch, and hate typing more than we absolutely need to (have you ever read an APL program?), so we factor up code like that into functions, then we have only one lot of typing to do, and the bugs have fewer dusty corners to hide in.

The Arduino IDE also has a handy auto-format tool - use Ctrl-T to transform the legibility of your code.
« Last Edit: March 27, 2011, 10:03:17 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i see what you mean but I'm still not quite that familiar with the language and programming in general so that was the only way I could quickly ensure that none of the variable would interferes with each other. I had serious struggles with the three sensors interfering with each other and this was the only way I could get it to work together.
Logged

Pages: [1] 2   Go Up
Jump to: