AF_Motorshield & Sensors... Howto???

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
arts
 
Posts: 3
Joined: Sat Oct 23, 2010 8:34 am

AF_Motorshield & Sensors... Howto???

Post by arts »

Hi all,

yes - i am new and lucky now with my new Arduino UNO an the AF_Motorshield!

The code for my DC-Motor 12V on the page http://www.ladyada.net/make/mshield/use.html works very well. I am able to change values ;) But... i would like to control the dc-motor with switches an sensors.

Please can someone have a look at my attached presentation. The functions are listed there.
How do I do now to build the right sketch

Thank you for your hints
arts
Attachments
Schema AF_Sensoren_Motor.png
Schema AF_Sensoren_Motor.png (192.94 KiB) Viewed 1518 times

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: AF_Motorshield & Sensors... Howto???

Post by adafruit_support_bill »

Have you been through the Arduino tutorials? That is always a good place to start.

Then have a look at the tutorial for the PIR sensor. There is sample code there. If you put the motion detection code in your Setup() function, your program won't start until motion is detected.
Switches are easy. These are covered in the Arduino tutorials. For the Parallax ultrasonic, you should check the Parallax site. The Adafruit ultrasonic tutorial is for the Maxbotics sensor.

User avatar
len17
 
Posts: 394
Joined: Sat Mar 14, 2009 7:20 pm

Re: AF_Motorshield & Sensors... Howto???

Post by len17 »

arts wrote:i would like to control the dc-motor with switches an sensors.
I've done that. I published the code here: http://forums.adafruit.com/viewtopic.ph ... 705#p55848
That code is a bit complicated - you may want to go through the tutorials first as arduwino suggested.

Also, make sure your switches and sensors are on pins that aren't used by the MotorShield. The FAQ has a list of which pins are used: http://www.ladyada.net/make/mshield/faq.html

User avatar
arts
 
Posts: 3
Joined: Sat Oct 23, 2010 8:34 am

Re: AF_Motorshield & Sensors... Howto???

Post by arts »

hi
thanks for your help and your hints. you are right :wink: i will have to dive in to the arduino-tutorials to find out how i can use the free analog pins for my application. it will be a hart peace of work for me. as soon as i find out how it works, i will place it here.
greetings
arts

User avatar
arts
 
Posts: 3
Joined: Sat Oct 23, 2010 8:34 am

Re: AF_Motorshield & Sensors... Howto???

Post by arts »

hi,
the first steps are resolved. The control of the dc-motor with 2 switches work very well.
The next steps with the Sensors "PIR & Ultrasonic" will be more difficult. I have found the tutorials for this...
Attached you can find the sketch and the schematic of my current solution.

Code: Select all

/* ***************************************
DC_Motor turns with puls from SWITCH_A >>FORWARD & with puls from SWITCH_B <<BACHKWARD;
adapted by arts 25.10.2010; based on sketch www.ladyada.net/make/mshield/ 
**************************************** */
#include <AFMotor.h>
#define SWITCH_A 14  //digital input pin A0 resp. 14
#define SWITCH_B 15  //digital input pin A1 resp. 15
int val = 0;
AF_DCMotor motor(2, MOTOR12_64KHZ);  // create motor #2, 64KHz pwm
void setup() {
  pinMode(SWITCH_A, INPUT);  // and SWITCH_A is an input
  pinMode(SWITCH_B, INPUT);  // and SWITCH_B is an input
  motor.setSpeed(255);  // set the speed to 200/255
}
void loop() {
  val = digitalRead(SWITCH_A);   // read input value of SWITCH_A and store it
  if (val == HIGH)   // check whether the input is HIGH (SWITCH_A pressed)
  { 
    motor.run(RELEASE);   // motor stopp
    delay(1000);    // motor wait 1000ms
    motor.run(FORWARD);  // motor turns forward
    delay(1000);    // motor wait 1000ms
  } 
  {
    val = digitalRead(SWITCH_B); // read input value of SWITCH_B and store it
    if (val == HIGH)  // check whether the input is HIGH (SWITCH_B pressed)
    {
      motor.run(RELEASE);  // motor stopp
      delay(1000);    // motor wait 1000ms  
      motor.run(BACKWARD);  // motor turns BACKWARD
      delay(1000);  // motor wait 1000ms
    }  
  }
}
Attachments
Schema AF_Sensoren_Motor2.png
Schema AF_Sensoren_Motor2.png (334.27 KiB) Viewed 1471 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”