Components and supplies
Ultrasonic Sensor - HC-SR04 (Generic)
Arduino Pro Mini 328 - 5V/16MHz
DC motor (generic)
Driver DRV8825 for Stepper Motors for Theremino System
3V Lion battery 3000mAh
Arduino MKR1000
Apps and platforms
Processing 3
Arduino IDE
Project description
Code
The whole MicroLab Radar code
processing
1//this is the whole code running via Processing 3.3.6. (MicroLab-Greece) 2//All parts tests carried out in Arduino IDE. The plastic parts are made via 3D printer 3import processing.serial.*; //import library in order serial interface data 4import java.awt.event.KeyEvent; //import library for reading data from serial port 5import java.io.IOException; 6Serial myPort;//defines serial object 7//variable definition 8String angle=""; 9String distance=""; 10String data=""; 11String noObject; 12float pixsDistance; 13int iAngle, iDistance; 14int index1=0; 15int index2=0; 16PFont orcFont; 17 18void setup() { 19 20 size (860, 860); 21 22 smooth(); 23 myPort = new Serial(this,"COM5", 57600); //starting communication with specofic port 24 myPort.bufferUntil('.'); //reads data from port delimited by '.' 25 26} 27 28void draw() { 29 30 fill(98,245,31); 31 //simulation of moving line (motion and fade) 32 noStroke(); 33 fill(0,4); 34 rect(0, 0, width, height); 35 fill(7,246,23); 36//draws the radar calling functions 37 drawRadar(); 38 drawLine(); 39 drawObject(); 40 drawText(); 41} 42 43void serialEvent (Serial myPort) { //start reading data from specified port 44 //reads data from port delimited by (.) and assigns them in string defined variable "data" 45 data = myPort.readStringUntil('.'); 46 data = data.substring(0,data.length()-1); 47 48 index1 = data.indexOf(","); //detect charachter ',' and assign it to the defined string variable 'index1' 49 angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or the value of the angle, via bluetooth, sents into the Serial Port 50 distance= data.substring(index1+1, data.length()); //reads the data from index() from first to last (distance) 51 //convert stings variables into integer 52 iAngle = int(angle); 53 iDistance = int(distance); 54} 55 56void drawRadar() { 57 pushMatrix(); 58 translate(420,420); //moving the coordinats start 59 noFill(); 60 strokeWeight(1); 61 stroke(255,245,255); 62 // draws the arc lines 63 arc(0,0,860,860,0,TWO_PI); 64 arc(0,0,720,720,0,TWO_PI); 65 arc(0,0,580,580,0,TWO_PI); 66 arc(0,0,440,440,0,TWO_PI); 67 arc(0,0,300,300,0,TWO_PI); 68 arc(0,0,160,160,0,TWO_PI); 69 arc(0,0,20,20,0,TWO_PI); 70//darw of angle lines 71 line(-width/2.0,0,width/2.0,0); 72 line(0,0,-width*cos(radians(30)),-width*sin(radians(30))); 73 line(0,0,-width*cos(radians(60)),-width*sin(radians(60))); 74 line(0,0,-width*cos(radians(90)),-width*sin(radians(90))); 75 line(0,0,-width*cos(radians(120)),-width*sin(radians(120))); 76 line(0,0,-width*cos(radians(150)),-width*sin(radians(150))); 77 line(0,0,-width*cos(radians(180)),-width*sin(radians(180))); 78 line(0,0,-width*cos(radians(210)),-width*sin(radians(210))); 79 line(0,0,-width*cos(radians(240)),-width*sin(radians(240))); 80 line(0,0,-width*cos(radians(270)),-width*sin(radians(270))); 81 line(0,0,-width*cos(radians(300)),-width*sin(radians(300))); 82 line(0,0,-width*cos(radians(330)),-width*sin(radians(330))); 83 line(0,0,-width*cos(radians(360)),-width*sin(radians(360))); 84 line(-width*cos(radians(30)),0,width/2.0,0); 85 popMatrix(); 86} 87 //this function draws the detected object converting the distance into pixels on screen according the angle 88void drawObject() { 89 pushMatrix(); 90 translate(420,420); 91 strokeWeight(3); 92 stroke(255,10,10); 93 pixsDistance = iDistance*2; //converting distance from cm into pixels 94 //with (if) we define the limit range to 2meter (200cm) ! anyone can change the limits according to sensors specifications and drwas the line converting distance into pixel 95 if(iDistance<200){ 96 line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),950*cos(radians(iAngle)),-950*sin(radians(iAngle))); 97 } 98 popMatrix(); 99} 100//this function draws the radar rotatable line 101void drawLine() { 102 pushMatrix(); 103 strokeWeight(6); 104 stroke(10,74,250); 105 translate(420,420); 106 line(0,0,950*cos(radians(iAngle)),-950*sin(radians(iAngle))); 107 popMatrix(); 108} 109//function drawing text on screen nad its values taking from sensors 110void drawText() { 111 112 pushMatrix(); 113 114 fill(0,0,0); 115 noStroke(); 116 rect(0, 1010, width, 600); 117 textSize(15); 118 fill(5,255,5); 119 120 translate(640,294); 121 rotate(-radians(-5)); 122 text("30°",0,0); 123 resetMatrix(); 124 translate(548,200); 125 rotate(-radians(-5)); 126 text("60°",0,0); 127 resetMatrix(); 128 translate(420,160); 129 rotate(radians(0)); 130 text("90°",0,0); 131 resetMatrix(); 132 translate(292,199); 133 rotate(radians(-30)); 134 text("120°",0,0); 135 resetMatrix(); 136 translate(202,296); 137 rotate(radians(-60)); 138 text("150°",0,0); 139 resetMatrix(); 140 translate(166,422); 141 rotate(radians(-90)); 142 text("180°",0,0); 143 resetMatrix(); 144 translate(197,550); 145 rotate(radians(-110)); 146 text("210°",0,0); 147 resetMatrix(); 148 translate(292,641); 149 rotate(radians(360)); 150 text("240°",0,0); 151 resetMatrix(); 152 153 translate(420,677); 154 rotate(radians(-360)); 155 text("270°",0,0); 156 resetMatrix(); 157 158 translate(544,640); 159 rotate(radians(-380)); 160 text("300°",0,0); 161 resetMatrix(); 162 163 translate(641,547); 164 rotate(radians(-5)); 165 text("330°",0,0); 166 resetMatrix(); 167 168 translate(674,422); 169 rotate(radians(-360)); 170 text("360°",0,0); 171 resetMatrix(); 172 173 translate(50,50); 174 rotate(radians(0)); 175 textSize(17); 176 fill(255,103,1); 177 text("MicroLab Radar",0,0); 178 179 resetMatrix(); 180 181 if(iDistance>200) { 182noObject = "Out of Range"; 183} 184else { 185noObject = "In Range"; 186} 187fill(0,0,0); 188noStroke(); 189rect(0, 1010, width, 1080); 190fill(26,230,32); 191 192textSize(20); 193text("Object: " + noObject, 250, 50); 194text("Angle: " + iAngle +" °", 500, 50); 195text("Distance: ", 650, 50); 196if(iDistance<200) { 197text(" " + iDistance +" cm", 750, 50); 198} 199 200 popMatrix(); 201 202 203 204 }
Motor sketch (code)
arduino
Defines and regulates the 2-phased motor rotation
1//This sketch defines and regulate the 2-phased stepper motor 2int trigPinA =13; 3int echoPinA=12; 4volatile unsigned long durationA; 5volatile int distanceA; 6volatile uint16_t counter; 7 8 9int trigPinB =11; 10int echoPinB=10; 11long durationB; 12int distanceB; 13 14volatile unsigned long Start; 15unsigned long timer1_counter; 16void setup() { 17 // put your setup code here, to run once: 18 // Arduino initializations 19Serial.begin(9600); 20 21Serial.write("AT+NAMERADAR"); 22 23 delay(1000); 24 25 Serial.write("AT+PIN1234"); 26 27 delay(1000); 28 Serial.write("AT+BAUD8"); 29 30 31 delay(1000); 32 33Serial.end(); 34 35 36 Serial.begin(115200); 37 38 //pinMode(2,INPUT); 39 pinMode(2, OUTPUT); 40 41 pinMode(3,OUTPUT); 42 pinMode(9,OUTPUT); 43 pinMode(10,INPUT); 44 pinMode(12,INPUT); 45 pinMode(11,OUTPUT); 46 pinMode(13,OUTPUT); 47 digitalWrite(2,LOW); 48 digitalWrite(9,LOW); 49 digitalWrite(2,HIGH); 50 //pinMode(2,OUTPUT); 51 52 53 54 // initialize timer1 55 noInterrupts(); // disable all interrupts 56 TCCR1A = 0; 57 TCCR1B = 0; 58 59 // Set timer1_counter to the correct value for our interrupt interval 60 timer1_counter = 65505; // preload timer 65536-16MHz/256/100Hz 61 //timer1_counter = 64286; // preload timer 65536-16MHz/256/50Hz 62 //timer1_counter = 34286; // preload timer 65536-16MHz/256/2Hz 63 64 TCNT1 = timer1_counter; // preload timer 65 TCCR1B |= (1 << CS12); // 256 prescaler 66 TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt 67 interrupts(); // enable all interrupts 68 69 70} 71 72 73ISR(TIMER1_OVF_vect) // interrupt service routine 74{ 75 TCNT1 = timer1_counter; // preload timer 76 digitalWrite(3, digitalRead(3) ^ 1); 77 counter++; 78 if (counter>=12800*2) 79 counter=0; 80} 81 82void loop() { 83 84 85digitalWrite(trigPinA, LOW); 86delayMicroseconds(2); 87// Sets the trigPin on HIGH state for 10 micro seconds 88digitalWrite(trigPinA, HIGH); 89delayMicroseconds(10); 90 91digitalWrite(trigPinA, LOW); 92//Reads the echoPin, returns the sound wave travel time in microseconds 93durationA= pulseIn(echoPinA, HIGH); 94distanceA= durationA*0.029/2; 95 noInterrupts(); 96 int i=(counter/2)/35.5555; 97 interrupts(); 98 Serial.print(i); 99 Serial.print(","); 100 Serial.print(distanceA,DEC); 101 Serial.print("."); 102 103 104digitalWrite(trigPinB, LOW); 105delayMicroseconds(2); 106// Sets the trigPin on HIGH state for 10 micro seconds 107digitalWrite(trigPinB, HIGH); 108delayMicroseconds(10); 109 110digitalWrite(trigPinB, LOW); 111//Reads the echoPin, returns the sound wave travel time in microseconds 112durationB= pulseIn(echoPinB, HIGH); 113distanceB= durationB*0.029/2; 114 noInterrupts(); 115 i=(180+(counter/2)/35.5555); 116 if(i>360) 117 i=i-360; 118 interrupts(); 119 Serial.print(i); 120 Serial.print(","); 121 Serial.print(distanceB,DEC); 122 Serial.print("."); 123 124 125 126delay(0); 127 128 129 130} 131
Motor sketch (code)
arduino
Defines and regulates the 2-phased motor rotation
1//This sketch defines and regulate the 2-phased stepper motor 2int trigPinA =13; 3int echoPinA=12; 4volatile unsigned long durationA; 5volatile int distanceA; 6volatile uint16_t counter; 7 8 9int trigPinB =11; 10int echoPinB=10; 11long durationB; 12int distanceB; 13 14volatile unsigned long Start; 15unsigned long timer1_counter; 16void setup() { 17 // put your setup code here, to run once: 18 // Arduino initializations 19Serial.begin(9600); 20 21Serial.write("AT+NAMERADAR"); 22 23 delay(1000); 24 25 Serial.write("AT+PIN1234"); 26 27 delay(1000); 28 Serial.write("AT+BAUD8"); 29 30 31 delay(1000); 32 33Serial.end(); 34 35 36 Serial.begin(115200); 37 38 //pinMode(2,INPUT); 39 pinMode(2, OUTPUT); 40 41 pinMode(3,OUTPUT); 42 pinMode(9,OUTPUT); 43 pinMode(10,INPUT); 44 pinMode(12,INPUT); 45 pinMode(11,OUTPUT); 46 pinMode(13,OUTPUT); 47 digitalWrite(2,LOW); 48 digitalWrite(9,LOW); 49 digitalWrite(2,HIGH); 50 //pinMode(2,OUTPUT); 51 52 53 54 // initialize timer1 55 noInterrupts(); // disable all interrupts 56 TCCR1A = 0; 57 TCCR1B = 0; 58 59 // Set timer1_counter to the correct value for our interrupt interval 60 timer1_counter = 65505; // preload timer 65536-16MHz/256/100Hz 61 //timer1_counter = 64286; // preload timer 65536-16MHz/256/50Hz 62 //timer1_counter = 34286; // preload timer 65536-16MHz/256/2Hz 63 64 TCNT1 = timer1_counter; // preload timer 65 TCCR1B |= (1 << CS12); // 256 prescaler 66 TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt 67 interrupts(); // enable all interrupts 68 69 70} 71 72 73ISR(TIMER1_OVF_vect) // interrupt service routine 74{ 75 TCNT1 = timer1_counter; // preload timer 76 digitalWrite(3, digitalRead(3) ^ 1); 77 counter++; 78 if (counter>=12800*2) 79 counter=0; 80} 81 82void loop() { 83 84 85digitalWrite(trigPinA, LOW); 86delayMicroseconds(2); 87// Sets the trigPin on HIGH state for 10 micro seconds 88digitalWrite(trigPinA, HIGH); 89delayMicroseconds(10); 90 91digitalWrite(trigPinA, LOW); 92//Reads the echoPin, returns the sound wave travel time in microseconds 93durationA= pulseIn(echoPinA, HIGH); 94distanceA= durationA*0.029/2; 95 noInterrupts(); 96 int i=(counter/2)/35.5555; 97 interrupts(); 98 Serial.print(i); 99 Serial.print(","); 100 Serial.print(distanceA,DEC); 101 Serial.print("."); 102 103 104digitalWrite(trigPinB, LOW); 105delayMicroseconds(2); 106// Sets the trigPin on HIGH state for 10 micro seconds 107digitalWrite(trigPinB, HIGH); 108delayMicroseconds(10); 109 110digitalWrite(trigPinB, LOW); 111//Reads the echoPin, returns the sound wave travel time in microseconds 112durationB= pulseIn(echoPinB, HIGH); 113distanceB= durationB*0.029/2; 114 noInterrupts(); 115 i=(180+(counter/2)/35.5555); 116 if(i>360) 117 i=i-360; 118 interrupts(); 119 Serial.print(i); 120 Serial.print(","); 121 Serial.print(distanceB,DEC); 122 Serial.print("."); 123 124 125 126delay(0); 127 128 129 130} 131
The whole MicroLab Radar code
processing
1//this is the whole code running via Processing 3.3.6. (MicroLab-Greece) 2//All parts tests carried out in Arduino IDE. The plastic parts are made via 3D printer 3import processing.serial.*; //import library in order serial interface data 4import java.awt.event.KeyEvent; //import library for reading data from serial port 5import java.io.IOException; 6Serial myPort;//defines serial object 7//variable definition 8String angle=""; 9String distance=""; 10String data=""; 11String noObject; 12float pixsDistance; 13int iAngle, iDistance; 14int index1=0; 15int index2=0; 16PFont orcFont; 17 18void setup() { 19 20 size (860, 860); 21 22 smooth(); 23 myPort = new Serial(this,"COM5", 57600); //starting communication with specofic port 24 myPort.bufferUntil('.'); //reads data from port delimited by '.' 25 26} 27 28void draw() { 29 30 fill(98,245,31); 31 //simulation of moving line (motion and fade) 32 noStroke(); 33 fill(0,4); 34 rect(0, 0, width, height); 35 fill(7,246,23); 36//draws the radar calling functions 37 drawRadar(); 38 drawLine(); 39 drawObject(); 40 drawText(); 41} 42 43void serialEvent (Serial myPort) { //start reading data from specified port 44 //reads data from port delimited by (.) and assigns them in string defined variable "data" 45 data = myPort.readStringUntil('.'); 46 data = data.substring(0,data.length()-1); 47 48 index1 = data.indexOf(","); //detect charachter ',' and assign it to the defined string variable 'index1' 49 angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or the value of the angle, via bluetooth, sents into the Serial Port 50 distance= data.substring(index1+1, data.length()); //reads the data from index() from first to last (distance) 51 //convert stings variables into integer 52 iAngle = int(angle); 53 iDistance = int(distance); 54} 55 56void drawRadar() { 57 pushMatrix(); 58 translate(420,420); //moving the coordinats start 59 noFill(); 60 strokeWeight(1); 61 stroke(255,245,255); 62 // draws the arc lines 63 arc(0,0,860,860,0,TWO_PI); 64 arc(0,0,720,720,0,TWO_PI); 65 arc(0,0,580,580,0,TWO_PI); 66 arc(0,0,440,440,0,TWO_PI); 67 arc(0,0,300,300,0,TWO_PI); 68 arc(0,0,160,160,0,TWO_PI); 69 arc(0,0,20,20,0,TWO_PI); 70//darw of angle lines 71 line(-width/2.0,0,width/2.0,0); 72 line(0,0,-width*cos(radians(30)),-width*sin(radians(30))); 73 line(0,0,-width*cos(radians(60)),-width*sin(radians(60))); 74 line(0,0,-width*cos(radians(90)),-width*sin(radians(90))); 75 line(0,0,-width*cos(radians(120)),-width*sin(radians(120))); 76 line(0,0,-width*cos(radians(150)),-width*sin(radians(150))); 77 line(0,0,-width*cos(radians(180)),-width*sin(radians(180))); 78 line(0,0,-width*cos(radians(210)),-width*sin(radians(210))); 79 line(0,0,-width*cos(radians(240)),-width*sin(radians(240))); 80 line(0,0,-width*cos(radians(270)),-width*sin(radians(270))); 81 line(0,0,-width*cos(radians(300)),-width*sin(radians(300))); 82 line(0,0,-width*cos(radians(330)),-width*sin(radians(330))); 83 line(0,0,-width*cos(radians(360)),-width*sin(radians(360))); 84 line(-width*cos(radians(30)),0,width/2.0,0); 85 popMatrix(); 86} 87 //this function draws the detected object converting the distance into pixels on screen according the angle 88void drawObject() { 89 pushMatrix(); 90 translate(420,420); 91 strokeWeight(3); 92 stroke(255,10,10); 93 pixsDistance = iDistance*2; //converting distance from cm into pixels 94 //with (if) we define the limit range to 2meter (200cm) ! anyone can change the limits according to sensors specifications and drwas the line converting distance into pixel 95 if(iDistance<200){ 96 line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),950*cos(radians(iAngle)),-950*sin(radians(iAngle))); 97 } 98 popMatrix(); 99} 100//this function draws the radar rotatable line 101void drawLine() { 102 pushMatrix(); 103 strokeWeight(6); 104 stroke(10,74,250); 105 translate(420,420); 106 line(0,0,950*cos(radians(iAngle)),-950*sin(radians(iAngle))); 107 popMatrix(); 108} 109//function drawing text on screen nad its values taking from sensors 110void drawText() { 111 112 pushMatrix(); 113 114 fill(0,0,0); 115 noStroke(); 116 rect(0, 1010, width, 600); 117 textSize(15); 118 fill(5,255,5); 119 120 translate(640,294); 121 rotate(-radians(-5)); 122 text("30°",0,0); 123 resetMatrix(); 124 translate(548,200); 125 rotate(-radians(-5)); 126 text("60°",0,0); 127 resetMatrix(); 128 translate(420,160); 129 rotate(radians(0)); 130 text("90°",0,0); 131 resetMatrix(); 132 translate(292,199); 133 rotate(radians(-30)); 134 text("120°",0,0); 135 resetMatrix(); 136 translate(202,296); 137 rotate(radians(-60)); 138 text("150°",0,0); 139 resetMatrix(); 140 translate(166,422); 141 rotate(radians(-90)); 142 text("180°",0,0); 143 resetMatrix(); 144 translate(197,550); 145 rotate(radians(-110)); 146 text("210°",0,0); 147 resetMatrix(); 148 translate(292,641); 149 rotate(radians(360)); 150 text("240°",0,0); 151 resetMatrix(); 152 153 translate(420,677); 154 rotate(radians(-360)); 155 text("270°",0,0); 156 resetMatrix(); 157 158 translate(544,640); 159 rotate(radians(-380)); 160 text("300°",0,0); 161 resetMatrix(); 162 163 translate(641,547); 164 rotate(radians(-5)); 165 text("330°",0,0); 166 resetMatrix(); 167 168 translate(674,422); 169 rotate(radians(-360)); 170 text("360°",0,0); 171 resetMatrix(); 172 173 translate(50,50); 174 rotate(radians(0)); 175 textSize(17); 176 fill(255,103,1); 177 text("MicroLab Radar",0,0); 178 179 resetMatrix(); 180 181 if(iDistance>200) { 182noObject = "Out of Range"; 183} 184else { 185noObject = "In Range"; 186} 187fill(0,0,0); 188noStroke(); 189rect(0, 1010, width, 1080); 190fill(26,230,32); 191 192textSize(20); 193text("Object: " + noObject, 250, 50); 194text("Angle: " + iAngle +" °", 500, 50); 195text("Distance: ", 650, 50); 196if(iDistance<200) { 197text(" " + iDistance +" cm", 750, 50); 198} 199 200 popMatrix(); 201 202 203 204 }
Documentation
2-phased stepper motor of the Microcon
The motor has regulated for continiously rotation
2-phased stepper motor of the Microcon
ultrasonic distance sensors for Arduino
Radar uses two (2) ultrasonic sensors
ultrasonic distance sensors for Arduino
ultrasonic distance sensors for Arduino
Radar uses two (2) ultrasonic sensors
ultrasonic distance sensors for Arduino
Batteries Lion 3000mAh each
The batteries are rechargeable
Batteries Lion 3000mAh each
Arduino mini pro
Arduino mini pro
HC-05 6 Pin Wireless Bluetooth RF Transceiver Module Serial For Arduino
Radar gets the data via bluetooth communication
HC-05 6 Pin Wireless Bluetooth RF Transceiver Module Serial For Arduino
Plastics
All the plastic parts have made via 3D printer
Plastics
Plastics
All the plastic parts have made via 3D printer
Plastics
2-phased stepper motor of the Microcon
The motor has regulated for continiously rotation
2-phased stepper motor of the Microcon
HC-05 6 Pin Wireless Bluetooth RF Transceiver Module Serial For Arduino
Radar gets the data via bluetooth communication
HC-05 6 Pin Wireless Bluetooth RF Transceiver Module Serial For Arduino
DRV8825 Stepper Motor Driver Carrier
DRV8825 Stepper Motor Driver Carrier
Batteries Lion 3000mAh each
The batteries are rechargeable
Batteries Lion 3000mAh each
Arduino mini pro
Arduino mini pro
Comments
Only logged in users can leave comments
Microlab_Aigio_Greece
0 Followers
•0 Projects
Table of contents
Intro
23
0