Learn how to build an IoT workshop using a soil moisture sensor and Particle Photon


#1

Originally published at: https://blog.particle.io/2019/01/28/learn-how-to-build-an-iot-workshop-using-a-soil-moisture-sensor-and-particle-photon/

It all started when my wife signed me up to talk with the kids at my town’s local 4-H group. The 4-H group is a youth organization that focuses around nature and the local community. Our group in town works with farm animals, agriculture, and just other fun stuff that exposes kids to new experiences.

I wanted to create a lab and a small talk, but I had a very small budget. I decided that I would just do demonstrations of various projects I’ve already done and have it more focused on computer programming. But something kept telling me to do a lab and focus on a project that 4-H could actually use. Since 4-H does agriculture projects, building a soil moisture sensor would be something that would work with future projects they might have.

Editor’s note: This post originally appeared on Will’s personal site and is shared here with his permission.

Planning the 4-H lab

First, I started with a prototype of the project using an existing Particle Photon and some parts I had. Once the prototype was built, finding enough parts of the entire group was pretty tricky, but most were pretty cheap and on eBay or Amazon.

After communicating with the 4-H group leader, we decided that there was going to be around 30 or so kids. Obviously 30 sensors gets to be pretty expensive, but with some budgeting we could make it work with 15 sensors and have the kids pair up into groups of two for the lab.

Lab material list

I also had another USB hub that I previously purchased that had 5 more connections so I could have all the soil sensors plugged in at once.

The most expensive part was the Particle Photon at $19.99 a piece. So, I reached out via twitter to @Particle and asked if they would maybe want to help out with the lab.

Building the soil moisture project for the 4-H kids presentation next month. Using the @particle photon to interface with the soil moisture sensor and built a custom dashboard to visualize the data using the particle api. 👊👊 pic.twitter.com/9CftQqpUke

— 🧙🏻‍♂️ willywos 🔥 (@willywos) December 11, 2018


To my surprise they were more than happy to help. (Thx you Joe!). Particle sent me all the Photons and even maker kits for the lab for free. They are AMAZING people.

Building & Testing

Before the lab, everything needed to be tested to make sure it worked. This was also a good time to make sure the documentation and my slides were all correct. My kids also helped me and made sure it wasn’t confusing to understand.

Step 1. Adding the Photons to breadboards

Step 1

The Photons need to be in the correct pins and in the right position on the breadboard. This is also where in the presentation I explain what a breadboard is and how it works, and how we interact with the pins on the Photon.

I found that making diagrams for each step is also important documentation. There is a free software called Fritzing which lets you make diagrams and pictures. Below you’ll see an example of a Fritzing diagram.

Step 2. Wiring up the Photons

Step 2

Once a Photon is attached to the breadboard it’s time to wire everything up. You can wire the lab sensors up using fewer wires, but this way was easier for the kids to understand and easier for them make sure they weren’t using the wrong pins on the breadboard.

The different color wires were used for the main reason that I didn’t have enough of the same color, but I found it keeps it less confusing for kids to learn. This is why there is a white wire for 3V3 and a brown and orange wire connecting to the soil sensor.

Step 3. Adding soil sensors

Step 3

The soil sensors we used have a plug that you can insert jumper wires in. The only part that got confusing was matching the colors up, but most of the kids got this figured out pretty quickly. Having the diagram showing the colors was very helpful.

Step 4. Testing


Step 4

The circuit is setup to run the code below and designed to tell you when your plant needs watering. The green LED blinks when moisture is detected, but when no moisture is detected the red LED blinks and lets you know to add some water.

The moisture data is read from the sensor attached to pin A0. The moisture value from the sensor gets read every second and pushed to the Particle Device Cloud using via the soilSensor variable. You can monitor the sensor remotely by using the Particle Cloud API and querying the soilSensor variable. This allows you to integrate this information into other applications.

int soilSensor = 0;
int redLed = D1;
int greenLed = D3;

void setup() {
    Serial.begin(9600);
    Particle.variable("soilSensor", &soilSensor, INT);
    pinMode(A0, INPUT);
    pinMode(redLed, OUTPUT);
    pinMode(greenLed, OUTPUT);
}

void loop() {
    soilSensor = analogRead(A0);
    if(soilSensor > 2000) {
        digitalWrite(redLed, HIGH);
        delay(1000);
        digitalWrite(redLed, LOW);
    } else {
        digitalWrite(greenLed, HIGH);
        delay(1000);
        digitalWrite(greenLed, LOW);
    }
    delay(1000);
}

The flashing is pretty simple to setup and I had no problem uploading the code to 15 different Photon boards. Hat’s off to the developers and everyone who made this experience super easy.

Here’s how I did the flashing. I already had the particle-cli application installed on my machine from other projects so I simply just login and run $ particle setup and setup the Wi-Fi settings so that each one could connect to the Wi-Fi where the lab was at. Then using the the Device Cloud each Photon was updated with the above code.

Once all the Particle Photons were working, I took each one apart and put its parts into their own bag. Everything was set for the lab now.

Presentation

The presentation starts off with just a quick about me and I talk a little about programming. Showed them a sample website that used the sensor information and gave them an overview of what they were going to be building. Since time is limited, the remaining talk moves on to building the circuit.

You can view my slides. There are more detailed instructions on how to build the circuit step by step in the slides.

Conclusion

It was a blast doing this presentation and lab with the kids. They were all very excited and you could tell they were into it. It’s nice to give back and maybe someday one of these kids will go off and invent something that changes everyone’s lives.

Here are some pics from the lab.

Lab

Lab

Special Thank You!

I wanted to give a special thank you to all the 4-H kids and parents. Thank you to all those that give up their time on the weekend to help teach kids and expose them to new and different experiences.

A special shout out to Particle. They donated the Particle Photons for the lab and without them it wouldn’t have been possible.

Thank you!