We wanted to grow some herbs at home and ensure they are well watered. So, we started with a low maintenance herb, the Basil Plant. Using a Grove soil moisture, it sends the sensor value every 30 minutes and shows it to water when the soil moisture gets below a certain level.
Wire up the HardwareHardware requirement is only the Grove soil moisture sensor, a Particle Photon and a breadboard. Take note of the Photon's Device ID
and Access Token
. Wiring up is really easy with just 3 pins from the soil moisture sensor:
Pin VIN
on Photon toVCC
on soil moisture sensor
Pin GND
on Photon toGND
on soil moisture sensor
Pin A0
on Photon toSIG
on soil moisture sensor
Finally connect the Particle Photon to a power source via the USB cable.
Flash the FirmwareFlash the firmware on Photon
int analogvalue = 0;
void setup()
{
pinMode(D7, OUTPUT);
if (Particle.variable("moisture", analogvalue) == false) {
digitalWrite(D7, HIGH);
}
pinMode(A0, INPUT);
}
void loop()
{
analogvalue = analogRead(A0);
delay(200);
}
As you can see from the code above, it will publish a variable called moisture
. You can also curl this value from the command line. Remember to replace the {DEVICE_ID}
and {ACCESS_TOKEN}
which your Photon's values.
curl "https://api.particle.io/v1/devices/{DEVICE_ID}/moisture?access_token={ACCESS_TOKEN}"
The web server will query this moisture sensor value every 30 minutes and will push the values on a web page. To setup the web server on your laptop you can follow these steps:
- Ensure Nodejs is installed in your laptop
- Clone the repository with
git clone https://github.com/sayanee/cosmic
- Setup the environment variables on file
.env
- Install all the Node packages with
npm i
- Start the server with
npm start
- View the webpage on your laptop at
localhost:1337
Comments