/*
Unfinished People Counter Sketch
*/
const int irLED = 13; // the number of the irLED pin
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 0.02631579; // interval at which to blink (milliseconds)
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards
pinMode(13, OUTPUT);
pinMode (12, OUTPUT); //assign pin 12 as output to power the irRec
Serial.begin(38400); //just in there so I can watch what's happening on the serial monitor
pinMode(2, INPUT); //assign pin 2 as input for the irRec
}
void loop()
{
{
int irRec = digitalRead(2); //arduino will read the value at pin 2 and assign a number (1 or 0) to it
Serial.println(irRec, DEC); //value IR rec. will be printed on serial monitor
digitalWrite(12, HIGH); } // set pin 12 on high so IR receiver has 5Vs
{
unsigned long currentMillis = millis(); //check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
//'unsigned long' is a variable which can store 32 bits, and no negative numbers
if(currentMillis - previousMillis > interval){
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set irLED with the ledState of the variable:
digitalWrite(irLED, ledState); }
}
}
Hey guys,
<snip>
It is important to realise that the input to the Arduino from the IR receiver module is going to be 1,0,1,0,1.... (going from HIGH to LOW at 38kHz) so I can't simply say in my sketch that whenever there is a 1 or a 0 the Arduino should output to the GSM modem. I need a way to say that when there is a LOW (yes a LOW not a HIGH. The ir receiver outputs a LOW) for, let's say 0.05s (or the time it takes a person to walk through a beam of IR light), then the Arduino should output HIGH/LOW. How do I do this?
<snip>
I haven't used arduino but there is no way you can't use a long variable to store a float number
long interval = 0.02631579; // interval at which to blink (milliseconds)
Alex
I'm quite a novice when it comes to programming, so could you explain what you mean?
long interval = 0.02631579; // interval at which to blink (milliseconds)
float interval = 0.02631579; // interval at which to blink (milliseconds)
double interval = 0.02631579; // interval at which to blink (milliseconds)
Basically, when I detected a high, I started a timer to detect the next high based on the expected frequency. If the next high is not detected, that indicated a beam break. The next high indicates a "make" and the process is repeated. You can detect highs, lows, or transitions. For counting people, I think 1 KHz will be more than adequate. My routine also had an error correction scheme. In your case, you might assume that a walking person will interrupt the beam for at least 30 mS, so any break of less than 30 mS may be an interference, like a fly or bird.
John
I haven't used arduino but there is no way you can't use a long variable to store a float number
long interval = 0.02631579; // interval at which to blink (milliseconds)
Alex
/*
People Counter sketch.
*/
#include <TimedAction.h>
TimedAction pulsefunction = TimedAction (0.6, pulse);
int irLED = 13; // the number of the irLED pin
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 0.02631579; // interval at which to blink (milliseconds)
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards
pinMode(13, OUTPUT);
pinMode (12, OUTPUT); //assign pin 12 as output to power the irRec
digitalWrite (12, HIGH); //give irREC power
Serial.begin(9600); //just in there so I can watch what's happening on the serial monitor
pinMode(2, INPUT); //assign pin 2 as input for the irRec
}
void loop()
{
{
pulsefunction.check(); //check pulsefunction to see if the interval is complete
int irRec = digitalRead(2); //arduino will read the value at pin 2 and assign a number (1 or 0) to it
Serial.println(irRec, DEC);} //value IR rec. will be printed on serial monitor
}
void pulse() {
digitalWrite(13, HIGH); // set the IR LED on #1
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #2
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #3
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #4
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #5
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #6
delay(0.02631579); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
}
void pulse() {
digitalWrite(13, HIGH); // set the IR LED on #1
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #2
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #3
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #4
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #5
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, HIGH); // set the IR LED on #6
delayMicroseconds(26); // wait for 1/38 of a milisecond
digitalWrite(13, LOW); // set the IR LED off
}
I suggest having more pulses per packet. A typical packet (Figure 3) has about 22 pulses (i.e, 0.6 mS).
.The receiver goes low when it detects the proper light pulses (see: Figure 1). It then goes high after a short time (also shown in Figure 1)
Finally, when I say Rx LOW, it may be easier and better to look at the transition of the input pin on the Arduino rather than its high/low state per se.
Using a delay is not the best method, however with a frequency of 38kHz you are pushing the limitations of a 16MHz clocked Arduino/AVR and the available libraries. A more viable option maybe using an Arduino Timer routine.
BigDog
Hey thanks BigDog! As you can see I have put a timed action routine in there... would you suggest something like Metro (Arduino playground - Metro) instead of using delay()?
What sort of issues will I have if I stick to my current sketch?
So does this mean the receiver goes back to HIGH before it detects the proper light again? That's a bit odd isn't it?
Source: Datasheet
Suitable Data Format
The circuit of the TSOP341.. is designed in that way that unexpected output pulses due to noise or disturbance signals are avoided. A bandpass filter, an integrator stage and an automatic gain control are used to suppress such disturbances. The distinguishing mark between data signal and disturbance signal are carrier frequency, burst length and duty cycle. The data signal should fulfill the following conditions:
• Carrier frequency should be close to center frequency
of the bandpass (e.g. 38 kHz).
• Burst length should be 6 cycles/burst or longer.
• After each burst which is between 6 cycles and 70
cycles a gap time of at least 10 cycles is necessary.
• For each burst which is longer than 1.8 ms a corresponding
gap time is necessary at some time in the
data stream. This gap time should have at least same
length as the burst.
• Up to 2200 short bursts per second can be received
continuously.
<snip>
When a disturbance signal is applied to the TSOP341.. it can still receive the data signal. However the sensitivity is reduced to that level that no
unexpected pulses will occur. Some examples for such disturbance signals which are suppressed by the TSOP341.. are:
• DC light (e.g. from tungsten bulb or sunlight)
• Continuous signal at 38 kHz or at any other frequency
• Signals from fluorescent lamps with electronic ballast
(an example of the signal modulation is in the figure
below). <snip>
/*
* Timer1 library example
* June 2008 | jesse dot tane at gmail dot com
*/
#include "TimerOne.h"
void setup()
{
pinMode(10, OUTPUT);
Timer1.initialize(500000); // initialize timer1, and set a 1/2 second period
Timer1.pwm(9, 512); // setup pwm on pin 9, 50% duty cycle
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
}
void callback()
{
digitalWrite(10, digitalRead(10) ^ 1);
}
void loop()
{
// your program here...
}
so PWM is set to 50% using Timer1.pwm(9, 512);The duty cycle is specified as a 10 bit value, so anything between 0 and 1023
#include <TimerOne.h>
void setup() {
pinMode(9, OUTPUT);
Timer1.initialize();
Timer1.attachInterrupt(pwm, 5000000);
}
void loop(){
digitalWrite(13,HIGH);
}
void pwm(){
digitalWrite(9, HIGH);
delay(250);
digitalWrite(9,LOW);
delay(250);
digitalWrite(9, HIGH);
delay(250);
digitalWrite(9,LOW);
delay(250);digitalWrite(9, HIGH);
delay(250);
digitalWrite(9,LOW);
delay(250);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?