Skip to main content

· 9 min read
Tessa Nikander

LED spectrum. Plant cultivation system built with CanSat NeXT

Did you know that you can grow plants hydroponically all year long?

With this project, you can start your own journey of sustainable farming. The project is easy to set up and provides you with basic knowledge to grow locally sourced products indoors.

The role of the CanSat NeXT kit is to operate as a controller unit and provide an easy hardware and software platform to integrate the sensors and functionalities to.

Project specification

The goal is to build an indoor plant cultivation system that:

  • provides optimal light conditions around the clock
  • monitors plant health by measuring growth medium temperature and humidity
  • optimizes energy consumption (extra)

LED spectrum.

The selected LEDs are designed to produce blue and green light, chosen specifically for cultivation applications. Blue light enhances leaf growth and is crucial in the seeding phase and root development, while green light enhances light penetration into the deeper layers of the plant's leaves, which is beneficial in dense canopies. The LED technology featured in the project is engineered to replace traditional white LEDs in dual-channel (white + red) horticultural lighting systems. The result is a more energy-efficient solution when the goal of the system is to increase growth rather than blooming.

What you will need

Part nameImageDescriptionAmountUsed in
CanSat NeXTCanSat NeXT boardThe "brain" of the system1Controller
BreadboardBreadboardProtoboard to construct the project on1Controller
Debug LED(s)BreadboardAny1-3Illuminating unit
NMOS transistorBreadboardIe. SI2318DS1-4Illuminating unit
18V DC Power supplyBreadboardProviding power to the LEDs1Power unit
Jumper wiresBreadboardFor prototypingAs many as you needAll
ResistorsBreadboard1k, 10k, and 100 Ohm10All
Botanical LEDsBreadboardIe. JB2835BWT12Illuminating unit
LDO regulatorBreadboardIe. LDL1117S33R1Power unit
CapacitorBreadboard4Power unit
PolyfuseBreadboardIe. 30R400UMR1Power unit
TVS diodeBreadboardIe. ESDALC12-1T21Power unit

Modules of the device

The device consists of five modules: illuminating unit with botanical LEDs, a sensor suite, a browser-based user interface, a power module, and controller unit (CanSat NeXT).

LED illuminating unitBuilt from botanical LEDs that are specifically designed for plant growth
Humidity sensor, temperature sensorA sensor suite designed for monitoring growth conditions
Remote UIA browser-based remote interface designed for monitoring sensor data and controlling illuminating units. The remote interface can be accessed with any network-capable device, such as a smartphone, tablet or PC, as long as the user is logged in to the same WiFi network as the CanSat device.
LDR sensorA sensor which, based on the sensor data it provides, allows the product to be remotely controlled via a user interface to turn it on or off
CanSat NeXTActs as a controller and provides a server to the browser UI

Electrical interface

Breadboard Illuminating unit prototype with CanSat NeXT.

The design of the illuminating unit consists of 1-4 LED strips connected in parallel. See below for the circuit diagrams. Breadboard Individual LED string in the illuminating unit showing NMOS transistor, a 10K pull-down resistor, and LEDs connected in serial, controlled by a DIN/CTRL pin connected to CanSat NeXT GPIO.

When choosing the NMOS transistor (in this case, SI2318DS), remember to go with one that can withstand the Drain-Source voltage (>18 V) coming from the power unit.

Please also bear in mind that the botanical LEDs have internal resistance and a max forward current. In case you are using some other LED model besides JB2835BWT, remember to calculate the resistor value between ground and the LED string (in this case, 5 Ohms).


The illuminating unit in the parallel circuit context. DIN is connected to a I/O pin controlled by CanSat NeXT.


The software will have the following components:

  • Web server for remote control
  • GPIO control for the NMOS transistor
  • Reading local time from NTP server, and
  • taking environmental measurements from the plant to monitor growth.

While still setting up the hardware, writing and testing some software components in parallel can feel like a good idea.

Setting up the server for remote control is straightforward. To see your local IP address, flash CanSat NeXT with the following code:

// Load Wi-Fi library
#include <WiFi.h>

// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Set web server port number to 80
WiFiServer server(80);

void setup() {
// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
// Print local IP address and start web server
Serial.println("WiFi connected.");
Serial.println("IP address: ");

In my case, this was This is the address where you will be navigating to when controlling the system remotely.

Setting up the web server

Test circuit

Test circuit for validating the web server, adapted from Later on we will migrate to using GPIO26 as the NMOS control pin.

To test the web server for remote control, build a test circuit and flash your CanSat NeXT with this server code (from

Rui Santos
Complete project details at

// Load Wi-Fi library
#include <WiFi.h>

// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

// Auxiliar variables to store the current output state
String output26State = "off";
String output27State = "off";

// Assign output variables to GPIO pins
const int output26 = 26;
const int output27 = 27;

// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;

void setup() {
// Initialize the output variables as outputs
pinMode(output26, OUTPUT);
pinMode(output27, OUTPUT);
// Set outputs to LOW
digitalWrite(output26, LOW);
digitalWrite(output27, LOW);

// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
// Print local IP address and start web server
Serial.println("WiFi connected.");
Serial.println("IP address: ");

void loop(){
WiFiClient client = server.available(); // Listen for incoming clients

if (client) { // If a new client connects,
currentTime = millis();
previousTime = currentTime;
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c =; // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Connection: close");

// turns the GPIOs on and off
if (header.indexOf("GET /26/on") >= 0) {
Serial.println("GPIO 26 on");
output26State = "on";
digitalWrite(output26, HIGH);
} else if (header.indexOf("GET /26/off") >= 0) {
Serial.println("GPIO 26 off");
output26State = "off";
digitalWrite(output26, LOW);
} else if (header.indexOf("GET /27/on") >= 0) {
Serial.println("GPIO 27 on");
output27State = "on";
digitalWrite(output27, HIGH);
} else if (header.indexOf("GET /27/off") >= 0) {
Serial.println("GPIO 27 off");
output27State = "off";
digitalWrite(output27, LOW);

// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}</style></head>");

// Web Page Heading
client.println("<body><h1>ESP32 Web Server</h1>");

// Display current state, and ON/OFF buttons for GPIO 26
client.println("<p>GPIO 26 - State " + output26State + "</p>");
// If the output26State is off, it displays the ON button
if (output26State=="off") {
client.println("<p><a href=\"/26/on\"><button class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/26/off\"><button class=\"button button2\">OFF</button></a></p>");

// Display current state, and ON/OFF buttons for GPIO 27
client.println("<p>GPIO 27 - State " + output27State + "</p>");
// If the output27State is off, it displays the ON button
if (output27State=="off") {
client.println("<p><a href=\"/27/on\"><button class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/27/off\"><button class=\"button button2\">OFF</button></a></p>");

// The HTTP response ends with another blank line
// Break out of the while loop
} else { // if you got a newline, then clear currentLine
currentLine = "";
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
// Clear the header variable
header = "";
// Close the connection
Serial.println("Client disconnected.");

Upload the sketch on your CanSat NeXT device and test if you can access the web address on another device by typing the value of WiFi.localIP() into the address bar. Remember to make sure that both CanSat NeXT and your reader device (phone, tablet, pc etc.) have to be uring the same WiFi network. After confirming the server functionality, test the circuit debug LEDs to see if your GPIO configuration is correct. Pretty intuitive, right?

Next steps

In Part 2, we will do the following:

  1. Update the web server code to run custom javascript for controlling the LED strings
  2. Implement time reading from NTP server
  3. Read environmental sensor measurements and print them to the remote UI with dynamic refresh
  4. Build the custom power unit and integrate it all together.

Until next time! 👋

· 12 min read
Samuli Nyman

In this first project, I'll be using CanSat NeXT board to add a real-time remote reading feature to the the electricity meter in my house. Most modern electricity meters have a pulse LED, which blinks once per measured watt-hour of electricity. My idea is to use the light-dependant resistor (LDR) on the CanSat NeXT board to monitor this LED, and use that to calculate the real time power consumption of my home.

The basic concept is that the resistance of the LDR will change depending on the intensity of light hitting it, and by mounting the board so that most variability comes from the indicator LED itself, we could try to detect when it is on and when it is off based on the LDR voltage.

The indicator LED is mounted on a panel inside the electricity meter, which makes reading it with a CanSat NeXT shaped board slightly difficult. To mitigate this, I designed a support structure with a baffel built in, which can be used to mount the board to the electricity meter, so that only the light from the indicator LED can reach the LDR.

Structure with the baffle.

The structure is designed so that the distance to the board is 12 mm, which is the same distance as with the breakout boards. This way, I can use the basic standoffs to directly mount the baffle to the PCB. The baffle will be mounted to the electricity meter with the help of some two-sided tape. Keep it simple, stupid!

After some 3d-printing, this is what it looks like. Some light was able to leak through the PCB from the side, so I added a piece of electric tape to mitigate that.

CanSat with baffle.

Reading with LDR

Next, I'd like to test if we are able to see the pulses in the data. We can use the plotting tool in Arduino IDE to see the pulses, however there is a small problem - it can only display 50 values on the x-axis, which means that if we want to see even 5 seconds of data, we need to print only once every 100 ms. This means that the pulses might happen between the readings. So, instead of just reading the data every 100 ms and printing the value, I actually read the data as fast as the MCU can read the analog input - roughly 10 times per millisecond. Finally, it keeps track of the lowest value (highest brightness) and prints this lowest value every 100 milliseconds.

Brightness plotter
#include "CanSatNeXT.h"

unsigned long previousMillis = 0; // Stores last time the LDR value was updated
const long interval = 100; // Interval at which to print the LDR value (100ms)
int minValue = 4095; // Initialize with the highest possible value from analogRead

void setup() {

void loop() {
unsigned long currentMillis = millis();

int value = analogRead(LDR);
// Update minValue if the current reading is lower than the previous minValue
if (value < minValue) {
minValue = value;

// Check if 100ms have passed
if (currentMillis - previousMillis >= interval) {
// Save the last time the LDR value was updated
previousMillis = currentMillis;

// Print the lowest LDR value

// Reset minValue for the next interval
minValue = 4095;

With this code, it seems to detect all fast light changes very reliably. Time to mount it to the meter!

CanSat mounted to the electricity meter.

Looking at the data, it looks like we can read the pulses quite clearly. They are very visible in the data in dark conditions.

First data from the LDR.

Pulse detection

Next, we need write some software to automatically detect the pulses from the data stream. Some relatively simple solution would probably work when the device is in a dark box and the LED is bright, however a solution based on fixed limits or other really simple method might struggle if there is some light leaking through the PCB, or if it is used in different conditions. It would be more fun to create some kind of self-adjusting mechanism for detecting the pulses.

I decided to go with a statistical method. I keep track of 1000 last readings, and calculate the median and standard deviation from these. Also, I maintain a running average of the current value in order to reduce noise in the readings. Then, I can make the decision that we are currently seeing a pulse based on the deviation from the mean. I am currently using quite sensitive 3 * standard deviation, where as a more would probably make it more robust while being less sensitive. This current setting seems to be enough so that we can actually detect the on-board LED of another CanSat from 5 cm away in a brightly lit room, without a baffle or anything else to help us.

Detecting the LED of another CanSat.

Now that it is based on statistics rather than a fixed value, the detection works nicely even if a change the lights in the room or move the blinking LED closer or further away. To make the detection more challenging, the LED was on only 10 ms, then off 200 ms.

Additionally, we need some additional statistical tracking to calculate the average power consumption. I decided to keep track of the latest delay between two detected pulses, which corresponds to one Wh of consumed energy. Additionally, I'll keep track of an average over the last minute, as well as average over one hour. These statistics can then be transmitted to a receiver outside the electricity meter.

First Tests

Now that we are able to detect pulses in various lighting conditions, we can send the data from the CanSat NeXT in the electricity meter to another ESP32. We can use the sendData functionality of the CanSat NeXT library. I'll send three values - the latest reading, minute average and hour average. These are tranmsitted once every pulse, or once a second if the pulses are more frequent than that. The data is sent as binary - timeBetweenLastPulses is just the time between pulses as uint milliseconds, while the average values are floating point values. These are written to a buffer as binary, and then transmitted with command sendData.

Sending measurements
char msg[12];
// Copy the memory content of each variable into the packedData array
memcpy(msg, &timeBetweenLastPulses, sizeof(timeBetweenLastPulses));
memcpy(msg + 4, &minuteAverage, sizeof(minuteAverage)); // Offset by 4 bytes for the next position
memcpy(msg + 8, &hourAverage, sizeof(hourAverage)); // Offset by 8 bytes for the last position

sendData(msg, sizeof(msg));

And this worked beautifully! I am now able to read the pulse from outside the electricity meter... unless I walk too far. The signal is rather weak, which makes sense, as the electricity meter is inside a metal box - it's almost a faraday cage. We'll need to get an antenna outside the box to send the data any meaningful distances.

New Antenna

I decided to build an antenna out of coaxial cable, a bit like with the standard monopole antenna with CanSat NeXT. However, usually the PCB of the CanSat NeXT itself acts as part of the antenna, but now I need a longer cable. Therefore, I made a simple dipole antenna, where both the shield and inner conductor have length of quarter the wavelength.

Coaxial dipole antenna.

It would be much better to create a structure where the dipole elements are perpendicular to the coaxial cable, however for us, it is sufficient to simply bend the shield backwards, and add some heat shrink tubing for weather protection.

The connector on CanSat NeXT is U.FL type, which I did not have at hand. I however had SMA connectors, so I added one of them at the other end of the coaxial cable, and used an SMA-U.FL adapter to connect the antenna to CanSat NeXT. Again, not quite ideal, but the adapters actually don't affect the signal all that much.

CanSat NeXT with the antenna.

Final Setup

All remaining now is to add old phone charger for USB power so that we don't need to keep changing batteries, and the device is ready to be installed!

Electricity meter installed.

The antenna cable is routed through a pass-through in the meter box, and then placed between the spruce branches so that it stays in pretty free-space for good signal strength.

With this updated setup, I'm able to now read the output in my lab from the ESP32. I'm still not sure how I'll use the data, perhaps by making a nice online GUI so that I can monitor it. Let's see!

Finally, here are the codes that the MCU's are running. First, the groundstation:

Receiver code
#include "CanSatNeXT.h"

uint8_t groundsationMAC[] = {0xA8, 0x42, 0xE3, 0xDA, 0x86, 0x48};

void setup() {

void loop() {

void onBinaryDataReceived(const uint8_t *data, int len) {
// Ensure the length of the data received is at least 12 bytes
// (4 bytes for uint32_t and 4 bytes for each float)
if (len < 12) {
// Handle the error case where data is not of expected length
Serial.println("Received data is of incorrect length.");

uint32_t timeBetweenLastPulses;
float minuteAverage;
float hourAverage;

// Copy the binary data into the variables
memcpy(&timeBetweenLastPulses, data, sizeof(timeBetweenLastPulses));
memcpy(&minuteAverage, data + 4, sizeof(minuteAverage)); // Offset by 4 bytes for the float
memcpy(&hourAverage, data + 8, sizeof(hourAverage)); // Offset by 8 bytes for the second float

// Print the extracted values
Serial.print("Time between last pulses: ");

Serial.print("Average time between pulses in the last minute: ");
Serial.println(minuteAverage, 2); // '2' specifies the number of decimal places

Serial.print("Average time between pulses in the last hour: ");
Serial.println(hourAverage, 2); // '2' specifies the number of decimal places


And then the program used to read the pulse and transmit the data.

Electricity Meter
#include "CanSatNeXT.h"
#include <algorithm>

// Buffer size for the measurements
const int bufferSize = 1000;
// Running average size
const int runningAvgSize = 10;
// Array to store last 1000 measurements
int measurements[bufferSize];
// Array for running average
int runningAvgBuffer[runningAvgSize];
// Variables to keep track of indices
int bufferIndex = 0;
int runningAvgIndex = 0;
// Variables for statistics
float median = 0;
float runningAverage = 0;
float standardDeviation = 0;
bool pulseActive = false;

unsigned long lastPulseTime = 0; // To store the timestamp of the last pulse
unsigned long secondLastPulseTime = 0; // To store the timestamp of the second last pulse

const int minutePulseCount = 60; // Assuming at most 60 pulses can be detected in a minute for averaging
const int hourPulseCount = 3600; // Assuming at most 3600 pulses can be detected in an hour for averaging
unsigned long pulseIntervalsMinute[minutePulseCount]; // Circular buffer for last minute
unsigned long pulseIntervalsHour[hourPulseCount]; // Circular buffer for last hour
int minuteIndex = 0, hourIndex = 0; // Indices for circular buffers
unsigned long lastPrintTime = 0; // Last time statistics were printed
bool readingUpdated = false;

uint8_t groundsationMAC[] = {0xA8, 0x42, 0xE3, 0xDA, 0x86, 0x48};

void setup() {
pinMode(LED, OUTPUT); // Initialize the LED pin as an output
digitalWrite(LED, LOW);
// Initialize the measurements array
for (int i = 0; i < bufferSize; i++) {
measurements[i] = 0;
// Initialize the running average buffer
for (int i = 0; i < runningAvgSize; i++) {
runningAvgBuffer[i] = 0;

void loop() {
unsigned long currentTime = millis(); // Current time in milliseconds
int value = analogRead(LDR);

// Update the running average buffer
runningAvgBuffer[runningAvgIndex] = value;
runningAvgIndex = (runningAvgIndex + 1) % runningAvgSize;

// Calculate the running average

// Update the measurements buffer
measurements[bufferIndex] = value;
bufferIndex = (bufferIndex + 1) % bufferSize;

// Periodically update median and standard deviation
if (bufferIndex == 0) {

if (!pulseActive && runningAverage < median - 3 * standardDeviation) {
pulseActive = true;
readingUpdated = true;
digitalWrite(LED, HIGH);

// Time tracking
secondLastPulseTime = lastPulseTime;
lastPulseTime = currentTime;
unsigned long interval = lastPulseTime - secondLastPulseTime;

// Update minute and hour circular buffers
pulseIntervalsMinute[minuteIndex++] = interval;
if (minuteIndex >= minutePulseCount) minuteIndex = 0; // Reset index if it exceeds the buffer size

pulseIntervalsHour[hourIndex++] = interval;
if (hourIndex >= hourPulseCount) hourIndex = 0; // Reset index if it exceeds the buffer size

} else if (pulseActive && runningAverage > median - standardDeviation) {
pulseActive = false;
digitalWrite(LED, LOW); // Turn off the LED

// Print time statistics every second
if (readingUpdated && currentTime - lastPrintTime >= 1000) {
readingUpdated = false;
lastPrintTime = currentTime;

// Calculate and print statistics
uint timeBetweenLastPulses = lastPulseTime - secondLastPulseTime;
Serial.print("Time between last pulses: ");
float minuteAverage = calculateAverageTime(pulseIntervalsMinute, minutePulseCount);
float hourAverage = calculateAverageTime(pulseIntervalsHour, hourPulseCount);
// Calculate and print averages for the last minute and last hour
// You need to implement calculateAverageTime which calculates the average of intervals in a buffer
Serial.print("Average time between pulses in the last minute: ");

Serial.print("Average time between pulses in the last hour: ");

//Let's transmit the data to GS as binary data.
// 4 bytes for uint32_t and 4 bytes for each float
char msg[12];
// Copy the memory content of each variable into the packedData array
memcpy(msg, &timeBetweenLastPulses, sizeof(timeBetweenLastPulses));
memcpy(msg + 4, &minuteAverage, sizeof(minuteAverage)); // Offset by 4 bytes for the next position
memcpy(msg + 8, &hourAverage, sizeof(hourAverage)); // Offset by 8 bytes for the last position

sendData(msg, sizeof(msg));


void updateRunningAverage() {
long sum = 0;
for (int i = 0; i < runningAvgSize; i++) {
sum += runningAvgBuffer[i];
runningAverage = sum / (float)runningAvgSize;

void updateMedianAndStdDev() {

std::nth_element(measurements, measurements + 499, measurements + 1000); // For the 500th element
std::nth_element(measurements, measurements + 500, measurements + 1000); // For the 501st element

// Calculate the median for an even number of elements
median = (measurements[499] + measurements[500]) / 2.0;

// Calculate standard deviation
float sum = 0;
for (int i = 0; i < bufferSize; i++) {
sum += pow(measurements[i] - median, 2);
standardDeviation = sqrt(sum / bufferSize);

float calculateAverageTime(unsigned long intervals[], int count) {
unsigned long sum = 0;
int nonzero_count = 0;
for (int i = 0; i < count; i++) {
if (intervals[i] != 0) {
sum += intervals[i];
if (nonzero_count == 0) return 0.0; // Avoid division by zero
return (float)sum / nonzero_count; // Cast to float to ensure floating-point division

· One min read
Samuli Nyman
Tessa Nikander

Welcome to the CanSat NeXT blog! Here, we plan to write small posts about projects done with CanSat NeXT. These are probably mostly not CanSat projects, but rather small projects done using the CanSat NeXT hardware. The idea is that we want to showcase possibilites of the hardware, and also give fun ideas about how to use CanSat NeXT. Sometimes the projects use features already on the board itself, while other ones will likely expand the CanSat NeXT to fulfill the project needs.