ARDUINO PROGRAMMING

/* arduino program using "milis" command for DS18B20 sensor at pin 9 that measures temperature continuously and shown in I2C LCD and to move servo motor at pin 13 when temperature is 70 to 65 degree celcius and hold for 5 minutes while continuously measuring temperature

/*


#include <OneWire.h> //include OneWire library #include <DallasTemperature.h> //include DallasTemperature library #include <Wire.h> //include Wire library #include <LiquidCrystal_I2C.h> //include LiquidCrystal_I2C library #include <Servo.h> //include Servo library

//define DS18B20 sensor pin #define ONE_WIRE_BUS 9

//create object for the sensor OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire);

//create object for the I2C LCD LiquidCrystal_I2C lcd(0x27, 16, 2);

//create object for the servo motor Servo myservo;

//variables to store temperature and servo position float temperature; int servoPos = 0; unsigned long startTime;

void setup() { //begin communication with the sensor sensors.begin();

//begin communication with the I2C LCD lcd.begin(); lcd.backlight();

//attach the servo motor to pin 13 myservo.attach(13);

//initialize startTime startTime = millis(); }

void loop() { //read temperature from the sensor sensors.requestTemperatures(); temperature = sensors.getTempCByIndex(0);

//display temperature on the I2C LCD lcd.clear(); lcd.print("Temperature: "); lcd.print(temperature); lcd.print(" C");

//check if temperature is between 70 and 65 degrees if (temperature >= 70 && temperature <= 65) { //move the servo motor to the defined position for (servoPos = 0; servoPos <= 180; servoPos += 1) { myservo.write(servoPos); delay(15); } //hold the servo motor in position for 5 minutes if (millis() - startTime >= 300000) { //move the servo motor back to the initial position for (servoPos = 180; servoPos >= 0; servoPos -= 1) { myservo.write(servoPos); delay(15); } //reset the startTime startTime = millis(); } } }