I made this Project and ive connected everything right. Ive uploaded the program to Arduino and the other one to the Process Software. The servo doesnt move at all and the Sonar is maxed out at all times. Please help
here is the project: How to Make a Radar with Arduino, project with code - AndProf
Sonar implies 'under water, sound waves'. Is this an under water implementation?
Its not for under water use its just like a Radar but i read somewhere that it is a sonar since it uses a ultrasonic sensor
What are you trying to measure and at what distance. Your link system will not go very far and is good only for usage in air. Sonar is sound navigation and ranging, is this for a robot?
Your wiring must be wrong and power supply not right.
Processing is just to draw.
The sketch sweeps the servo from 15 to 165 and the SONAR (ALL CAPS for a reason) definitely detects change in proximity.
The baseline simulation shows a graph of max (ORG, 400), min (GRN, 0), SONAR (CYN, 200), SERVO (15..165..15..., MAG).
This test shows continued SERVO sweep with SONAR change in proximity in CYN.
Simulated on WOKWI.COM
click for sketch.ino
// Includes the Servo library
#include <Servo.h>.
// Defines Tirg and Echo pins of the Ultrasonic Sensor
const int trigPin = 10;
const int echoPin = 11;
//by www.andprof.com
// Variables for the duration and the distance
long duration;
int distance;
Servo myServo; // Creates a servo object for controlling the servo motor
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
myServo.attach(12);
}
void loop() {
for (int i = 15; i <= 165; i++) {
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(0);
Serial.print(",");
Serial.print(400);
Serial.print(",");
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
Serial.println();
}
for (int i = 165; i > 15; i--) {
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(0);
Serial.print(",");
Serial.print(400);
Serial.print(",");
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
Serial.println();
}
}
int calculateDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
return distance;
}
click for diagram.json
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": -4.8, "left": -0.5, "attrs": {} },
{
"type": "wokwi-hc-sr04",
"id": "ultrasonic1",
"top": -132.9,
"left": 43.9,
"attrs": { "distance": "194" }
},
{
"type": "wokwi-servo",
"id": "servo1",
"top": -212.2,
"left": -75,
"rotate": 270,
"attrs": {}
}
],
"connections": [
[ "nano:10", "ultrasonic1:TRIG", "green", [ "v0" ] ],
[ "nano:11", "ultrasonic1:ECHO", "green", [ "v-14.4", "h18.7" ] ],
[ "ultrasonic1:VCC", "nano:5V", "red", [ "v9.6", "h-96", "v86.4" ] ],
[ "ultrasonic1:GND", "nano:GND.1", "black", [ "v0" ] ],
[ "servo1:PWM", "nano:12", "green", [ "v38.4", "h77" ] ],
[ "ultrasonic1:VCC", "servo1:V+", "red", [ "v9.6", "h-96" ] ],
[ "ultrasonic1:GND", "servo1:GND", "black", [ "v19.2", "h-135.6" ] ]
],
"dependencies": {}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.