int greenLedPin = 5; // Pin Green LED is connected to
int yellowLedPin = 3; // Pin Yellow LED is connected to
int redLedPin = 4; // Pin Red LED is connected to
int temp_sensor = A2; // Pin DS18B20 Sensor is connected to
float temperature = 0; //Variable to store the temperature in
int lowerLimit = 15; //define the lower threshold for the temperature
int upperLimit = 35; //define the upper threshold for the temperature
Serial.print("Temperature is ");
Serial.print(temperature);
//Setup the LEDS to act as outputs
if (temperature <= lowerLimit) {
Serial.println(", Yellow LED is Activated");
digitalWrite(yellowLedPin, HIGH);
}
else if (temperature > lowerLimit && temperature < upperLimit) {
Serial.println(", Green LED is Activated");
digitalWrite(greenLedPin, HIGH);
}
else if (temperature >= upperLimit) {
Serial.println(", Red LED is Activated");
digitalWrite(redLedPin, HIGH);
}
delay(500);
}
/*
This example shows how to measure DC current
*/
// We have 30 amps version sensor connected to A0 pin of arduino
// Replace with your version if necessary
ACS712 sensor(ACS712_30A, A0);
void setup() {
Serial.begin(9600);
// calibrate() method calibrates zero point of sensor,
// It is not necessary, but may positively affect the accuracy
// Ensure that no current flows through the sensor at this moment
// If you are not sure that the current through the sensor will not leak during calibration - comment out this method
Serial.println("Calibrating... Ensure that no current flows through the sensor at this moment");
int zero = sensor.calibrate();
Serial.println("Done!");
Serial.println("Zero point for this sensor = " + zero);
}
void loop() {
// Read current from sensor
float I = sensor.getCurrentDC();
// Send it to serial
Serial.println(String("I = ") + I + " A");
// Wait a second before the new measurement
delay(1000);
}
/*
This example shows how to measure the power consumption
of devices in 230V electrical system
or any other system with alternative current
*/
// We have 30 amps version sensor connected to A0 pin of arduino
// Replace with your version if necessary
ACS712 sensor(ACS712_30A, A0);
void setup() {
Serial.begin(9600);
// calibrate() method calibrates zero point of sensor,
// It is not necessary, but may positively affect the accuracy
// Ensure that no current flows through the sensor at this moment
// If you are not sure that the current through the sensor will not leak during calibration - comment out this method
Serial.println("Calibrating... Ensure that no current flows through the sensor at this moment");
sensor.calibrate();
Serial.println("Done!");
}
void loop() {
// We use 230V because it is the common standard in European countries
// Change to your local, if necessary
float U = 230;
// To measure current we need to know the frequency of current
// By default 50Hz is used, but you can specify desired frequency
// as first argument to getCurrentAC() method, if necessary
float I = sensor.getCurrentAC();
// To calculate the power we need voltage multiplied by current
float P = U * I;
Serial.println(String("I = ") + I + " A");
Serial.println(String("P = ") + P + " Watts");