Ciao a tutti.
Premesso che sono le mie prime prove con arduino quindi abbiate pazienza😅😅
Dovrei creare la ventilazione per la cabina DIY della mia stampante.
La velocita della ventola viene modificata da arduino in base alla temperatura.
Ho questo sketch:#include <LiquidCrystal.h>LiquidCrystal lcd(7, 8, 9, 10, 11, 12);float temp; // set temp as a whole numberint tempPin = A0; //arduino pin used for temperature sensorint tempMin = 23; // the temperature to start the buzzerint tempMax = 25; // temperature full speedint fan = 3; // the pin where fan is connectedint fanSpeed = 0; // fan speed variablevoid setup() { pinMode(fan, OUTPUT); // declaring fan pin 6 as output pinMode(tempPin, INPUT); // declaring tempPin A0 as input lcd.begin(16, 2); // LCD intialize lcd.clear(); // clears lcd lcd.print("Fan Speed:"); // prints "Fan Speed" 75-255 PWM lcd.setCursor(0,1); // Sets cursor for next line lcd.print("Temp:"); // Prints "Temperature" below "Fan Speed" Serial.begin(9600); // begins the serial monitor}void loop() { temp = analogRead(tempPin); float voltage = float(5000.0d/1024.0d)*(float)temp; float temp = voltage/10.0d; // formula for degrees celcius Serial.println(temp); // prints temp in serial monitor lcd.setCursor(12,1); // 12 character to the right on the first column lcd.print(temp); // prints the number on the 12 character delay(1000); // delay in between reads for stability if(temp < tempMin) { // if temp is lower than minimum temp fanSpeed = 0; // fan is not spinning digitalWrite(fan, LOW); // pin 6 output is low } if((temp >= tempMin) && (temp <= tempMax)) //if temperature is higher than the minimmum range { fanSpeed = map(temp, tempMin, tempMax, 75, 255); // the actual speed of fan analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed Serial.println(fanSpeed); // prints fan speed in serial monitor lcd.setCursor(12,0); // sets cursor lcd.print(fanSpeed); // prints lcd.print(" "); // fixes an error of random number display } }tutto funziona come dovrebbe tranne che quando si raggiunge la temperatura MAX la ventola non parte mai a piena velocità resta a valore 168 su 255 e sono erogati 8v invece di 12v.Qualcuno saprebbe darmi qualche suggerimento su perchè questo accade??Ho provato con un altro sketch a specificare velocità 255 e funziona, alla ventola arrivano 12v.