Paso 6: Programación de Arduino
El siguiente paso es agregar el código del programa a Arduino. Para esto necesitamos descargar algún software IDE libre desde este sitio (http://arduino.cc/en/Main/Software). Descargar el Software más reciente de IDE está disponible en el sitio.
1. descargar e instalar el software desde el sitio.
2. abrir el programa y luego conecte el clúster de Arduino a tu ordenador mediante el puerto USB.
3. Seleccione Herramientas y tabla de planchar y el Arduino que está utilizando.
3. Seleccione Puerto de herramientas y seleccione el puerto que es seleccionable.
4. descargar y abrir el archivo de abajo o iniciar un nuevo archivo y copia y pegue el código de abajo.
5. Presione el botón de flecha a la derecha en la barra de programa para subir el dibujo a tu Arduino.
// Title: Solar Collector & Radiant Heat Grid Controller// Date:12/01/14 // Author: Chris Biblis (My First Adruino Project )#include LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // define some values used by the panel and buttons int lcd_key = 0; int adc_key_in = 0; #define btnRIGHT 0 #define btnUP 1 #define btnDOWN 2 #define btnLEFT 3 #define btnSELECT 4 #define btnNONE 5 // read the buttons int read_LCD_buttons(){ adc_key_in = analogRead(0); // buttons when read are centered at these valies: 0, 144, 329, 504, 741 // we add approx 50 to those values and check to see if we are close if (adc_key_in > 1000) return btnNONE; if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 250) return btnUP; if (adc_key_in < 450) return btnDOWN; if (adc_key_in < 625) return btnLEFT; //Changed value to 625 do to double read from select button Default is 650. if (adc_key_in < 850) return btnSELECT; return btnNONE; } // Setup relay shield pin array. //RELAY SHIELD PIN SWAPS, D7 = D3, D9 = D11, D10 = D12 int relayPin[] = {2, 3, 11, 12}; int pinCount = 4;// Set On/Off Differentials for collector/tank temperatures. const int diffON = 5; const int diffOFF = 2;// Set Default Thermostat temperature int setTemp = 60;//Used for calibration int offSet[] = {-2, -1, 0, 1, 2};//Button Variables. int select = 0; int up = 0; int down= 0; int backLight = 10; boolean BLbutton = false; void setup(){ lcd.begin(16, 2); lcd.setCursor(0,0); //Introduction Screen lcd.print("Solar Collection"); lcd.setCursor(0,1); lcd.print("& Radiant Heater"); delay(2000); for (int thisPin = 0; thisPin < pinCount; thisPin++) { pinMode(relayPin[thisPin], OUTPUT);} } // Read average voltage from sensors int ReadSens(int x){ int i; int sval = 0; for (i = 0; i < 10; i++){ sval = sval + analogRead(x); } sval = sval / 10; return sval; } // Calculate temperature in F from voltage of sensors. int getTemp(int y){ //Convert to Celcius float a = (((y / 1024.0) * 5000)/10)-273.15; //Convert Celcius to Fahrenheit float b = a * 9.0 / 5.0 + 32.0; return b; }void loop(){ // Get average Voltage int amb = ReadSens(1); int col = ReadSens(2); int tk = ReadSens(3); int tt1 = ReadSens(4); int tt2 = ReadSens(5); // Get Temperatures & Apply OffSet { -2, -1 , 0, 1, 2 } int ambient = (getTemp(amb) + offSet[0]); int collector = (getTemp(col) + offSet[0]); int tank = (getTemp(tk) + offSet[0]); int transferTemp = (getTemp(tt1) + offSet[0]); int transferTemp1 = (getTemp(tt2) + offSet[0]); //Backlight button selection... if (BLbutton == true){pinMode(backLight, INPUT);} //turn backlight off else{pinMode(backLight,OUTPUT);} //turn backlight on // Display screens if (select == 3){select = 0;} if (select == 0){ lcd.clear(); lcd.setCursor(0,0); lcd.print(" Ambient Temp "); lcd.setCursor(6,1); lcd.print(ambient); lcd.print(" F"); } if (select == 1) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Set Ambient To:"); lcd.setCursor(6,1); lcd.print(setTemp); lcd.print(" F"); } if (select == 2) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("C: "); lcd.print(collector); lcd.print("F"); lcd.setCursor(9, 0); lcd.print("TK:"); lcd.print(tank); lcd.print("F"); lcd.setCursor(0, 1); lcd.print("T1:"); lcd.print(transferTemp); lcd.print("F"); lcd.setCursor(9, 1); lcd.print("T2:"); lcd.print(transferTemp1); lcd.print("F"); } lcd_key = read_LCD_buttons(); // read the buttons switch (lcd_key){ case btnSELECT:{ BLbutton = !BLbutton; delay(100); break; } case btnUP: { setTemp++; select = 1; delay(100); break; } case btnDOWN: { setTemp--; select = 1; delay(100); break; } case btnRIGHT: { select++; delay(100); break; } case btnLEFT: { select--; delay(100); break; } } // Runs circulation pump from collector to tank. if(collector > (tank + diffON)) {digitalWrite(relayPin[0], HIGH);digitalWrite(relayPin[1], HIGH);} if(collector <= (tank + diffOFF)) {digitalWrite(relayPin[0], LOW);digitalWrite(relayPin[1], LOW);} //Runs circulation pump from tank to radiant heat grid. if ((ambient < setTemp) && (tank >= 100)) {digitalWrite(relayPin[2], HIGH);} if (tank <= (setTemp + 10)) {digitalWrite(relayPin[2], LOW);} if (ambient > (setTemp + 2)) {digitalWrite(relayPin[2], LOW);} delay(500); }