I was working on controlling a high power motor with a heavy duty motor controller, and I was able to make my motor spin, but I wasn't able to incorporate a program for my pressure sensor and make it determine the speed of the motor. I'm pretty sure I connected the parts correctly on my circuit board, so I figure my code must have some mistake, or something missing. The pressure sensor I'm using: The motor controller I'm using: http://www.robotshop.com/en/arduino-compatible-mega-motor-shield-1a-5-28v.html#Useful The code I have:
int motorValue=0;
int sensorValue=0;
int sensorPin=A0;
int EnablePin=8;
int PWMPin2=3;
void setup() {
// put your setup code here, to run once:
pinMode(EnablePin, OUTPUT);
//pinMode(sensorPin, OUTPUT);
Serial.begin(9600);
pinMode(PWMPin2, OUTPUT);
pinMode(sensorPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
sensorValue = analogRead(sensorPin);
//float voltage = sensorValue * (5.0 / 1023.0);
//Serial.println(voltage);
delay(50);
motorValue=map(sensorValue,0,1023,0,255);
//motorValue=sensorValue / 4;
//analogWrite(motorPin,motorValue);
digitalWrite(EnablePin, HIGH);
analogWrite(PWMPin2, motorValue);
}
Edit: The sensor works by reading the voltage. Here's an actual picture of how I wired it: I used this wiring to print out the voltage with just the Arduino and it worked, and I'm using it with the same wiring but while having the motor shield on top, so that's why I'm guessing that I must not be programming the sensor right with the motor controller. I couldn't get the voltage readings when I used this setup with the motor driver shield.
"I'm pretty sure I connected the parts correctly"
- You may be pretty sure, but we aren't certain at all. Can we maybe see what you have wired up and how it is all connected?