Show Posts
Pages: 1 2 [3] 4 5 ... 8
31  Community / Bar Sport / Re: Recursion on: August 04, 2012, 10:51:56 am
Have you seen this one?

pkunzip.zip
32  Using Arduino / LEDs and Multiplexing / Re: 8x1 LED bar on: August 04, 2012, 12:52:25 am
Is this
Quote
The ultrasonic sensor is tested and it works(it stores the distance to an integer).
consistent with this? How can the sensor work if it only goes to 5?
Quote
In the serial monitor I only get distances less then 5 cm(5 cm is max dont know why)

The code looks OK to me, but the condition you end up with also happens to be the last else if.  Suspicious. As a sanity check, change the last else if to another value, for instance
Code:
else if (15<cm && cm<=30){
broj = B00001111;}
and see if the result changes.  If it does, then you must listen to Magician and use more curly braces.
33  Using Arduino / Programming Questions / Re: Trying to program a speedometer on: August 03, 2012, 11:57:39 pm
Glad you got it to work!  I was going to suggest
Code:
mph = 681818.2/(stopTime - startTime);
which would accomplish the same thing.

Pulldown resistors are fine.  The reason I used the internal pullup resistors is because I cheated and just used bare wires.  No breadboard, switches or resistors.
34  Using Arduino / Project Guidance / Re: I would like to ask for advice on a project on: August 03, 2012, 11:05:49 pm
Sounds like a cool project!

You can do it, just take small steps.  Make a sketch for each part of the project.  Play with the ping sensor first, get it to print the distance in the serial monitor.  Make another sketch to move one of the motors.  Then make it move back and forth.  Then make a motor move using the ping sensor, and so on.
35  Using Arduino / Sensors / Re: What is the best way of X-axis motion sensing? on: August 03, 2012, 10:17:20 pm
Yes, I think it would work.  In fact, you should use 2 of them separated by a meter!

Wire them in series with one side at 5V and the other at ground.  Now if you read the analog value between the 2 sensors, you will be able to tell which direction each person was moving.  That's because blocking the light to one sensor will make the analog reading go up, and blocking the light to the other sensor will make the analog reading go down.
36  Using Arduino / Programming Questions / Re: Trying to program a speedometer on: August 03, 2012, 10:01:40 pm
I think your math is OK, but there are a several problems with the code:  floating inputs, division with ints, wrong variable type for micros(), etc.  

Try the sketch with my modifications below.  It stays in the first while loop until the first switch closes.  Then it stays in the second loop until the second switch closes.  Then it calculates the answer and prints it.  The delay is to prevent a lot of junk from printing. 1 second may be longer than necessary, but I assume your lap times are more than 1 second!

I used 2 wires connected to pins 9 and 10. A 3rd wire was connected to ground.  To simulate the 2 switches closing, I held the first 2 wires close together and dragged the ground wire over them so that each was grounded in rapid succession (first pin 9, then pin 10).  The numbers I got in the serial monitor were believeable mph values.  
Code:

const int startPin = 9;
const int stopPin = 10;
unsigned long startTime=0;
unsigned long stopTime=0;
float mph;

void setup () {
  Serial.begin(9600);
  pinMode(startPin, INPUT_PULLUP);
  pinMode(stopPin, INPUT_PULLUP);
}

void loop () {
  while(!startTime) {
    if(digitalRead(startPin) == LOW)
      startTime = micros();
  }
  while(!stopTime) {
    if(digitalRead(stopPin) == LOW)
      stopTime = micros();
  }
  mph = (3600000000/((stopTime - startTime)*5280));
  Serial.println(mph);
  startTime=0;
  stopTime=0;
  delay(1000);
}

(edit - added code tags!)
37  Community / Bar Sport / Re: C64=30 on: August 02, 2012, 01:30:47 pm
Quote
The C64 was the second computer I owned.

Vic 20?  Wait, the C64 was the THIRD computer I owned!
38  Using Arduino / Project Guidance / Re: Vat sitter on: August 01, 2012, 10:39:43 pm
Quote
Adding the exact amount of pulp and keeping the water to fiber ratio appropriate for a specific weight of paper is labor intensive and subjective at best.

I know you want a sensor, but...

The more pulp, the higher the specific gravity, right?  Suppose you had a float that would sink or rise depending on the density of the mix.  Something like a thin wooden rod about 10 inches long with a weight on one end.  You could mark it at the ideal level.
39  Community / Bar Sport / Re: C64=30 on: August 01, 2012, 10:27:25 pm
The C64 was the second computer I owned.  It had better sound, graphics, and was faster than the Atari.  I remember standing there in the store typing my prime number testing program into each machine...
40  Using Arduino / Programming Questions / Re: Arduino counter on: July 31, 2012, 10:17:51 pm
Code:
if (counter3 = 0){

Does that look right?  Not saying that's the whole problem, but it does need fixing. 

Also, when you get some time, have a look at arrays.  Arrays can make your sketch cleaner and easier to work with.
41  Using Arduino / Project Guidance / Re: Reading frequency on: July 31, 2012, 09:53:01 pm
Quote
I'll fool around with pulseIn tomorrow and see if i can get some results.

Hi plank,
Here's an easy way to play around with pulseIn().  The sketch measures the Arduino PWM frequency and the length of the HIGH and LOW pulses for each PWM value.  Try it out - you only need one wire!
Tom

Code:
// PWM analysis, Tom Fangrow, July 8, 2012
// connect a wire from digital pin 2 to digital pin 3

long hi, lo, x;
 
void setup() {
  pinMode(3, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for(x=1; x<255; x++) {              // for all useful values
    analogWrite(3, x);                // output PWM on pin 3
    hi = pulseIn(2, HIGH);            // measure HIGH pulse
    lo = pulseIn(2, LOW);             // measure LOW pulse
    Serial.print("PWM: ");            // PWM value (1-254)
    Serial.print(x);                 
    Serial.print(", HI: ");           // signal at 5 volts
    Serial.print(hi);                 // for 'hi' microseconds
    Serial.print(", LO: ");           // signal at 0 volts
    Serial.print(lo);                 // for 'lo' microseconds
    Serial.print(", Freq: ");         // PWM frequency
    Serial.print(1000000/(hi + lo));
    Serial.println(" Hz");            // in pulses per second
  }
}
42  Community / Bar Sport / Re: Countdown to Level Up on: July 31, 2012, 11:59:16 am
The next ranking could be Shockley Member.  William Shockley was the 'other' inventor of the transistor.
43  Community / Bar Sport / Re: Countdown to Level Up on: July 30, 2012, 07:15:15 pm
Quote
I'll second that (so I can have an additional post!  smiley-mr-green)

Ha! good one.  Maybe there should be a special thread dedicated to getting additional posts? 

Wait, some threads seem to be like that already!  <wink>
44  Using Arduino / Sensors / Re: Measuring speed of a motorbike wheel on: July 30, 2012, 07:10:06 pm
Hi again Markosec,

You've made progress, but it still seems more complicated than it needs to be.  4 magnets? arrays? interrupts?  Maybe it would help if you saw an example of a simpler way.  One measurement per rotation.  See if you can work through the logic in loop() on the sketch below. The code is tested and works.  You can ignore the lines having to do with the lcd display if you want, and you will need to change the rollout to 1880 and convert from miles per hour to kilometers per hour.

Code:
// Written by Tom Fangrow, July 15, 2012
// reed switch on pin 4, LED on pin 13

#include <LiquidCrystal.h>

LiquidCrystal lcd(3, 5, 9, 10, 11, 12);
unsigned long newTime, oldTime=0;
float newPeriod, oldPeriod=0.0, velocity;
float rollout = 2085.0;      // tire circumference in mm

void setup() {
  pinMode(4, INPUT_PULLUP);  // other side of switch to ground
  pinMode(13, OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Bike Computer");              // welcome screen
  lcd.setCursor(0, 1);
  lcd.print("version 1.0");
  delay(3000);
}

void loop() {
  if(digitalRead(4) == LOW) {              // switch is closed
    newTime = millis();                    // note the time
    digitalWrite(13, HIGH);                // turn on LED
    newPeriod = float(newTime-oldTime);    // rotation period
    velocity = rollout*60*60/(newPeriod*1609.34);     // mph
    updateScreen();
    oldTime = newTime;                     // update oldTime
    oldPeriod = newPeriod;                 // update oldPeriod
    delay(60);           // allow time for switch to open again
  }
  else {                                   // switch is open
    digitalWrite(13, LOW);                 // turn off LED
    if(millis()-oldTime > 3000) {          // if bike stopped
      velocity = 0.0;                      // zero out display
      updateScreen();
      oldTime = millis();    // this will refresh every 3 seconds
    }
  }
}

void updateScreen() {
  lcd.clear();
  lcd.setCursor(0, 0);                    // first line
  lcd.print("Current Speed");
  lcd.setCursor(0, 1);                    // second ine
  lcd.print(velocity);
  lcd.print(" mph   ");     // extra spaces erase previous data
}
45  Using Arduino / Sensors / Re: Sensor indicator light reset on: July 29, 2012, 03:46:46 pm
That's interesting because I used your code with my changes (below) and it worked fine on my Uno.

Quote
Code:

pinMode(buttonPin3, INPUT_PULLUP);

...
Code:

if (reading3 == LOW)
Pages: 1 2 [3] 4 5 ... 8