ronfrtek
Published © LGPL

Find Out When Someone Entered a Room

In this tutorial we will learn how to Find out when someone entered a room using RTC module, PIR sensor,OLED display and arduino.

IntermediateProtip1 hour164
Find Out When Someone Entered a Room

Things used in this project

Hardware components

0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Pi RTC (DS1307)
Seeed Pi RTC (DS1307)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino visuino

Story

Read more

Schematics

pir-rtc-entering-space_kCxg6xbVhG.visuino

Code

pir-rtc-entering-space.visuino

Arduino
Use Visuino
//----------------------------------------------
//
//        Sketch Generated by Visuino
//              www.visuino.com
//          Version 7.8.3.24
//
//----------------------------------------------

#define VISUINO_ARDUINO_UNO
#define _MITOV_DISPLAY_SSD1306_I2C

#include <OpenWire.h>
#include <Mitov.h>
#include <Wire.h>
#include <Mitov_Basic_I2C.h>
#include <Mitov_RTC_DS1307.h>
#include <Mitov_Display_SSD1306_I2C.h>
#include <Fonts\Fixed\GraphicsFont5x7.h>
#include <Mitov_ChangeOnly.h>
#include <Mitov_Timing.h>
#include <Mitov_Switch.h>
#include <Mitov_LogicGates.h>

// Shared Component Member Variables

namespace ComponentVariables
{
class
{
public:
  bool Value1 : 1;
  bool Value2 : 1;
  bool Value3 : 1;
  bool Value4 : 1;
  bool Value5 : 1;
  bool Value6 : 1;
  bool Value7 : 1;
  bool Value8 : 1;

} BitFields;

class Variable1
{
public:
  inline static bool GetValue() { return BitFields.Value1; }
  inline static void SetValue( bool AValue ) { BitFields.Value1 = AValue; }

};
class Variable2
{
public:
  inline static bool GetValue() { return BitFields.Value2; }
  inline static void SetValue( bool AValue ) { BitFields.Value2 = AValue; }

};
class Variable3
{
public:
  inline static bool GetValue() { return BitFields.Value3; }
  inline static void SetValue( bool AValue ) { BitFields.Value3 = AValue; }

};
class Variable4
{
public:
  inline static bool GetValue() { return BitFields.Value4; }
  inline static void SetValue( bool AValue ) { BitFields.Value4 = AValue; }

};
class Variable5
{
public:
  inline static bool GetValue() { return BitFields.Value5; }
  inline static void SetValue( bool AValue ) { BitFields.Value5 = AValue; }

};
class Variable6
{
public:
  inline static bool GetValue() { return BitFields.Value6; }
  inline static void SetValue( bool AValue ) { BitFields.Value6 = AValue; }

};
class Variable7
{
public:
  inline static bool GetValue() { return BitFields.Value7; }
  inline static void SetValue( bool AValue ) { BitFields.Value7 = AValue; }

};
class Variable8
{
public:
  inline static bool GetValue() { return BitFields.Value8; }
  inline static void SetValue( bool AValue ) { BitFields.Value8 = AValue; }

};
} // ComponentVariables

// Arduino Constant Declarations

namespace VisuinoConstants
{
class FloatValue0
{
public:
    inline static constexpr float GetValue() { return 0.811999976634979; }
};

} // VisuinoConstants

// Pin Call Declarations

namespace PinCalls
{
class PinCallerReceive0
{
public:
  void Notify( void *_Data );

};
class PinCallerReceive1
{
public:
  void Notify( void *_Data );

};
class PinCallerReceive2
{
public:
  void Notify( void *_Data );

};
class PinCallerReceive3
{
public:
  void Notify( void *_Data );

};
class PinCallerReceive4
{
public:
  void Notify( void *_Data );

};
class PinCallerReceive5
{
public:
  void Notify( void *_Data );

};
class PinCallerReceive6
{
public:
  void Notify( void *_Data );

};
} // PinCalls

// Call Chains

namespace CallChains
{
class Render1
{
public:
  static void ChainCall();

};
} // CallChains

// Arduino Board Declarations

namespace BoardDeclarations
{
Mitov::ArduinoDigitalOutputChannel<
  Mitov::ConstantProperty<22, bool, false>, // IsAnalog
  Mitov::ConstantProperty<24, bool, false>, // IsCombinedInOut
  Mitov::ConstantProperty<21, bool, false>, // IsOpenDrain
  Mitov::ConstantProperty<26, bool, false>, // IsOutput
  Mitov::ConstantProperty<20, bool, false>, // IsPullDown
  Mitov::ConstantProperty<2, bool, false >, // IsPullUp
  Mitov::ConstantProperty<23, bool, false>, // IsRawInput
  Mitov::DigitalPin_EmbeddedPinImplementation<1, ::PinCalls::PinCallerReceive0 >, // OutputPin
  8 // PIN
  > ArduinoDigitalChannel_8;

} // BoardDeclarations

// Declarations

namespace Declarations
{
Mitov::RTC_DS1307<
  TwoWire, // 0_TYPE_PIN
  Wire, // 1_NAME_PIN
  Mitov::ConstantProperty<3, uint8_t, 104 >, // Address
  Mitov::ConstantProperty<4, Mitov::TArduinoRTCDS1307ClockFrequency, Mitov::rtc1307fDisabledLow >, // ClockFrequency
  Mitov::ConstantProperty<9, bool, true >, // Enabled
  Mitov::ConstantProperty<5, bool, false >, // Halt
  Mitov::TypedPin_EmbeddedPinImplementation_ChangeOnly<7, ::PinCalls::PinCallerReceive1, Mitov::TDateTime > // OutputPin
   > _o_RealTimeClock1;

Mitov::DisplaySSD1306<
  Mitov::DisplaySSD1306Buffered<Mitov::DisplaySSD1306_Up<Mitov::Display_odtSSD1306_I2C<
  TwoWire, // 0_TYPE_PIN
  Wire, // 1_NAME_PIN
  Mitov::ConstantProperty<3, uint8_t, 60 >, // Address
  Mitov::ConstantProperty<16, Mitov::TArduinoMonochromeColor, Mitov::tmcBlack >, // BackgroundColor
  Mitov::ConstantPropertyFloat<12, float, ::VisuinoConstants::FloatValue0 >, // Contrast
  Mitov::EmbeddedCallChain<CallChains::Render1 >, // Elements_Render
  Mitov::FixedSizeFont<Mitov::GraphicsFont5x7, 6, 8>, // Font
  64, // Height
  Mitov::ConstantProperty<24, bool, true >, // PowerOn
  Mitov::NestedProperty<15, Mitov::TArduinoDisplaySSD1306PreChargePeriod<
    Mitov::ConstantProperty<14, uint32_t, 1 >, // Phase1
    Mitov::ConstantProperty<15, uint32_t, 15 > // Phase2
     > >, // PreChargePeriod
  Mitov::DisplaySSD1306NoReset<Mitov::DigitalPin_NoImplementation<5 > >, // ResetOutputPin
  Mitov::NestedProperty<23, Mitov::TGraphicsTextSettings<
    Mitov::ConstantProperty<22, Mitov::TArduinoMonochromeColor, Mitov::tmcNone >, // BackgroundColor
    Mitov::ConstantProperty<21, Mitov::TArduinoMonochromeColor, Mitov::tmcWhite >, // Color
    Mitov::ConstantProperty<18, uint32_t, 1 >, // Size
    Mitov::ConstantProperty<20, bool, false >, // UseCodePage437Symbols
    Mitov::ConstantProperty<19, bool, true > // Wrap
     > >, // Text
  Mitov::ConstantProperty<11, bool, false >, // UseChargePump
  128 // Width
  >, 128, 64>, 128, 64>, 128, 64, // EMBEDDED
  0x12, 0x07 // PARAM
   > _o_DisplayOLED1;

Mitov::ArduinoSerialObjectInput<Mitov::DisplaySSD1306<
  Mitov::DisplaySSD1306Buffered<Mitov::DisplaySSD1306_Up<Mitov::Display_odtSSD1306_I2C<
  TwoWire, // 0_TYPE_PIN
  Wire, // 1_NAME_PIN
  Mitov::ConstantProperty<3, uint8_t, 60 >, // Address
  Mitov::ConstantProperty<16, Mitov::TArduinoMonochromeColor, Mitov::tmcBlack >, // BackgroundColor
  Mitov::ConstantPropertyFloat<12, float, ::VisuinoConstants::FloatValue0 >, // Contrast
  Mitov::EmbeddedCallChain<CallChains::Render1 >, // Elements_Render
  Mitov::FixedSizeFont<Mitov::GraphicsFont5x7, 6, 8>, // Font
  64, // Height
  Mitov::ConstantProperty<24, bool, true >, // PowerOn
  Mitov::NestedProperty<15, Mitov::TArduinoDisplaySSD1306PreChargePeriod<
    Mitov::ConstantProperty<14, uint32_t, 1 >, // Phase1
    Mitov::ConstantProperty<15, uint32_t, 15 > // Phase2
     > >, // PreChargePeriod
  Mitov::DisplaySSD1306NoReset<Mitov::DigitalPin_NoImplementation<5 > >, // ResetOutputPin
  Mitov::NestedProperty<23, Mitov::TGraphicsTextSettings<
    Mitov::ConstantProperty<22, Mitov::TArduinoMonochromeColor, Mitov::tmcNone >, // BackgroundColor
    Mitov::ConstantProperty<21, Mitov::TArduinoMonochromeColor, Mitov::tmcWhite >, // Color
    Mitov::ConstantProperty<18, uint32_t, 1 >, // Size
    Mitov::ConstantProperty<20, bool, false >, // UseCodePage437Symbols
    Mitov::ConstantProperty<19, bool, true > // Wrap
     > >, // Text
  Mitov::ConstantProperty<11, bool, false >, // UseChargePump
  128 // Width
  >, 128, 64>, 128, 64>, 128, 64, // EMBEDDED
  0x12, 0x07 // PARAM
   >, Declarations::_o_DisplayOLED1, Mitov::TDateTime> _o_DisplayOLED1_DateTime_1;

Mitov::ChangeOnlyDigital<
  Mitov::ConstantProperty<2, bool, true >, // Enabled
  Mitov::TypedVariable<1, bool, ::ComponentVariables::Variable3 >, // FData
  Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable2 >, // FStarted
  Mitov::DigitalPin_EmbeddedPinImplementation_ChangeOnly<3, ::PinCalls::PinCallerReceive2, Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable1 > > // OutputPin
   > _o_ChangeOnly1;

Mitov::DetectEdge<
  Mitov::ConstantProperty<3, bool, true >, // Enabled
  Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable4 >, // FLastValue
  Mitov::ClockPin_EmbeddedPinImplementation<1, ::PinCalls::PinCallerReceive3 >, // OutputPin
  Mitov::ConstantProperty<4, bool, true > // Rising
   > _o_DetectEdge1;

Mitov::ClockSwitch<
  Mitov::TypedVariableValue<4, bool, ::ComponentVariables::Variable5, false >, // InitialEnabled
  Mitov::ClockPin_EmbeddedPinImplementation<1, ::PinCalls::PinCallerReceive4 > // OutputPin
   > _o_ClockSwitch1;

Mitov::Timer<
  Mitov::ConstantProperty<3, bool, false >, // AutoRepeat
  Mitov::ConstantProperty<4, bool, true >, // CanRestart
  Mitov::ConstantProperty<1, bool, true >, // Enabled
  Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable7 >, // FValue
  Mitov::ConstantProperty<2, uint32_t, 10000000 >, // Interval
  Mitov::DigitalPin_EmbeddedPinImplementation_ChangeOnly<7, ::PinCalls::PinCallerReceive5, Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable6 > > // OutputPin
   > _o_Timer1;

Mitov::BooleanInverter<
  Mitov::ConstantProperty<2, bool, true >, // Enabled
  Mitov::DigitalPin_EmbeddedPinImplementation_ChangeOnly<3, ::PinCalls::PinCallerReceive6, Mitov::TypedVariable<0, bool, ::ComponentVariables::Variable8 > > // OutputPin
   > _o_Inverter1;

} // Declarations

// Call Chains

namespace CallChains
{
void Render1::ChainCall()
{
}

} // CallChains

// Pin Call Implementations

namespace PinCalls
{
void PinCallerReceive0::Notify( void *_Data )
{
  Declarations::_o_ChangeOnly1.InputPin_o_Receive( _Data );
}

void PinCallerReceive1::Notify( void *_Data )
{
  Declarations::_o_DisplayOLED1_DateTime_1.InputPin_o_Receive( _Data );
}

void PinCallerReceive2::Notify( void *_Data )
{
  Declarations::_o_DetectEdge1.InputPin_o_Receive( _Data );
}

void PinCallerReceive3::Notify( void *_Data )
{
  Declarations::_o_ClockSwitch1.InputPin_o_Receive( _Data );
}

void PinCallerReceive4::Notify( void *_Data )
{
  Declarations::_o_Timer1.StartInputPin_o_Receive( _Data );
  Declarations::_o_RealTimeClock1.ClockInputPin_o_Receive( _Data );
}

void PinCallerReceive5::Notify( void *_Data )
{
  Declarations::_o_Inverter1.InputPin_o_Receive( _Data );
}

void PinCallerReceive6::Notify( void *_Data )
{
  Declarations::_o_ClockSwitch1.EnableInputPin_o_Receive( _Data );
}

} // PinCalls

namespace ComponentsHardware
{
void SystemUpdateHardware()
{
}
} // ComponentsHardware

//The setup function is called once at startup of the sketch
void setup()
{
  Wire.begin();

  BoardDeclarations::ArduinoDigitalChannel_8.SystemInit();
  Declarations::_o_RealTimeClock1.SystemInit();
  Declarations::_o_DisplayOLED1.SystemInit();

  BoardDeclarations::ArduinoDigitalChannel_8.SystemStart();
  Declarations::_o_DisplayOLED1.SystemStart();
  Declarations::_o_Timer1.SystemStart();

  OpenWire::SystemStarted();
}

// The loop function is called in an endless loop
void loop()
{
  BoardDeclarations::ArduinoDigitalChannel_8.SystemLoopBegin();
  Declarations::_o_Timer1.SystemLoopBegin();
  Declarations::_o_DisplayOLED1.SystemLoopEnd();
}

Credits

ronfrtek

ronfrtek

13 projects • 4 followers
Arduino Fan!

Comments

Add projectSign up / Login