Summary
Trying to create/code a project that uses an Arduino, a VL53L0X laser range finder,
a 1602 LCD to display distance text, a TFT LCD to display sweeping RADAR/SONAR scope
with red dots for nearby contacts, and a servo to sweep the range finder back and forth.
The testbed 3d print is a base for the above. Code is still a work in progress as there are some problems erasing the sweep lines after the red contacts are displayed.
Print Settings
Infill:
15
Notes:
Should use supports due to the servo bracket.
Post-Printing




Arduino Code
/***
Name: RadarTestBed02
Version: 02
Date: 08-01-22
Last Rev: 08=03-22
By: dcc
Description: Tried to create/code a project that uses an Arduino,
a VL53L0X laser range finder, a 1602 LCD to display distance text,
a TFT LCD to display sweeping RADAR/SONAR scope with red dots
for nearby contacts, and a servo to sweep the range finder back
and forth. It is a work in progress as we still have trouble erasing
sweep lines after red contacts are displayed. Was also going to
add a beep & light flash when a contact appears on the RADAR screen.
Other Files:
-- <2022_RadarTestBed.stl> = main body base
-- <2022_RadarMastShort.stl> & <2022_RadarMastLong.stl>
-- <67x8x3_4_5_Bars.stl> = for size differences in battery boxes
-- and a couple ".jpg" photos
-- <Can use project & &
---- to set servo before assembly
Hardware:
-- Arduino MEGA 2560 (or equal) with mounted 2.8 inch TFT LCD
-- Twin 9V batteries in switched boxes with Std. plugs
-- Half breadboard with a power supply
-- 1602 LCD display - mounted I2C version
-- Active buzzer and mounted RGB LED
-- 2 each 24.7k to 10k pull up resistors for i2c buss
****/
/***
Include Libraries, Pin Definitions, Declare & Define
Constants & Variables, and Initialize Objects:
****/
// Libraries
include // for the I2C
include // for the serial monitor
include // for the 1602 LCD
include // for the servo
include // core graphics library
include // hardware specific library
//#include "Adafruit_VL53L0X.h" // laser range finder (couldn't get it to work)
include // Pololu version
// Set LCD address to 0x27 for a 16 char x 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2); // other is 0x29 (VL53L0X ???)
// Set laser time-of-flight distance sensor
//Adafruit_VL53L0X lox = Adafruit_VL53L0X(); // had problems
VL53L0X sensor;
// TFT LCD
define LCD_CS A3 // Chip Select goes to Analog 3
define LCD_CD A2 // Command/Data goes to Analog 2
define LCD_WR A1 // LCD Write goes to Analog 1
define LCD_RD A0 // LCD Read goes to Analog 0
define LCD_RESET A4 // Can alt connect to Arduino's reset pin
int X1, Y1, X2, Y2, X3, Y3, X4, Y4, L1, L2, L3; // line end point coordinates and length
int mm, cm, in; // distance in milimeters, centimeters, and inches
int D1, D2, D3; // angle in degrees
float R1, R2, R3; // angle (in radians)
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// Assign Names to 16-bit color values
define BLACK 0x0000
define BLUE 0x001F
define CYAN 0x07FF
define DARKCYAN 0x03EF
define DARKGREEN 0x03E0
define DARKGREY 0x7BEF
define GREEN 0x07E0
define GREENYELLOW 0xAFE5
define LIGHTGREY 0xC618
define MAGENTA 0xF81F
define MAROON 0x7800
define NAVY 0x000F
define OLIVE 0x7BE0
define ORANGE 0xFD20
define PINK 0xF81F
define PURPLE 0x780F
define RED 0xF800
define WHITE 0xFFFF
define YELLOW 0xFFE0
// Servo, Buzzer, and Lights (RGB LED module
// or include 220 ohm resisters)
Servo servo01; // create a servo object
float servoAngle = 20; // to store servo horn (arm) angle
const int servoPin = 37; // servo pin for dish movement
const int buzzer = 49; // active buzzer pin (direct fit 49 to Grnd)
const int LED_R = 39; // mounted RGB-LED red pin
const int LED_G = 41; // mounted RGB-LED green pin
const int LED_B = 43; // mounted RGB-LED blue pin
/***
Initial 'Setup' Code To Run Once:
****/
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor.init();
sensor.setTimeout(500);
// Servo, Buzzer, and Lights
servo01.attach(servoPin); // attach servo to servo object
servo01.write(90); // servo starts facing forward
pinMode(buzzer, OUTPUT); // set pins to "output"
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
digitalWrite(LED_R, LOW); // default LEDs to "off"
digitalWrite(LED_G, LOW);
digitalWrite(LED_B, LOW);
// Initialize LCD, turn on backlight, and print message
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Starting up.....");
delay(100);
// Draw RADAR/SONAR Scope Background on 320x240 TFT LCD
// Center hub is x=160, y=230 (mid-screen, 10 pixels off the bottom)
tft.reset();
tft.begin(0x9341); // or use to get variable to insert
tft.setRotation(3);
tft.fillScreen (DARKGREEN);
tft.setTextColor (YELLOW);
tft.setTextSize (2);
tft.println ("Radar/Sonar Test Bed");
tft.setTextSize (1);
tft.println ("(Jul 2022)");
tft.drawCircle (160, 230, 150, ORANGE);
tft.drawCircle (160, 230, 148, ORANGE);
tft.drawLine (160, 230, 5, 230, LIGHTGREY);
tft.drawLine (160, 230, 50, 120, LIGHTGREY);
tft.drawLine (160, 230, 160, 75, LIGHTGREY);
tft.drawLine (160, 230, 270, 120, LIGHTGREY);
tft.drawLine (160, 230, 315, 230, LIGHTGREY);
tft.setTextSize (2);
tft.setTextColor (ORANGE);
tft.setCursor(205, 73);
tft.print ("75 cm");
tft.setTextColor (LIGHTGREY);
tft.setCursor (17, 210);
tft.print ("0");
tft.setCursor (30, 100);
tft.print ("45");
tft.setCursor (150, 55);
tft.print ("90");
tft.setCursor(270, 100);
tft.print ("135");
tft.setCursor (270, 210);
tft.print ("180");
// Test
tft.drawLine (160, 230, 200, 120, WHITE);
tft.fillCircle (200, 120, 4, RED);
tft.drawLine (160, 230, 80, 120, YELLOW);
tft.fillCircle (80, 120, 4, RED);
delay(1500);
// Signal Startup
blip();
flashGreen();
blip();
flashYellow();
blip();
flashRed();
blip();
delay(500);
tft.drawLine (160, 230, 200, 120, DARKGREEN);
tft.fillCircle (200, 120, 4, DARKGREEN);
tft.drawLine (160, 230, 80, 120, DARKGREEN);
tft.fillCircle (80, 120, 4, DARKGREEN);
}
/
Main 'Loop' Code To Run Repeatedly:
/
void loop()
{
// Sweeping the Servo
for (servoAngle = 20; servoAngle <= 160; servoAngle += 2) // sweep 20 to 160 by 2's
{
servo01.write(servoAngle); // send servo to "servoAngle" position
delay(50); // wait 50 ms for servo to move
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" DISTANCE in cm ");
lcd.setCursor(0, 1);
lcd.print(sensor.readRangeSingleMillimeters() / 10);
if (sensor.timeoutOccurred())
{
lcd.print("Timeout");
}
}
for (servoAngle = 160; servoAngle >= 20; servoAngle -= 2) // sweep 160 to 20 by 2's
{
servo01.write(servoAngle); // send servo to "servoAngle"
delay(50);
}
}
/
Other Functions to be called:
/
void beep() // sounds buzzer for 200/1000 second
{
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
return;
}
void blip() // blips buzzer for 100/1000 second
{
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer, LOW);
return;
}
void flashRed() // flash RGB LED red for 300/1000 second
{
digitalWrite(LED_R, HIGH);
digitalWrite(LED_G, LOW);
digitalWrite(LED_B, LOW);
delay(300);
digitalWrite(LED_R, LOW);
return;
}
void flashYellow() // flash RGB LED yellow for 300/1000 second
{
digitalWrite(LED_R, HIGH);
digitalWrite(LED_G, HIGH);
digitalWrite(LED_B, LOW);
delay(300);
digitalWrite(LED_R, LOW);
digitalWrite(LED_G, LOW);
return;
}
void flashGreen() // flash RGB LED green for 300/1000 second
{
digitalWrite(LED_R, LOW);
digitalWrite(LED_G, HIGH);
digitalWrite(LED_B, LOW);
delay(300);
digitalWrite(LED_G, LOW);
return;
}
void flashBlue() // flash RGB LED blue for 300/1000 second
{
digitalWrite(LED_R, LOW);
digitalWrite(LED_G, LOW);
digitalWrite(LED_B, HIGH);
delay(300);
digitalWrite(LED_B, LOW);
return;
}
void flickBlue() // flick RGB LED blue for 100/1000 second
{
digitalWrite(LED_R, LOW);
digitalWrite(LED_G, LOW);
digitalWrite(LED_B, HIGH);
delay(100);
digitalWrite(LED_B, LOW);
return;
}
Etiquetas
Fuente del modelo
