hi i have a motor shield from adafruit and am trying to controll a motor with it but it does not work as expected
here is the code
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include
AF_DCMotor Drill(4);
int drill = 0;
int drill2 = 0;
void setup() {
// turn on motor
Drill.setSpeed(200);
Drill.run(RELEASE);
// pinmodes
pinMode(A2, INPUT);
pinMode(A3, INPUT);
}
void loop() {
drill = analogRead(A2);
drill2 = analogRead(A3);
if (drill >= 1100) {
Drill.run(FORWARD);
}
else if (drill2 >= 1100) {
Drill.run(BACKWARD);
} else {
Drill.run(RELEASE);
}
}
this code should run the motor forward when A2 is high and reverse when A3 is high but when i give either pins 5V it goes forward
What Arduino board do you have?
What motor? Post a data sheet.
What is the motor power supply? Power supply specifications (volts, amps)?
Read the forum guidelines to see how to properly post code and some infrmation on how to get the best from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
1 Like
Your code will not compile.
jon45676543:
#include
#include what?
JCA34F
December 29, 2021, 1:13am
4
What is connected to pins A2 and A3? How is whatever it is wired?
My mistake, that was to include the motor shield library
A couple of push switches
Why use analogRead() on switches? How are they wired?
Why not answering questions?
jon45676543:
if (drill >= 1100) {
What Arduino board's analogRead() returns greater than 1023?
You can go back and fix the improperly posted code in your original post by highlighting the code and clicking the </> in the menu bar.
system
Closed
June 28, 2022, 2:37am
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.