Show Posts
Pages: 1 ... 4 5 [6] 7
76  Using Arduino / Project Guidance / Re: weather station on: February 10, 2013, 07:13:42 pm
I would think about using an I2C bus.  Two wires instead of one, but it is a reliable, proven, robust technology with lots of products and tutorials. A Google search on "Arduino I2C" will produce everything you need. There is even an Arduino I2C library named "wire" in the reference or playground.

Good luck!
77  Using Arduino / Programming Questions / Re: T Button on: February 09, 2013, 10:55:33 pm
Docedison, it appears that none of the code at the links you provided contain the Tbutton.h that jwhardie is looking for, methinks.

jwhardie, why not go to the source at bruce@momjian.us.

BTW, I hear that AdvButton.h is supposed to be better. No emperical knowledge, just what I hear.
78  Using Arduino / Project Guidance / Re: Need to power small dc motor car for specific distance and stop on: February 09, 2013, 07:13:58 pm
GrisGris (nice sobriquet)

I would be happy to help you. You have mentioned that the students -- at this time -- just need to read and follow instructions. Thus, you don't seem to have the luxury of the hard knocks method. If I am sensing your situation correctly (and I have been wrong in larger towns than this) here are some resources for you.

The car would have a Hall Effect Detector (HED) (such as this one at https://www.sparkfun.com/products/9312?) attached to the body/frame and a magnet placed on one of the wheels. I would suggest a non-drive wheel so that any slippage due to motor torque does not get counted.  If a HED is not available then a reed switch that closes to ground to produce a LOW when the magnet is aligned will do. The HED is much cleaner, more sensitive and reliable.

The DC motor would be connected with a 2n2222 npn transistor (or equivalent -- handling about 200mA max) between the motor and ground.  If your motor draws more than 200mA, then TO-220 NPN transistor (like the TIP31) will need to be used. Be sure to place a reversed diode (cathode toward +DCV) in parallel with the motor to handle any back-EMF when the motor is stopped. A 1N4001 is a defacto standard, methinks. Run a 4.7k ohm resistor from the Arduino pin to the base of the transistor (if you decide to use a lower beta power transistor, you might want to use a 1k resistor to assure saturation), the emitter goes to ground, and the collector goes to the bottom (negative) side of the motor. I would place a 0.1uFd capacitor in parallel with the motor and diode just to keep noise down.

Here is the code
Code:
/****************************************************************************************************\
** This code is intended to allow an Ardino Uno to control a model car having a small brushed DC motor
** and drive it forward a given distance and then stop
**
** It expects a latching Hall Effect sensor (such as the one at https://www.sparkfun.com/products/9312)
** attached to the body and a magnet attached to a non-drive wheel so that, as the wheel rotates, the
** magnet and sensor align once a revolution.
**
** The motor will draw too much current for the Arduino pin so an NPN transistor (such as a 2N2222)
** is driven through a 4.7k ohm resistor to drive the motor. If the motor draws more than 200mA, use
** a TO-220 power transistor.
**
** It first waits for the wheel to be turned to align the magnet and the sensor.
**
** Once it sees alignment, it turns ON the on-board Arduino LED that is attached to digital pin 13
** to notify the user that it is ready to run.
**
** It then awaits a SPST N.O. momentary switch to be pressed as a signal for the car to go.
**
** When pressed, it does a quick re-check to make sure the wheel is still in a known position.
**
** It starts the motor and then counts wheel revolutions until the required distance has been reached.
**
** It then turns OFF the motor
\****************************************************************************************************/

// pin declarations
// pins chosen to avoid PWM pins to leave them free in case the project is expanded
const int MOTOR_PIN = 7; // pin 7 is an OUTPUT that has an NPN transistor attached which turns ON and OFF the DC motor
const int GO_PIN = 8; // pin 8 is an INPUT looking for a LOW signal to start the car
const int WHEEL_PIN = 12; // pin 12 is an INPUT that has the Hall Effect sensor attached -- LOW = magnet is present
const int READY_PIN = 13; // pin 13 is an OUTPUT that has an LED which signals that the car is ready for a run
                                        // i.e. magnet is aligned with the Hall Effect sensor

// non-pin declarations
const int MAX_WHEEL = 10; // number of wheel rotations to the target area -- 10 is a dummy number that needs to be set after experimentation
const int READY = LOW; // a LOW on the ready pin means that the magnet and hall effect sensor are aligned
const int UNREADY = HIGH; // a HIGH on the ready pin means that the magnet and hall effect sensor are not aligned

void setup()
{
// initialize pins
pinMode( GO_PIN, INPUT_PULLUP );
pinMode( WHEEL_PIN, INPUT_PULLUP );
pinMode( MOTOR_PIN, OUTPUT );
pinMode( READY_PIN, OUTPUT );

        // DEBUG
        Serial.begin(9600);
        Serial.println("---== start ==---");
}

void loop()
{
   int loop_flg; // flag to exit do while loop
int i; // for loop index

// turn OFF motor & READY LED
digitalWrite(MOTOR_PIN, LOW);
digitalWrite(READY_PIN, LOW);

        Serial.println("init over -- begin looking for wheel");
        
// LOOP waiting for ready signal -- wheel turned till magnet aligned with Hall Effect sensor
do
{
     loop_flg = digitalRead(WHEEL_PIN);

// debounce pin
if( loop_flg == READY )
{
delay(150); // wait 150mS and check again
loop_flg = digitalRead(WHEEL_PIN);
}
} while ( loop_flg == UNREADY );

// turn ON ready LED
digitalWrite( READY_PIN, HIGH );

        Serial.println("Found wheel -- turned ON ready led -- looking for go");
        
// LOOP waiting for GO signal -- LOW on pin 8
do
{
     loop_flg = digitalRead(GO_PIN);

// debounce pin
if( loop_flg == READY )
{
delay(50); // wait 50ms and check again
loop_flg = digitalRead(GO_PIN);
}
} while ( loop_flg == UNREADY );

        Serial.println("found go -- rechecking wheel");
        
//here: we have been waiting for the GO signal, so re-check that wheel is still ready
loop_flg = digitalRead(WHEEL_PIN);

if( loop_flg == READY )
{
                Serial.println("wheel rechecked ok -- turning on motor");
                
// turn ON the motor
digitalWrite(MOTOR_PIN, HIGH);

                Serial.println("motor on -- starting count");

// FOR LOOP counting wheel rotations
for( i = 0 ; i < MAX_WHEEL ; i++ )
{
// LOOP waiting for ready signal to go HIGH -- magnet no longer sensed by Hall Effect sensor
do
{
     loop_flg = digitalRead(WHEEL_PIN);

// debounce pin
if( loop_flg == UNREADY )
{
delay(50); // wait 50ms and check again
loop_flg = digitalRead(WHEEL_PIN);
}
} while ( loop_flg == READY );

                        Serial.println("magnet gone");
                        
//here: the Hall Effect no longer sees the magnet

// LOOP waiting for ready signal to go LOW -- magnet now aligned with Hall Effect sensor
do
{
     loop_flg = digitalRead(WHEEL_PIN);

// debounce pin
if( loop_flg == READY )
{
delay(50); // wait 50ms and check again
loop_flg = digitalRead(WHEEL_PIN);
}
} while ( loop_flg == UNREADY );

//here: the Hall Effect now sees the magnet = a revolution has been completed
                        // so complete interation of for loop

                        Serial.println("magnet present");
                        Serial.print("revolution number ");
                        Serial.println( i + 1 );
}

//here: the necessary revolutions have been executed

// turn OFF motor
digitalWrite( MOTOR_PIN, LOW );
                Serial.println("motor off");
                Serial.println("---== DONE ==---");
}
        else
        {
                Serial.println("----- wheel mis-aligned when go was pressed -- redo -----");
        }
}

I think that it works, but don't have the hardware to fully test. If you need a schematic, I could rustle one up. For the transistor driving a DC motor look here http://www.jeremyblum.com/2011/01/31/arduino-tutorial-5-motors-and-transistors/ for a cool tutorial thanks to Jeremy Blum. There's a video and everything!

Let us know if you need more help, and let us know how it turns out. Photos or videos would be cool.
79  Using Arduino / Project Guidance / Re: Lie Detector on: February 03, 2013, 03:17:33 am
I'm not sure that this thread was very kind or welcoming to the newbie that initiated it.  Have we been as hospitable as we could to someone coming here asking for help? 

Just sayin'...
80  Using Arduino / Project Guidance / Re: Challenge: horizontally / inertially stabilize a pizza on motorcycle on: February 03, 2013, 03:11:51 am
Do you need an Arduino?

Won't this work: http://en.wikipedia.org/wiki/Gimbal?
81  Using Arduino / Programming Questions / Re: Button Debounce help on: February 03, 2013, 03:05:40 am
I would write the code like this:
Code:
void loop()
{
  //start button code
  buttonState = digitalRead(buttonPin); //read the state of the button
  
  if (buttonState == HIGH)
  {
    //here: we have detected a button push, but it might be a glitch
    delay(10);  //wait 10 milliseconds

    if (buttonState == HIGH)
    {
      delay(4990);             //wait the rest of the 5 seconds
      servoMain.write(90); //turn servo 90 deg. left (locked)
   }
   //end button code


I would also swap the circuitry so that the button push produces a LOW by enabling the internal pullup resistor of the input pin and attaching the button from it to ground.  It is more reliable and has fewer parts.
82  Using Arduino / General Electronics / Re: Basic Ohms law problem on: February 02, 2013, 04:39:57 am
Before going too far, most wall warts have a significant internal thevenin resistance and put out a higher voltage with no load (read current).

Be sure the wall wart's voltage is measured with a reasonable load on it.

Just sayin'...
83  Using Arduino / General Electronics / Re: Is there a way to reduce resistor count in this circuit? on: February 02, 2013, 12:29:57 am
Here's a thought...

Use three digital output pins to drive a 74ls156 (open collector 3to8 decoder) and one digital input pin (with an internal pull-up resistor) tied to all eight outputs of the '156 and you can read all 8 switches individually without any external resistors!
84  Using Arduino / Programming Questions / Re: Error message... on: February 01, 2013, 08:34:13 pm
It is usual to name variables in lower case or Title Case and constants as UPPER CASE.

It looks to me that the compiler is seeing SENSOR_VALUE as a constant. The supplied code doesn't show the declaration of SENSOR_VALUE. Could the simple addition of an int at the start of the assignment solve the confusion?

Maybe I don't understand...
85  Using Arduino / General Electronics / Re: Wrong readings from voltage divider on: February 01, 2013, 08:20:31 pm
OK. Try a 47k in place of the 530k to +V and see what you get.
86  Using Arduino / General Electronics / Re: Is there a way to reduce resistor count in this circuit? on: February 01, 2013, 08:16:36 pm
So, if I get it, when you read A0 you get:

READINGSW7SW8
0.0Vopenopen
1.7Vopenclosed
2.5Vclosedopen
3.0Vclosedclosed

with Vcc being 5V

as suggested, replace the two series 10k resistors (R3 and R14) with one 20k.
87  Using Arduino / General Electronics / Re: Wrong readings from voltage divider on: February 01, 2013, 07:52:14 pm
Just for fun, swap the the resistor from +5 to the input pin to a 10k or 20k ohm resistor and see what happens.

My understanding is that most of these detectors are phototransistors which begin to conduct when (ir) light hits it.

Thus, this isn't really a voltage divider -- it just acts like one.  What is happening is that light strikes the base, the transistor begins to conduct.  The collector of a transistor closely approximates a current source.  The current flows through the resistor and Ohm's law dictates a voltage drop across it, which lowers the voltage at the connection of the R and T.
88  Using Arduino / General Electronics / Re: Wrong readings from voltage divider on: February 01, 2013, 07:26:26 pm
Hmmm. Is the IR receiver a photoresistor (LDR), a photodiode, or a phototransistor? Give me a part # and I'll poke around.
89  Using Arduino / Programming Questions / Re: how to add debounce code to pushingbox code on: February 01, 2013, 06:56:18 pm
You change your code in setup() to
Code:
pinMode(KEY, INPUT); 
digitalWrite(KEY, HIGH);
this initializes the pin as an input with a 20k ohm internal pullup resistor. This holds the pin HIGH unless something acts upon it.
You connect the button from the pin to ground.

Thus, the pin is held HIGH until the button is pressed -- then it goes LOW.

I didn't read your code but find where you are reading the pin (be sure to check for LOW now, instead of HIGH) with the digitalRead() and then add delay(100) to wait 1/10th of a second and then check that it is still HIGH.  That will usually be enough.
90  Using Arduino / General Electronics / Re: Wrong readings from voltage divider on: January 31, 2013, 08:09:13 pm
The ADC circuit in an Arduino charges a sample-and-hold capacitor to perform a read. If your source impedance is greater than about 10k ohms the sampling circuit can't charge up in time to get a good reading.  This is probably the cause of your problem -- even if it doesn't exactly explain it.  smiley

My very first (read kludgy) idea was, since most DMMs input impedance is about 10M ohms, you might just place a 10M ohm resistor in parallel or go down to 500k.

However, maybe your best bet is to isolate the Vdivider by using an op-amp voltage follower.

Unless you have a need to attach the IR sensor to +5V, I would swap the voltage divider so that I am reading the voltage across the sensor instead of the big R.

Let me know if this helps.

BTW, a lot of IR distance detectors (like the Sharp GP2Y0A21YK0F IR Range Sensor) output a voltage proportional to the range, that can be read easily by the Arduino without the voltage divider.
Pages: 1 ... 4 5 [6] 7