Read PWM from motherboard to move a servo

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 setup() {
Serial.begin(9600);
futaba.attach(pinservo, pulsomin, pulsomax);
lcd.begin (16, 2);
pinMode(pwmvalor, INPUT);

}

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);
}

lcd.setCursor (0,0);
lcd.print (pos_pwm);

}

Returned from where? The pulseIn()? What is the source of the PWM signal (what is connected to pin 3)?

What is the structure of the signal that the servomotor expects? A hobby servo would expect a pulse from 1000 to 2000 us long every 20ms ( 0 - 180°)

What does the code do that is not what you want?

Why do this inside the for loop for every iteration? Okey, it doesn't create the issue.

Missing a ';'.

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

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.