pittex
Published © GPL3+

Foaling Monitor

Help the breeders to follow the pregnancy of the mares and alert them when the birth is imminent and intervene as soon as possible.

BeginnerFull instructions provided5,531

Things used in this project

Hardware components

Arduino MKR Fox 1200
Arduino MKR Fox 1200
×1

Software apps and online services

Sigfox
Sigfox

Hand tools and fabrication machines

Battery support
Adafruit Tilt switch
Box

Story

Read more

Custom parts and enclosures

Arduino MKR Fox 1200

Not include in Fritzing by default

Schematics

Electrical wiring

Code

Pony

Arduino
#include <SigFox.h>
#include <ArduinoLowPower.h>

const uint8_t SWITCH_PIN = 1;
const String payload = "HORSE!";
const uint8_t debug = false;
int Count = 0; //Timer
int Circle = 0; //Number message send. After 3 messages, go sleep

void setup() 
{

  if (debug == true) 
  {
    Serial.begin(9600);
    while (!Serial) {};
  }
  
  if (!SigFox.begin()) 
  {
    Serial.println("Shield error or not present!");
    return;
  }
  
  delay(200);

  // Send the module to the deepest sleep
  SigFox.end();

  // Attach switch pin and enable the interrupt 
  pinMode(SWITCH_PIN, INPUT_PULLUP);

  // The mare lies on the side, switch close circuit
  LowPower.attachInterruptWakeup(SWITCH_PIN, CircuitClose, FALLING); 
}

void loop()
{
  LowPower.sleep();

  Circle = 0;
  Count = 0;
  
  //If the mare is lifted, switch is open module goes sleep
  //Or after 3 messages sent the module goes sleep 

  delay(1000);

  while (Circle!=1)

  {
   if (digitalRead (SWITCH_PIN) == HIGH)
   {
    Circle = 1;
   }
   
   // Timer Count
   delay(1000);

   Count++; 
       
   // Send message after 30s, 60s and 120s
   if (Count == 30 || Count == 60)
   {
    sendString(payload);
   }

   if (Count == 120)
   {
    Circle = 1;
    sendString(payload);
   }
   
  }
}

void sendString(String str) 
{
  // Start the module
  SigFox.begin();
  // Wait at least 100mS
  delay(100);
  // Clears all pending interrupts
  SigFox.status();
  delay(1);

  SigFox.beginPacket();
  SigFox.print(str);

  int ret = SigFox.endPacket();  // send buffer to SIGFOX network

  SigFox.end();
}


void CircuitClose() 
{
  
}

Credits

pittex

pittex

0 projects • 1 follower

Comments