a timer that goes logic high or low every 15mins ( using tiny85 chip)

Thread Starter

timtim1234

Joined Nov 30, 2023
246
That is what a pot would do. Pins cannot read resistance directly, though there are ways to do it. The pot outputs a voltage to the pin, and a pin can read a voltage (some pins, look at the datasheet to know which ones.)

A pot would preserve the setting across reboots without the complexity of storing it in bob-volatile memory.

If you want to change it infrequently, the pot could be a trimpot.

yes that is what i thought a pot would't need eeprom to store setting
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
Also those of you out there that is reading this thread and following along ( new people to programming like me) i have been reading, and this code is what you need it's call the bare minimum code. Also, the // lets you put comments next to the code so you can write notes on explaining what that line of code does.

void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run repeatedly:
}

as it states setup() is a run once so code that variables, pin state (in or out),etc
 

Jerry-Hat-Trick

Joined Aug 31, 2022
826
I've tried to explain before, but probably not very clearly enough. A potentiometer would give you the easiest way to select a number of minutes - let's say 1 to 16. The pot would be connected to the positive rail and the ground with the wiper into an A/D pin. The measured value would 10 bits resolution so between 0 and 1023. If you divide this value by 64 you would just have an integer value from 0 to 15 as it's integer arithmetic with no decimal points. Add 1 to have a timer from 1 minute to 16 minutes.

If you make it a single turn trimpot you can have a pointer which points to numbers written around the circle but with a multi turn trimpot you won't be able to see where it is. Personally, I'd use a pot with a knob with a pointer on it so it's easier to see where it's pointing. The exact angle of the pot is not critical because for a 270 degree pot you have a range of more than 15 degrees per selection. You can divide by 64 more elegantly with a bitwise shift left instruction, like a = b << 6;
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
I've tried to explain before, but probably not very clearly enough. A potentiometer would give you the easiest way to select a number of minutes - let's say 1 to 16. The pot would be connected to the positive rail and the ground with the wiper into an A/D pin. The measured value would 10 bits resolution so between 0 and 1023. If you divide this value by 64 you would just have an integer value from 0 to 15 as it's integer arithmetic with no decimal points. Add 1 to have a timer from 1 minute to 16 minutes.

If you make it a single turn trimpot you can have a pointer which points to numbers written around the circle but with a multi turn trimpot you won't be able to see where it is. Personally, I'd use a pot with a knob with a pointer on it so it's easier to see where it's pointing. The exact angle of the pot is not critical because for a 270 degree pot you have a range of more than 15 degrees per selection. You can divide by 64 more elegantly with a bitwise shift left instruction, like a = b << 6;
I think i see what you are trying to say and that is make one of the pins be A/D? or you mean another circuit for that?
 

Jerry-Hat-Trick

Joined Aug 31, 2022
826
I think i see what you are trying to say and that is make one of the pins be A/D? or you mean another circuit for that?
Yes, take a look at the datasheet. I think pins 1, 2, 3 and 7 can be used for 10 bit resolution analogue to digital conversion. The potentiometer is the only other component you need
Having said that, depending on how you plan to power the processor, you’ll probably need a voltage regulator. It’s why the Digispark board is so neat but you said you want to use the bare IC
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
Yes, take a look at the datasheet. I think pins 1, 2, 3 and 7 can be used for 10 bit resolution analogue to digital conversion. The potentiometer is the only other component you need
Having said that, depending on how you plan to power the processor, you’ll probably need a voltage regulator. It’s why the Digispark board is so neat but you said you want to use the bare IC

ok and yes power supply is not a problem, I have access to 12-3.3VDC volts 1 amp with a good filter cap too!!
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
I also been reading about fuses on the ttiny85. AVRdude program that fuses can be set so the tttiny85 can't be read? What fuses address are set for this to happen?
 

be80be

Joined Jul 5, 2008
2,395
Play with this code a bit


Code:
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read
//int oldval = 0;
//int newval = 0;
void setup() {
  Serial.begin(9600);           //  setup serial
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  val = map(val, 610, 900, 0, 5);

  //Serial.println(val);

switch (val) {
  case 1:
    Serial.println(val);
    digitalWrite(2, HIGH);
    delay(50);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    //digitalWrite(2,LOW);
    break;
  case 2:
    Serial.println(val);
    digitalWrite(3, HIGH);
    delay(50);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(1,LOW);
    digitalWrite(2,LOW);
    break;
    case 3:
    Serial.println(val);
    digitalWrite(4, HIGH);
    delay(50);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(1,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 4:
    Serial.println(val);
    digitalWrite(5, HIGH);
    delay(50);
   digitalWrite(6,LOW);
    digitalWrite(1,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 5:
    Serial.println(val);
    digitalWrite(6, HIGH);
    delay(50);
    digitalWrite(1,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
}
}
change the case to give var to your timer code i have it lighting five leds based on the adc reading
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
Play with this code a bit


Code:
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read
//int oldval = 0;
//int newval = 0;
void setup() {
  Serial.begin(9600);           //  setup serial
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  val = map(val, 610, 900, 0, 5);

  //Serial.println(val);

switch (val) {
  case 1:
    Serial.println(val);
    digitalWrite(2, HIGH);
    delay(50);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    //digitalWrite(2,LOW);
    break;
  case 2:
    Serial.println(val);
    digitalWrite(3, HIGH);
    delay(50);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(1,LOW);
    digitalWrite(2,LOW);
    break;
    case 3:
    Serial.println(val);
    digitalWrite(4, HIGH);
    delay(50);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(1,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 4:
    Serial.println(val);
    digitalWrite(5, HIGH);
    delay(50);
   digitalWrite(6,LOW);
    digitalWrite(1,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 5:
    Serial.println(val);
    digitalWrite(6, HIGH);
    delay(50);
    digitalWrite(1,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
}
}
change the case to give var to your timer code i have it lighting five leds based on the adc reading

ok i will give this a try this weekend won't be home intill then. but if i am reading your code right the (cathode (-) end) of the led thru a current limiting resistor ( 1k yes i can go lower for brighter) to 5v. This is because it's saying logic low.

This being the uno board it would go of course to the digital side of the board pins 1,5,4,3,2 this is because of the digitalWrite(1,LOW); command digitalWrite = means digital pins 1 = pin1 low = the state it will be "on". i see that in the "run" once code area you have to tell it what those pins are input or output. in this case output.

i also see you comment out ( meaning commands won't run) these command
//int oldval = 0;
//int newval = 0;

i am not sure why you did that yet. and you didn't need to uses any libraries so i don't see any. this is all i know so far not sure if iam right or not..lol
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
i forgot to say i am not sure what you mean " change the case to give var to your timer code " ?

var = varible correct??
 

be80be

Joined Jul 5, 2008
2,395
You would have to change the case to match what you want to happen. Right now i have it turning on a led with HIGH you could change this to what you want
make it longer time me i would want see it run for the time i set .

Code:
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read
//int oldval = 0;
//int newval = 0;
void setup() {
  Serial.begin(9600);           //  setup serial
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  val = map(val, 610, 900, 0, 5);
  long timer = 0;

  //Serial.println(val);

 switch (val) {
  case 1:
    Serial.println(val);
    digitalWrite(2, HIGH);
    timer = (10*1000);
    delay(timer);
    digitalWrite(2,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    //digitalWrite(2,LOW);
    break;
  case 2:
    Serial.println(val);
    digitalWrite(3, HIGH);
    timer = (15*1000);
    delay(timer);
    digitalWrite(3,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(1,LOW);
    digitalWrite(2,LOW);
    break;
    case 3:
    Serial.println(val);
    digitalWrite(4, HIGH);
    timer = (20*1000);
    delay(timer);
    digitalWrite(4,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(1,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 4:
    Serial.println(val);
    digitalWrite(5, HIGH);
    timer = (25*1000);
    delay(timer);
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
    digitalWrite(1,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 5:
    Serial.println(val);
    digitalWrite(6, HIGH);
    timer = (30*1000);
    delay(timer);
    digitalWrite(6,LOW);
    digitalWrite(1,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
}
}
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
You would have to change the case to match what you want to happen. Right now i have it turning on a led with HIGH you could change this to what you want
make it longer time me i would want see it run for the time i set .

Code:
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read
//int oldval = 0;
//int newval = 0;
void setup() {
  Serial.begin(9600);           //  setup serial
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  val = map(val, 610, 900, 0, 5);
  long timer = 0;

  //Serial.println(val);

switch (val) {
  case 1:
    Serial.println(val);
    digitalWrite(2, HIGH);
    timer = (10*1000);
    delay(timer);
    digitalWrite(2,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    //digitalWrite(2,LOW);
    break;
  case 2:
    Serial.println(val);
    digitalWrite(3, HIGH);
    timer = (15*1000);
    delay(timer);
    digitalWrite(3,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(1,LOW);
    digitalWrite(2,LOW);
    break;
    case 3:
    Serial.println(val);
    digitalWrite(4, HIGH);
    timer = (20*1000);
    delay(timer);
    digitalWrite(4,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(1,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 4:
    Serial.println(val);
    digitalWrite(5, HIGH);
    timer = (25*1000);
    delay(timer);
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
    digitalWrite(1,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
  case 5:
    Serial.println(val);
    digitalWrite(6, HIGH);
    timer = (30*1000);
    delay(timer);
    digitalWrite(6,LOW);
    digitalWrite(1,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
    digitalWrite(2,LOW);
    break;
}
}
ohhh ok i missed that "high" "digitalWrite(6, HIGH);"I was reading the low which means off so case 5 pin 6 high (on) for 30,000 milli secs which would equal 30 secs then it turns off pins 6,1,5,4,3,2

so with that being said it being a high i will have to change on how the led is hooked up
 

be80be

Joined Jul 5, 2008
2,395
It works really good you don't need all the digitalWrites i just used them for testing but a pot not the best idea you could mark it but it would get off as the pot wares out

I use this

button.png
 
Last edited:

Thread Starter

timtim1234

Joined Nov 30, 2023
246
It works really good you don't need all the digitalWrites i just used them for testing but a pot not the best idea you could mark it but it would get off as the pot wares out

I use this

View attachment 328798
yes a pot will wear out if its being turned all the time. the switch idea is not bad as long it a dip switch and not a tact switch this way if power goes out and comes back the tact switch would need the time reset. the above setup i would assume is a dip switch voltage divder?
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
Endless discussion of every option you might use is not the way to learn a new discipline.

Just implement what you originally proposed on the UNO. Then start thinking about options.
It may be endless to some people, but I am still learning along the way. Because some of the basics are still being taught, which would be used in the original and in options too.

But ok will get back on the topic and get back to the original :)
 

ericgibbs

Joined Jan 29, 2010
21,447
Hi tim.

I know that you have stated that you have no design specification for the project, but would you please tell use what device is being triggered by this timer and why?

E
 

Thread Starter

timtim1234

Joined Nov 30, 2023
246
Hi tim.

I know that you have stated that you have no design specification for the project, but would you please tell use what device is being triggered by this timer and why?

E

I think I said in the other post is going to trigger another circuit that has a pre-record message on it. why its like an noise maker type setup not sure why that needs to be known? Mater of fact, that seems to be Endless discussion. the important part is a logic high for one sec every 15min or adjustable :)
 
Last edited:
Top