

In order to visualize the outputted angular position and approximate ranging of the HC-SR04 - Python code was implemented on a Raspberry Pi to create a plan position indicator on a polar plot. The HC-SR04 uses sound waves to approximate the distance between its receiver and an object in the distance, while the MG90S servo rotates in a prescribed fashion according to pulse-width modulation signals controlled by the Arduino board. The goal of this project was to introduce a novel concept related to real-world technology, but implemented through inexpensive tools available to the maker and aspiring engineer. If the person is further than 400cm, then the sensor may not register the person, whereas if the person is within 400cm, then it will recognize it over multiple angles.Īn Arduino-based radar project was implemented in this tutorial using an Arduino, HC-SR04 ultrasonic distance sensor, MG90S micro servo motor, and Python code run on a Raspberry Pi. If we assume a person is about 50cm wide, this means that at about 400cm the HC-SR04 will properly recognize it. If the object is larger than 130cm, then it may register over multiple angles until it is out of the majority sight of the sensor. If the area is smaller, then it may misinterpret the size of the object and therefore its ability to recognize it. As an example, an object that is 1m away will need to be 130cm for the HC-SR04 to properly detect it. The 15° cone of direction amounts to roughly an object area of 13% of the distance it might be. Its cone of detection is roughly 15° - meaning that it can accurately predict distances at short range, but at longer ranges it has difficulty discerning small area objects from larger area objects. Ento veja a seguir como usar Servo Motor com Arduino. One final thing to note is that the HC-SR04 does not produce perfect points in space. Neste tutorial iremos mostrar os primeiros passos com esse servo e como fazer um programa em Arduino para controle do servo. Click Upload button on Arduino IDE to upload code to Arduino. Copy the above code and open with Arduino IDE. Click Install button to install keypad library. Search keypad, then find the keypad library by Mark Stanley, Alexander Brevig. On Arduino IDE, Go to Tools Manage Libraries. close( 'all' ) print( 'Keyboard Interrupt' ) break Open Arduino IDE, select the right board and port. flush_events() # flush for next plot else : if data = 'Radar Start' : # stard word on Arduno start_word = True # wait for Arduino to output start word print( 'Radar Starting.' ) else : continue except KeyboardInterrupt : plt. replace( ' \n ', '' ) if start_word: vals = if len(vals) r_max: dist = 0.0 # measuring more than r_max, it's likely inaccurate dists = dist if angle % 5 = 0 : # update every 5 degrees pols. decode( 'utf-8' ) # decode data to utf-8 data = (decoded_bytes. readline() # read Arduino serial data decoded_bytes = ser_bytes. pack_configure() # show toolbar if close_bool: # closes radar window plt. show() # inifinite loop, constantly updating the # 180deg radar with incoming Arduino data # start_word,stop_bool,close_bool = False, False, False while True : try : if stop_bool: # stops program fig. add_axes() close_but = Button(close_ax, 'Close Plot' ,color = '#FCFCFC' ,hovercolor = 'w' ) close_but. close( 'all' ) stop_bool = 1 close_bool = 1 close_ax = fig.

on_clicked(stop_event) # button to close window def close_event (event): global stop_bool,close_bool if stop_bool: plt. add_axes() pstop = Button(prog_stop_ax, 'Stop Program' ,color = '#FCFCFC' ,hovercolor = 'w' ) pstop. bbox) # background to keep during loop # button event to stop program # def stop_event (event): global stop_bool stop_bool = 1 prog_stop_ax = fig. draw() # draw before loop axbackground = fig. Once it reaches 180 degree, it is programmed to rotate back to 10 degree step by step. In the first for loop, motor shaft is rotated from 10 degrees to 180 degrees step by step with a time delay of 15 milliseconds. pack_forget() # remove toolbar for clean presentation fig. The position of the shaft is kept at 10 degrees by default and the Servo PWM input is connected to the 3rd pin of the Arduino Uno. Servo_1.attach(servo_pin) // start servo controlįor (pos = 0 pos = 0 pos -= 1) '.

* * Created by ArduinoGetStarted.Servo servo_1 // servo controller (multiple can exist) int trig = 4 // trig pin for HC-SR04 int echo = 5 // echo pin for HC-SR04 int servo_pin = 3 // PWM pin for servo control int pos = 0 // servo starting position float duration,distance
