Go Down

Topic: help with arduino motor shield r3 (Read 896 times) previous topic - next topic


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);
    digitalWrite(dirA, LOW);
    analogWrite(speedA, 0);


May 01, 2012, 11:49 am Last Edit: May 01, 2012, 11:53 am by Krodal Reason: 1
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.

Go Up