Final project


Plan and sketch a potential final project
  • Sketched your final project idea/s.
  • Described briefly what it will do and who will use it.
  • At least one sketch (something visual) and one paragraph (a few senteces) of text.

Ideas:

Idea 1: BB8 During the course called "Fundamentals of digital fabrication" I took in my fifth semester at university, I tried building the BB-8 droid from the Star Wars franchise. I did not completely finish it at my first attempt, so the first idea that came to my mind for the final project of Fab Academy was to finish the droid.



Idea 2: Selfwatering Flowerpot I regularly order cooking boxes from Hello Fresh. To keep the food cold and fresh, they send you ice packs with the food. After you put the food in your fridge, you can wait for the ice packs to melt and then water your plants with them. Since I don't want to have them lying around in my kitchen, I want to build a flower pot, that has an integrated space for those ice packs. A pump will then pump the water to the plant when needed.

Proposed Final Project: Smart Self-Watering Flowerpot

This text was generated with the help of ChatGPT and edited by me.

Description:

My final project is a smart self-watering flowerpot that will incorporate the various units covered in the FabAcademy. The flowerpot consists of two water tanks, an electronics compartment, and a gutter for ice pack storage. It utilizes a pump and an ultrasonic distance sensor (HC-SR04) to measure and maintain the water level in the left tank (which the flower sits in), ensuring automatic watering for the flower when needed.
It is supposed to solve the problem of me having the icepacks of Hellofresh laying around in my kitchen. I get weekly cooking boxes that come with ice to keep the groceries cold. The ice will melt in the tank and the flower will receive the water via a pump.



1. 2D and 3D Design:
The flowerpot's design will involve both 2D and 3D elements. The overall structure, including the water tanks, gutter, and electronics compartment, will be designed in 3D to ensure proper fit and functionality. The 2D design will include creating schematics and diagrams for the electronic connections and layout.

2. Additive and Subtractive Fabrication Processes:
To construct the flowerpot I will mostly use additive fabrication processes. Additive processes such as 3D printing can be used to create the main structure and components, including the water tanks, gutter, and electronics compartment. Subtractive processes may involve cutting or drilling holes for the pump, sensor, and other electronic components. But I will mainly use subtrative processes such as lasercutting to add small decorations to the project.

3. Electronics Design and Production:
The project will require designing the electronics system to control the water level and automate the watering process. This includes selecting and integrating connections for the components such as the XIAO SAMD21, pump, ultrasonic distance sensor, and any other necessary electronic components (5V regulator, MOSFET etc). Circuit design and PCB layout will be created in KiCad, and the PCB can be fabricated using the CNC in the Lab.

4. Embedded Microcontroller Interfacing and Programming:
The heart of the project will be this previously described embedded microcontroller responsible for controlling the water level and pump activation. The microcontroller will interface with the ultrasonic distance sensor to measure the water level in the left tank. Programming the microcontroller will involve writing code to read sensor data, control the pump, and implement the self-watering logic.

5. System Integration and Packaging:
Once all the individual components are designed, fabricated, and programmed, the system integration phase begins. This involves assembling the 3D-printed parts, mounting the electronics components inside the electronics compartment, and connecting all the necessary wires and tubes for proper functionality. The final packaging will ensure a neat and organized flowerpot design.


Bill of Materials (BOM):
  1. 3D-Printed Components:
    • Main structure (flowerpot body, water tanks, gutter)
    • Electronics compartment enclosure
  2. Electronics Components:
    • PCB components (copper plate, pin headers, Resistors, capacitors, and other electronic components as required)
    • Ultrasonic distance sensor (HC-SR04)
    • Water pump
    • Wires and connectors
    • 12V DC power supply
  3. Fasteners and Mounting Hardware:
    • Screws, nuts, bolts for assembling components
  4. Ice Packs (for water supply):
    • Ice packs or similar frozen water containers to melt and provide water for the right tank -> in my case, supplied by my weekly HelloFresh cooking boxes.
  5. Miscellaneous:
    • Tools for fabrication (3D printer, cutting tools, drilling tools)
    • Soldering iron and solder (if applicable)
    • Computer and cables for programming and testing

Final Project Q&A


- What will it do?

The smart self-watering flowerpot will automatically monitor the water level in the left tank and provide water to the flower whenever the water level is low. It achieves this by using an ultrasonic distance sensor (HC-SR04) to measure the water level and a pump to transfer water from the right tank (from HelloFreshs' melted ice packs) to the left tank. The system will be designed to ensure optimal watering for the flower, maintaining an adequate water level.

- Who has done what beforehand?

Similar self-watering systems and automated flowerpots exist in the market. Various DIY projects and commercial products have implemented similar concepts using different techniques and components. Some projects may have used sensors like HC-SR04 for water level measurement, while others might have used different types of sensors and control mechanisms.

Antoher project I came across is the Smart Planter from Svetlana Shishkovets. Her project includes a lot of features and extras such as growth light, a desktop app and a waterlevel indiator. It is a very cool project and I read her final project page for some inspiration.

In comparison to her project, I want mine to be smaller, as it should fit my windowsill. In general, my final project is very much tailored to my needs and is supposed to solve one of my own problems and it's not looking to solve a general problem a lot of people might have or not have. It is a specific use case that only uses the minimum of components to achieve it's task. This approach made it possible for me to spend time on the integrating and packaging aspect of the project.

- What will you design?

The design will include:

  • 3D design for the flowerpot structure, including the main body, water tanks, gutter, and electronics compartment.
  • Electronics system design, including the selection and integration of components such as the microcontroller, ultrasonic distance sensor, pump, and necessary supporting circuitry.
  • Embedded system programming for the microcontroller to monitor the water level and control the pump.

- What materials and components will be used?

The materials and components required will include:

  • 3D-printed parts for the flowerpot structure.
  • Electronics components such as a ultrasonic distance sensor (HC-SR04), water pump, wires, connectors, tubing, resistors, capacitors, and potentially a PCB board for electronics integration.
  • Power supply (DC power supply or battery pack).
  • Fasteners and mounting hardware.
  • Ice packs or similar frozen water containers.
- Where will they come from?

The 3D-printed parts can be created using a 3D printer. Electronics components such as the PCB will be self-made and other components can be sourced from local electronics stores, online retailers, or specialized suppliers. Power supplies, fasteners, and other miscellaneous items can be obtained from hardware stores or online suppliers. Ice packs will be provided through my weekls orders of HelloFresh.

- How much will they cost?

The cost will vary depending on factors such as the quality of components, the quantity required, and the availability of materials. The follwing is an estimate that includes expenses for 3D printing, electronics components, power supply, fasteners, and miscellaneous items:

Component Price (€) Source
Peristaltic Pump 5 FabLab
HC-SR04 3.80 FabLab
Filament 25 FabLab
PCB Plate and Components 10 FabLab
Test Plant 11.90 Self-bought
Ice Packs 0 Self-bought
Wires, Screws, etc. 8 FabLab + Self-bought
Total Cost 63.7
Self-bought Cost 15.9
- What parts and systems will be made?

The parts and systems that will be made include:

  • 3D-printed flowerpot structure, including the main body, water tanks, gutter, and electronics compartment.
  • Electronics system with the microcontroller, ultrasonic distance sensor, water pump, and associated circuitry.
  • Embedded system programming for the microcontroller to control the watering process.
- What processes will be used?

The processes involved in the project include:

  • 2D and 3D design + printing for the flowerpot structure.
  • Electronics design and PCB production.
  • Embedded system programming for the microcontroller.
  • Assembly and integration of all components.
  • Lasercutting/ -engraving for decoration purposes.
  • Testing and troubleshooting to ensure proper functionality.
- What questions need to be answered? + answers
  • How accurate and reliable is the ultrasonic distance sensor (HC-SR04) for water level measurement? Are there any alternative sensors that can be considered?
  • The HC-SR04 has an inaccuracy of about +/- 6mm. I included this inaccuracy in my code so that it doesn't affect the functionality. Other than that it has worked very reliable so far. I also could have used float level sensors or soil moisture sensors. I still chose the HC-SR04, because it allowed me to have a nicely integrated product that has no sensors sticking out of the electronics compartment. I also read, that the other sensor erode quite quickly. And for the float level sensor I would have maybe had to work with seals. WHich I didn't want.
  • What is the optimal pumping mechanism and flow rate to ensure efficient watering without damaging the flower?
  • I chose a plant that comes in a plastic pot that has a string attached to it at the bottom. The plant is therefore slightly elevated and the soil sucks up water by itself whenever needed.
  • How will the system handle situations such as power outages or low battery conditions?
  • Power outages are not a problem. The power supply is a 12V power adapter. Nothing gets lost with the loss of power. As soon as power is supplied again, the mechanism will start to work again.
  • Are there any safety considerations or measures to prevent overwatering or potential water leakage?
  • This is the biggest problem of the construction. It's far from safe regarding the risk of electronics coming in contact with water. You have to bevery careful when using it. The roof of the electronics compartment is beveled so water can flow away. But it is still very much possiblefor water to get inside. Especially from the bottom. This is the topic of further improvement ofthe project.
  • How will the system handle maintenance?
  • All components can be unscrewed and all the 3D printed parts can be deassembled. You can reprogram the PCB withoutremoving it from the electronics compartment.
- How will it be evaluated?

  1. Program Functionality: Test the program that controls the water level monitoring and pumping mechanism. Verify that the program effectively detects low water levels in the left tank and activates the pump to water the flower. Ensure that the program runs without errors and performs the desired actions reliably.
  2. 3D Print Quality: Inspect the 3D-printed parts of the flowerpot structure, including the main body, water tanks, gutter, and electronics compartment. Evaluate the overall quality of the prints, considering factors such as surface finish, dimensional accuracy, structural integrity, and visual appeal. Ensure that the 3D-printed parts fit together properly and provide adequate support for the components.
  3. Water Pumping: Verify that the water pump operates correctly and delivers water from the right tank (melted ice packs) to the left tank when needed. Observe the pumping mechanism to ensure it functions smoothly without any leaks or blockages. Confirm that the pump delivers an adequate amount of water to effectively water the flower.
  4. Watering Effectiveness: Monitor the flower's hydration level and health after using the self-watering system. Assess whether the flower receives sufficient water to maintain its health and growth. Observe any improvements in the flower's vitality compared to manual watering or traditional methods.
  5. Overall Aesthetics: Evaluate the visual appeal and overall aesthetics of the smart self-watering flowerpot. Consider factors such as the design coherence, color choices, and integration of the electronic components. Ensure that the flowerpot's appearance and size is visually pleasing and enhances the overall presentation.

Gantt Chart:

3D design:

I decided to pursue idea 2 "Selfwatering flowerpot" first. For this week I will design the flowerpot in Fusion360. To start off, I need to measure the dimensions of one of my other flowerpots, since I want the selfwatering one to fit in with the rest.

Now over to Fusion:
Sincen I don't know if I'll make changes to the model in the following weeks, I am using paramaters for all of the dimensions. Like this, I can change the value of any parameter here in this very same window and the changes will be applied everywhere automatically.

Process:

1. Use offset construction planes for sketches at different heights.

2. Extrude bottom and Loft between the different faces for an evenly interpolated volume.

3. Create new sketch for the watertank. Project the ground-sketch into this sketch and use constraints to fix the watertank to the border of the flowerpot.

Before I can go on with the design, I need to think about the electronic components I will be using. This is crucial since I need to know how much space they will occupy.

Components and their dimensions (LxWxH):
  • Selfmade PCB: 6 x 3.2 x 0,2cm
  • (Waterpump) Kamoer NKP-DC-S10Y: 6.75 x 5.45 x 4.03cm
  • 1x (Ultrasonic distance sensor) HC-SR04: 4.5 x 2.1 x 1.8cm

I looked for holders of these components on different forums and websites, but I would have needed to edit them anyway, so I figured it would make more sense and even save some time to just design them myself from scratch.

Starting with the HC-SR04 holder:

This is the sensor, I took measurements myself to create the holder for it.

Here it is sketched out. I added half a millimeter to the dimensions that needed to fit parts f the HC-SR04 such as the holes for the emitter and receiver etc. This was important, because our 3D printers aren't that accurate (as I learned in the 3d printing assignment ). It's similar to the Kerf of a lasercutter, just that here, the holes usually end up being smaller (instead of bigger). The material gets squeezed out by the nozzle and makes to holes about 0.5mm smaller than they are in the design file. You can download the Fusion file to have a closer look at the dimensions, or get them from the datasheet.

I extruded the sketch and added holes on the vertical wall, just in case I need them later on to mount the holder.

To test if the HC-SR04 would actually fit in this holder, I made a test print with the Ultimakers.

Fits perfectly. You can see the bit of room that I left. It even has some extra space, but this is optimal. This holder doesn't need to be a super snug fit!

Now going on with the pump holder:

Here we have the pump, I inted to fixate it with the two holes it has on each side.

I took the needed measurements and sketched it out.

The extruded sketch.

To test if the pump would actually fit in this holder, I made a test print for it as well.

The first one wasn't optimal, so I made the holes a few millimeters closer together in Fusion.

Second try et voilá.

Two down one to go: PCB holder

This is my PCB.

I took the dimensions and sketched it in Fusion.

I extruded the sketch.

And the test print.

Fits very well!

To make a compact design that can fit all my electronics into the electronics compartment, I decided to join the pump holder and the pcb holder.

This test print shows me, that having the PCB holder in the middle would make to connections of some cables very hard.

So in Fusion I moved it to the left. I didn't make another test print for this, because I already could tell from all of my previous test that the dimensions were right.

Designing the pot:

Create new sketch for the watertank. Project the ground-sketch into this sketch and use constraints to fix the watertank to the border of the flowerpot.

Now with the dimension of my components in mind, I design and extrude the watertank

Added tunnels to connect each watertank with it's respective part of the electronics compartment.

Extruded the electronics compartment.

As well as the gutter--part.

I then sketched the actual gutter part and extruded it.

Slight bevel added so that the water can flow downwards.

Here I added the part on which the roof will lay on.

The roof itself is modeled by using Loft between two sketches I drew. Here you can see a section analysis of the roof laying ontop of the electronics compartment.

Now I am inserting the previously modeled component holders. First off, the HC-SR04. It's placed over the water tank part that is connected to the plant. It senses whne the plant has now water left.

The gutter was a bit too big for the Ultimaker S5. I used construction planes to spit the body and remove some centimeters.

I also added the PCB/pump holder.

Here you can see that I lowered a part of the wall of the watertank so that I can stack the electronics compartment on top of it.

Same thing for the gutter. This ensures easy removeabilty and a stable and snug fit.

I'm using Fusion 3D print option to send the different bodies directly to Cura.

Electronics compartment in cura. Sliced and in preview mode. ~19h

Gutter: ~19h

Watertank: ~1d

Electronics roof: ~4h

All downloads:

3d printing

I worked with the Ultimaker S5 for all of my prints. I used regular PLA for all pieces. After saving the file from Cura to a USB stick, you can simply plug it into the printer, load the PLA and then print. I had to break away a few supports, but other than that it was super easy to print all of my parts.

Here you can see the parts.



Assembly:

And done.

2D design for laser cutting

Deigning his decoration for my plant with the FabLab logo.

Save it as DXF on a USB.



Cutting the edges + engraving the logo

And done.

Stick it in the soil. :))

PCB design

This section is taken from my previous assignment about electronics design and embedded progamming.

Board Features

I am designign my PCB around the Seeed Studio XIAO SAMD21 as my microcontroller. The manufacturer has an elaborate documentation about the Seeduino XIAO SAMD21. It carries the ATSAMD21G18A-MU which is a low-power microcontroller. It's documentation describes it as having good performance in processing while not needing a lot of power. It's designed to be small and can be used for wearable devices and small projects.

Documentations I used for this page: Seedstudio (official) | Dronebotworkshop

All pins except Pin 0 support PWM.

For general I/O pins: Working voltage of MC is 3.3V. Voltage input connected to general I/O pins may cause chip damage if its higher than 3.3V. For power supply pins: The built-in DC-DC converter circuit is able to change 5V voltage into 3.3V and allows to power the device with a 5V supply via VIN-PIN and 5V-PIN. Please pay attention, do not lift the shield cover.

Item Value
CPU ARM Cortex-M0+ CPU(SAMD21G18) running at up to 48MHz
Flash Memory 256KB
SRAM 32KB
Digital I/O Pins 11
Analog I/O Pins 11
I2C interface 1
SPI interface 1
QTouch 7 (A0,A1,A6,A7,A8,A9,A10)
UART interface 1
Power supply and downloading interface Type-C
Power 3.3V/5V DC
Dimensions 20x17.5x3.5mm

Pinout diagram:

This SAMD21 can be programmed via USB and doesn't need pins for that. The following I/O-devices will have to connect to the board:

Also needed:

My circuit needs different voltage supplies for the pump (12V) and the microcontroller (5V), but I only want to use one power supply. The solution is a 5V regulator. This component can be connected to any DC supply voltage between 7 and 35 volts. It has three pins: Pin one is the input for unregulated voltage. Pin 2 is the ground pin and pin 3 is the regulated 5 volt output. The manufacturer recommends a capacitor on the input and the output. It notes that the input capacitor is required if the regulator is far away from the power supply filter. The capacitor is going to help smooth out interruptions to the supply and also low frequency distortions.

The board also includes a programmable button and an LED that turn on on receiving power (plus the needed capacitors and resistors).

Designing the PCB in KiCad

Find more detail on this on my Electronics design assignment.

Creating a new project and working with it:

File>New Project to create a new project.
My project
Double click the schema file.
This should open, in your case everything will be empty of course if you haven't added anything yet.
By going to File>Page settings you can change the size of the sheet and the metadata. I never really use it, but do whatever you prefer!
An important thing to note though is the Grid and its' properties. If you want to change the Grid, right click on this button and click Grid properties.
Now to the important functionality: With this button, you can add symbols. The window on the left will open, where you can find all symbols KiCad has to offer, also the ones you just added. You can use the search function to quickly find what you need
Added 2 pin headers for both HC-SR04's. I create the connection logic with labels. This way, I can connect two pins without drawing a cable.
The LED: by connecting it to 3V3 it automatically turn on, when power is supplied to the board.
The pump: A pin header serves as the connection place for the pump. A MOSFET is integrated into this circuit to control the pump. Gate pin is connected to the SAMD21, when power is supplied to this pin, the circuit of the pump gets closed and it can work -> SIG_PIN can be programmed. Pump get power from 12V adapter, so it's not connected to normal VCC, but to EXTERN_VCC.
5V regulator: On the left, we have the pin header which serves as the place to connect the 12 power adapter. The 5V regulator in the middle turns 12V into 5V and "connects" EXTERN_VCC and normal VCC. Capacitors between the 5V regulator and the GND are neccessary.
The programmable button with a pull-down resistor: In a circuit, a "pull-up" or "pull-down" resistor is used to ensure that a digital input signal is in a well-defined state when no input is present. This pull-down resistor connects the input to ground, so that when the button is not pressed, the input is at a logic low level. When the button is pressed, the input is connected to the voltage source through the button, and the input goes to a logic high level.
It's finally time to create your pcb layout. Click this button in your schema workspace to get to the pcb workspace. There, press the button to update your pcb with changes made to the schematic.
You will get something that is roughly similar to this. A lot of components with a lot of white lines. The white lines represent the logical connections.
You might want to change your track width before the wiring step. To do so, click this button.
Go to Net Classes. Here you can change the Clearance and the Track width. Go with about 0.4mm minimum clearance and track width.
You have to turn the logical connections into physical ones using the wire tool. You can layout your components by moving them with the mouse and then drawing wires between them, until all white lines disappear and everything is connectd the right way. You can always go back to your schematic to change the logic if you realize you made a mistake or something doesn't fit. Just press update PCB afterwards and your changes will be applied.
Another best practice is to change the pad shape of the pin headers. Usually they are round when you start out, but an oval like shape is often better. To change, right click on any of the pads and choose Properties.
Change whatever you have to these settings and apply.
After this you can copy the properties to all of the other pads.
After you are done arranging and wiring your PCB, it should look something like this. But there's two more important things to note also visible on this picture, a ground layer and an outline + mounting holes.
How to make a ground layer: A layer that connects all GND's is super useful as it saves you a ton of connections. Click on the Add a filled zone button and click where you want to start your filled zone.
This windows will pop up, choose GND and hit ok.
Start drawing your zone. When you are done, press B on your keyboard to hatch it.
For the outline, draw a rectangle around your PCB along with circles for mounting holes. Right click on the lines and choose properties and change te Layer to Edge.cuts. And you're done!
PCB
Schema
Download my KiCad project file

PCB production

This section is taken from my previous assignment about electronics production.

Milling my PCB

The machine will get the tool by itself and will check the z height as well all on its' own.
Milling the top layer.
The program will tell you when the machine is finished.
Here's the milled board.
Break the tabs just like this to remove the board from the plate.

Soldering the components

Now the milled PCB had to be stuffed/soldered. To do so, the first step is to get all the materials:

Name Description Amount
Controller Seeeduino XIAO SAMD21 1
Pin-Header Conn_02 Male 3
Pin-Header Conn_04 Male 2
Pin-Header Conn_05 Male 1
LED (R_1206) LED indicates power 1
Capacitor (C_1206) 10uF 2
Capacitor (C_1206) 1uF 1
Capacitor (C_1206) 0.1uF 1
Resistor (R_1206) 49Ω 1
Resistor (R_1206) 10kΩ 1
Button 4 Pins SMD 1
Voltage Regulator 5V 1
MOSFET SMD 50V 16A 1

After soldering this is what my PCB looks like:

Programming

Setting up Arduino IDE for the board

How to:
Download and launch the Arduino IDE
Click on File > Preference, and fill Additional Boards Manager URLs with this URL: https://files.seeedstudio.com/arduino/ package_seeeduino_boards_index.json
Click Tools-> Board-> Boards Manager..., print keyword "Seeed Xiao SAMD" in the searching blank. Here comes the "Seeed SAMD Boards". Install it.
After installing the board, click Tools-> Board, find "Seeeduino XIAO" and select it. Now you have already set up the board of Seeed Studio XIAO SAMD21 for Arduino IDE.
Select Tools > Port. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.
Now write any program (or choose from the examples), connect the board via USB-C to your PC and click the "Upload" button in the environment.

The code

It makes sense to program the microcontroller before connecting other devices, since they might interfere with the upload connection for the code.
The program shown below combines my two codes from Embedded programming / Output devices
It defines the pin connected to the MOSFET's Gate as an output pin as well as all the pins for the HC-SR04 (the input device of this assignment). Everytime the HC-SR04 senses a distance of less more than 8.8cm (meaning the watertank is empty) the pump will activate. The pump gets activated by power that is supplied to the pin, which bridges the connection between the Drain and the Source of the MOSFET, connecting the GND of the pump to the common GND and therefore enabling it to run:

(This code was written with the help of ChatGPT and Rui Santos, https://randomnerdtutorials.com and modified by me.)


int trigPin = 5;    // Trigger 
int echoPin = 6;    // Echo
double duration, cm, cmNew, inches;
int pumpPin = 9;    // MOSFET Pin for pump control
int buttonPin = 10;      // Button Pin
double maxDistance = 8.8; // Max distance for pump activation in cm
unsigned long previousMillis = 0;    // Stores the time of the last measurement
unsigned long measurementInterval = 60000;   // Measurement interval set to 1min

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {
	//Serial Port begin
	Serial.begin (9600);
	//Define inputs and outputs
	pinMode(trigPin, OUTPUT);
	pinMode(echoPin, INPUT);
	pinMode(pumpPin, OUTPUT); // Set pumpPin as an output  pinMode(buttonPin, INPUT); // Internal pull-up resistor for button pin
	pinMode(buttonPin, INPUT); // Internal pull-up resistor for button pin
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop() {

	if (digitalRead(buttonPin) == HIGH) {      
	cm = returnDistance();
	checkAndPump(cm);
	}
	
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= measurementInterval) { //if it's been 1min since the last check
	previousMillis = currentMillis;
	cm = returnDistance();  //gets measured distance and stores it in cm
	checkAndPump(cm);       //looks if cm is mre than maxDistance, if so->pump, if not don't pump
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void checkAndPump(double thiscm){
	
	// Activate pump if distance is less than minDistance
	if (thiscm >= maxDistance) {    //if measured distance is greater than 8.8cm
	digitalWrite(pumpPin, HIGH);  // Turn on the pump
	delay(40000);                 //40 seconds
	digitalWrite(pumpPin, LOW);   // Turn on the pump
	cmNew = returnDistance();     //get the distance now, after pumping
	//Serial.println(thiscm);
	//Serial.println(cmNew);
		if (thiscm-0.6 <= cmNew) {        //If the original distance is still the same (or even smaller) as the new one (0.6 is inaccuracy of HC-SR04)       
			measurementInterval=3600000; //(3,600,000ms = 1h)if the water level didnt go up,
										//the next check is in 1h, this is done
			}                              //in case of the right water tank being empty       
	} else {
	digitalWrite(pumpPin, LOW); // If the left water tank has water, pump is off
	measurementInterval=60000;  // Next time water level is checked is 1min later
	}
	
Serial.print("measurementInterval: ");
Serial.print(measurementInterval);
Serial.println();

	
	delay(250);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double returnDistance(){
	// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
	// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
	digitalWrite(trigPin, LOW);
	delayMicroseconds(5);
	digitalWrite(trigPin, HIGH);
	delayMicroseconds(10);
	digitalWrite(trigPin, LOW);

	// Read the signal from the sensor: HIGH pulse (duration of the time (in microseconds) 
	// from sending of the ping to reception of its echo off of an object.)
	pinMode(echoPin, INPUT);
	duration = pulseIn(echoPin, HIGH);//Reads a pulse (either HIGH or LOW) on a pin. 
		//For example, if value is HIGH, pulseIn() waits
		//for the pin to go from LOW to HIGH, starts timing, 
		//then waits for the pin to go LOW and stops timing.

	// Convert the time into a distance
	cm = (duration/2) / 29.1;     // Divide by 29.1 or multiply by 0.0343

	Serial.print(cm);
	Serial.print("cm");
	Serial.println();

	return cm;
}
Now upload the program to the board as described above.

Connections of the input + output device

Testing the pumping mechanism.

Components mentioned:

Connect the 5V regulator to the pin header. Mind the right orientation. Input to 12V side, Ground to GND, Output to 5V side -> You can check this in a datasheet or test it on a breaboar with a multimeter.
Connect the pump: VCC to 12V and GND to common GND
Connect the power adapter (don't connect it to a power outlet yet): VCC to VCC and GND to GND.
Connect the HC-SR04 to the corresponding pins.
Overview:
Make sure everything is correctly connected. Check your KiCad design to make sure.
Now connect the power adapter to a power outlet.
I first checked if the HC-SR04 is working correctly (with one of the previous weeks program).
Working HC-SR04 + pump (pumps water when the HC-SR04 gets closer than 4cm to the ground):

This is a test code that just uses the normal activate if distance is more than 4.4cm part of the program. Fine more detail here.

Now, with all of the preparation done, which included 2D and 3D design of the flowerpot in Fusion, PCB design and production with KiCad and CNC milling, programming and testing with Arduino IDE and my PCB, it is time to put everything together.

Integration

At the bottom you can see the HCSR04 placed above the plants water tank. Right next to it is the peristaltic pump, and below the peristaltic pump is my PCB. Everything is connected. The external power supply can also be seen as the cable that leaves the electronics component.
View from below. You can see emitter and receiver, as well as the pumps' two tubes. The black tube will go into the reserve water tank and the other one will hang over the plants watertank.
The PCB is already programmed. But in case any changes need to be done, you can plug the USB cable in here from underneath.
Guiding the tubes into the right tank.
Assembling all parts.

How it works:

Case 1: The reserve water tank has water inside.
I plug in the power supply.
Shortly after power is supplied, the sensor will measure if the plant has water or not. If the plant watertank is empty, it will advise the pump to pump from one tank to the other for 40 seconds.
Now let's say that the plant uses it's water or it evaporates. I simulate this by removing the water.
The sensor chekcs the current waterlevel every minute. And as soon as the tank is (close to) empty, the pump will pump as soon as the level gets checked again.
Case 2: The reserve watertank is empty.
Now let's say that the plant uses it's water or it evaporates. I simulate this by removing the water.
Of course there wn't be any water pumped into the plants tank. And the sensor would sense every minute that there is n water inside and will try to pump again, to no avail. This is why the sensor check after each pump if the water level has risen. And if it din't the interval to check gets set to 1 hour. To avoid unneccessary pumping.
In use: Now you can cut open one side of your ice pack and place it ontop of the gutter. It will melt over time directly into the reserve tank.
The reserve tank will store the water until it gets used by the plant. As soon as the ice pack is empty, you can remove the plastic.
After 1 month of using the flowerpot, the plant inside is still alive and well! :)

Presentation video and slide

Lastly I want to give my special thanks to my instructor Ahmed Abdellatif. He is an exceptional instructor and has helped me tremendously on this 20 weeks journey. Throughout the course he went above and beyond to ensure that we understand the material and successfully complete our assignments. His extensive knowledge of the subjects and his patience and willingness to address our questions and concerns created a supportive learning environment that motivated me throughout the whole FabAcademy experience. I am incredibly grateful for the opportunity to complete FabAcademy under his guidance and I will carry the knowledge and skills that I gained here through my further academic and professional journey. :)

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.