Skip to main content
Tweeted twitter.com/StackArduino/status/716906892933644288
added 251 characters in body
Source Link

I am trying to use map command which is used to power servo 180 degrees as the potentiometer moves...

Forward

digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);

Backward in fact what i want to do is just when i adjust my potentiometer to zero; stop the dc motor then after turn the pot to 512 analog value turn the motor to the left (digitalWrite(I1, HIGH); digitalWrite(I2, LOW);)and then stop when it reach 512 then when adjust the pot back to zero turn the dc motor to the right (digitalWrite(I1, HIGH); digitalWrite(I2, LOW);) but the think is what i am trying to do is exactly what we can do with the servo motor in the knob http://www.arduino.cc/en/Tutorial/Knob

digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);

val = analogRead(potpin);        
  val = map(val, 0, 1023, 0, 180); 
  myservo.write(val);

I'm using a normal DC motor and l293D IC but I want to control the DC as knob method like the 200 degrees.

Code

#define E1 11    // Enable Pin for motor 
#define I1 10    // Control pin a for motor 
#define I2 9     // Control pin b for motor 
const int analogPin = A0;  
int analogValue ;  

void setup() {
  pinMode(E1, OUTPUT);
  pinMode(I1, OUTPUT);
  pinMode(I2, OUTPUT);

}
 
void loop() {
  
  int analogValue = analogRead(analogPin);

  if(analogValue > 20 && analogValue < 500512)  {
    
  analogWrite(E1, 255);   
  digitalWrite(I1, HIGH);
  digitalWrite(I2, LOW);
    delay(100); 
} else 
  analogWrite(E1, 255);  
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
 }

I am trying to use map command which is used to power servo 180 degrees as the potentiometer moves...

Forward

digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);

Backward

digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);

val = analogRead(potpin);        
  val = map(val, 0, 1023, 0, 180); 
  myservo.write(val);

I'm using a normal DC motor and l293D IC but I want to control the DC as knob method like the 200 degrees.

Code

#define E1 11    // Enable Pin for motor 
#define I1 10    // Control pin a for motor 
#define I2 9     // Control pin b for motor 
const int analogPin = A0;  
int analogValue ;  

void setup() {
  pinMode(E1, OUTPUT);
  pinMode(I1, OUTPUT);
  pinMode(I2, OUTPUT);

}
 
void loop() {
  
  int analogValue = analogRead(analogPin);

  if(analogValue > 2 && analogValue < 500)  {
    
  analogWrite(E1, 255);   
  digitalWrite(I1, HIGH);
  digitalWrite(I2, LOW);
    delay(100); 
} else 
  analogWrite(E1, 255);  
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
 }

I am trying to use map command which is used to power servo 180 degrees as the potentiometer moves...

in fact what i want to do is just when i adjust my potentiometer to zero; stop the dc motor then after turn the pot to 512 analog value turn the motor to the left (digitalWrite(I1, HIGH); digitalWrite(I2, LOW);)and then stop when it reach 512 then when adjust the pot back to zero turn the dc motor to the right (digitalWrite(I1, HIGH); digitalWrite(I2, LOW);) but the think is what i am trying to do is exactly what we can do with the servo motor in the knob http://www.arduino.cc/en/Tutorial/Knob

I'm using a normal DC motor and l293D IC but I want to control the DC as knob method like the 200 degrees.

Code

#define E1 11    // Enable Pin for motor 
#define I1 10    // Control pin a for motor 
#define I2 9     // Control pin b for motor 
const int analogPin = A0;  
int analogValue ;  

void setup() {
  pinMode(E1, OUTPUT);
  pinMode(I1, OUTPUT);
  pinMode(I2, OUTPUT);

}
 
void loop() {
  
  int analogValue = analogRead(analogPin);

  if(analogValue > 0 && analogValue < 512)  {
    
  analogWrite(E1, 255);   
  digitalWrite(I1, HIGH);
  digitalWrite(I2, LOW);
    delay(100); 
} else 
  analogWrite(E1, 255);  
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
 }
Post Migrated Here from electronics.stackexchange.com (revisions)
Source Link

Using map for DC motor instead of servo

I am trying to use map command which is used to power servo 180 degrees as the potentiometer moves...

Forward

digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);

Backward

digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);

val = analogRead(potpin);        
  val = map(val, 0, 1023, 0, 180); 
  myservo.write(val);

I'm using a normal DC motor and l293D IC but I want to control the DC as knob method like the 200 degrees.

Code

#define E1 11    // Enable Pin for motor 
#define I1 10    // Control pin a for motor 
#define I2 9     // Control pin b for motor 
const int analogPin = A0;  
int analogValue ;  

void setup() {
  pinMode(E1, OUTPUT);
  pinMode(I1, OUTPUT);
  pinMode(I2, OUTPUT);

}
 
void loop() {
  
  int analogValue = analogRead(analogPin);

  if(analogValue > 2 && analogValue < 500)  {
    
  analogWrite(E1, 255);   
  digitalWrite(I1, HIGH);
  digitalWrite(I2, LOW);
    delay(100); 
} else 
  analogWrite(E1, 255);  
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
 }