Go Down

Topic: how can i create a program for a 6v motor (Read 742 times) previous topic - next topic

navatodd

i was making some programs for this but my motor doesn't work pleas help me!!!!
(i believe) this is the best program:


#include <IRremote.h>

int RECV_PIN = 9;
int motor1 =  7;
int motorpwm=  3;
int motor2 =  6;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the ir receiver
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(motorpwm, OUTPUT);
}

void loop() {


if (irrecv.decode(&results)) {
   Serial.println(results.value, DEC);


   if(results.value == 2800){  //if you want to configure with your remote controll change the results.value
     digitalWrite(motor1, HIGH);   // set the LED on 
     digitalWrite(motor2, LOW);
  if (irrecv.decode(&results)) {
   Serial.println(results.value, DEC);
  if(results.value == 2672)
     digitalWrite(motor1, LOW);   // set the LED off
     digitalWrite(motor2, LOW);
     
   irrecv.resume(); // Receive the next value
  }
   if(results.value == 752)
     digitalWrite(motor1, HIGH);   // set the LED on
     digitalWrite(motor2, LOW);
   if(results.value == 2672)
     digitalWrite(motor1, LOW);   // set the LED off
     digitalWrite(motor2, LOW);

   irrecv.resume(); // Receive the next value

}
}
  analogWrite (motorpwm, 220);
}

Simplify your sketch and try one thing at a time.

First create a sketch that just runs the motor back and forth. Get that working before going to the next step

Then create another sketch that reports the IR status on the Serial Monitor window. Get that working.

Now you can combine the two.

Without getting into the sketch itself, your problem could be just about anything, so you need to take things one step at a time, and verify that the parts of your scheme work as expected. Maybe you're not using the right type of IR remote for the codes you're looking for. Who knows.

Go Up