Liamlambchop
Member level 2
Hey guys,
I am making a break beam people counter which uses an infrared beam and an infrared sensor. When a person walks through the beam a count is recorded and is then sent with a GSM modem to a web server.
The infrared LED, which makes my beam, pulses at 38kHz and my infrared sensor, known as an IR receiver module, only responds to 38kHz infrared. This stops ambient light from interfering with the system.
I am using an arduino to do the following:
1. make the LED pulse at 38kHz for 6 cycles (ie HIGH to LOW 6 times) then pause for 60 microseconds
2. power the IR receiver module
3. receive an input from that IR receiver
4. output a short (0.1s maybe) HIGH/LOW to the GSM modem's data logger.
I need help with the code to do this.
The code I have written so far consists of modified example sketches. I have gotten as far as making, what I think (I haven't been able to test it) is, a sketch which will: make the LED pulse CONSTANTLY (remember I need it to pause for 60 microseconds) at 38kHz, power the IR receiver, and receive an input for that IR receiver. The rest of the things I need to do (getting the LED to pause, outputing a short HIGH/LOW) I need help with.
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?
How do I get the LED to pause for 60 microseconds without delaying the entire loop?
Here is my sketch thus far:
Thanks heaps to anyone who can help )))
I am making a break beam people counter which uses an infrared beam and an infrared sensor. When a person walks through the beam a count is recorded and is then sent with a GSM modem to a web server.
The infrared LED, which makes my beam, pulses at 38kHz and my infrared sensor, known as an IR receiver module, only responds to 38kHz infrared. This stops ambient light from interfering with the system.
I am using an arduino to do the following:
1. make the LED pulse at 38kHz for 6 cycles (ie HIGH to LOW 6 times) then pause for 60 microseconds
2. power the IR receiver module
3. receive an input from that IR receiver
4. output a short (0.1s maybe) HIGH/LOW to the GSM modem's data logger.
I need help with the code to do this.
The code I have written so far consists of modified example sketches. I have gotten as far as making, what I think (I haven't been able to test it) is, a sketch which will: make the LED pulse CONSTANTLY (remember I need it to pause for 60 microseconds) at 38kHz, power the IR receiver, and receive an input for that IR receiver. The rest of the things I need to do (getting the LED to pause, outputing a short HIGH/LOW) I need help with.
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?
How do I get the LED to pause for 60 microseconds without delaying the entire loop?
Here is my sketch thus far:
Code:
/*
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); }
}
}
Thanks heaps to anyone who can help )))
Last edited by a moderator: