This project is an industrial-grade smart parking system that uses a Traffic LED module, Arduino Uno/Nano, and the TOF10120 time-of-flight sensor. The project uses a trimmed mat as the parking area, first measuring the length of the mat, and then defining codes for different distances, lighting (ON) and extinguishing (OFF) these LEDs one after another to help drivers park safely:
When the car is about to enter the parking area, the green LED lights up. Then, the yellow LED lights up, reminding the driver that they are approaching the target parking position, indicating that half of the car is already in the parking area.
When the red LED starts to flash, it warns the driver to slow down and pay attention. After reaching the parking point, the driver should turn off the car or continue moving until the red LED stops flashing.
As a prototype for understanding the parking system, all components used in the project are inexpensive. Readers can upgrade the circuit, such as changing the distance measurement values in the code, or even replacing sensors in the circuit to make the project more practical.
TOF10120 Time-of-Flight Sensor
The greatest advantage of the TOF10120 laser module is its long-distance measurement and ease of operation. In the program, it only needs to send a command string to the module’s serial port via the microcontroller to receive distance data back from the microcontroller. If the automatic distance measurement command string is sent, the module will automatically return data at a certain frequency, and related physical quantities can be set through the command string. The sensor only requires a serial port to function.
TOF10120 is based on Sharp’s low-cost standard CMOS process and SPAD technology, providing precise and repeatable long-distance measurements for autofocus (AF), with results unaffected by object reflection. Key features include:
・ Small ceramic package (20×13.2×2.0mm);
・ Can measure up to 1.8m indoors with an accuracy of 5%;
・ Measurement distance is not affected by ambient reflections;
・ Advanced crosstalk compensation technology;
・ 30ms high-speed measurement;
・ Powered by a single supply;
・ Txd interface for device control and data transmission;
・ Lead-free, compliant with RoHS directive.
TOF10120 typical measurement range is 100-1800mm, power supply voltage 3-5v, current consumption 35mA, compatible with Arduino, ESP8266, ESP32, etc. 5V and 3.3V control boards, suitable for indoor and outdoor environments ranging from -20°C to +70°C.
TOF10120 supports UART, I2C communication. Pins 1, 2, 3, 4, 5, and 6 are GND, VDD, RXD, TXD, SDA, and SCL respectively. In this project, only GND, VDD, SDA, and SCL are used.
According to the datasheet, the I2C address of TOF10120 is 0xA4, but addressing uses the high 7 bits, which is 0x52, equivalent to 82.
This module provides indications for the driver and comes with a current-limiting resistor, eliminating the need for an additional resistor.
The module has 4 male headers, with the GND pin connected to the controller’s GND pin or digital pin. Thus, a 5v signal will extinguish the module, and a GND or LOW signal will activate the module. Among them, R represents the red LED, Y represents the yellow LED, and G represents the green LED, which lights up at a high signal level.
First, according to the circuit diagram, the 5V power supply is provided to the Arduino Nano by the LM7805 three-terminal voltage regulator, and a 470uF decoupling aluminum electrolytic capacitor needs to be connected later.
The 5v voltage regulator connects to the VIN pin of the Arduino Nano, while the SCL and SDA pins of the TOF10120 laser distance module are connected to the A5 and A4 pins of the Arduino board, and the power lines connect to the 5V and ground pins of the Arduino board.
The ground pin of the LED module connects to pin 5 of the Arduino board, the red LED connects to pin 4 of the Arduino, the yellow LED connects to pin 3, and the green LED connects to pin 2.
Next, design the Arduino Nano PCB development board, with female headers for 3.3V, 12V, 5V, and ground. The left side serves as a Vero board for soldering other electronic components, and both sides of the Arduino Nano are designed with female headers to connect jumpers, which can also connect sensors and electronic components, such as the TOF10120 sensor and the I2C pins of the OLED display module.
Finally, connect the Traffic LED module to pins 5, 4, 3, and 2 of the Arduino board, and connect the GND, Vdd, SCL, and SDA leads of the TOF10120 sensor with male headers.
After completing the above connections, use the following code for I2C addressing:
Serial.println(“\nI2C Scanner”);
Serial.println(“Scanning…”);
for(address = 0; address <= 127; address++ )
Wire.beginTransmission(address);
error = Wire.endTransmission();
Serial.print(“I2C device found at address 0x”);
Serial.print(address, HEX);
Serial.print(“Unknown error at address 0x”);
Serial.println(address,HEX);
Serial.println(“No I2C devices found\n”);
Serial.println(“done\n”);
Serial.println(“\nI2C Scanner”);
Serial.println(“Scanning…”);
for(address = 0; address <= 127; address++ )
Wire.beginTransmission(address);
error = Wire.endTransmission();
Serial.print(“I2C device found at address 0x”);
Serial.print(address, HEX);
Serial.print(“Unknown error at address 0x”);
Serial.println(address,HEX);
Serial.println(“No I2C devices found\n”);
Serial.println(“done\n”);
Once the above code is uploaded, open the serial monitor to see the I2C address of the TOF10120 laser sensor. According to the datasheet, the I2C address of the TOF10120 module is 0xA4, and since its addressing uses the high 7 bits, it becomes 0x52, equivalent to 82.
At this point, you already know the I2C address, and you can fix the TOF10120 distance sensor module onto the board. This sensor must be fixed at an appropriate height to detect vehicles and distances. This is not difficult; you can stand a block of glue with screws at the bottom; I used a charger case for convenience, as long as the height is sufficient.
Below is the code for this project, which I wrote according to the size of the trimmed mat, which is exactly the size of the parking area.
/* Smart Car Parking system Code
* In this project the TOF10120 Laser Distance Sensor is used for measuring the distance.
// Traffic LED Module interfacing with Arduino Uno or Arduino Nano
unsigned short lenth_val = 0;
unsigned char i2c_rx_buf[16];
unsigned char dirsend_flag=0;
int x_mm; // distance in millimeters
float y_inches; // distance in inches
Serial.begin(9600,SERIAL_8N1);
pinMode(GND_PIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
digitalWrite(GND_PIN, LOW);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
// Serial.println(” mm”);
// You can convert millimeters to inches in one of two ways: divide the number of millimeters by 25.4, or multiply the number of millimeters by 0.0394
y_inches = x_mm * 0.0394;
// Serial.print(y_inches);
// Serial.println(” inches”);
if ( (y_inches > 0) && (y_inches <= 3) )
digitalWrite(RED_PIN, HIGH);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
if ( (y_inches > 3) && (y_inches <= 6) )
digitalWrite(RED_PIN, HIGH);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
if ( (y_inches > 6) && (y_inches <= 10) )
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
if ( (y_inches > 10) && (y_inches <= 20) )
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
int serial_putc( char c, struct __file * )
fdevopen( &serial_putc, 0 );
void SensorRead(unsigned char addr,unsigned char* datbuf,unsigned char cnt)
// step 1: instruct sensor to read echoes
Wire.beginTransmission(82); // transmit to device #82 (0x52), you can also find this address using the i2c_scanner code
// the address specified in the datasheet is 164 (0xa4)
// but i2c addressing uses the high 7 bits so it’s 82
Wire.write(byte(addr)); // sets distance data address (addr)
Wire.endTransmission(); // stop transmitting
// step 2: wait for readings to happen
delay(1); // datasheet suggests at least 30uS
// step 3: request reading from sensor
Wire.requestFrom(82, cnt); // request cnt bytes from slave device #82 (0x52)
// step 5: receive reading from sensor
if (cnt <= Wire.available()) { // if two bytes were received
*datbuf++ = Wire.read(); // receive high byte (overwrites previous reading)
*datbuf++ = Wire.read(); // receive low byte as lower 8 bits
SensorRead(0x00,i2c_rx_buf,2);
lenth_val|=i2c_rx_buf[1];
/* Smart Car Parking system Code
* In this project the TOF10120 Laser Distance Sensor is used for measuring the distance.
// Traffic LED Module interfacing with Arduino Uno or Arduino Nano
unsigned short lenth_val = 0;
unsigned char i2c_rx_buf[16];
unsigned char dirsend_flag=0;
int x_mm; // distance in millimeters
float y_inches; // distance in inches
Serial.begin(9600,SERIAL_8N1);
pinMode(GND_PIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
digitalWrite(GND_PIN, LOW);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
// Serial.println(” mm”);
// You can convert millimeters to inches in one of two ways: divide the number of millimeters by 25.4, or multiply the number of millimeters by 0.0394
y_inches = x_mm * 0.0394;
// Serial.print(y_inches);
// Serial.println(” inches”);
if ( (y_inches > 0) && (y_inches <= 3) )
digitalWrite(RED_PIN, HIGH);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
if ( (y_inches > 3) && (y_inches <= 6) )
digitalWrite(RED_PIN, HIGH);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
if ( (y_inches > 6) && (y_inches <= 10) )
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
if ( (y_inches > 10) && (y_inches <= 20) )
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(RED_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
int serial_putc( char c, struct __file * )
fdevopen( &serial_putc, 0 );
void SensorRead(unsigned char addr,unsigned char* datbuf,unsigned char cnt)
// step 1: instruct sensor to read echoes
Wire.beginTransmission(82); // transmit to device #82 (0x52), you can also find this address using the i2c_scanner code
// the address specified in the datasheet is 164 (0xa4)
// but i2c addressing uses the high 7 bits so it’s 82
Wire.write(byte(addr)); // sets distance data address (addr)
Wire.endTransmission(); // stop transmitting
// step 2: wait for readings to happen
delay(1); // datasheet suggests at least 30uS
// step 3: request reading from sensor
Wire.requestFrom(82, cnt); // request cnt bytes from slave device #82 (0x52)
// step 5: receive reading from sensor
if (cnt <= Wire.available()) { // if two bytes were received
*datbuf++ = Wire.read(); // receive high byte (overwrites previous reading)
*datbuf++ = Wire.read(); // receive low byte as lower 8 bits
SensorRead(0x00,i2c_rx_buf,2);
lenth_val|=i2c_rx_buf[1];
The above is the programming code, provided that the Wire.h library file has been downloaded. The distance unit in the code is in inches, and you are welcome to practice and share.
Author:Hard City Allchips, Source:Breadboard Community
Link: https://mbb.eet-china.com/blog/3975615-427316.html
Copyright Notice: This article is original by the author, and reprinting is prohibited without permission!
Follow the Breadboard Community for daily selected electronic technology knowledge
▼
-
Common lithium battery charging chips
-
Brush ESC – An engineer’s awkward day
-
Chip failure analysis five-step therapy
-
Dismantling a switch power supply, what circuits are there?
-
A hands-on guide to analyzing over-voltage protection circuit design, have you grasped the essence?
-
Can you really draw a timing diagram? No, you can’t!
-
Making PCB shielding cover drawings
-
Making PCB shielding cover drawings