i have arduino uno , motor shield connected it. have connected 2 dc motors (those yellow ones arduino car) when put in code turn on motors @ speed works when put commands in if function motors don't work except on pwm 255
here code i'm not professional in can revise
sorry new topic i'm in bit hurry
#include <irremote.h>
#include <servo.h>
#include<wire.h>
int recv_pin = 2;
irrecv irrecv(recv_pin);
decode_results results;
void setup()
{
irrecv.enableirin();
//setup channel a
pinmode(12, output); //initiates motor channel pin
pinmode(9, output); //initiates brake channel pin
//setup channel b
pinmode(13, output); //initiates motor channel pin
pinmode(8, output); //initiates brake channel pin
pinmode(11, output);
pinmode(3, output);
serial.begin(9600);
}
void loop() {
if (irrecv.decode(&results)) {
irrecv.resume();
if (results.value == 0xec27d43d){ // type remote forward robot control button hex value in underlined area.
//motor forward @ full speed
digitalwrite(12, high); //establishes forward direction of channel a
digitalwrite(9, low); //disengage brake channel a
analogwrite(11, 255); //spins motor on channel @ full speed
//motor b backward @ half speed
digitalwrite(13, high); //establishes backward direction of channel b
digitalwrite(8, low); //disengage brake channel b
analogwrite(3, 123); //spins motor on channel b @ half speed
serial.print("naprijed");
}
else if(results.value == 0x1a422e43){ // type remote left robot control button hex value in underlined area.
digitalwrite(12,high);
digitalwrite(9,low);
analogwrite(3, 123);
serial.print("lijevo");
}
else if(results.value == 0xa23bd824){ // type remote right robot control button hex value in underlined area.
digitalwrite(13,high);
digitalwrite(8,low);
analogwrite(11, 123);
serial.print("desno");
} else if(results.value == 0x86bd99c){ // type remote backward robot control button hex value in underlined area.
digitalwrite(12,low);
digitalwrite(9,low);
digitalwrite(13,low);
digitalwrite(8,low);
digitalwrite(11, 123);
analogwrite(3, 123);
serial.print("natrag");
}
else if(results.value == 0x7295a904){ // type remote stop robot control button hex value in underlined area.
digitalwrite(12,low);
digitalwrite(9,high);
digitalwrite(13,low);
analogwrite(8,high);
serial.print("stop");
}
}
}
here code i'm not professional in can revise
sorry new topic i'm in bit hurry

#include <irremote.h>
#include <servo.h>
#include<wire.h>
int recv_pin = 2;
irrecv irrecv(recv_pin);
decode_results results;
void setup()
{
irrecv.enableirin();
//setup channel a
pinmode(12, output); //initiates motor channel pin
pinmode(9, output); //initiates brake channel pin
//setup channel b
pinmode(13, output); //initiates motor channel pin
pinmode(8, output); //initiates brake channel pin
pinmode(11, output);
pinmode(3, output);
serial.begin(9600);
}
void loop() {
if (irrecv.decode(&results)) {
irrecv.resume();
if (results.value == 0xec27d43d){ // type remote forward robot control button hex value in underlined area.
//motor forward @ full speed
digitalwrite(12, high); //establishes forward direction of channel a
digitalwrite(9, low); //disengage brake channel a
analogwrite(11, 255); //spins motor on channel @ full speed
//motor b backward @ half speed
digitalwrite(13, high); //establishes backward direction of channel b
digitalwrite(8, low); //disengage brake channel b
analogwrite(3, 123); //spins motor on channel b @ half speed
serial.print("naprijed");
}
else if(results.value == 0x1a422e43){ // type remote left robot control button hex value in underlined area.
digitalwrite(12,high);
digitalwrite(9,low);
analogwrite(3, 123);
serial.print("lijevo");
}
else if(results.value == 0xa23bd824){ // type remote right robot control button hex value in underlined area.
digitalwrite(13,high);
digitalwrite(8,low);
analogwrite(11, 123);
serial.print("desno");
} else if(results.value == 0x86bd99c){ // type remote backward robot control button hex value in underlined area.
digitalwrite(12,low);
digitalwrite(9,low);
digitalwrite(13,low);
digitalwrite(8,low);
digitalwrite(11, 123);
analogwrite(3, 123);
serial.print("natrag");
}
else if(results.value == 0x7295a904){ // type remote stop robot control button hex value in underlined area.
digitalwrite(12,low);
digitalwrite(9,high);
digitalwrite(13,low);
analogwrite(8,high);
serial.print("stop");
}
}
}
your code hard understand. if used names instead of numbers pins:
always use digitalwrite() brake , direction pins.
always use analogwrite() pwm pins.
don't use "high" , "low" analogwrite(). high 1 mean "very slow".
code: [select]
// arduino motor shield pins
// channel a: left motor
const int leftbrakepin = 9; // set low move
const int leftdirectionpin = 12;
const int leftpwmpin = 3;
// channel b: right motor
const int rightbrakepin = 8; // set low move
const int rightdirectionpin = 13;
const int rightpwmpin = 11;
always use digitalwrite() brake , direction pins.
always use analogwrite() pwm pins.
don't use "high" , "low" analogwrite(). high 1 mean "very slow".
Arduino Forum > Using Arduino > Programming Questions > arduino motor shield
arduino
Comments
Post a Comment