Hello all,
Let my start by saying I am new to code and barely understand the basics.......Up to this point I have done a few ARDUINO projects (examples) and I have hacked around at different examples to change there outcome in an attempt to understand how ARDUINO (code) works.
Let me also say that I do have a pretty solid background with hardware, I have worked in the electronics industry as an electronics tech for 10 years, I also have completed simple engineering projects at home . At work I have also been involved in many engineering tasks but they are specific to our products.
I SIMPLY want to monitor how many times one of my heating systems run, while my family is away during the day with my ARDUINO. I have basic ideas that involve: A) doing something like a knock sensor and letting it log to the serial input to a laptop all day (I have tweaked this example for other projects in the past). B) using the data logging example with a piezo and logging data via my SD shield. C) building a thermometer project and logging the data to the SD shield or the serial output.......
option A seems simple enough.....the problem is I do not understand how to use interrupts or create some type of timing setup, THEREFOR at the end of the day my serial read-out on the laptop would just(print.fXXXX) XXXX over and over and over with no way of separating the data and telling how many times the boiler turned on.
Thoughts please !!!!! ??
I know that this could be turned into complete monitoring system with times on/off, temps and the whole deal BUT REMEMBER .....I'm still quite ignorant when it comes to code, SO PLEASE KEEP IT SIMPLE !!
Ok........
I have no idea how to apply that in context to my application....
Lets try this,
How can I get the "knock sensor" example to just print serial data ONE TIME when the input goes above or meets its per-determined threshold and than another time when the input goes to "0" or another per-determined threshold. Rather than a constant read out.
example ;
the analog input threshold is set to (lets say) "200", when that threshold is reached the serial read out says "boiler on" just once, than when analog input threshold falls back to "0" the serial read out says "boiler off" just once
the way the current code is, it would repeat "boiler on" (or whatever text is entered) over and over again for the whole duration of the piezo sensing vibration.
I guess I'm looking for a hybrid between "Knock sensor" and "stage change detection"....
Use a boolean variable to keep track of whether the boiler is on or off. When you read the knock sensor check the variable; if the knock sensor says the boiler is on and the variable says it isn't, set the variable to the new state and print "Boiler is on". Similar logic for getting the "off" message.
// these constants won't change:
const int ledPin = 13; // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 1020; // threshold value to decide when the detected sound is a knock or not((was 100)) range=0-1023
//**sp. I am using reads 1023 (digital out) without detecting vibration
//**first change was threshold from 100 to 900, ((100 ALWAYS detected knock, 900 not sensitive enough !!!!))
//**second change, from >= (greater than or equal to), to, <=(less than or equal to)
//**third change, threshold from 900 to 1000 ((1000 still seemed not sensitive enough))
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is less than or equal to threshold: ((changed threshhold to 900))
if (sensorReading <= threshold) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string "Knock!" back to the computer, followed by newline
Serial.println("BOILER ON");
if (sensorReading = threshold)
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string "Knock!" back to the computer, followed by newline
Serial.println("BOILER OFF");
}
delay(100); // delay to avoid overloading the serial port buffer **((REMEBER EVERYTHING IS IN MILLISECONDS))
}
wildbill:
Use a boolean variable to keep track of whether the boiler is on or off. When you read the knock sensor check the variable; if the knock sensor says the boiler is on and the variable says it isn't, set the variable to the new state and print "Boiler is on". Similar logic for getting the "off" message.
I understand what you mean, but not how to implement it.......
in my case the integer value of 1023 could be; OFF
and almost anything else could be ;ON
but just have ONE message sent when the state changes.......
I don't quite understand what you're doing with your threshold, but for this snippet I have assumed that at or over the threshold, the boiler is on, otherwise off. The boilerOn variable keeps track of what your sketch believes the boiler state to be. When that proves to be incorrect, the state is corrected and a message emitted.
wildbill:
I don't quite understand what you're doing with your threshold, but for this snippet I have assumed that at or over the threshold, the boiler is on, otherwise off. The boilerOn variable keeps track of what your sketch believes the boiler state to be. When that proves to be incorrect, the state is corrected and a message emitted.
for my code above when the piezo is just SITTING STILL the output (I believe the integer) is 1023 and when you tap (or vibrate) the threshold falls toward zero, I set the threshold @ 1020 due to the boiler BARELY being able to move the piezo. the analog output of the peizo is 0-5v then when it goes through the A/D converter on ARDUINO its 0-1023
therefore when the piezo senses vibration it falls to or below 1020 and sends "BOILER ON" and when it is sitting still with no vibration it goes back to 1023 and sends "BOILER OFF".
Ok that pretty much works they same way my code above works..............I am really using the wrong type of sensor for this !
How can I get this to insert space between text in hyperlink, That way I can actually tell when the boiler starts and stops,
The reason it keeps spitting out "boiler on","boiler off" is because by design the speaker within the piezo will ALWAYS return to its nesting position which equals more than threshold (hence my reason for saying this is the wrong type of sensor), BUT I'm fine with that as long as I can space out the data EXAMPLE;
it looks like this:
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF But I need some difference like this:
BOILER ON
BOILER OFF
BOILER ON ------------boiler is running
BOILER OFF
BOILER ON
BOILER OFF
---------------boiler is obviously off
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF --------------boiler is running
BOILER ON
BOILER OFF
----------------boiler was obviously off
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF ---------------boiler was on
BOILER ON
BOILER OFF
BOILER ON
BOILER OFF
In that case I suggest that you need to look at timing to help you. Whenever the sensor indicates that the boiler is on, note the time using millis(). If it's a minute (or whatever) since you got such an indication, you can assume that the boiler has gone off.
Use my mechanism above to send messages to serial only when the state changes.
I may go another direction with this.......this way seems simpler
The thermostat (after its closed) sources 24vAC to the coil of a relay which allows power to the burner motor or fan motor.
that being said;
I'm thinking tap into the AC output from the T-stat and create 5v DC.
24vAC > diode (rectifier) > filter circuit (2 caps smoothing and coupling) > 7805 > 5vDC > I/O pin of ARDUINO.
getting GND from the transformer.
with code to monitor the "state change" of a switch, My 5v DC input would go HI when thermostat calls for heat and LO when it shuts of, and display the state change on in "hyperlink"
wsar10:
I'm thinking tap into the AC output from the T-stat and create 5v DC.
24vAC > diode (rectifier) > filter circuit (2 caps smoothing and coupling) > 7805 > 5vDC > I/O pin of ARDUINO.
getting GND from the transformer.
I would certainly go this route, this way you know for sure you are calling for heat and are not picking up on some kind of background noise or other outside influences.
If you have this hooked to a laptop/PC a simple script should be able to be generated to monitor the state/out and associate a timestamp with it.
In my case I have the Arduino hooked to my network and writing to a mysql database sitting on a PC. State changes could easily be inserted into the DB and a timestamp automatically associated with them; may be a bit complex for simple "on/off" recording though.