![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
Moderátor: Moderátori
A čo keby si nám Ty dal schému a tvoj zdroják, boli by sme múdrejší.risik12 napísal:Zdravím, mám problém s Arduino PWM ventilátorom pretože keď regulujem rýchlosť tak pri hodnote 0 mi ventilátor točí pri malých otáčkach ....ostatne hodnoty do 255 krásne fungujú. Neviem čím by to mohlo byť, keď tak mi pošlite schému, zdroják alebo poradte. Ďakujeem![]()
![]()
![]()
![]()
![]()
![]()
Kód: Vybrať všetko
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4,7);
int fanSpeed = 0;
String command;
char werd;
int currentFan = 0;
int rearSpeed = 0;
int front_a = 5;
int pin4 = 4;
int pin2 = 7;
int frontSpeed = 0;
int commandCheck;
String rearMarker = " ";
String frontMarker = "-> ";
String radiatorMarker = " ";
void setup() {
pinMode(2, OUTPUT);
digitalWrite(5, LOW);
// fans
pinMode(5, OUTPUT);//front 140mm
pinMode(4, OUTPUT);//front 140mm
analogWrite(5,0);
Serial.begin(9600);
Serial.println();
Serial.flush();
}
void loop(){
// this is what reads your serial commands
while ( Serial.available() > 0 ) {
// small delay because it can only deliver the bytes so quickly
delay(5);
// you have to read one byte (one character) at a time
werd = Serial.read();
// append the character to our "command" string
command += werd;
}
// clear serial so it's ready for your next command
Serial.flush();
if ( command.length() > 0 ) {
commandCheck = 0;
if ( command == "front" ) {
currentFan = 0;
frontMarker = "-> ";
}
else {
// flag so we know it wasn't a change fan command
commandCheck = 1;
}
if ( commandCheck == 1 ) {
// the ".toInt()" appended to the command variable is to convert
// the user entered "command" from a string into an integer so
// that we can use it to set the pin's PWM pulse width
// (it'll error if you send an integer in string format)
if ( currentFan == 0 ) {
//front
analogWrite(front_a, command.toInt());
frontSpeed = command.toInt();
}
}
command = "";
Serial.print(frontMarker);
Serial.print("Aktualna hodnota: ");
Serial.println(frontSpeed);
Serial.print(rearMarker);
// this function (below) is just to print a ton of empty lines so that the UI "appears" to be refreshing like a screen.
// you'll have to set your serial monitor to a certain width to get that effect to work correctly, of course
clear();
}
}
void clear() {
Serial.println();Serial.println();Serial.println();
}
Kód: Vybrať všetko
int pwmPin = 9; // digital pin 9
int pwmVal = 0;
void setup()
{
pinMode(pwmPin, OUTPUT); // sets the pin as output
Serial.begin(9600);
}
void loop()
{
if (pwmVal != 255) {
analogWrite(pwmPin, pwmVal);
//pwmVal += 10;
Serial.print(pwmVal); // Print red value
Serial.print("\n"); // Print a tab
} else {
Serial.print('at max high'); // Print red value
Serial.print("\n"); // Print a tab
}
delay(1000);
}
Ja vrelo doporučujem to čo sender teda možnosť č. 3.You have basically three options:
1) Use inverting output mode and 255-duty as OCR value (not having a full on is much less annoying than not having a full off).
2) Use the Phase Correct PWM Mode.
3) Disconnect the OC pin for duty=0.
Kód: Vybrať všetko
void analogWrite(uint8_t pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them. Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
pinMode(pin, OUTPUT);
if (val == 0)
{
digitalWrite(pin, LOW);
}
else if (val == 255)
{
digitalWrite(pin, HIGH);
}
else