Skip to content

Instantly share code, notes, and snippets.

@logikal
Created February 22, 2016 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logikal/fbfc36d6ba51121f020f to your computer and use it in GitHub Desktop.
Save logikal/fbfc36d6ba51121f020f to your computer and use it in GitHub Desktop.
// http://openenergymonitor.org/emon/node/1267
//inclue lcdLibrary
#include
//intialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//set input pin
int sensorPin = A4;
int ledPowerOn = 3;
int ledPowerOff = 2;
int sensorMax;
int sensorMin;
int sensorValue;
void setup(void) {
//set up the LCD
lcd.begin(16, 2);
//Serial.begin(9600);
//set ledPin as an output
pinMode(ledPowerOff, OUTPUT);
pinMode(ledPowerOn, OUTPUT);
}
void loop(void) {
sensorMin = 1023;
sensorMax = 0;
sensorValue = 0;
for (int n = 0; n<200; n++)
{
sensorValue = analogRead(sensorPin);
if (sensorMax < sensorValue)
sensorMax = sensorValue;
if (sensorMin > sensorValue)
sensorMin = sensorValue;
}
if (sensorMax - sensorMin < 100)
{
digitalWrite(ledPowerOff, HIGH);
digitalWrite(ledPowerOn, LOW);
//write to lcd
lcd.clear();
lcd.print(sensorMax - sensorMin);
//Serial.print(max5 - min5);
//Serial.print(" ");
delay(1000);
}
else
{
digitalWrite(ledPowerOn, HIGH);
digitalWrite(ledPowerOff, LOW);
//write to lcd
lcd.clear();
lcd.print(sensorMax - sensorMin);
//Serial.print(max5 - min5);
//Serial.print(" ");
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment