Skip to content

Instantly share code, notes, and snippets.

@peterfoxflick
Created August 11, 2018 06:50
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 peterfoxflick/ed59843c6a8567972b84252c02a43d19 to your computer and use it in GitHub Desktop.
Save peterfoxflick/ed59843c6a8567972b84252c02a43d19 to your computer and use it in GitHub Desktop.
The code for a flower pot that has a built-in sensor to detects when the soil is dry and lets you know. The circuit uses an ATtiny85 as the brain and copper tape as the sensor.
/*
ATtiny Indoor Plant
This program flashes a blue light when there is dry dirt.
Pin OUT (only pins that are shown are used)
--[[()]]-- 5V
A3 --[[[]]]--
--[[[]]]--
GND --[[[]]]-- D0
Created by Peter Flickinger ( http://www.peterfoxflick.com )
With help from http://highlowtech.org/?p=1695
Parts can be bought from sparkfun.com or from this wish list http://sfe.io/w90611
Instructions can be found on Instructables: https://www.instructables.com/id/ATtiny-Flower-Pot/
Published on December 11, 2014
*/
//pins
int dirt = 3; //dirt is an analog pin
int blue = 0; //blue is a digital pin
//variables
int threshold = 475; //This is the light level that determins wheather it is bright or dark
void setup() {
pinMode(blue, OUTPUT);
}
void loop() {
int moisture = analogRead(dirt);
//This is the decision part
if(moisture >= threshold) {
//If the dirt is dry then blink
//The number is how many times to blink in a second and the blue is which pin to make blink
blink(2,blue);
}
else{
//else just wait one second before checking again
delay(1000);
}
}
//this function will blink the PIN a certain amount of TIMES in a second
void blink(int times, int pin){
int time = 1000/times;
for (int i=1; i <= times; i++){
digitalWrite(pin, HIGH);
delay(time);
digitalWrite(pin, LOW);
delay(time);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment