Input devices

Soil Moisture sensor

I used the soil moisture sensor from sparkfun. It is an open sourse product.




I startred by reading and learning about the sensor and I found out that the Soil Moisture Sensor is pretty straightforward to hookup. We need to supply VCC and GND, and you we get analog signal out, which will be between almost VCC and GND, depending on the amount of water in the soil.

The two probes are acting as a variable resistor – more water in the soil means better conductivity and results in a lower resistance and a higher SIG out. The analog readings varies depending on what voltage you use for Vcc as well as the resolution of the ADC pins.

I soldered three wires to the sensor. Red (VCC) goes to VCC on the board, Black (GRN) goes to ground on the board, and pink (SIG) goes to PA0 on the board.




An issue with soil moisture senors is their short lifespan when exposed to a moist environment and to extend the lifespan of the sensor, it is recommended to only power it when it is taking a reading. But I didn't do that in my board, as the sensor will be conected to VCC on the microcontroller.

Designing the board

I used the board from my electronic design week and I modified it by adding pads for the sensor. I connected the sensor's signal output to PA0 on the board. According to ATtiny24/44/84 Datasheet only PA ports have ADC.




Here is the board design exproted from kokopelli:




I exported the traces with resolution of 25 pixels/mm.




I learned from my previous mistake in electronics design week and I exported the interior boarder of the board.




As you can see in the board pictures I used XTAL1 pads to make my sensor pads, but this gave me hard time in soldering. So our guru Francisco gave us a class to teach us how to make a custom pad in kokopelli. Here is echo hello-world board with a custom pad added to it.




Fabricating the board

To fabricate the board I used Fab Modules to generate the rml file and then milled the board with SRM-20 machine, the process was easy beacuase I've done it a lot and the steps are explained in my electronics production week.

Except that one of my colleagues broke the last (1/64) milling bit so I used a broken one therefore the quality of the traces wasn't that good and I had to use the microscope and a cutter to modify the traces. And then I started soldering the components.




This is the board after finishing soldering




After finishing the board I had to make sure that the board did not have any short circuits. But I found that the VCC and GND are connected together. And using the microscope I saw that the red sensor wire is connected to the trace next to it. I removed the copper connection using a cutter.

Programming the board

I connected the board to the ISP programmer that I have made before in electronic production assignment and I tried to upload a blinking LED program first to make sure that the board is working.

The next step is writing a program that will convert the analog signal from the Soil Moisture Sensor to digital values that the microcontroller can read . And then if the converted value is more than a cetain value , the LED will be on and if it goes below that value the LED will be off.

So , I started reading about ADC, and how to convert the from analog signal to digital signal. Also, I opened attiny44 datasheet and read the ADC chapter.

The microcontroller is a digital device so it can only send and receive digital signals. But it has part of it called ADC that converts analog values to digital values so the microcontroller can read it.

In attiny44, the ADC is hooked to PORTA (pins PA0 to PA7) only. And it is a 10-bit ADC, so its resolution is 1024.

Firstly, I need to set the ADC Prescaler , the range should be from 50kHz to 200kHz. So, for the program I will make the predivision factor 128, as the board has an external clock with frequency of 20MHz.







So in my case, I don't need to select the multiplexerm because the sensor is connected to PA0 and Vcc is selected as an analog reference.

To start programming, I started with Neil's code Hello.light.45 and I modified the ADC code.

Then, I tested my sensor by measuring the output voltage by a multimeter while it is in the Air and it was 0v. And then I put the sensor in water and the output voltage 4.4v.

So in my code I wanted LED to turn on when the sensor is in water, and here is the code:

if ( ADC > 650 )
{
PORTB |= (1 << PB2);
}

else
{
PORTB &= ~(1 << PB2);
}

Here is a video fo the sensor working:

Files