i want my motors speed to be constant with the temperature via an equation, its a school project. help!? Answered
my project is to make a fan that will be constant (speed) with the temperature of the surrounding, display the temperature on an lcd screen and have a servo tilt it up and down. I have made my code for now and it seems correct, i think my problem is with the clarity of my code or the power. lcd + motor + servo = aprox 15 volts, i use the aruinos 5v connected from my laptop to power the lcd screen and i have an external 9v battery for motor and servo. Please help me connect the battery correctly or change my code?
Speed = temp * 6.375
why? because= max speed is 255, and i think 40 *C is a max temperature + 10*C was the lowest temperature and 64 was lowest speed i preferred.
so 255%40 = 6.375
to test then i used lowest temp and speed.
64%10 = 6.4 so i thought 6.375 was good because any higher would mean it would reach a number higher than 255.
but this equation seems to give decimals, maybe arduino wont read decimals as speed? or am i coding for something different than what i want to accomplish?
english is my second language there fore it was probably a bit unclear to understand, sorry!
Copy of Code:
//Temperature Run fan with Servo angle tilter
#include <Servo.h> // Servo library of commands
#include <LiquidCrystal.h> //lcd library of commands
LiquidCrystal lcd(12,11,5,4,3,2); //set pins
const int temperaturePin = 0;
const int motorPin = 9;
float voltage,degreesc, degreesF;
voltage = getVoltage (temperaturePin);
degreesc = (voltage - 0.5) * 100.0;
// Tell servo to go to 180 degrees, stepping by two degrees
for(position = 0; position < 180; position += 2)
servo1.write(position); // Move to next position
delay(20); // Short pause to allow it to move
speed = constrain(speed, 0, 255);
speed = degreesc * 6.375;
lcd.print(" deg C: ");
float getVoltage (int pin)
return (analogRead(temperaturePin) * 0.004882814);