HI everyone,
I hope you can help me with something. please forgive me if I have left out some important info, I am a complete newbie to arduino and this ( my first project) is also
a learning project for me. The sketch below is a mash up of various other sketches - I welcome any suggestions to improve it
What the sketch is for:
recording temperature of two points on a alcohol distillation column, one at the top and the other half way down the column. display them on an lcd screen and log the data
on a sd card.
then switch two servos that open gate valves at specific times (actually specific temperatures) which allow the flow of alcohol vapor into different condensers.
what I would like to add to this sketch is the switching of two servos 'once' when the differences in the two sensors are at a defined point.
I can get it all to work but The problem I'm having is with turning the servos only once. they turn every time the loop executes. I have played around with
for (int i = 0; i < 1; i++)
{
servo()
}
but can't get it to work as desired within the main loop ( is this because the int i; is reset back to 0 at the start of each loop?)
I have also used it in 'setup' which worked once of course but this isn't much use to me.
thanks in advance for your help
cheers
Jim
The code so far is
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <Servo.h>
RTC_DS1307 RTC;
File myFile;
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
Servo myservo;
int angle = 180;Â Â // variable to store the servo direction
int angle2 = 90;
int angle3 = 0;
void setup(void)
{
 lcd.begin(16, 2);
 // start serial port
 Serial.begin(9600);
 Serial.println("Dallas Temperature IC Control Library Demo");
 pinMode(10, OUTPUT);
 myservo.attach(3); // attaches the servo on pin 3 to the servo object
Â
  if (!SD.begin(10)) {
  Serial.println("initialization failed!");
  return;
 }
 Serial.println("initialization done.");
Â
 myFile = SD.open("test.txt", FILE_WRITE);
Â
 Wire.begin();
 RTC.begin();
Â
 // Start up the library
 sensors.begin();
Â
 // locate devices on the bus
 Serial.print("Locating devices...");
 Serial.print(sensors.getDeviceCount(), DEC);
 Serial.println(" devices.");
 // report parasite power requirements
 Serial.print("Parasite power is: ");
 if (sensors.isParasitePowerMode()) Serial.println("ON");
 else Serial.println("OFF");
 // show the addresses we found on the bus
 Serial.print("Device 0 Address: ");
 printAddress(insideThermometer);
 Serial.println();
 Serial.print("Device 1 Address: ");
 printAddress(outsideThermometer);
 Serial.println();
 // set the resolution to 9 bit
 sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
 sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
 Serial.print("Device 0 Resolution: ");
 Serial.print(sensors.getResolution(insideThermometer), DEC);
 Serial.println();
 Serial.print("Device 1 Resolution: ");
 Serial.print(sensors.getResolution(outsideThermometer), DEC);
 Serial.println();
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
 for (uint8_t i = 0; i < 8; i++)
 {
  // zero pad the address if necessary
  if (deviceAddress[i] < 16) Serial.print("0");
  Serial.print(deviceAddress[i], HEX);
 }
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
 float tempC = sensors.getTempC(deviceAddress);
 Serial.print("Temp C: ");
 Serial.print(tempC);
}
// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
 Serial.print("Resolution: ");
 Serial.print(sensors.getResolution(deviceAddress));
 Serial.println(); Â
}
// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
 Serial.print("Device Address: ");
 printAddress(deviceAddress);
 Serial.print(" ");
 printTemperature(deviceAddress);
 Serial.println();
}
void loop(void)
{
Â
Â
 sensors.requestTemperatures();
 float T1 = sensors.getTempC(insideThermometer);
 T1 = T1 + sensors.getTempC(insideThermometer);
 T1 = T1 + sensors.getTempC(insideThermometer);
 T1 = T1/3;
Â
 float T2 = sensors.getTempC(outsideThermometer);
 T2 = T2 + sensors.getTempC(outsideThermometer);
 T2 = T2 + sensors.getTempC(outsideThermometer);
 T2 = T2/3;
Â
// int X = 1;
Â
//Â if (T1 > T2+2 && X > 0 )
//{
//Â myservo.write(angle);Â Â Â Â Â Â Â // tell servo to go to position in variable 'pos'
//Â Â delay(1240);
 // myservo.write(angle2);
 // X = X - 1;
//}
Â
 Serial.begin(57600);
 DateTime now = RTC.now();
  myFile.print(now.hour(), DEC);
  myFile.print(':');
  myFile.print(now.minute(), DEC);
  myFile.print(':');
  myFile.print(now.second(), DEC);
  myFile.print(", ");
 Â
 Â
 Serial.begin(9600);
 Serial.print(now.hour(), DEC);
 Serial.print(':');
 Serial.print(now.minute(), DEC);
 Serial.print(':');
 Serial.print(now.second(), DEC);
 Serial.print(", ");
Â
 myFile.print("inside, ");
 myFile.print(T1);
 myFile.print(",");
Â
 Serial.print("Inside, ");
 Serial.print(T1);
 Serial.print(", ");
Â
 myFile.print("Outside, ");
 myFile.println(T2);
 myFile.print(", ");
Â
 Serial.print("Outside, ");
 Serial.println(T2);
 Serial.print(", ");
Â
 lcd.setCursor(0, 0);
 lcd.print("inside ");
 lcd.print(T1);
Â
 lcd.setCursor(0, 1);
 lcd.print("outside ");
 lcd.print(T2);
Â
Â
 delay(2000);
Â
}