Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:40 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Playing with ATTINY85 using Arduino IDE

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 571
Posted: 04:32am 22 Nov 2023
Copy link to clipboard 
Print this post

I though this would be very easy to do. My first time using Arduino IDE and ATTINY85

Wasn't sure if I had an ADC or map problem.
Four breadboards with different test. No print or serial output was PITA debugging.
 
The problem was at the higher 40 to 50 sec it never timed out.
Here is the working raw code.


/*
 16 Nov 2023
 Quazee137
 
 Using ATTINY85 as an over flow control with alert.
 
 Read float switch if high
 blink heartbeat
 else
 Reads OnTime analog input pin (10Kohm pot) maps the result to range
 from 10000 to 60000 i.e 10 to 60 seconds used to set the pump on time.
 turn on pump
 delay(OnTime)
 turn off pump
 if float is still low turn on alert

 rinse and repeat LOL

 The circuit: (n) chip pin
 - Vcc           pin(8)
 - GND           pin(4)
 - Reset         pin(1)  10K to Vcc
 - HeartBeat_LED pin 0(5) to Led to 220 ohm to gnd
 - AlertTone     pin 1(6) to buzzer to gnd
 - Float_Sw      pin 3(2) to 10K Pullup to switch to gnd
 - Pump_Relay    pin 4(3) to 1K to transistor base
                         collector to relay to +5 (diode)
                         emitter to gnd
 - TSet          pin A1(7) to center of the potentiometer
                         sides go to +5V and ground  
*/

const int TSetPin = A1;     // Analog input pin that the potentiometer is attached to
const int HeartBeatPin = 0; // output pin that the LED is attached to
const int FSwPin = 3;       // the number of the FloatSW input pin
const int PumpRyPin = 4;    // relay  pin
const int AlertPin = 1;     // Tone out pin

int PumpOn = 0;             // value read from the pot
int Ptime = 0;              // pump time on
int FSW = 1;                // Float Switch flag
int HBC = 0;                // HeartBeat counter
int HBF = 0;                // HeartBeat Flag

void setup() {
 
  pinMode(HeartBeatPin, OUTPUT); //HeartBeat Led
  pinMode(PumpRyPin, OUTPUT);    //Relay
  pinMode(FSwPin, INPUT);        //Float Sw
  pinMode(AlertPin, OUTPUT);     //Alert Tone
 // analogReference(DEFAULT);    //ADC ref Vcc unsure if needed or works
}

void loop() {

   // blink HeartBeat
   HBC = ++HBC;
   if (HBC >= 20000) {
     HBF = not(HBF);
     digitalWrite(HeartBeatPin, HBF);
     HBC = 0;
   }
   
   digitalWrite(PumpRyPin, LOW);  // start with pump off
   
  // check Float switch if high we are ok, low start pump.
  FSW = digitalRead(FSwPin);

  if (FSW == LOW) {
     FSW = HIGH; // clear flag
     
     // get time from pot and turn on pump
     PumpOn = analogRead(TSetPin);
     
     // map it to the range of the 10 to 60 seconds:
     Ptime = map(PumpOn, 0, 1023, 9000, 25000); // apx 15 to 50 sec's

/*   used this when I though map was the problem
 if (PumpOn < 255)   Ptime = 9000;                   // 0.00 to 1.25
 if (PumpOn > 256 and PumpOn  < 511) Ptime = 12000;  // 1.25 to 2.50
 if (PumpOn > 512 and PumpOn  < 767) Ptime = 18000;  // 2.50 to 3.75
 if (PumpOn > 768 and PumpOn  < 1024) Ptime = 25000; // 3.75 to 5.00
*/

// turns out the size of the delay was the problem
//  do to int/long int compiler stuff.

     digitalWrite(PumpRyPin, HIGH);    // High volume pump on
     digitalWrite(HeartBeatPin, HIGH);    // a bit of feed back
     delay(Ptime);                     // delays over 40000 was the problem
     digitalWrite(HeartBeatPin, LOW);     // showing the split delay works
     delay(Ptime);                     // so doing half the time twice.
     digitalWrite(PumpRyPin, LOW);     // High volume pump off
     
     // if Float is still on, turn on Alert. alert till float clears.
     FSW = digitalRead(FSwPin);
      if (FSW == LOW) {
        digitalWrite(AlertPin, HIGH);
        delay(500);
        digitalWrite(AlertPin, LOW);
        delay(250);
        digitalWrite(AlertPin, HIGH);
        delay(500);
        digitalWrite(AlertPin, LOW);
        delay(250);
        digitalWrite(AlertPin, HIGH);        
       }
       
  } else {
   digitalWrite(AlertPin, LOW);    // make sure these
   digitalWrite(PumpRyPin,LOW);    // are off
 }
}


having FUN learning some new hardware-software
 
 Quazee137

I'm using a nano to program the ATTINY85. can use it to put BASIC85 on it?
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024