Skip to content

Instantly share code, notes, and snippets.

@angelaleong
Created February 26, 2017 05:08
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 angelaleong/e8cca6e0a54750f420438b678d97cc0d to your computer and use it in GitHub Desktop.
Save angelaleong/e8cca6e0a54750f420438b678d97cc0d to your computer and use it in GitHub Desktop.
Code that runs on an Arduino Uno to monitor moisture levels in an under-the-sink compost bin and alert users via LED lights and a message on an LCD screen whether the compost is too dry/too wet/just right.
#include <LiquidCrystal.h>
#include <Servo.h>
int ledR = 4; // RED pin of LED to PWM pin 4
int ledG = 5;
int ledB = 6;
int moistPin = A0;
int moisture = 85;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
Servo myservo;
int pos = 0;
float temp;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledR, OUTPUT);
pinMode(ledG, OUTPUT);
pinMode(ledB, OUTPUT);
lcd.begin(16, 2);
}
void loop() {
// get temperature reading
// display temperature reading on LCD
lcd.setCursor(0,0);
lcd.print("T: 25C");
// get moisture reading
// moisture = digitalRead(moistPin);
// moisture = map(moisture, 730, 880, 0, 100);
// humidity monitoring
if (moisture < 80) { // LED turns red
digitalWrite(ledR, HIGH);
digitalWrite(ledG, LOW);
digitalWrite(ledB, LOW);
lcd.setCursor(7,0);
lcd.print("Too dry. ");
lcd.setCursor(0,1);
lcd.print("Add some fruits!");
delay(100);
} else if (moisture >= 80 and moisture <= 90) { // LED turns green
digitalWrite(ledR, LOW);
digitalWrite(ledG, HIGH);
digitalWrite(ledB, LOW);
lcd.setCursor(7,0);
lcd.print("Moisture ");
lcd.setCursor(0,1);
lcd.print("levels on point.");
delay(100);
} else if (moisture > 90) { // LED turns blue
digitalWrite(ledR, LOW);
digitalWrite(ledG, LOW);
digitalWrite(ledB, HIGH);
lcd.setCursor(7,0);
lcd.print("Too wet. ");
lcd.setCursor(0,1);
lcd.print("Add sawdust plz.");
delay(100);
} else {
// do nothing
}
// // temperature control
// if () { // too hot
// // switch heat source off
// } else if () { // too cold
// // switch heat source on
// } else () { // temp. in acceptable range
// // do nothing
// }
// // spin mixing rod at regular intervals
// for (pos=0; pos < 180; pos += 1) {
// myservo.write(pos);
// delay(15);
// }
//
// for (pos = 180; pos >= 1; pose -=1) {
// myservo.write(pos);
// delay(15);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment