Hi,
I am trying to run a project where I need my temperature sensor recording all day with no stop. I also need a servo motor to run, but that has a very long delay (12 hours). I was wondering if its is possible to run it on the same arduino. I have both of the codes below.
Servo motor code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
delay(5000); // waits 15ms for the servo to reach the position
for (pos = 180; pos >= 0; pos -= 1) // goes from 180 degrees to 0 degrees
delay(15);// waits 15ms for the servo to reach the position
delay(43200000);
}
Temperature sensor code
//DHT humidity/temperature sensors
#include "DHT.h"
#include <Servo.h>
#define DHTPIN 7 // what pin we're connected to
Servo myservo;
//whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
int pos = 0;
void setup() {
Serial.begin(9600);
myservo.attach(9);
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float t = dht.readTemperature ();
float h = dht.readHumidity ();
Serial.print("Temperature: ");
Serial.println(t*9/5+32);
Serial.print("Humidity: ");
Serial.print(h);
Serial.println("%");
delay(3000);
}