I guess I hate coding.

So this potentio meter reading is jumping all over the place. the One on the left is the Raw Potentiometer value ```ino -122 122 687 -120 120 684 -56 56 522 -121 121 686 -124 124 692 -57 57 524 -123 123 690 -120 120 683
14 Replies
MaderDash
MaderDash5w ago
So what are all the numbers? Post the code your useing to read the pot @TheStudier
TheStudier
TheStudierOP5w ago
´´´ino int motSpeedPin=3; int speed; int speed2; int xPin=A0; int xVal; int leftPin=5; int leftVal; int rightPin=4; int rightVal; void setup() { Serial.begin(9600); pinMode(motSpeedPin,OUTPUT); pinMode(leftPin,OUTPUT); pinMode(rightPin,OUTPUT); pinMode(xPin,INPUT); } void loop() { // step one step: xVal=analogRead(xPin); speed2=map(xVal,505,1023,50,255); speed=speed2*(-1); Serial.print(speed); Serial.print(" "); Serial.print(speed2); Serial.print(" "); Serial.println(xVal); if(xVal>530){ analogWrite(motSpeedPin,speed2); digitalWrite(leftPin,LOW); digitalWrite(rightPin,HIGH); } if(xVal<515){ analogWrite(motSpeedPin,speed); digitalWrite(leftPin,HIGH); digitalWrite(rightPin,LOW); } delay(100); } the code
MaderDash
MaderDash5w ago
Your mapping it incorrectly. Just print xval. And remove all the other mess. Just comment the rest out and print that out with no input. So we can see how much its changing please Also realize. This is a science. You can't just slap thing together and expect: 1 to learn. 2 to work. 3 to get repeatable results without giving repeating input. So you need to approach this systematically. @TheStudier Also fix your code formatting.
TheStudier
TheStudierOP4w ago
thanjs a lot
MaderDash
MaderDash4w ago
Let me know what the just raw value is. And no math or nothing. And mo moving the pot just let it sit and take like 10 samples please.@TheStudier
TheStudier
TheStudierOP4w ago
So the potentio meter here is at the "0-position" but it reads this: 23 23 23 22 24 26 27 28 28 27 27 28 29 28 28 0 29 28 So like every few seconds it goes to 0 This only happens when I put this code in "speed = map(xVal,0,522,255,0);" It works fine without this
MaderDash
MaderDash4w ago
This is why I asked again for the RAW data please. Because that map is no good. @TheStudier I just need to see the raw data; just serial print out the analog read with the wiper somewhere in the middle, not being touched. Get it?
TheStudier
TheStudierOP4w ago
517 518 518 517 517 518 517 517 517 518 those are the raw values from the middle works perfectly without the map like I said
MaderDash
MaderDash4w ago
Ok so your pots fine now fix your map. speed2=map(xVal,0,1023,0,255); Now set that and print out that output.
TheStudier
TheStudierOP4w ago
517 518 518 518 518 518 517 516 517
MaderDash
MaderDash4w ago
Ok we should be printing out speed2 now
TheStudier
TheStudierOP4w ago
got it kinda working thanks a lot for helping
MaderDash
MaderDash4w ago
Thats my goal verify the componunt is working within reason. Then get you reset on a path with level footing. So you can make progress. If you took/take anything I said/say as talking down. Or insulting or anything. Please dont. I simply need a direct responce to what I am attempting to do as fast as possible. So I can assist you as best as I can and as efficiently as I can. If the pot proven to be defective or say wireing messed up or what ever we would had a great spot for farther analysis. Also in the arduino ide. Ctrl and T key should auto format your code so it looks better. 😉
TheStudier
TheStudierOP4w ago
okay tjanks again

Did you find this page helpful?