-
-
Save sankarcheppali/c327c786380f304eda039697aa1d4845 to your computer and use it in GitHub Desktop.
dc water pump speed control using arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* receive command from serial and contorl motor speed by setting pwm duty | |
*/ | |
// motor A Control pins (output 1,ouptut 2) | |
#define IN1 5 | |
#define IN2 6 | |
#define ENA 3 | |
void setup() { | |
pinMode(IN1,OUTPUT); | |
pinMode(IN2,OUTPUT); | |
pinMode(ENA,OUTPUT); | |
// put the motor in forward direction | |
digitalWrite(IN1,HIGH); | |
digitalWrite(IN2,LOW); | |
// set default speed | |
analogWrite(ENA,100); | |
Serial.begin(115200); | |
} | |
void loop() { | |
if (Serial.available()) { | |
String inputString = Serial.readStringUntil('\n'); | |
if(inputString.startsWith(":")){ | |
String sliderValueStr = inputString.substring(1); // extract the angle | |
int sliderValue = strtol(sliderValueStr.c_str(), NULL, 10); // convert str to int | |
Serial.print("Received angle set cmd "); | |
Serial.println(sliderValue); | |
analogWrite(ENA,map(sliderValue, 0, 180, 0, 255)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment