#define TRIGGER_PIN 4 // Establish digital pin connection to the trigger pin of the ultrasonic sensor
#define ECHO_PIN 5 // Establish digital pin connection to the echo pin of the ultrasonic sensor
// Establish pin connection for flame sensor
const int flamePin = 6; // Flame sensor pin connected to pin 6 of the board
// Establish pin connection for the temperature sensor
const int tempPin = A0; // Temperature sensor pin will be connected to analog pin A0
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(TRIGGER_PIN, OUTPUT); // Set trigger pin as output
pinMode(ECHO_PIN, INPUT); // Set echo pin as input
// Set the flame sensor pin as an input
pinMode(flamePin, INPUT);
}
void loop() {
// Trigger a pulse to start the ultrasonic measurement
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
// Measure the duration of the echo pulse
long duration = pulseIn(ECHO_PIN, HIGH);
// Calculate distance in centimeters
float distance_cm = duration * 0.034 / 2;
// Check if distance is within a certain range to determine bin level; Bin is full is level is higher than 5 inch to lid
if (distance_cm < 12.7) {
Serial.println("Bin full!");
} else {
Serial.println("Bin Ok");
}
// Check status of flame sensor
int flameState = digitalRead(flamePin);
// Check if flame is detected
if (flameState == HIGH) {
Serial.println("Flame detected!");
} else {
Serial.println("No flame detected.");
}
// Read the analog value from the temperature sensor
int sensorValue = analogRead(tempPin);
// Convert the analog value to temperature in Celsius
float temperatureC = (sensorValue * 5.0 / 1024.0) * 100.0;
// Check if temperature is higher than 200degrees celcius (for PoC purposes only)
if (temperatureC >200 ) {
// Print the temperature to the serial monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" High and abnormal");
} else {
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" Normal");
}
}