0

I am trying to transmit signal to servo from transmitter through Arduino DUE and wrote code like this:

#include<Servo.h>

Servo servo1;

int ch1;


void setup() {
  // put your setup code here, to run once:

  pinMode(40,INPUT);
  pinMode(31,OUTPUT);
  servo1.attach(31);
  Serial.begin(9600);
  ch1 = 2000;
}

void loop() {
  // put your main code here, to run repeatedly:
ch1 = pulseIn(40,HIGH,25000);
 if (ch1 <= 2800 && ch1>= 1600)
 {

  Serial.print("Aileron:");
  Serial.println(ch1);

 }
   delay(100);
   }

Without if statement I get values of on average 2200, if I insert if statement values drop to 1800. I don't get why?

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
  • maybe the serial commands and the conditional statement delay the main loop and influence the measured pulse length. You can try to decrease the delay(100)... – user3704293 Jan 23 '16 at 16:50
  • I took out delay. Now it gives different number. If I put delay(0) or delay(1) it gives same old numbers of around 1800. I changed lower bound to 1200, numbers changed to around 1400. If I plug servo directly to receiver, servo doesn't fluctuate, if I plug in to arduino and connect receiver to arduino as well I receive a lot of noise. – user3076675 Jan 23 '16 at 22:53

0 Answers0