Go Down

Topic: Car counter using IR sensor and Data Logger Module Logging Shield Data Recorder  (Read 265 times) previous topic - next topic

martinkulik

Hello, I am new to this but I want to build Counter to count cars on the street from both directions using the IR Infrared Obstacle Avoidance Sensor Module with Arduino uno R3 and
Data Logger Module Logging Shield Data Recorder Shield to write the count per day to SD card. I can also have the I/O module to display numbers. Please help!

Thank you.
Martin

jremington

First, make sure that the IR module can reliably detect cars, going in both directions at the location of interest. Sunlight, or sometimes just changing light conditions will be a real problem.

Then, learn how to use the data logger module, starting with the example code.

When all that works perfectly, putting the two together should be easy. But the final problems will be to deal with powering the equipment at location and protection from weather, vandalism and theft.

martinkulik

Thank you.
I was able to do some research and found a Sharp IR sensor which can go upto 550cm which is about 18 feet.
and use the code and everything works ok but to get the data logger add it to it is a challenge for me.


"
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
//#include <TinyWireM.h> // Enable this line if using Adafruit Trinket, Gemma, etc.

#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix = Adafruit_7segment(); //end Adafruit requirements

const int sensorPin = 0; //analog pin 0
const int ledPin = 13;  // the pin that the LED is attached to

// vars
int sensorCounter = 0;   // counter for the number of button presses
int sensorState = 0;     // current state of the sensor

void setup() {
  // initialize the sensor pin and input
  pinMode(sensorPin, INPUT);
  // initialize the LED as an output
  pinMode(ledPin, OUTPUT);
  // initialize serial communication
  Serial.begin(9600);
 
// set the matrix
    matrix.begin(0x70);
  }


void loop() {
  // read the sensor input pin:
  sensorState = analogRead(sensorPin);

  // if sensor is closer than than x distance
  if (sensorState > 600 ) {
   
    sensorCounter++;
    Serial.println(sensorState);
    Serial.print("number of counts:  ");
    Serial.println(sensorCounter);
   
    // show output on the digital display
    matrix.print(sensorCounter);
    matrix.writeDisplay();
   
    // slow down the output
    delay(500);
  }

 
  // turns on the LED every ten counts
  if (sensorCounter % 10 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }

}
 
"


jremington

Please use code tags to post code, as described in the How to use this forum post.

Quote
everything works ok
Does the code reliably detect cars going both directions on a sunny day?

martinkulik

I am not sure if does. I tested only indoor and since its wrong season it will be hard to really tested. I will see how it goes. I do need to tested only for about month anyway and then calculate traffic volume. he is the code but I need someone to help to add the data logger programming code to it.
"#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
//#include <TinyWireM.h> // Enable this line if using Adafruit Trinket, Gemma, etc.

#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix = Adafruit_7segment(); //end Adafruit requirements

const int sensorPin = 0; //analog pin 0
const int ledPin = 13;  // the pin that the LED is attached to

// vars
int sensorCounter = 0;   // counter for the number of button presses
int sensorState = 0;     // current state of the sensor

void setup() {
  // initialize the sensor pin and input
  pinMode(sensorPin, INPUT);
  // initialize the LED as an output
  pinMode(ledPin, OUTPUT);
  // initialize serial communication
  Serial.begin(9600);
 
// set the matrix
    matrix.begin(0x70);
  }


void loop() {
  // read the sensor input pin:
  sensorState = analogRead(sensorPin);

  // if sensor is closer than than x distance
  if (sensorState > 460 ) {
   
    sensorCounter++;
    Serial.println(sensorState);
    Serial.print("number of counts:  ");
    Serial.println(sensorCounter);
   
    // show output on the digital display
    matrix.print(sensorCounter);
    matrix.writeDisplay();
   
    // slow down the output
    delay(500);
  }

 
  // turns on the LED every ten counts
  if (sensorCounter % 10 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }

}
  "

jremington

Please edit both your posts to add code tags.

No point in adding the data logger until the code works to count cars, reliably.


martinkulik

Thank you. I will test it and let you know. I might change it to a different sensor if this one is not going to be reliable. It might work if it has a shield to blog the sun rays. It will also depends on the direction and position of the sensor. Either way I will post my results here. Thank you again.
Martin

martinkulik

Thank you. I will test it and let you know. I might change it to a different sensor if this one is not going to be reliable. It might work if it has a shield to blog the sun rays. It will also depends on the direction and position of the sensor. Either way I will post my results here. I know vandalism and other factors might be a problem also cars and other vehicles going over the shoulder might hit the sensor. Putting the sensor on top of the fence or tree might be too far. Thank you again.
Martin

Go Up