Menu Close

Tag / how

How to Design a Cheap Plant Watering Sensor (Part 6)

This is the sixth part of the meta-tutorial, where I talk about designing a cheap plant watering sensor. If you did not already read the firstsecondthirdfourth and fifth part please do it now. These parts contain a lot information which lead to this point of the tutorial.

The fifth part ended with step 24, where I talked about calculating the total bill of materials. This part will focus on preproduction of a small batch of sensors to solve some final details.

Just note, I obviously do not follow these steps in a perfect sequential way. Often I start with some tasks earlier and things are running in parallel. There are various dependencies and it would make no sense to wait with some task just to follow a strict sequence. 🙂

If you follow my blog you may already read some details about ongoing tasks. I will just briefly talk about them in this article. You will find more details in the other blog posts.

Step 25: Build an Alpha Series

Everything looks very promising, so its time to build a small batch of the final devices to see if they work as expected. This is also a test to see how a larger number of these devices can be produced and what kind of tools are needed for this task.

Order the Components

First I order the components. This is very important, because the availability of electronic components changes all the time. It is nice to have all required components, so you can order the boards with the correct footprints. If you order the boards first and are unlucky, an important component is suddenly unavailable and you have lots of boards with wrong component footprints on it.

The components for the plant sensor are really cheap, so there is no huge risk. Even it turns out a huge issue requires a component change – it will be a small loss. SMD components also do not take a lot of space, I can easily store all of them in a very small box.  Continue Reading

How to Design a Cheap Plant Watering Sensor (Part 3)

This is the third part of the meta-tutorial, where I talk about designing a cheap plant watering sensor. If you did not already read the first and second part, please do it now. These parts contain a lot information which lead to this point of the tutorial.

The second part ended with step 14, designing a first prototype PCB. So let us start with the next steps in this journey. This article will be the smooth transition from prototyping to the initial planing for a final design.

Step 15: Assemble and Check the Prototype

After receiving the prototype PCBs from OSH Park, I assemble one completely, including the cable and with one of the sensor plate prototypes as foot part.

Set the Fuses of the Microcontroller

The microcontroller ATtiny13A requires programming using SPI before it can be soldered to the board. There are special bits in the memory, called “fuses”, which control very basic settings of the chip. One of this fuse controls if the chip can be programmed and debugged via the debugWire protocol. This protocol just uses one single wire to program and debug the chip, bus has to be enabled first.

So I put the microcontroller into the programming adapter and connect everything via the Atmel ICE to the computer.

lucky-resistor-1 Continue Reading

How to Design a Cheap Plant Watering Sensor (Part 1)

In this article I will talk about how I designed a cheap plant watering sensor. My goal is some kind of meta tutorial, where you can see the steps involved from the initial idea to the final sensor. If you ever planed to create a own device, I hope this article give you some inspiration to start your own project soon.

Why a Plant Watering Sensor?

I have a couple of plants in flowerpots and this plants not only like some light, they also need water from time to time. Watering this plants is something I often forget, with sad results. There are ready made solutions for this, but I have some objections with all of them. To be clear: There are really smart products out there – it is absolutely nothing wrong with them. It is just as I like to build my own fan controller, I like to build my own plant watering sensor in my very own fashion.

Here a list of already existing projects and devices I own or checked out:

Step 1: Define the Expectations and Goals

After deciding to create a own plant watering sensor, I spend some days to think about my expectations and goals for this sensor.

For my personal case, I like to put a small sensor in each flowerpot. There will be five and more pots, therefore that number of sensors are required. A single sensor should be really cheap, so I can distribute as many of them as I like. Battery life should be at least one year, better two years. I collected all this thoughts into the following list:

  • Cheap: Ideally less than €5 including the PCB.
  • Visual Signal: A flashing LED, simple to notice but easy to ignore.
  • Simple: Easy and simple to build with few components.
  • Beautiful: It should ideally look like a decoration.
  • Long Battery Life: The battery should last at least 1 year or longer.
  • Small: The sensor should be almost invisible from far away.
  • Reliable: The measurement should be reliable and the sensor must not corrode or degrade over years.
  • Safe: The sensor must be safe for the plant and environment.
  • Low Battery Indicator: The sensor should detect if the battery is at end of life and signal this.

Continue Reading

How to Debug Time Critical Code using an Oscilloscope

From time to time you have to debug time critical code. If you are using interrupts, you are interested in the actual performance on the code. This is especially true, if you are using timed interrupts.

In this cases, using the serial interface is impossible. If you write to the serial interface, the whole timing of your application changes and you will get no usable results.

If you own an oscilloscope, there is a really simple way to debug many applications. I used this technique many times, for example with projects featured on these pages: For the timing of the sound output of the cat protector, or the timing of the display interrupt of the Meggy Jr library.

This technique is obvious ans simple. Nevertheless I hope this article will give some inspiration to help solving timing problems.

Continue Reading

How and Why to Avoid Preprocessor Macros

While most naming conflicts in C++ can be solved using namespaces), this is not true for preprocessor macros.

This post is outdated. You will find an updated version here:
How and Why to Avoid Preprocessor Macros

Macros can not be put into namespaces. If you would try to declare a new class called Stream, but somewhere in a header you include would be a macro called Stream, things would break. While compiling your code, the preprocessor would simply replace the Stream in your class Stream { declaration. You could get a really confusing error message, and it would take time and energy to find the actual problem.

Especially people developing software for controllers, often overuse macros for almost everything. They believe it will save RAM, speed up the code or make it more flexible. Often none of these three things are true. Actually each additional macro is a risk for name conflicts and makes the code less readable. You should reduce the use of macros to the absolute minimum, and especially avoid macros in your header files.

Continue Reading

How and Why to use Namespaces

Namespaces are a feature of C++ which address the problem of name conflicts. There is a “global” namespace, where everything lives which was declared without namespace. Especially the Arduino environment declares a huge amount of variables and constants there, so it is a good practice to put everything you write in a own namespace. Namespaces are only used while compile time, and they do not use any memory at runtime nor make they run your program slower.

In my case I choose the namespace lr which stands for Lucky Resistor. Everything I declare in this namespace is accessible trough the :: operator which you probably already know from function definitions.

Continue Reading