0

I am using teensy 2.0 as DAC. I am trying to write signals on rudder and throttle of the ship via relay. How can I write these analog signals? Should I specify voltage for every pin?

Here is my code:

int Rudder_p= 21; //Digital Write
int Rudder_s= 20; //Digital Write
int Throttle_p= 19; //Analog write
int Throttle_s= 18; //Analog write
int Throttle_T= 17; //Digital Write

void setup() {
  Serial.begin(9600);
  pinMode(Realy1,OUTPUT);
  pinMode(Rudder_p,INPUT);
  pinMode(Rudder_s,INPUT);
  pinMode(Throttle_p,OUTPUT);
  pinMode(Throttle_s,OUTPUT);
  pinMode(Throttle_T,INPUT);
  
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
  }
}

// the loop routine runs over and over again forever:
void loop() {

  //Relay 
  digitalWrite(Relay1,HIGH);
  delay(500);
  digitalWrite(Relay1,LOW);
  delay(500);
  
   //I am missing logic here:

  // read the input on analog pin 21
  int Value = analogWrite(F0);
  delay(1);        // delay in between reads for stability
}
  • 1
    You don't use an analog signal to control a relay. – Edgar Bonet Jun 19 at 8:24
  • I am using digital signal to control relay. But I need to be able to write analog write to control throttle and rudders. Each of them has reference voltage 5V and signal voltage between 0.5-4.5 VDC. I don't know how to use analogWrite() while setting up these voltages. – Fourier Jun 19 at 8:39
  • Do you really need an analog voltage, or a PWM signal? Normally throttle and rudders are controlled via servos, which need a PWM like signal, not an analog signal – chrisl Jun 19 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.