Electric Sliding Gate based on STM32F0-Discovery

If you like it, share it

This is a simple electric Sliding Gate based on STM32F0-Discovery, this project was developed using CUBE-MX, ATOLLIC IDE and the HAL libraries.

The schematic is below.
Here there is a large image.

We used a surplus components and is for this reason that we used the relays for interface the input signals.
Also, using relays, we have saved a lot of solder joints, but of course is not cheaper if you must buy the new relays.
I suggest the schematic below for substitute the relays in input.

You should choose R5, R1 and R2 to have the right input voltage supported by your MCU input pins.
The formulas to calculate the resistors are shown below.

Vi
| R1 R2
|    ____           ____
|---|____|---------|____|----- GND
|<--- Vr1 --->|<--- Vr2 --->|
|

Vr2 = ( Vi / (R1+R2 ) ) * R2
Vr1 = ( Vi / (R1+R2 ) ) * R1

Suppose that MCU is powered at 3V and that Vi is 12V the resistor must be:
R5 == 9,7K
R1 == 330
R2 == 3,3K
Vr2 == 2,970V


The MOC component for drive TRIAC

The MOC3012 is a Random-Phase Optoisolators Triac Driver Output.


CUBE-MX pins allocation

 * Pin  Nb PINs  FUNCTIONs    LABELs
 * 14  PA0     GPIO_EXTI0  B1 [Blue PushButton]
 * 16  PA2     USART2_TX
 * 17  PA3     USART2_RX
 * 18  PF4     GPIO_Output LUCI
 * 19  PF5     GPIO_Output ESER
 * 20  PA4     GPIO_Output MA
 * 21  PA5     GPIO_Output MC
 * 22  PA6     GPIO_Output MCOM
 * 23  PA7     TIM14_CH1
 * 25  PC5     GPIO_Input  FCC
 * 26  PB0     GPIO_Input  FCA
 * 34  PB13    GPIO_Input  PP
 * 35  PB14    GPIO_Input  FOTO Safety photocell, NC (normally closed)
 * 39  PC8     GPIO_Output LD4 [Blue Led]
 * 40  PC9     GPIO_Output LD3 [Green Led]
 * 46  PA13    SYS_SWDIO   SWDIO
 * 49  PA14    SYS_SWCLK   SWCLK

Basic Functions

uint8_t MovMot(void); Function that decide the direction where to move the Gate
  Test FOTO, if it is CLOSE (OK)
  Test FCA, if it is PRESSED, return DoCLOSE
  Test FCC, if it is PRESSED, return DoOPEN
  If NO FCA & FCC are PRESSED, return NotDefineMovement
If FOTO is OPEN return DoNotMove
uint8_t TestFOTO(void); Function that check the status of the safety photocells
  If FOTO is CLOSED means OK, return OK
  Else return FAIL
 
uint8_t TestFCC(void) Function that check the status of the limit switch signaling the status of closed
  If FCC==Close, return Pressed
  Else return NotPressed
 
uint8_t TestFCA(void) Function that check the status of the limit switch signaling the status of opened
  If FCA==Close, return Pressed
  Else return NotPressed
 
uint8_t TestPP(void) Function that check the status of the PP
  If PP==Close, return Pressed
  Else return NotPressed
void StartLAMP(void); Start flashing normal
void StartLAMPfast(void); Start flashing fast
void StopLAMP(void); Stop flashing
void FastFlash(void);  
   
void MotClose(void);  
void MotOpen(void);
void AllMotorRelayOFF(void);

Define

#define NotDefineMovement 15  
#define DoNotMove 10 10 means that there is an obstacle in front of the FOTO
#define DoOpen 0  
#define DoClose 1  
#define Open 0  
#define Close 1  
#define Pressed 0  
#define NotPressed 1  
#define NotDefine 20 20 means undefine
#define DLYAR 80 Dly for debounce
#define OK 1  
#define FAIL 0

Variables

uint8_t StatusGate = NotDefine; Could be:
  NotDefineMovement
  DoOpen
  DoClose
   
uint8_t MovementToDo = DoNotMove; Could be:
  DoClose
  DoOpen
  DoNotMove
   
uint8_t LastMovement = NotDefine; Could be:
Close
Open
NotDefine

How to get the SW for this project

Please send us an email and ask us the password for: F0DiscoGate
Please specify also your country and your city, this are only for our personal statistics.

Get the SW clicking here, but remember to ask us the password for open it.

For import in Atollic this project see here.


NOTE:

  • Use FIREFOX or CHROME for a clear view of the images present in this web site
  • For enlarge the image press: CTRL +
    For reduce the image press: CTRL –