├── Mini radar circuit drawing.png ├── README.md └── Arduino based mini radar.ino /Mini radar circuit drawing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mkishore7/Arduino-based-Mini-radar-HC-SR04-ST7735-Display/HEAD/Mini radar circuit drawing.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino-based-Mini-radar-HC-SR04-ST7735-Display 2 | I have made a Mini compact Radar with display for that I have used HC-SR04 ultrasonic sensor, this sensor emit ultrasonic sound which came back to sensor after reflecting from an object, all the data visualization is displayed on 1.8" ST7735 display, if any object detect by radar it'll show in display in red line. 3 | 4 | I have prepared a custome made PCB and order it from JLCPCB.COM to get professional touch to my project 5 | 6 | 3D files link 7 | https://www.thingiverse.com/thing:3465440 8 | 9 | Install this library in arduino IDE before compiling 10 | https://github.com/olikraus/ucglib 11 | 12 | Arduino nano :- https://amzn.to/2Eq3tSK 13 | 14 | HC-SR04 ultrasonic sensor :- https://amzn.to/2SEU4vQ 15 | 16 | SG 90 Servo :- https://amzn.to/2NG807N 17 | 18 | 1.8" ST7735 Dispaly :- https://www.aliexpress.com/item/NEW-1-8-inch-4-IO-SPI-serial-Full-Color-128x160-TFT-LCD-Display-ST7735-Module/32673683146.html 19 | -------------------------------------------------------------------------------- /Arduino based mini radar.ino: -------------------------------------------------------------------------------- 1 | #include . 2 | 3 | #include 4 | #include "Ucglib.h" 5 | const int trigPin = 6; 6 | const int echoPin = 5; 7 | int Ymax = 128; 8 | int Xmax = 160; 9 | int base = 8; 10 | int pos = base+6; 11 | int deg=0; 12 | int x; 13 | int val =200; 14 | int j = 2; 15 | Servo myServo; 16 | 17 | long duration; 18 | int distance; 19 | int k; 20 | 21 | 22 | Ucglib_ST7735_18x128x160_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8); 23 | 24 | void setup(void) 25 | { 26 | delay(1000); 27 | myServo.write(80); 28 | // ucg.begin(UCG_FONT_MODE_TRANSPARENT); 29 | ucg.begin(UCG_FONT_MODE_SOLID); 30 | ucg.setFont(ucg_font_6x10_tr); 31 | ucg.clearScreen(); 32 | ucg.setRotate270(); 33 | 34 | pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 35 | pinMode(echoPin, INPUT); // Sets the echoPin as an Input 36 | Serial.begin(9600); 37 | myServo.attach(3); // Defines on which pin is the servo motor attached 38 | 39 | } 40 | 41 | void loop(void) 42 | { 43 | 44 | 45 | 46 | fix(); 47 | 48 | for ( x=80; x >= 10; x--){ 49 | 50 | distance = calculateDistance(); 51 | Serial.println(distance); 52 | 53 | k = map(x, 80, 10, 15,165); 54 | myServo.write(k); 55 | if (distance < 30){ 56 | int f = x+6; 57 | ucg.setColor(255, 0, 0); 58 | ucg.drawLine(Xmax/2, pos, -val*cos(radians(f*2)),val*sin(radians(f*2))); 59 | } 60 | ucg.setColor(0, 207, 0); 61 | ucg.drawLine(Xmax/2, pos, -200*cos(radians(x*2)),200*sin(radians(x*2))); 62 | 63 | int d = x+1; 64 | ucg.setColor(0, 207, 0); 65 | //ucg.drawLine(Xmax/2, pos, -200*cos(radians(d*2)),200*sin(radians(d*2))); 66 | int c = x+2; 67 | ucg.setColor(0, 207, 0); 68 | //ucg.drawLine(Xmax/2, pos, -200*cos(radians(c*2)),200*sin(radians(c*2))); 69 | int b = x+3; 70 | ucg.setColor(0, 102, 0); 71 | //ucg.drawLine(Xmax/2, pos, -200*cos(radians(b*2)),200*sin(radians(b*2))); 72 | int a = x+4; 73 | ucg.setColor(0, 102, 0); 74 | //ucg.drawLine(Xmax/2, pos, -200*cos(radians(a*2)),200*sin(radians(a*2))); 75 | int e = x+5; 76 | ucg.setColor(0, 0, 0); 77 | ucg.drawLine(Xmax/2, pos, -200*cos(radians(e*2)),200*sin(radians(e*2))); 78 | ucg.setColor(255, 0, 0); 79 | ucg.setPrintPos(160,0); 80 | ucg.setPrintDir(2); 81 | ucg.print("Deg :"); 82 | deg = map (x, 80, 10 , 0, 180); 83 | ucg.setPrintPos(120,0); 84 | ucg.setPrintDir(2); 85 | ucg.print(deg); 86 | ucg.setPrintPos(10,0); 87 | ucg.print(distance); 88 | ucg.setColor(0, 0, 255); 89 | ucg.setPrintPos(90,38); 90 | ucg.setPrintDir(2); 91 | ucg.print("0.25"); 92 | ucg.setPrintPos(90,70); 93 | ucg.print("0.50"); 94 | ucg.setPrintPos(90,110); 95 | ucg.print("1.00"); 96 | } 97 | 98 | 99 | 100 | 101 | 102 | 103 | // ucg.clearScreen(); 104 | 105 | fix(); 106 | 107 | 108 | for ( x=10; x <= 80; x++){ 109 | distance = calculateDistance(); 110 | Serial.println(distance); 111 | k = map(x, 10, 80, 165,15); 112 | myServo.write(k); 113 | if (distance < 10){ 114 | int e = x-5; 115 | ucg.setColor(255, 0, 0); 116 | ucg.drawLine(Xmax/2, pos, -val*cos(radians(e*2)),val*sin(radians(e*2))); 117 | } 118 | 119 | 120 | ucg.setColor(0, 207, 0); 121 | ucg.drawLine(Xmax/2, pos, -200*cos(radians(x*2)),200*sin(radians(x*2))); 122 | 123 | int a = x-1; 124 | 125 | //ucg.drawLine(Xmax/2, pos, -200*cos(radians(a*2)),200*sin(radians(a*2))); 126 | 127 | int b = x-2; 128 | ucg.setColor(0, 102, 0); 129 | //ucg.drawLine(Xmax/2, pos, -200*cos(radians(b*2)),200*sin(radians(b*2))); 130 | 131 | int c = x-3; 132 | ucg.setColor(0, 102, 0); 133 | //ucg.drawLine(Xmax/2, pos, -200*cos(radians(c*2)),200*sin(radians(c*2))); 134 | 135 | int d = x-4; 136 | ucg.setColor(0, 0, 0); 137 | ucg.drawLine(Xmax/2, pos, -200*cos(radians(d*2)),200*sin(radians(d*2))); 138 | ucg.setColor(255, 0, 0); 139 | ucg.setPrintPos(160,0); 140 | ucg.setPrintDir(2); 141 | ucg.print("Deg :"); 142 | deg = map (x, 10, 80 , 0, 180); 143 | ucg.setPrintPos(120,0); 144 | ucg.setPrintDir(2); 145 | ucg.print(deg); 146 | ucg.setPrintPos(10,0); 147 | ucg.print(distance); 148 | 149 | 150 | 151 | 152 | 153 | 154 | ucg.setColor(0, 0, 255); 155 | ucg.setPrintPos(90,38); 156 | ucg.setPrintDir(2); 157 | ucg.print("0.25"); 158 | ucg.setPrintPos(90,70); 159 | ucg.print("0.50"); 160 | ucg.setPrintPos(90,110); 161 | ucg.print("1.00"); 162 | 163 | 164 | } 165 | //ucg.clearScreen(); 166 | 167 | } 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | void fix(){ 176 | ucg.setColor(255, 0, 0); 177 | ucg.drawDisc(Xmax/2, base, 5, UCG_DRAW_LOWER_RIGHT); 178 | ucg.drawDisc(Xmax/2, base, 5, UCG_DRAW_LOWER_LEFT); 179 | 180 | 181 | 182 | ucg.setColor(225, 255, 50); 183 | ucg.drawCircle(80, base, 115, UCG_DRAW_LOWER_RIGHT); 184 | ucg.drawCircle(80, base, 115, UCG_DRAW_LOWER_LEFT); 185 | 186 | ucg.drawCircle(80, base, 78, UCG_DRAW_LOWER_RIGHT); 187 | ucg.drawCircle(80, base, 78, UCG_DRAW_LOWER_LEFT); 188 | 189 | ucg.drawCircle(80, base, 40, UCG_DRAW_LOWER_RIGHT); 190 | ucg.drawCircle(80, base, 40, UCG_DRAW_LOWER_LEFT); 191 | 192 | ucg.drawLine(0, base, 160,base); 193 | 194 | 195 | ucg.setColor(0, 0, 0); 196 | ucg.drawBox(100, 0, 30, 8); 197 | 198 | 199 | 200 | } 201 | 202 | 203 | int calculateDistance(){ 204 | 205 | digitalWrite(trigPin, LOW); 206 | delayMicroseconds(2); 207 | // Sets the trigPin on HIGH state for 10 micro seconds 208 | digitalWrite(trigPin, HIGH); 209 | delayMicroseconds(10); 210 | digitalWrite(trigPin, LOW); 211 | duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds 212 | distance= duration*0.034/2; 213 | return distance; 214 | } 215 | --------------------------------------------------------------------------------