Hello, I have tried some codes out there but most of them wont work. Here is the best result I´ve found but it is not accurate to use that signal to move a servo for example. The returned value goes from 0 to 1000 but I know its not giving precise data because the fan speed it different. What am I doing wrong?
My idea is to amplify that signal to move a servomotor accordinlgly to move a big turbine engine,according to the PWM signal of the motherboard.
#include <LiquidCrystal.h>
LiquidCrystal lcd (9,8,7,6,5,4);
int suma;
int pos_pwm
int pwmvalor = 3;
int pwm_value;
void loop() {
suma = 0;
for (int i=0; i<10; i++){ // this is to get an average of readings
pwm_value = pulseIn(pwmvalor, HIGH,25000);
suma = suma + pwm_value;
pos_pwm = suma/10;
delay (100);
}
You forgot to #include the Servo library and define 'futaba'.
You forgot to define pulsomin and pulsomax.
You calculate the 'pos_pwm' value but don't use it for anything. You should tell the 'futaba' object that you want the servo to move: futaba.writeMicroseconds(1000+pos_pwm);
With various fixes:
#include <LiquidCrystal.h>
#include <Servo.h>
Servo futaba;
LiquidCrystal lcd (9, 8, 7, 6, 5, 4);
int suma;
int pos_pwm;
const int pwmvalor = 3;
const int pinservo = 2;
int pwm_value;
void setup()
{
Serial.begin(9600);
futaba.attach(pinservo);
lcd.begin (16, 2);
pinMode(pwmvalor, INPUT);
}
void loop()
{
// this is to get an average of 10 readings
suma = 0;
for (int i = 0; i < 10; i++)
{
pwm_value = pulseIn(pwmvalor, HIGH, 25000);
suma = suma + pwm_value;
delay (100);
}
pos_pwm = suma / 10;
lcd.setCursor (0, 0);
lcd.print (pos_pwm);
futaba.writeMicroseconds(1000 + pos_pwm);
}
Sorry the mesagge is a bit confusing because i just selected the part of the code where i had the problem. Thanks a lot for your help. The numbers shown on the screen goe from 0 to 50, being 50 the max rpm for the fan