Pages: [1]   Go Down
Author Topic: help with arduino motor shield r3  (Read 702 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am new in using arduino and especially arduino motor shield and I cannot deal with this shield I tried this program but it doesnot work I know it have mistakes but I am searching in the web but I cannot find a solution

the program that I need to read two switches every switch will forward or reverse some motors
 I used if statement and I do not know what is the wrong with the program 

this a simple program of what I want

int sensor1 = 2;
int dirA = 12;
int speedA = 3;
int val1 = 0;

void setup() {
  pinMode(sensor1, INPUT);
  pinMode(dirA, OUTPUT);
  pinMode(speedA, OUTPUT);
}
 void loop() {
   val1 = digitalRead(sensor1);
   
   if (val1 == HIGH)
   {
     digitalWrite(dirA, HIGH);
     analogWrite(speedA, 128);
   }
   else
   {
    digitalWrite(dirA, LOW);
    analogWrite(speedA, 0);
   }
 }
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1015
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your loop is running very fast.
So the analogWrite() function is called repeatedly very fast, it should be called just once.
You can start to add a delay of 1 second: "delay(1000);" in your loop, just for testing purposes.
After that you should test for a change of the input. Perhaps you might even need a debouce.

If it doesn't work, make small pieces to find the problem.
Try switching a led (perhaps you have a 'uno', a led is at pin 13) according to the input.
Try turning the motor forward backward with delays.
If those are okay, connect them toghether can let the input change the direction and speed.
« Last Edit: May 01, 2012, 04:53:04 am by Krodal » Logged

Pages: [1]   Go Up
Jump to: