Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Ardumoto - Motor Driver Shield on: April 30, 2011, 02:23:54 pm
hi there im trying to make two, two way motors work with a thumb stick.
and all i have is this and i cant seem to get is to work

int pin1 = 0;
int pin2 = 0;
int pwm_a = 3;  //PWM control for motor outputs 1 and 2 is on digital pin 3
int pwm_b = 11;  //PWM control for motor outputs 3 and 4 is on digital pin 11
int dir_a = 12;  //direction control for motor outputs 1 and 2 is on digital pin 12
int dir_b = 13;  //direction control for motor outputs 3 and 4 is on digital pin 13


void setup()
{
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(pwm_b, OUTPUT);
  pinMode(dir_a, OUTPUT);
  pinMode(dir_b, OUTPUT);
 
  analogWrite(pwm_a, 100);  //set both motors to run at (100/255 = 39)% duty cycle (slow)
  analogWrite(pwm_b, 100);
 
}

void loop()
{
  digitalWrite(dir_a, LOW);  //Set motor direction, 1 low, 2 high
  digitalWrite(dir_b, LOW);  //Set motor direction, 3 high, 4 low
 
  delay(1000);
 
  analogWrite(pwm_a, 255);  //set both motors to run at 100% duty cycle (fast)
  analogWrite(pwm_b, 255);
 
  delay(1000);
 
  digitalWrite(dir_a, HIGH);  //Reverse motor direction, 1 high, 2 low
  digitalWrite(dir_b, HIGH);  //Reverse motor direction, 3 low, 4 high
 
  delay(1000);
 
  analogWrite(pwm_a, 100);  //set both motors to run at (100/255 = 39)% duty cycle
  analogWrite(pwm_b, 100);
 
  delay(1000);
}
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: arduino processing on: January 14, 2011, 10:06:05 am
can you send email to any were with an enthernet sheild
3  Forum 2005-2010 (read only) / Syntax & Programs / arduino processing on: January 14, 2011, 09:28:40 am
can any one  help me please im tryng to send an email threw processing and arduino can any one tell me what to do
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with delay on: January 14, 2011, 06:06:31 am
that dosnt work anything else
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with delay on: January 13, 2011, 11:18:18 am
hi there do you have any way to write
if (delay is longer than 4000){
digitalWrite(led, HIGH);
}
6  Forum 2005-2010 (read only) / Syntax & Programs / help with delay on: January 13, 2011, 03:52:38 am
hi there i need help with arduino i need some way to delay until buttonpin == high
 
this  is my code im using now


const int buttonPin = 2;     // the number of the pushbutton pin
const int one =  6;      // the number of the LED pin
const int call =  5;      // the number of the LED pin
const int endCall =  4;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int waitTime =4000;          // delay bettween call and end call

void setup() {
  // initialize the LED pin as an output:
  pinMode(one, OUTPUT);
  pinMode(call, OUTPUT);
  pinMode(endCall, OUTPUT);  
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);  
  digitalWrite(one, HIGH);
  digitalWrite(call, HIGH);  
  digitalWrite(endCall, HIGH);
   delay(3000);
}

void loop(){

  // read the state of the pushbutton value:


  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (digitalRead(buttonPin) == LOW)

      {
    digitalWrite(one, LOW);
    delay(500);
    digitalWrite(one, HIGH);
    delay(300);
    digitalWrite(call, LOW);
    delay(500);
    digitalWrite(call, HIGH);
    delay(waitTime);
    digitalWrite(endCall, LOW);
    delay(500);
    digitalWrite(endCall, HIGH);
// the problem    
delay(digitalRead(buttonPin) == HIGH);
     
  
  }
 
  

}


7  Forum 2005-2010 (read only) / Syntax & Programs / Re: MODIFIED - SECRET KNOCK DOOR LOCK on: December 31, 2010, 09:01:39 am
hi there i have this code for a knock detecting lock with servo but when i conect the servo the green led starts flashing and every thing gose weaird

/* Detects patterns of knocks and triggers a servo to unlock
   it if the pattern is correct.
  
   By Raymond Botha, original version by Steve Hoefer from http://grathio.com
   Version 0.1
   Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0
   http://creativecommons.org/licenses/by-nc-sa/3.0/us/
   (In short: Do what you want, just be sure to include this line and the four above it, and don't sell it or use it in anything you sell without contacting me.)
  
   Analog Pin 0: Piezo speaker (connected to ground with 1M pulldown resistor).
   Digital Pin 2: Switch to enter a new code.  Short this to enter programming mode.
   Digital Pin 3: Yellow LED.
   Digital Pin 4: Red LED.
   Digital Pin 5: Green LED.
   Digital Pin 6: Hall Effect Switch attached to the door.
   Digital Pin 12 (PWM): Servo attached to the lock.
   Digital Pin 18 (TX): LCD Screen (16x2 lines, Serial interface, SparkFun)
  
   Update - February 2010:
   Heavily modified Steve Hoefer's version of the door lock code.

   Did the following:
   -Used the Arduino Mega
   -Added LCD Feedback Screen
   -Added Yellow LED
   -Switched the gear motor with a Servo
   -Added door open/close sensor (Hall Effect Switch)
   -Lots of code changes
  
   Email me if you've fixed something in the code so that I can update it, my address is mail@raymondbotha.co.cc.
   I'm also available on the Arduino forums. (Prof.)
 */
 
// Library Includes
#include <Servo.h>
#include <SoftwareSerial.h>

// Pin definitions
const int knockSensor = 0;         // Piezo sensor on pin 0.
const int servoMotor = 11;          // The Servo
const int programSwitch = 2;       // If this is high we program a new code.
const int yellowLED = 3;           // Gear motor used to turn the lock.
const int redLED = 4;              // Status LED
const int greenLED = 5;            // Status LED
const int hallSwitch = 6;          // Hall Effect Switch (Door open/close)
const int lcdSerial = 18;          // LCD Feedback
 
// Tuning constants.  Could be made vars and hoooked to potentiometers for soft configuration, etc.
const int threshold = 3;           // Minimum signal from the piezo to register as a knock
const int rejectValue = 25;        // If an individual knock is off by this percentage of a knock we don't unlock..
const int averageRejectValue = 15; // If the average timing of the knocks is off by this percent we don't unlock.
const int knockFadeTime = 150;     // milliseconds we allow a knock to fade before we listen for another one. (Debounce timer.)
const int lockTurnDegrees = 170;   // Degrees that we turn the servo to unlock the door.

const int maximumKnocks = 20;       // Maximum number of knocks to listen for.
const int knockComplete = 1200;     // Longest time to wait for a knock before we assume that it's finished.


// Variables.
int secretCode[maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};  // Initial setup: "Shave and a Hair Cut, two bits."
int knockReadings[maximumKnocks];   // When someone knocks this array fills with delays between knocks.
int knockSensorValue = 0;           // Last reading of the knock sensor.
int programButtonPressed = false;   // Flag so we remember the programming button setting at the end of the cycle.

// Objects
SoftwareSerial LCD = SoftwareSerial(18, lcdSerial);
Servo servoLock;

void setup() {
  digitalWrite(yellowLED, HIGH);
  digitalWrite(greenLED, HIGH);
  digitalWrite(redLED, HIGH);

  pinMode(knockSensor, OUTPUT);
  pinMode(servoMotor, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(programSwitch, INPUT);
  pinMode(hallSwitch, INPUT);
  pinMode(lcdSerial, OUTPUT);
  
  servoLock.attach(servoMotor); // PWM Pin 12
  servoLock.write(lockTurnDegrees/2);
  
  LCD.begin(9600);                                 // Initializes the LCD.
  
  delay(200);
  digitalWrite(yellowLED, LOW);
  digitalWrite(redLED, LOW);
  
  LCD.print("System Started.");                    // Notification.
  delay(500);
}

void loop() {

  if (DoorOpen() == true) {
  LCD.print("Door Open.");
  digitalWrite(yellowLED, HIGH);
  } else {
    LCD.print("Door Closed.");
  }
  
  // Listen for any knock at all.
  knockSensorValue = analogRead(knockSensor);
  
  if (digitalRead(programSwitch)==HIGH){  // is the program button pressed?
    programButtonPressed = true;          // Yes, so lets save that state
    digitalWrite(redLED, HIGH);           // and turn on the red light too so we know we're programming.
  } else {
    programButtonPressed = false;
    digitalWrite(redLED, LOW);
  }
  
  if (knockSensorValue >=threshold){
    listenToSecretKnock();
  }
}

// Records the timing of knocks.
void listenToSecretKnock() {
  LCD.print("Knock Detected.");  

  int i = 0;
  // First lets reset the listening array.
  for (i=0;i<maximumKnocks;i++){
    knockReadings=0;
  }
  
  int currentKnockNumber=0;                           // Incrementer for the array.
  int startTime=millis();                             // Reference for when this knock started.
  int now=millis();
  
  digitalWrite(greenLED, LOW);                        // we blink the LED for a bit as a visual indicator of the knock.
  if (programButtonPressed==true){
     digitalWrite(redLED, LOW);                         // and the red one too if we're programming a new knock.
  }
  delay(knockFadeTime);                                     // wait for this peak to fade before we listen to the next one.
  digitalWrite(greenLED, HIGH);  
  if (programButtonPressed==true){
     digitalWrite(redLED, HIGH);                        
  }
  do {
    //listen for the next knock or wait for it to timeout.
    knockSensorValue = analogRead(knockSensor);
    if (knockSensorValue >=threshold){                   //got another knock...
      //record the delay time.
      LCD.print("Knocking...");
      now=millis();
      knockReadings[currentKnockNumber] = now-startTime;
      currentKnockNumber ++;                             //increment the counter
      startTime=now;          
      // and reset our timer for the next knock
      digitalWrite(greenLED, LOW);  
      if (programButtonPressed==true){
        digitalWrite(redLED, LOW);                       // and the red one too if we're programming a new knock.
      }
      delay(knockFadeTime);                              // again, a little delay to let the knock decay.
      digitalWrite(greenLED, HIGH);
      if (programButtonPressed==true){
        digitalWrite(redLED, HIGH);                        
      }
    }

    now=millis();
    
    //did we timeout or run out of knocks?
  } while ((now-startTime < knockComplete) && (currentKnockNumber < maximumKnocks));
  
  //we've got our knock recorded, lets see if it's valid
  if (programButtonPressed==false){             // only if we're not in programming mode.
   if (validateKnock() == true){
   if (servoLock.read() == lockTurnDegrees) {
        triggerDoorUnlock();
      } else if (servoLock.read() != lockTurnDegrees) {
        triggerDoorLock();
    } else {
      LCD.print("Incorrect Knock.");
      digitalWrite(greenLED, LOW);              // We didn't unlock, so blink the red LED as visual feedback.
      for (i=0;i<4;i++){                              
        digitalWrite(redLED, HIGH);
        delay(100);
        digitalWrite(redLED, LOW);
        delay(100);
      }
      digitalWrite(greenLED, HIGH);
    }
  } else { // if we're in programming mode we still validate the knock, we just don't do anything with the lock
    validateKnock();
    // and we blink the green and red alternately to show that program is complete.
    LCD.print("New lock stored.");
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
    for (i=0;i<3;i++){
      delay(100);
      digitalWrite(redLED, HIGH);
      digitalWrite(greenLED, LOW);
      delay(100);
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, HIGH);      
    }
  }
}
}

// Runs the servo to unlock the door.
void triggerDoorUnlock(){

  LCD.print("Door unlocking...");
  int i=0;
  
  // turn the servo.
  servoLock.write(lockTurnDegrees);
  digitalWrite(greenLED, HIGH);            // And the green LED too.
  
  // Blink the yellow LED a few times for more visual feedback.
  for (i=0; i < 15; i++){  
      digitalWrite(yellowLED, HIGH);
      delay(100);
      digitalWrite(yellowLED, LOW);
      delay(100);
        
  }
  

}

// Runs the servo to lock the door.
void triggerDoorLock(){
  if (DoorOpen() == true) {
  LCD.print("Open - No lock!");
  } else {
  LCD.print("Door locking...");
  int i=0;
  
  // turn the servo.
  servoLock.write(0);
  digitalWrite(redLED, HIGH);            // And the red LED too.
  
  // Blink the red LED a few times for more visual feedback.
  for (i=0; i < 15; i++){  
      digitalWrite(redLED, HIGH);
      delay(100);
      digitalWrite(redLED, LOW);
      delay(100);
    }
  }
  
}

// Sees if our knock matches the secret.
// returns true if it's a good knock, false if it's not.
boolean validateKnock(){
  int i=0;
 
  // simplest check first: Did we get the right number of knocks?
  int currentKnockCount = 0;
  int secretKnockCount
8  Forum 2005-2010 (read only) / Interfacing / Re: roborealm + arduino on: October 26, 2010, 07:20:31 am
hello can someone help me with roborealm
can someone help me i want to make a robo that will folow a red dot
i have see people do this on youtube i know how to make one turn in one direction (x axis)
but now i need to make it work on x z axis
pleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssse can some one help  :-/ :question
9  Forum 2005-2010 (read only) / Interfacing / joystick shield > xbee >servo on: November 28, 2010, 02:21:08 am
hi can any one help me please i am trying to get a joystick shield to control 2 servos(pan tilt) wireless i have 2 xbee sheilds; 2 arduinos; 2 xbee modules;  1 joy stick shield;
can some one help with code
10  Forum 2005-2010 (read only) / Interfacing / Re: Arduino > Xbee > Xbee > Arduino? on: November 27, 2010, 05:39:39 am
im trying something like that. i have 2 arduino 2 xbee moduals 2 xbee shields and a joystick shield 2 servos
now im trying to control 2 servos (pan and tilt) can any one give ideas or even better code
please help
thanks
P.S. im new at this
11  Forum 2005-2010 (read only) / Workshops / joystick shield>xbee>servos on: November 27, 2010, 03:55:08 pm
sorry if this is in the wrong place
hi can any one help me please i am trying to get a joystick shield to control 2 servos(pan tilt) wireless i have 2 xbee sheilds; 2 arduinos; 2 xbee modules;  1 joy stick shield;
can some one help with code (can you just make a code for me[smiley=cheesy.gif]) please i realy want to do this but i re aly dont know how to write code
12  Forum 2005-2010 (read only) / Bar Sport / roborealm on: October 26, 2010, 09:52:57 am
hi there can any one help me with roborealm i have two full rotation sevos attached to a robot and now i want to make that robot follow someone that is wearing a red shirt please can some one help with code i have no idea were to start  smiley
Pages: [1]