Fan speed control
2 posters
Page 1 of 1
Fan speed control
So i tried to follow roboremo's dc motor speed project but changed the arduino coding and just add a diode to my circuit. I wanted the motor to only have three fixed speed. My problem is the motor turns on right away when powered on and not after command is given as it supposed to.And i'm not sure if the problem is because of the connection or the coding. Can someone please help?
Below is my schematic and my coding:
Below is my schematic and my coding:
- Code:
int motorPin = 9;
int speed;
String readString = "";
void setup() {
pinMode(motorPin, speed);
analogWrite (motorPin, 0);
Serial.begin(9600);
}
void loop() {
if (Serial.available()>0);
{
delay(3);
char c = Serial.read();
readString += c;
if(readString.length() > 0){
Serial.print(readString);
if (readString == "on") {
analogWrite(motorPin, 80);
if (readString == "slow"){
analogWrite(motorPin, 80);
}
if (readString == "medium"){
analogWrite (motorPin, 170);
}
if (readString == "fast"){
analogWrite (motorPin, 255);
}
}
if (readString == "off"){
analogWrite(motorPin, 0);
}
}
}
}
oheeela- Posts : 2
Join date : 2016-05-12
Re: Fan speed control
Circuit is OK.
There are problems with the code.
1) Why you added delay(3); ?
2) if (readString == "on")
I'm not sure that Arduino can compare strings with ==
3) if (readString == "on") {
analogWrite(motorPin, 80);
if (readString == "slow"){ ...
Second if is inside the first if, but string can not be "on" and "slow" at the same time, so the second if will never execute.
4) char c = Serial.read();
readString += c;
You keep adding characters to readString, but you never reset it.
If you send "on", then "slow", you think readString will be "slow",
but it will be "onslow".
Try to use an example from roboremo.com, and modify the exeCmd function.
There are problems with the code.
1) Why you added delay(3); ?
2) if (readString == "on")
I'm not sure that Arduino can compare strings with ==
3) if (readString == "on") {
analogWrite(motorPin, 80);
if (readString == "slow"){ ...
Second if is inside the first if, but string can not be "on" and "slow" at the same time, so the second if will never execute.
4) char c = Serial.read();
readString += c;
You keep adding characters to readString, but you never reset it.
If you send "on", then "slow", you think readString will be "slow",
but it will be "onslow".
Try to use an example from roboremo.com, and modify the exeCmd function.
Re: Fan speed control
I did try to do exactly as from roboremo but my motor doesnt rotate at all. The app was connected to the HC-05 but when i moved the slider nothing happen. so i dont know what goes wrong.
Here is my circuit just in case something's wrong with it.
Here is my circuit just in case something's wrong with it.
oheeela- Posts : 2
Join date : 2016-05-12
Similar topics
» toggle - control
» Add slider to control led intensity [ESP]
» Deltabot 3D Printer Control
» need to control smart servo with roboremo app slider
» Add slider to control led intensity [ESP]
» Deltabot 3D Printer Control
» need to control smart servo with roboremo app slider
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|