Go Down

Topic: Problem controlling SSR with arduino via PID library (Read 207 times) previous topic - next topic

drksun

Hey guys I'm working on my first arduino project, a PID controller. I'm still working on the user input section of the code so right now I'm just defining a set temp and trying to get the heater to hold at that temp (100*C). My code compiles but the heater never turns on, i checked the digital pin driving the relay and it's outputting a voltage but the SSR never comes on.

Initially I read that relays need a higher current than what the arduino can output but the datasheet for my Fotek SSR-25DA says the trigger current is 7.5mA/12v, i tested the trigger load on the relay at 5v to be close to 5mA (I'm also confused why the current attenuates with lower driving voltages, I would think it would follow V=IR). Since the arduino can put out 40mA? shouldn't this be working or do I still need an NPN transistor (i was thinking a 2n2222).

For wiring it just  D6 to the + on relay and - to ground, I even tested a new sketch just to turn the relay on without any PID control and was unable to. If i take a 5v 1A power supply right to the relay it turns on fine. Again measuring D6 shows that it is outputting something. It sounds like I need more current but according to the datasheets I should be ok?

Code: [Select]
/***************************************************
  This is an example for the Adafruit Thermocouple Sensor w/MAX31855K

  Designed specifically to work with the Adafruit Thermocouple Sensor
  ----> https://www.adafruit.com/products/269

  These displays use SPI to communicate, 3 pins are required to 
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
****************************************************/

#include "Adafruit_MAX31855.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <PID_v1.h>

// set replay pin for PID
#define RelayPin 6

double Setpoint, Input, Output;

int thermoCLK = 5;
int thermoCS = 4;
int thermoDO = 3;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

int WindowSize = 5000;
unsigned long windowStartTime;


// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// initialize the library and set the LCD address to 0x27 for a 16x2 line display
LiquidCrystal_I2C lcd(0x27,16,2);

 
void setup() {

  Serial.begin(9600);
  windowStartTime = millis();
 
// inital setpoint before implementing control
  Setpoint = 100;
 
  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);
 
  //turn the PID on
  myPID.SetMode(AUTOMATIC);
 
  // set up the LCD's number of columns and rows:
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  lcd.print("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  Input = thermocouple.readCelsius();
 
  myPID.Compute();

  /************************************************
   * turn the output pin on/off based on pid output
   ************************************************/
  if(millis() - windowStartTime>WindowSize)
  { //time to shift the Relay Window
    windowStartTime += WindowSize;
  }
  if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
  else digitalWrite(RelayPin,LOW);
 
 
 
  // basic readout test, just print the current temp
   lcd.setCursor(0, 0);
   lcd.print("Set Temp = ");
   lcd.println(Setpoint);
   lcd.print("  ");
   lcd.setCursor(0, 1);
   if (isnan(Input))
   {
     lcd.print("T/C Problem");
   }
   else
   {
     lcd.print("C = ");
     lcd.print(Input);
     lcd.print("  ");
   }

   delay(100);
}

drksun

nice i fixed it! apparently you need to set the pin mode first..

Code: [Select]
  pinMode(RelayPin, OUTPUT);

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy