Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino Coding..

Status
Not open for further replies.

PhilipWarence

New Member
I have a problem in coding this graph in arduino. As i display the serial monitor, it logs analog values up to 730units. the value is indicated in the attached graph..
My objective is to count how many pulses(high) there have in a defined time.
Can I ask for a help. Thanks in advance..
Very much appreciated!
 

Attachments

  • Capture.PNG
    Capture.PNG
    52.2 KB · Views: 385
You just want to count them without outputting them to the serial monitor?
 
Yes Sir, The value that'll be displayed on the monitor should be the amount of pulses it have in a defined time, for example 60seconds..
 
The pulses seem to be coming from an AD input (analogRead())?
 
This shows how to time a pulse that comes from a digital input. Modifying it so the pulse comes from the AD is simple. This shows how to use the millis() function to time things. You can use it to count things just as easily.


Code:
const byte Squelch = 2;                   // Receiver Squelch is connected to pin 2

const byte Led = 13;                        // Uno's built-in LED, used to indicate for debugging

long  time=0;                                   // declare time to be long

...                                                       // Wait for Rising Edge and return Duration of the Pulse
{ while(!(digitalRead(Squelch)))    //Wait for rising Edge       
 
  time = millis();                              //store time now  
  digitalWrite(Led,true);                 //Turn On Led
  while(digitalRead(Squelch))        //Wait for falling Edge     
 
  Dur=millis()-time;                       //Compute duration of On time
 
Im having a problem in what point to set before the variable will increment because the analog reading is a series of 0's and exponentially goes up to series of around 730 and drop down to series on 0's again without a definite time when and how long the pulse is. The time each pulse last is different to each other..
 
long A = 0;
int x = 0;
long pulse;
long counter = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
delay(1000);
for(x = 0; x<=60000; x++){
A = analogRead(A0);
if(A >= 20){
pulse = pulse + A;
counter = counter + 1;
}
}
Serial.println(counter);
Serial.println(pulse);
}

void loop()
{
A = analogRead(A0);
delay(50);

Serial.print("Heart Rate = ");
Serial.println(A);
delay(1000);

}
 
You can't count a analog pin your setting it with this A = analogRead(A0) back to ADC that's going to give you a value of 1 to 1024.
What your seeing is the voltage go from 0 to around 3.5 volts to count if it goes up to 3.5 you need to do some thing like this.
If A= >720
counter = counter +1
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top