Represent distance by colors
If the object is 20 cm away or less the RGB LED goes RED
If the object is more than 20 cm away, the RGB goes Green
GUI that contains ( button & label)
if the user presses the "ShowDistance" button, the distance that the sensor measures shown on the screen.
Software:
TinkerCAD
Processing
Components:
1- RGB LED
2- Breadboard
3- Arduino Uno
4- Jumper wires
5- Ultrasonic sensor
A) Wiring
1- Attach RGB LED on Breadboard
2- Wire the RGB with the Arduino using 220 ohm resistors
RED >> pin 11
BLUE >> pin 10
Green >> pin 9
Cathode >> GND
3- Wire the ultrasonic sesnor
Trigger >> pin 13
Echo >> pin 12
VCC >> 5V
GND >> GND
4- Attach the Arduino GND to the -ve of the breadboard
5- Attach the Arduino 5V to the +ve of the breadboard
B) Coding
Arduino
1- Edit Arduino code to print the distance if the button is pressed
processing button sends "1" to arduino
Then Arduino sends the distance value
inData is a char variable that stores the value that comes from processing
Processing
1- Import controlp5 library and processing.serial
2- define objects myport, cp5,label
3- initialize string x to 0
4- in Setup: make the background color black, size 400*400 pixels, no stroke.
5- In Setup: set the button parameters
name; ShowDistance
position: (100,100)
size: 200*19
6- In Setup: set the label parameters
name; Distance is
position: (100,50)
Color: yellow (0xffffff00)
Font: Georgia
size: 20
7- In Setup: set the port to make the serial communication between Arduino and processing
8- In Draw: if the communication is available, read the distance value from Arduino
9- print on screen "Distance is + (distance value)"
10- make the background black again to remove the old distance
11- Write to Arduino "1" if the button is pressed by ShowDistance function
Schematic Diagram
A) Circuit wiring
1- Attach RGB LED on Breadboard
2- Wire the RGB with the Arduino using 220 ohm resistors
RED >> pin 11
BLUE >> pin 10
Green >> pin 9
Cathode >> GND
3- Wire the ultrasonic sesnor
Trigger >> pin 13
Echo >> pin 12
VCC >> 5V
GND >> GND
4- Attach the Arduino GND to the -ve of the breadboard
5- Attach the Arduino 5V to the +ve of the breadboard
6- Copy text code from Tinkercad to Arduino IDE
7- Upload the code
Each distance value was written above the older ones
I searched for how to clear the distance variable in processing/java (String), and didn't work, then I realize that should set the background value again in draw function after printing the value on the screen and it worked !
Make a GUI for the robotic arm to control, show position
Hackathon