Very good, Thanks WaWa.
I have chopped up and cut down this code from Richard Steele
Not sure why using analogRead I can't seem to get the resolution that I can from this code, but I think it could serve the purpose.
I installed 2 resistors in series to get 110 ohms at the plug for the CT sensor and wired it back through with the 2.5 vdc from the arduino.
I multiplied result by 1000 and subtracted the "deadload"(?) to get near but above 0 as I assume it would be easier and maybe cleaner to look for an increase of >100 or something, instead of from 2500 to 2600. If that is wrong, please let me know.
Zero reading with this code as is fluctuates from 5 to 20 and with the 1500w heater on it reads around 142 immediately upon power-up and continues to climb up to 330.
It does seem to lock-up after a period of time or if I cycle power multiple times. Not sure what's going on there either..
Now that I look at it, i'll have to do those calculations elsewhere, couldn't reference them to find signal greater than X where they are..
int sensorMS01 = A0; // Analog input pin that sensor is attached to
float nVPP; // Voltage measured across resistor
void setup()
{
Serial.begin(9600);
pinMode(sensorMS01, INPUT);
}
void loop()
{
nVPP = getVPP();
Serial.print("Volts Through Resistor (Peak) : ");
Serial.println(nVPP*1000-2568,0);
}
float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1 Sec
{
readValue = analogRead(sensorMS01);
// see if you have a new maxValue
if (readValue > maxValue)
{
//record the maximum sensor value/
maxValue = readValue;
}
}
result = (maxValue * 5.0)/1024.0;//maxValue x Arduino Supply Voltage 5v or 3.3v change to suit your arduino board
return result;
}
beyond that for the censor, I have spent probably 60+ hours screwing up all kinds of codes, mostly with the goal of getting JMellers' Code to work, learned soo much while attempting this, but to no avail.
I did however manage to get a code that functions as intended, only thing I would like to change is:
- have time show on the LCD as XX hours - XX minutes instead of just XXX minutes
- log the last 10 "durations" just to be able to scroll through them with a button, possibly saved to eeprom?
- of course now "button" needs to be replaced to be the trigger from the CT.
If anyone see's any catastrophies in the making, feel free to scream and shout or throw objects.
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int numRows = 2;
const int numCols = 16;
const int button = 7;
const int button1 = 8;
const int ledPin = 13;
unsigned long startTime;
unsigned long endTime;
unsigned long duration;
byte timerRunning;
int alarm = 2000;
int buttonState = 0;
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
lcd.print("Cycle Monitor ");
lcd.setCursor(0,1);
lcd.print("First Run ");
pinMode (button, INPUT_PULLUP);
pinMode (button1, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop(){
if (timerRunning == 0 && digitalRead(button) == HIGH)
{
startTime = millis();
timerRunning = 1;
delay(50);
}
if (timerRunning == 1 && digitalRead(button1) == LOW)
{
lcd.setCursor(0,0);
lcd.print("Current Cycle ");
lcd.setCursor(0,1);
lcd.print(millis()/1000- endTime/1000);
lcd.print(" Minutes ");
}else{
lcd.setCursor(0,0);
lcd.print("Comp Cycle Time");
lcd.setCursor(0,1);
lcd.print(duration/1000);
lcd.print(" Minutes ");
}
if (timerRunning == 1 && digitalRead(button) == LOW)
{
endTime = millis();
timerRunning = 0;
duration = endTime - startTime;
delay(50);
Serial.println(duration);
lcd.setCursor(0,0);
lcd.print("Comp Cycle Time");
lcd.setCursor(0,1);
lcd.print(duration/1000);
lcd.print(" Minutes ");
if (duration < alarm){
digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(ledPin, LOW);
}
}
}