CC-BY-SA 3.0

Recommend Projects

ATtiny13 TinyMoisture

6 months ago 391
  • Description
  • Documents
  • BOM
  • Attachments
  • Members
  • Comments



TinyMoisture monitors the soil moisture of your plants and gives an alarm if you forget to water them again.



TinyMoisture uses the resistance measurement method to determine the soil moisture. The two probes together with the substrate form a variable resistor. The more humid the soil, the better its conductivity and the lower the electrical resistance. Together with the 10k fixed resistor, a voltage divider is formed. This voltage can be measured by the ADC of the microcontroller. The circuit is based on the SparkFun Soil Moisture Sensor.




The ATtiny13 spends most of its time in sleep mode. Every eight seconds it is woken up by the watchdog timer. It measures the moisture in the soil and compares it with the threshold value selected by the calibration potentiometer. If the soil is too dry, it emits a short acoustic signal via the buzzer and a short optical signal via the LED (ALARM). Then it goes back to sleep mode.

The ATtiny can also be woken up by pressing the TEST button (pin change interrupt). An acoustic and optical signal is then output first so that the user can determine whether the battery is still supplying sufficient power. Then measurements of the soil moisture are carried out until the button is released again. In this way, the correct threshold value can be found and set by turning the poti.

To avoid corrosion of the electrodes as far as possible, a voltage is only applied during the measurement. The ATtiny is clocked with only 128 kHz and all unused peripherals are switched off so that the power consumption is as low as possible.

// main function
int main(void) {
  // reset watchdog timer
  resetWatchdog();                        // do this first in case WDT fires

  // setup pins
  DDRB  = (1<<PE_PIN)|(1<<AL_PIN);        // set output pins
  PORTB = (1<<TB_PIN);                    // set pull-ups

  // disable unused peripherals and set sleep mode to save power
  ACSR   = (1<<ACD);                      // disable analog comperator
  DIDR0 |= (1<<MS_PIN)|(1<<CA_PIN);       // disable digital intput buffer on ADC pins
  PRR    = (1<<PRTIM0);                   // shut down timer0
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // set sleep mode to power down

  // setup pin change interrupt
  GIMSK = (1<<PCIE);                      // pin change interrupts enable
  PCMSK = (1<<TB_PIN);                    // set pins for pin change interrupt
  sei();                                  // enable global interrupts

  // main loop
  while(1) {
    if (~PINB & (1<<TB_PIN)) beep();      // alarm if test button is pressed

    ADCSRA |=  (1<<ADEN);                 // enable ADC
    PORTB  |=  (1<<PE_PIN);               // power measurement circuit
    _delay_us(125);                       // give it all a little time

    do {     
      if (readADC(MS_ADC) < (readADC(CA_ADC)>>1)) beep();  // beep if dry soil    
    } while(~PINB & (1<<TB_PIN));         // repeat if test button is hold

    PORTB  &= ~(1<<PE_PIN);               // power off to prevent corrosion
    ADCSRA &= ~(1<<ADEN);                 // disable ADC

    sleep();                              // sleep for a while ...

Compiling and Uploading

Since there is no ICSP header on the board, you have to program the ATtiny either before soldering using an SOP adapter, or after soldering using an EEPROM clip. The AVR Programmer Adapter can help with this.

If using the Arduino IDE

  • Make sure you have installed MicroCore.
  • Go to Tools -> Board -> MicroCore and select ATtiny13.
  • Go to Tools and choose the following board options:
    • Clock: 128 kHz internal osc.
    • BOD: BOD disabled
    • Timing: Micros disabled
  • Connect your programmer to your PC and to the ATtiny.
  • Go to Tools -> Programmer and select your ISP programmer (e.g. USBasp).
  • Go to Tools -> Burn Bootloader to burn the fuses.
  • Open TinyMoisture.ino and click Upload.

If using the precompiled hex-file

  • Make sure you have installed avrdude.
  • Connect your programmer to your PC and to the ATtiny.
  • Open a terminal.
  • Navigate to the folder with the hex-file.
  • Execute the following command (if necessary replace "usbasp" with the programmer you use):
    avrdude -c usbasp -p t13 -U lfuse:w:0x3b:m -U hfuse:w:0xff:m -U flash:w:main.hex

If using the makefile (Linux/Mac)

  • Make sure you have installed avr-gcc toolchain and avrdude.
  • Connect your programmer to your PC and to the ATtiny.
  • Open the makefile and change the programmer if you are not using usbasp.
  • Open a terminal.
  • Navigate to the folder with the makefile and main.c.
  • Run "make install" to compile, burn the fuses and upload the firmware.

Operating Instructions

Put the TinyMoisture deep enough into the earth that the two probes are just completely covered by earth. The device measures the soil moisture every eight seconds and gives a short alarm if the soil is too dry.

Pressing the test button always gives at least one short alarm. This can be used to check that the battery has sufficient charge and that the device is working properly. If the ground is too dry, the alarm remains on as long as the test button is held down.

To calibrate the TinyMoisture it should be placed in soil that is just too dry. Press and hold the TEST button. Turn the calibration potentiometer until the alarm is just triggered. Release the TEST button.




This work is licensed under Creative Commons Attribution-ShareAlike 3.0 Unported License. (





ID Name Designator Footprint Quantity BOM_Supplier BOM_Supplier Part
1 MMBT3904 Q2 SOT-23_1 1 LCSC C20526
2 MLT-5030 BUZZER1 MLT-5030 1 LCSC C95297
3 1k R6,R5 0603 2 LCSC C21190
4 10k R2,R1 0603 2 LCSC C25804
5 100R R3 0603 1 LCSC C22775
6 CR2032-BS-6-1 B1 BATTERY-3 1 LCSC C70377
7 DRY LED1 LED0603 1 LCSC C2286
8 PROBE1 H1 HDR-M-2.54_1X1 1 LCSC C81276
9 PROBE2 H2 HDR-M-2.54_1X1 1 LCSC C81276
10 ATtiny13A U6 SOP-8_150MIL 1 LCSC C14075
11 TEST KEY1 KEY-3.0*6.0 1 LCSC C46491
12 100n C1 0603 1 LCSC C14663
13 10u C2 0603 1 LCSC C466781
14 10k R4 TC33X 1 LCSC C719176
15 MMBT3904 Q1 SOT-23-3 1 LCSC C20526


The owner does not allow comments in this project now

Comments (0)

如果需要转移工程请在个人中心 - 工程 - 工程高级设置 - 下载工程,下载后在 打开保存即可。
有问题联系QQ 3001956291 不再提醒
svg-battery svg-battery-wifi svg-books svg-more svg-paste svg-pencil svg-plant svg-ruler svg-share svg-user svg-logo-cn svg-double-arrow
We use cookies to offer you a better experience. Detailed information on the use of cookies on this website is provided in our Privacy Policy. By using this site, you consent to the use of our cookies.