Thanks for reply,
- this is my code:
#include <math.h>
#include <avr/sleep.h>
#define interruptPin 2
float vout = 0.0;
float vin = 0.0;
float RV1 = 100000.0; // resistance of R1 (100K)
float RV2 = 10000.0; // resistance of R2 (10K)
int value = 0;
int ThermistorPin = 0;
int Vo;
float R1 = 10000;
float logR2, R2, T, HT, CT;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
int identifier = 88;
double thePower, tempC = 0, tempP = 0;
int count = 0;
char buffer1[30], buffer2[30];
int volt = 99;
int Irms = 999;
int index;
char inchar;
String temp = "";
char pos[80];
byte start_with = 0;
byte end_with = 0;
byte CRC = 0;
int b;
float a,y=0;
String incomingByte = "";
unsigned int stringLength;
int started = 0;
int l1 = 0;
int l2Pin = 3;
int lPin = 2;
int s1Pin = 13;
int s2Pin = 12;
int s3Pin = 11;
int s4Pin = 10;
int rbPin = 9;
int pPin = 8;
int lrPin = 5;
int lgPin = 6;
int lbPin = 7;
byte SENSE = 6;
int valve = 0;
void(* resetFunc) (void) = 0;//declare reset function at address 0
void Going_To_Sleep(){
//Serial.println("Standby");
delay(1000);
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // setting sleep mode (full sleep)
noInterrupts (); // make sure no interrupt before sleep
sleep_enable(); // enable sleep mode
EIFR = bit (INTF0); // clear flag for interrupt 0
attachInterrupt(0, wakeUp, FALLING); // attach an interrupt to pin d2
delay(1000); // wait a second to allow the led to be turned off before going to sleep
interrupts (); // interrupts allowed now, next instruction WILL be executed
sleep_cpu(); // activate sleep mode
sleep_disable(); // disable sleep mode (next line of code executed after the interrupt)
}
void wakeUp(){
detachInterrupt(0); //Removes the interrupt from pin 2;
}
void takeRead(){
Vo = analogRead(ThermistorPin);
R2 = R1 / (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T = T - 273.15;
}
void setup() {
pinMode(lPin, OUTPUT);
pinMode(s1Pin, OUTPUT);
pinMode(s2Pin, OUTPUT);
pinMode(s3Pin, OUTPUT);
pinMode(s4Pin, OUTPUT);
pinMode(rbPin, OUTPUT);
pinMode(pPin, OUTPUT);
pinMode(lbPin, OUTPUT);
pinMode(lgPin, OUTPUT);
pinMode(lrPin, OUTPUT);
digitalWrite(lPin, LOW);
digitalWrite(s1Pin, LOW);
digitalWrite(s2Pin, LOW);
digitalWrite(s3Pin, LOW);
digitalWrite(s4Pin, LOW);
digitalWrite(pPin, LOW);
digitalWrite(rbPin, LOW);
digitalWrite(lbPin, HIGH);
digitalWrite(lgPin, HIGH);
digitalWrite(lrPin, HIGH);
pinMode(interruptPin,INPUT_PULLUP);
Serial.begin(115200);
delay(1000);
for (int i=0; i < 3; i++){
digitalWrite(lgPin, LOW);
delay(800);
digitalWrite(lgPin, HIGH);
delay(400);
}
digitalWrite(s1Pin, LOW); // config solenoid 1 closed
digitalWrite(s2Pin, HIGH);
digitalWrite(s3Pin, LOW); // config solenoid 2 closed
digitalWrite(s4Pin, HIGH);
delay(10);
digitalWrite(s1Pin, LOW);
digitalWrite(s2Pin, LOW);
digitalWrite(s3Pin, LOW);
digitalWrite(s4Pin, LOW);
delay(10);
digitalWrite(pPin, HIGH); // power solenoid
delay(50);
digitalWrite(pPin, LOW);
}
void loop() {
Going_To_Sleep();
// *HOT* //
valve = 1;
digitalWrite(s1Pin, HIGH); // config solenoid
digitalWrite(s2Pin, LOW);
delay(10);
digitalWrite(s1Pin, LOW);
digitalWrite(s2Pin, LOW);
delay(10);
digitalWrite(pPin, HIGH); // power solenoid
delay(50);
digitalWrite(pPin, LOW);
for (int i=0; i < 92; i++){ // 46 blinks = 1 minute
digitalWrite(lrPin, LOW);
delay(1200);
digitalWrite(lrPin, HIGH);
digitalWrite(lgPin, LOW);
delay(100);
digitalWrite(lgPin, HIGH);
}
takeRead();
HT = T;
//Serial.print(" T ");
//Serial.println("52.7");
digitalWrite(s1Pin, LOW); // config solenoid
digitalWrite(s2Pin, HIGH);
delay(10);
digitalWrite(s1Pin, LOW);
digitalWrite(s2Pin, LOW);
delay(10);
digitalWrite(pPin, HIGH); // power solenoid
delay(50);
digitalWrite(pPin, LOW);
digitalWrite(lPin, LOW);
for (int i=0; i < 10; i++){ // led fush 1 complete
digitalWrite(lrPin, LOW);
delay(300);
digitalWrite(lrPin, HIGH);
delay(100);
}
delay(1000);
// *COLD* //
valve = 0;
digitalWrite(s3Pin, HIGH); // config solenoid
digitalWrite(s4Pin, LOW);
delay(10);
digitalWrite(s3Pin, LOW);
digitalWrite(s4Pin, LOW);
delay(10);
digitalWrite(pPin, HIGH); // power solenoid
delay(50);
digitalWrite(pPin, LOW);
for (int i=0; i < 96; i++){
digitalWrite(lbPin, LOW);
delay(1200);
digitalWrite(lbPin, HIGH);
digitalWrite(lgPin, LOW);
delay(100);
digitalWrite(lgPin, HIGH);
}
takeRead();
CT = T;
//Serial.print(" T ");
//Serial.println("17.8");
digitalWrite(s3Pin, LOW); // config solenoid
digitalWrite(s4Pin, HIGH);
delay(10);
digitalWrite(s3Pin, LOW);
digitalWrite(s4Pin, LOW);
delay(10);
digitalWrite(pPin, HIGH); // power solenoid
delay(50);
digitalWrite(pPin, LOW);
digitalWrite(lPin, LOW);
for (int i=0; i < 10; i++){ // led fush 2 complete
digitalWrite(lbPin, LOW);
delay(300);
digitalWrite(lbPin, HIGH);
delay(100);
}
for (int i=0; i < 30; i++){ // led fush sequence complete
digitalWrite(lgPin, LOW);
delay(80);
digitalWrite(lgPin, HIGH);
delay(80);
}
value = analogRead(1);
vout = (value * 5.18) / 1024.0; // see text
vin = vout / (RV2/(RV1+RV2));
if (vin<0.09) {
vin=0.0; // ignore undesired reading
}
//Serial.print("EXTPW ");
//Serial.print(vin);
//Serial.println("V");
Serial.print(HT);
Serial.print(",");
Serial.print(CT);
Serial.print(",");
Serial.println(vin);
delay(800);
Serial.flush();
Serial.end();
digitalWrite(rbPin, HIGH); // power cycle tag
delay(5000);
digitalWrite(rbPin, LOW);
Serial.begin(115200);
delay(1000);
resetFunc(); // call reset
}
-
As VCC and AVCC are connected, I've added a 0.1uf cap between VCC and GND.
-
Omron G6K uses 21.1mA at 5V. I have added a 1N4007 flyback diode across relay.