3 volt instant on - 3-5 minutes delay off for simple model train (non energized tracks)

AlbertHall

Joined Jun 4, 2014
12,345
You don't even need a relay I bet the motor stall current is nothing maybe 400mA run probably 100mA or less
I'd use a 10F200 and be done with it.
2 resistors one diode a 2n2222 and 1 cap
Run the 10F200 off the 3 volt supply set to sleep till button pressed
Yes, probably the best solution.
 

Thread Starter

advarp

Joined Jan 12, 2018
57
Excellent, thank you!

be80be, re the PIC, what would the schematic look like? And I would need to program it I assume? Never done that, might look up what I would need. I know about programming (probably not for PIC though), but no time lately to play, just bought kits that wait for.. retirement probably...
 
Last edited:

AnalogKid

Joined Aug 1, 2013
10,987
You don't even need a relay I bet the motor stall current is nothing maybe 400mA run probably 100mA or less
I'd use a 10F200 and be done with it.
That's probably because you know what a 10F200 is and you have a development system and a compiler and a programmer and programming experience - all of that assuming that a 10F200 is a programmable device of some kind..

ak
 

Thread Starter

advarp

Joined Jan 12, 2018
57
Programming hardware seems to be around $10 from Ebay China plus a PC and some software... But some specific advice about all this (including schematic)would be great. Can anyone program the chip for me for a nominal fee :)
 

Thread Starter

advarp

Joined Jan 12, 2018
57
Woo-hoo! I'll message you :)

EDIT: I am an idiot but I can't find any messaging area. I received a message when i joined but that's it... If you can send me a message to reply to it would be great...
 
Last edited:

AlbertHall

Joined Jun 4, 2014
12,345
Hover over the right hand end of the orange bar, and then move down to inbox. That's where the conversations are. You should see start a new conversation.
 

be80be

Joined Jul 5, 2008
2,072
Here a simple code that will work with the 10f200 it's a basic chip not much there so this uses a delay to get your 3 minutes
Code:
/*
* File:   newmain.c
* Author: burt
*
* Created on January 15, 2018, 7:29 AM
*/
// CONFIG
#pragma config WDTE = OFF       // Watchdog Timer (WDT disabled)
#pragma config CP = OFF         // Code Protect (Code protection off)
#pragma config MCLRE = ON       // Master Clear Enable (GP3/MCLR pin function  is MCLR)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 4000000
#include <xc.h>
void init (){
    TRISGPIO = 0B00000001;
}
void main(void) {
    init();
    if (GP0 =1){
        int i = 0;
        do {
         GP1 = 1;  // LED ON or motor for 3 minutes
          __delay_ms(1000); // 1 Second Delay
            i++;
        }while (i<180); //sets on time
         GP1 = 0;  // LED OFF or motor
    
    }
}
Download mplabx and xc8 from here https://www.microchip.com/mplab/mplab-x-ide
The zip has the hex for the 10f200
get a pickit3 these are fine https://www.aliexpress.com/item/PICKIT3-PIC-KIT3-PICKIT-3-Programmer-Offline-Programming-Simulation-PIC-Microcontroller-Chip-Monopoly/32794808295.html?src=google&albslr=223416562&isdl=y&aff_short_key=UneMJZVf&source={ifdyn:dyn}{ifpla:pla}{ifdbm:DBM&albch=DID}&src=google&albch=shopping&acnt=708-803-3821&isdl=y&albcp=653478879&albag=34653160498&slnk=&trgt=61865531738&plac=&crea=en32794808295&netw=g&device=c&mtctp=&gclid=Cj0KCQiAv_HSBRCkARIsAGaSsrAASemEXqHQkMEeIo5siITJgGOGwF1sGf0hr94ED1FjpONmBMB59zEaApidEALw_wcB
and you should be ready to go
 

Attachments

Last edited:

AlbertHall

Joined Jun 4, 2014
12,345
I see three problems with that code.
1. There are 180 seconds in 3 minutes not 160.
2. There is a return from a void function (newmain).
3. The button will only work once. The 'if' block should be wrapped in a while(forever) or similar.

It would surely be better, to extend the battery life in the off state, to sleep the uC and have the button wake from sleep.
 

LesJones

Joined Jan 8, 2017
4,174
There is a clever method that is used on the Banggood component tester that does not use the sleep function. It uses the start stop push button to initially supply power to the micro controller. The micro controller than switches on a transistor which then provides power to the micro controller until it times out. This is a link to the manual which contains the schematic on the last page. I have copied the idea for use with a timer using an ATtiny13.
This is the schematic for my timer.
Shutdown_timer_a.png



I think it should be possible to modify it to work on 3 volts. When it is off there is only the CE leakage current of the switching transistor,

Les.
 

be80be

Joined Jul 5, 2008
2,072
while (i<160); //sets on time the poster said 3 to 5
I said set this to what you want sorry I forgot to set it back to 180 before posting
I shorting it and it does work each press not just a one shot deal
The code works the return is in the if statement it returns to main and starts again

The xc8 said you can use return for more then a value Im using to start the if statement over.

The hex will run 3 minutes and stop each press of the button

The 10f200 you have to poll the timer there no T0IF So like i said I used a delay the code would be easy to test each loop for a press but I don't think anyone would do that with a train going around a track.
 
Last edited:

be80be

Joined Jul 5, 2008
2,072
How about he tries it first and then see's what he really want's to add.
sleep not a big deal to add
 
Last edited:
Top