Commit 9370911e authored by Beck-Sisyphus's avatar Beck-Sisyphus
Browse files

Science station code. Credit to Ahmed Awadallah

parent a9bdf334
No preview for this file type
No preview for this file type
const int humPin = A0;
int readingNumber = 0;
double readingSum = 0;
boolean calibrated = true;
double calibratedValue = 640.0;
void setup() {
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value from the pin
double humReading = 0;
humReading = analogRead(humPin);
readingSum+=humReading;
// calculate the sensor humidity
if(calibrated){
double sensorRH = humReading/calibratedValue*100.0;
Serial.print(sensorRH);
Serial.println("%");
// wait a second
delay(1000);
}
//Water Calibration
if(readingNumber==10 && calibrated){
double readingAvg=readingSum/10.0;
Serial.println(readingAvg);
Serial.println(humReading);
readingNumber = 0;
readingSum = 0;
}
delay(100);
readingNumber++;
}
int TimeBetweenReadings = 500;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Time (s) Voltage Readings from A0 (N)");
}
void loop() {
float Count;
float Voltage;
float SensorReading;
int ReadingNumber=0;
float Time;//the print below does the division first to avoid overflows
//Serial.print(ReadingNumber/1000.0*TimeBetweenReadings);
Count = analogRead(A0);
Voltage = Count / 1023 * 5.0;// convert from count to raw voltage
//Serial.print(" ");
Serial.print("Voltage: ");
Serial.println(Voltage);
Serial.print("pH: ");
Serial.println(Voltage/0.36);
delay(TimeBetweenReadings);// delay in between reads for stability
ReadingNumber++;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment