Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #30 on: May 03, 2010, 03:03:32 am » |
here is a "peak detector": http://www.falstad.com/circuit/e-555monostable.html(it works better than my RC-plan) :-) but u need the negative part of ur AC signal... so u dont need any rectification, because of the horizontal capacitor... for a 3.2kHz signal the horizontal capacitor should be 100nF and the vertical cap should be 150nF... -arne
|
|
|
|
« Last Edit: May 03, 2010, 04:08:53 pm by RIDDICK »
|
Logged
|
-Arne
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 185
Arduino rocks
|
 |
« Reply #31 on: May 03, 2010, 08:44:22 am » |
You also need to ensure the voltage on the Arduino input pin does not exceed 5 volts. There are many ways to do that, for example using a transistor (Grumpy_Mike explained this your “DC to the Arduino” thread) or you could use an opto-isolater. oh that's great, i am going to try this let see what we can see here is a "peak detector": http://www.falstad.com/circuit/e-555monostable.html(it works better than my RC-plan) but u need the negative part of uc AC signal... so u dont need any rectification, because of the horizontal capacitor... for a 3.2kHz signal the horizontal capacitor should be 100nF and the vertical cap should be 150nF... -arne Thanks for your advise, but i don't know about 555 timer, it is kind of difficult i will try it anyway, thanks let see what it can show me 
|
|
|
|
|
Logged
|
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #32 on: May 03, 2010, 04:28:20 pm » |
u could try this, too: http://arduino.cc/en/Reference/AttachInterruptthe short peak should trigger the interrupt safely... then u just measure the time between the interrupt calls... but looking for a peak should be good, too: const uint8_t pin = 5; // digital pin #5 void setup() { Serial.begin(115200); pinMode(pin,INPUT); digitalWrite(pin,HIGH); // pullup } void loop() { uint32_t sts = micros(); // start time stamp const uint32_t c = 1000; // wait for 1000 pulses for (uint32_t i=c; i>0; i--) pulseIn(pin,HIGH); uint32_t ets = micros(); // end time stamp Serial.println(c*1e-3/(ets-sts)); // output kHz } this circuit should be good in order to protect ur arduino: AC signal ---- diode anode diode cathode ---- 100k resistor lead A 100k resistor lead B ----- NPN transistor base NPN transistor emitter ---- arduino ground NPN transistor collector ----- resistor 1k lead A resistor 1k lead B ------ arduino pin #5 dont forget this: external circuit signal ground ----- arduino ground (but make sure that this doesnt cause a short circuit (e. g. when the external circuit uses USB 5V as ground and USB ground as -5V power supply)... :-) -arne
|
|
|
|
« Last Edit: May 03, 2010, 04:29:22 pm by RIDDICK »
|
Logged
|
-Arne
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #33 on: May 05, 2010, 02:04:29 pm » |
oh this Serial.println(c*1e-3/(ets-sts)); should be this (because ets-sts r _u_secs) Serial.println(c*1e3/(ets-sts)); :-) -arne
|
|
|
|
|
Logged
|
-Arne
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 185
Arduino rocks
|
 |
« Reply #34 on: May 10, 2010, 03:01:53 am » |
HELP!!  this code below still could not show the frequency. it keeps showing a number, god knows where it comes from. the number is around 45.19 whether there is sensor connecting to the analog or not int analogPin = 1; //sensor input is analog pin 1 int val = 0 ; long timeStart, timeStop; #include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { pinMode(analogPin, INPUT); lcd.begin(16, 2); Serial.begin(9600); }
void loop() { val = analogRead(1); { if (pulseIn(val, HIGH)); { // wait until pin goes high timeStart = micros(); // wait until input goes low again while (pulseIn(val, LOW) ); { // take the actual time in microseconds timeStop = micros(); // the timedifference is the the time between two rising // edges of the input pin (= 1 period) int timeStart1 = timeStop-timeStart; // normally the result is > 0, otherwise the // function micros() had an overflow (every 70 min) // the discard this measuring (or correct the value) if (timeStart1 > 0) { // calculate frequency // 1000000 microseconds/second, f = 1/t double f = 1000000.0/timeStart1; // report the measured frequency lcd.println(f); delay(1000); lcd.clear(); } } } } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #35 on: May 10, 2010, 03:15:24 am » |
void loop() { val = analogRead(1); [glow]{[/glow]
What's this curly brace for? if (pulseIn(val, HIGH))[glow]; {[/glow] Are you sure you want that semicolon there? // wait until pin goes high timeStart = micros(); // wait until input goes low again while (pulseIn(val, LOW) )[glow];[/glow] {
What about this one? The pulseIn function returns a value. The value is how long it took the pulse to go HIGH or LOW. You will get misleading results if you do not use that time.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 185
Arduino rocks
|
 |
« Reply #36 on: May 10, 2010, 03:29:26 am » |
Thanks Paul i have cancelled all the ";" however, it still keeps showing me a number it is much larger, around 30-900 what did i do wrong  ?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #37 on: May 10, 2010, 03:33:08 am » |
i have cancelled all the ";" Well, that probably wasn't the greatest idea. Post your current code.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 185
Arduino rocks
|
 |
« Reply #38 on: May 10, 2010, 03:34:33 am » |
here it is thanks int analogPin = 1; //sensor input is analog pin 1 int val = 0 ; long timeStart, timeStop; #include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { pinMode(analogPin, INPUT); lcd.begin(16, 2); Serial.begin(9600); }
void loop() { val = analogRead(1); if (pulseIn(val, HIGH)){ // wait until pin goes high timeStart = micros(); // wait until input goes low again while (pulseIn(val, LOW) ) { // take the actual time in microseconds timeStop = micros(); // the timedifference is the the time between two rising // edges of the input pin (= 1 period) int timeStart1 = timeStop-timeStart; // normally the result is > 0, otherwise the // function micros() had an overflow (every 70 min) // the discard this measuring (or correct the value) if (timeStart1 > 0) { // calculate frequency // 1000000 microseconds/second, f = 1/t double f = 1000000.0/timeStart1; // report the measured frequency lcd.println(f); delay(1000); lcd.clear(); } } } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #39 on: May 10, 2010, 03:36:34 am » |
Please read this: http://arduino.cc/en/Reference/PulseInThe first argument to pulseIn is the pin to measure, not some value read from that pin.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 185
Arduino rocks
|
 |
« Reply #40 on: May 10, 2010, 03:40:10 am » |
The first argument to pulseIn is the pin to measure, not some value read from that pin. umm so i am just giving a pulse to the pin, not reading it? how can i read pulse  ?
|
|
|
|
« Last Edit: May 10, 2010, 03:40:25 am by max88poon »
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #41 on: May 10, 2010, 04:16:15 am » |
Where is the pulse coming into the Arduino? To some pin, presumably. Pass that pin number to pulseIn.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 185
Arduino rocks
|
 |
« Reply #42 on: May 10, 2010, 06:40:41 am » |
Where is the pulse coming into the Arduino? To some pin, presumably. Pass that pin number to pulseIn i think that is digital 8 or 9 when i took out the digital 8 and 9, the screen show me nothing but how to pass the pin ? there should be no pulse in the first place, due to the fact that i didn't connect the sensor output to the arduino however, it keeps showing a number , i don't know what the pulse is i am sorry about that Paul, that i was off, it's because i gotta be out of the school, i am home now, and thanks, please keep talking to me  could some one guide me to do the program? i very appreciate it, it is my final project, i may not get a pass if i couldn't do it 
|
|
|
|
« Last Edit: May 10, 2010, 06:43:36 am by max88poon »
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 185
Arduino rocks
|
 |
« Reply #43 on: May 10, 2010, 06:58:27 am » |
ah hey guys, i found something there is nothing shown, if the arduino analog 0 is connected to the LCD analog 0 if i took out the analog input, the number is coming out again. someone know what is happening  ? could anyone help me checked the program, is it correct that the frequency can be determinated from the analog pin 1 ? and the pin 1 is connected to the sensor. Thanks everyone 
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #44 on: May 10, 2010, 07:05:44 am » |
if the arduino analog 0 is connected to the LCD analog 0
What sort of LCD are you using that has an analogue input? the frequency can be determinated from the analog pin 1 ? Analogue pin 1 (what's wrong with analogue pin zero?) can be used with "pulseIn", but you have to number it as a digital pin in your sketch. It's digital pin 15.
|
|
|
|
« Last Edit: May 10, 2010, 07:07:07 am by GrooveFlotilla »
|
Logged
|
Per Arduino ad Astra
|
|
|
|
|