Overview
This is one of the tutorial for the project ‘Smart Parking Philadelphia’, which is aiming to provide real-time parking information for the drivers in Philadelphia to help them make the decision more easily for parking in Center City.
In this tutorial, the induction loop will be introduced which is responsible for counting the vehicles on a section of the street, and the output will be communicated to the display remotely through a transmitter & receiver. To know more about how the data will be presented and transmitted, please look at the tutorial written by our group member Hongyi (visualization) and Jingyi (transmission).
In addition, this tutorial only include the coding part for detecting vehicles, counting them, and printing the number of passing vehicles onto the Serial Monitor. The additional calculation and following coding parts will be in Changhao’s tutorial.
Parts List
Sensor: Grove – 2-Channel Inductive Sensor (LDC1612)
Provider: Texas Instrument (TI), Seeed Studio
Wires: Grove cable (Seeed Studio)
Arduino UNO (Amazon)
Grove Base Shield V2.0 for Arduino (Seeed Studio)
Circuit Diagram
Below is the steps and diagram showing a basic way of connecting the parts: (Source: Seeed Studio)
Step 1. Connect the Grove – 2-Channel Inductive Sensor (LDC1612) to port I^2^C of Grove-Base Shield.
Step 2. Plug Grove-Base Shield into the Arduino UNO Board.
Step 3. Connect Arduino UNO Board to PC via a USB cable.
In this project, the Seeeduino V4.2 Board (the red board underneath) will be replaced by our Arduino UNO board, and of course it will connect to the power source using the USB or directly connect to a 9V battery.
If we look at the Induction Loop Detector more closely, it is comprised of one main connection board (which is called a sensor drive, showing at left in the diagram), and two coil sensor (which is called channel circular coil, showing at right in the diagram).
In this context, we are doing a multiple channel measurement, which means that the Coil 0 and Coil 1 need to be put at the two ends of the street, therefore in theory, the sensor drive will be placed at the middle, connected to the Base Shield and the Data Transmitter, while the two channel circular coil will be placed at the two ends of the street, connected to the sensor drive respectively. The diagram below shows the basic rule of connecting the circular coil and sensor drive. (Both through wires/cables)
Code
Before running the code, the library ‘Grove-2-Channel_Inductive_Sensor-LDC1612’ need to be downloaded either online on GitHub or installed directly in Arduino IDE. If you don’t know how to download library through GitHub and add ZIP library in Arduino IDE, please follow the steps shown in this website.
Now we have installed the library, and we can get started and run the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
/* Hang Zhao 2023/04/02 Group Member: Hang Zhao, Hongyi Li, Changhao Li, Jingyi Cai Group Project: Philly Smart Parking This is a partial code for the group project, which is aming to counting the vehicles on the street, calculating the correct number of vehicles, and transmit the output to the real-time display through a remote signal/radio transmitter & receiver. The code is basically based on the example code which can be viewed online: https://github.com/Seeed-Studio/Seeed_LDC1612 Or in the Arduino Library 'Grove - 2-Channel Inductive Sensor LDC1612' by Seeed Studio. Their sensor tutorial can also be viewed on this website: https://wiki.seeedstudio.com/Grove-2_Channel_Inductive_Sensor-LDC1612/ In addition, the code from: https://files.seeedstudio.com/products/E21011104/Grove%20Inductive%20Sensor_Published%20Version(3).pdf provided some extent of inspiration for completing this code. */ // Include the library #include "Seeed_LDC1612.h" #include "math.h" LDC1612 sensor; // Define all variables and constants int vehicleCount1 =0; int vehicleCount0 =0; bool startVehicleTimer =true; bool metalCurrent1 = false; bool metalCurrent0 = false; bool metalPrevious1 = false; bool metalPrevious0 = false; long int ambientInduction =0; long int inductiveValeLowest = 43719616; long int inductiveValueMargin = 1500000; long int channel0 =0; long int channel1 =0; // Begin the setup loop void setup() { Serial.begin(115200); delay(100); Serial.println("start!"); sensor.init(); /*multiple channel use case configuration.*/ if(sensor.LDC1612_mutiple_channel_config()) { Serial.println("can't detect sensor!"); while(1); } } // Check the Channel 0 (or Coil 0) void checkChannel0(){ if ((channel0>= inductiveValeLowest + inductiveValueMargin)){ Serial.println("metal0"); if (!metalPrevious0){ vehicleCount0++; Serial.print("vehicleCount0:"); Serial.println(vehicleCount0); //currentTime0 = millis(); metalPrevious0 = true; } } else { metalPrevious0 = false; } } // Check the Channel 1 (or Coil 1) void checkChannel1() { if ((channel1>= inductiveValeLowest + inductiveValueMargin)){ Serial.println("metal1"); if (!metalPrevious1){ vehicleCount1++; Serial.print("vehicleCount1:"); Serial.println(vehicleCount1); //currentTime1 = millis(); metalPrevious1 = true; } } else { metalPrevious1 = false; } } // Run the loop to make sure the counting is continuous void loop() { u32 result_channel0=0; u32 result_channel1=0; sensor.get_channel_result(0,&result_channel0); channel0 = result_channel0; sensor.get_channel_result(1,&result_channel1); channel1 = result_channel1; checkChannel0(); checkChannel1(); delay(1000); } |
Reference
Counting Cars and Buses with a Grove Inductive Sensor.
Seeed Studio Grove – 2-Channel Inductive Sensor (LDC1612)
https://wiki.seeedstudio.com/Grove-2_Channel_Inductive_Sensor-LDC1612/