Go Down

Topic: Attiny2313 analog comparator (Read 39 times) previous topic - next topic

TruePatrick

Hello,
I have Accidentally bought 2313A-PU, without first checking If it has analog pins. This is my second chip that I want to program. It does however have an analog comparator, which I think it is just what I need for my project. Correct me If I'm wrong.
I'm doing EMF detector. Very similiar to this project but with more leds.

I'm curious If this chip can be used to read signal from the probe.

Thank you in advance!

Here's the code that I have:
Code: [Select]

#define NUMREADINGS 15 // Number of readings
int senseLimit = 15; // Raise this num to decrease sensitivity
int val = 0;
int antenna = 9; THE PROBE that will read the signal
int LED[] = {0,1,2,3,4,5,6}; // After verify the position of red green and yellow leds // Variables for smoothing
int readings[NUMREADINGS];
int index = 0;
int total = 0;
int averange = 0;
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, INPUT);
// Test leds on start
for (int i=0; i<7; i++) {
digitalWrite(LED[i],HIGH);
delay(500);
}
for (int i=0; i<7; i++) {
digitalWrite(LED[i],LOW);
}
// Initialize all the readings
for (int i = 0; i < NUMREADINGS; i++) {
readings[i] = 0;
}
}
void loop() {
int val = analogRead(antenna);
if(val >= 1){
val = constrain(val, 1, senseLimit); // turn any readings higher than the senseLimit into the senseLmit
val = map(val, 1, senseLimit, 1, 1023); // remap the values
total -= readings[index]; // subtract the last reading
readings[index] = val;    // read from the sensor
total+= readings[index];  // add the reading to the total
index = (index + 1);      // advance to the next index
if (index >= NUMREADINGS)       index = 0;
averange = total / NUMREADINGS;

if (averange > 50) {
digitalWrite(0,HIGH);     }
else {
digitalWrite(0,LOW);     }

if (averange > 100) {
digitalWrite(1,HIGH);     }
else {
digitalWrite(1,LOW);     }

if (averange > 200) {
digitalWrite(2,HIGH);     }
else {
digitalWrite(2,LOW);     }

if (averange > 350) {
digitalWrite(3,HIGH);     }
else {
digitalWrite(3,LOW);     }

if (averange > 550) {
digitalWrite(4,HIGH);     }
else {
digitalWrite(4,LOW);     }

if (averange > 750) {
digitalWrite(5,HIGH);     }
else {
digitalWrite(5,LOW);     }

if (averange > 950) {
digitalWrite(6,HIGH);     }
else {
  digitalWrite(6,LOW);}
     }
}

Delta_G

1.  Format your code so it's indented right.  We don't do that just to make it pretty.  It also helps to read it and see the flow. 

2.  The analog comparitor is only good for comparing two analog signals.  It will tell you when one goes higher than the other or something.  But it won't take analog readings.  A good rule of thumb is to read the specs FIRST and plunk down the money SECOND.  Doing it the other way round just ends up emptying your bank account faster. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

TruePatrick

#2
Aug 25, 2019, 10:28 pm Last Edit: Aug 25, 2019, 10:31 pm by TruePatrick
I guess you're right Sir. I guess, I learned from my mistakes. Just wanted to make sure that this chip won't be useful for my project. Thank you. I'm gonna buy ATTiny24A-PU.

Go Up