Μotor doesn't perform analogWrite

Hi,
Recently i started to making a new robot with one motor controlled be an arduino nano ch340 and a transistor. I uploaded this code to test it (the first attachment) and it worked as i expected.Suddenly when i uploaded my code which is the seconde attachment my robot executed only the “digital” ones commands.Do you have any idea about my problem?Please answer me soon.

sketch_aug25a.ino (345 Bytes)

IR_COMMUNICATION.ino (617 Bytes)

my robot executed only the "digital" ones commands

What does that mean?

dionisis05:
Hi,
Recently i started to making a new robot with one motor controlled be an arduino nano ch340 and a transistor. I uploaded this code to test it (the first attachment) and it worked as i expected.Suddenly when i uploaded my code which is the seconde attachment my robot executed only the "digital" ones commands.Do you have any idea about my problem?Please answer me soon.

What do you mean by 'my robot executed only the "digital" ones commands'? Insert some serial prints in the case blocks in order to determine if you are actually receiving the IR codes you expect. Also print out the codes you do receive from the IR.

ToddL1962:
What do you mean by 'my robot executed only the "digital" ones commands'? Insert some serial prints in the case blocks in order to determine if you are actually receiving the IR codes you expect. Also print out the codes you do receive from the IR.

Ι mean that the motor doesnt do anything when i press the button which activates the motor at speed 100 of 255. The motor only run at 255 and 0.Also i tried to see if it is not receiving the correct code from my controller by adding a command : Serial.println(100) and it worked

Serial.println(100) and it worked

I have no idea what that is supposed to tell you.

Try this:

#include <IRremote.h>
#define fast 765
#define stp 39015
#define slow 43095

int motorPin = 3;
int receiver_pin = 6;
IRrecv receiver(receiver_pin);
decode_results output;

void setup()
{
   pinMode(motorPin , OUTPUT);
   Serial.begin(9600);
   receiver.enableIRIn();
}

void loop()
{
   if (receiver.decode(&output))
   {
      unsigned int value = output.value; // print remote 
      Serial.print("IR input value = <");  // input
      Serial.print(value);
      Serial.println(">");
      switch (value)
      {
         case fast:
            analogWrite(motorPin , 255);
            break;

         case slow:
            analogWrite(motorPin , 100);
            break;

         case stp:
            analogWrite(motorPin , 0);
            break;
      }
      receiver.resume();
   }
}

What is printed in serial monitor when you run that code (copy and paste the result into a new post)?

Note that the above code was auto formatted and posted in code tags.

Thats are the results

OP image:


It is better if you copy the serial monitor text output and paste to a reply than make us download an image.

What is the serial monitor output of this code? Note that I changed the value variable data type to unsigned long.

#include <IRremote.h>
#define fast 765
#define stp 39015
#define slow 43095

int motorPin = 3;
int receiver_pin = 6;
IRrecv receiver(receiver_pin);
decode_results output;

void setup()
{
   pinMode(motorPin , OUTPUT);
   Serial.begin(9600);
   receiver.enableIRIn();
}

void loop()
{
   if (receiver.decode(&output))
   {
      unsigned long value = output.value; // print remote *** changed to unsigned long data type 
      Serial.print("IR input value = <");  // input
      Serial.print(value);
      Serial.println(">   ");
      switch (value)
      {
         case fast:
            Serial.println("Fast");
            analogWrite(motorPin , 255);
            break;

         case slow:
            Serial.println("Slow");
            analogWrite(motorPin , 100);
            break;

         case stp:
            Serial.println("Stop");
            analogWrite(motorPin , 0);
            break;
      }
      receiver.resume();
   }
}

The serial print is the most valuable troubleshooting tool, for your code, that you have available. Use prints to follow the program flow and variable values.

Please post a schematic drawing of your wiring. What is the motor driver? Specs of the motor? Specs of the power supply(s)?