Adán Edmundo Perez
Published © GPL3+

Robotic Prosthesis

Universal access prosthesis

IntermediateWork in progress1,073
Robotic Prosthesis

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
SparkFun Electret Microphone Breakout
SparkFun Electret Microphone Breakout
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Webcam, Logitech® HD Pro
Webcam, Logitech® HD Pro
×2
Arduino UNO
Arduino UNO
×3
micro linnear actuator
×10
IC L293D
×2
gearmotor 12VCC
×4

Software apps and online services

Arduino IDE
Arduino IDE
Processing
The Processing Foundation Processing
Python 38-32

Hand tools and fabrication machines

Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter
Soldering iron (generic)
Soldering iron (generic)
Drill, Screwdriver
Drill, Screwdriver
Multitool, Screwdriver
Multitool, Screwdriver
metal cutter cutting shears
inverter welding plant

Story

Read more

Code

Radar Arduino

Arduino
The connections are very simple, the ultrasonic trigger is connected to pin 10 and echo to pin 11, the servo signal to pin 6, negative to gnd of arduino, and in my case, to protect it, I connected the current to a power supply externally regulated to 5v., optionally you can add a led with a 330 ohm resistor connected to the anode towards pin 8, which will flash at different frequencies according to the variation in distance or absence of the object.
/*
Original code of Dejan Nedelkovski 
Modified by adan9233
*/

// Imports Servo library
#include <Servo.h>. 

// Define Trig and Echo ultrasonic sensor pins
const int trigPin = 10;
const int echoPin = 11;
// Variables of duration and distance 
long duration;
int distance;

Servo myServo; // Creates myServo object

void setup() {
  pinMode(trigPin, OUTPUT); // Set pin trigPin as Output
  pinMode(echoPin, INPUT); // Set pin echoPin as Input
  Serial.begin(9600);
  myServo.attach(6); // Define Servo motor pin  
  
  pinMode(8, OUTPUT); //Set pin 8 as output led
}
void loop() {
  // Rotate servo of 15 at 165 degrees
  for(int i=50;i<=130;i++){  
  myServo.write(i);
  delay(25);
  distance = calculateDistance();//  Call this function to calculate distance for each degree
  Serial.print(i); // Sends actual inclination degree to serial port 
  Serial.print(","); // Sends a , as separation character
  Serial.print(distance); // Sends distance to serial
  Serial.print("."); // Sends a . like end of command 

   if(distance<40){ // If distance is less than 20cm the noise will be more acute than if distance it's between >20 and <40 
   tone(8, 500, 100); 
    delay(150);
    myServo.write(i);
  delay(0);
    
  }
   if(distance>40 && distance<80){
    
    delay(250);
    tone(8, 200, 100);
    myServo.write(i);
  delay(0);
     
  }
  else if(distance>80 && distance<120){
  tone(8, 200, 100);  
    delay(300);
  myServo.write(i);
  delay(0);  
  }
}
  //Repeat previous lines and makes the servo run of 15 at 165 degrees
  for(int i=140;i>60;i--){  
  myServo.write(i);
  delay(25);
  distance = calculateDistance();
  
  Serial.print(i);
  Serial.print(",");
  Serial.print(distance);
  Serial.print(".");
   
   if(distance<40){ // If the distance is less than 20cm the noise will be more acute than if the distance is between more than 20 and less than 40
   tone(8, 500, 100); 
    delay(150);
    myServo.write(i);
  delay(0);
  }
   if(distance>40 && distance<100){
    tone(8, 200, 100);
    delay(250);
    myServo.write(i);
  delay(0);
  }
  else if(distance>80 && distance<120){
   tone(8, 200, 100); 
    delay(300);
    myServo.write(i);
  delay(0);
   
  }
  }
}


// Function that calculates the real distance with the data returned by the ultrasonic sensor
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;
}

Radar Processing Object Detector Voice Warning

Processing
This code provides a graphical interface to the operation of the ultrasound transducer, distance data, angle and warnings about the proximity of an object, if the object is at a distance between 300 and 40 cm, a voice in mp3 format says: "An object detected ", which appears in the graphic interface, if an object is detected within 40 cm, the voice warns:" A near object detected ", showing the message on the screen.
I recommend using the latest version of Processing, adjust the resolution of your screen to that of the sketch, use recordings in mp3 format with a duration of a maximum of 1500 milliseconds so as not to overload the warnings one over the other, the import of the necessary libraries and the creation of the OCRAExtended font (it caused me a lot of problems when it started).
You should also choose a background image of the same size for the application so that it does not generate an error message when it is run.
/*   Arduino Warning Detector
 *
 *   
 *  Just change the screen values in the size() function,
 *  with your screen resolution.
 *  Based in Arduino Radar Project    
 *  by Dejan Nedelkovski. 
 *  
 *  Modified by adan9233.
 */

import processing.serial.*; // imports library for serial communication
import java.awt.event.KeyEvent; // imports library for reading the data from the serial port
import java.io.IOException;
import ddf.minim.*;
Minim soundengine;
AudioSample sonido1;
AudioSample sonido2;

PImage img1;

Serial myPort; // defines Object Serial
// defubes variables
String angle="";
String distance="";
String data="";
String noObject;
float pixsDistance;
int iAngle, iDistance;
int index1=0;
int index2=0;
PFont orcFont;

void setup() {

  size (1366, 768); // ***CHANGE THIS TO YOUR SCREEN RESOLUTION***
  img1 = loadImage("IMG_20200603_191421.jpg");

  myPort = new Serial(this, "COM3", 9600); // starts the serial communication
  myPort.bufferUntil('.'); // reads the data from the serial port up to the character '.'. So actually it reads this: angle,distance.
  orcFont = loadFont("OCRAExtended-30.vlw");
  soundengine = new Minim(this);
  sonido2 = soundengine.loadSample("warning_anobjectdetected.mp3", 1024);
  
  sonido1 = soundengine.loadSample("a_near_object_detected.mp3", 1024);
}


void draw() {

  
  background (img1);
  for (int i=0; i<20; i++) 
    textFont(orcFont);
  
  noStroke();
  fill(0, 4); 
  rect(0, 0, width, height-height*0.065); 

  


  drawText();
}
void mousePressed() {
  exit(); 
}

void serialEvent (Serial myPort) { // starts reading data from the Serial Port
  // reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
  data = myPort.readStringUntil('.');
  data = data.substring(0, data.length()-1);

  index1 = data.indexOf(","); // find the character ',' and puts it into the variable "index1"
  angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port
  distance= data.substring(index1+1, data.length()); // read the data from position "index1" to the end of the data pr thats the value of the distance

  // converts the String variables into Integer
  iAngle = int(angle);
  iDistance = int(distance);
}




void drawText() { // draws the texts on the screen

  pushMatrix();
  if (iDistance<40) {
    noObject = "Near Object Detected";
    
    sonido1.trigger();
    delay (3000);
    sonido2.stop();
   
    popMatrix();}
else if (iDistance>40==iDistance<300) {
  noObject = "Detected";
  sonido2.trigger();
  delay (3000);
  sonido1.stop();
  
  popMatrix();}
else {
  noObject = "No Object";
  
  delay (3000);
  sonido1.stop();
  sonido2.stop();
  popMatrix();
  
} 



fill(#FFFFFF); // text



textSize(30);
text("Object: " + noObject, width-width*0.7, height-height*0.5000);
text("Angle: " + iAngle +"", width-width*0.88, height-height*0.0999);
fill(#FFFFFF);

text("Distance: ", width-width*0.46, height-height*0.0999);
fill(#FFFFFF);
if (iDistance<100) {
  text("        " + iDistance +" cm", width-width*0.425, height-height*0.0999);
  resetMatrix();
  // text
}
} 

Python 3.8 A.I.

Python
System of voice recognition that initialize serial communication with external devices, yes, this no have all of this, seems only a chatbot, but the magic is after all!!!
    #!/usr/bin/env python2
# -*- coding: utf-8 -*-

from AssistantGif_ui import *
from PyQt5.QtWidgets import QMainWindow,QApplication,QLabel
from PyQt5.Qt import QMovie
import speech_recognition as sr
import pyttsx3
import pyjokes
import datetime
import time
import sys #Importamos módulo sys
from PyQt5 import uic, QtWidgets #Importamos módulo uic y Qtwidgets

qtCreatorFile = "AssistantGif.ui" # Nombre del archivo UI aquí.

Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) #El modulo ui carga el archivo

class VentanaPrincipal(QtWidgets.QMainWindow, Ui_MainWindow): #Abrimos la ventana
    def __init__(self): #Constructor de la clase
        QtWidgets.QMainWindow.__init__(self) #Constructor
        Ui_MainWindow.__init__(self) #Constructor
        self.setupUi(self) # Método Constructor de la ventana
        self.I = QLabel(self)
        self.I.resize(450,500)
        self.movi = QMovie("original.gif")
        self.I.setMovie(self.movi)
        self.movi.start()

        the_line = QtWidgets.QLineEdit(self) #  Open a box to write
        the_line.move(550, 140) #  Changes the location of the box
        the_line.resize(200,25)
        the_line.setStyleSheet("color: rgb(255, 255, 255);")


        
        #Aquí irá nuestro código funcional
listener = sr.Recognizer()
engine = pyttsx3.init()
rate = engine.getProperty('rate')
engine.setProperty("rate", 130)
volume = engine.getProperty('volume')
engine.setProperty('volume', volume-0.4)
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
now = datetime.datetime.now()



def speak(audio):
    print('Assistant: ' + audio)
    engine.say(audio)
    engine.runAndWait()

def timeSett():
    currentH = int(datetime.datetime.now().hour)
    if currentH >= 0 and currentH < 12:
        speak('Good Morning!')

    if currentH >= 12 and currentH < 18:
        speak('Good Afternoon!')

    if currentH >= 18 and currentH != 0:
        speak('Good Evening!')

timeSett()

def talk(text):
    engine.say(text)
    engine.runAndWait()

def take_command():
    try:
        with sr.Microphone() as source:
            print('Listenning...')
            voice = listener.listen(source)
            global command  
            command = listener.recognize_google(voice, language='en-english')
            command = command.lower()
            if 'Assistant' in command:
                command = command.replace('Assistant','')
                print(command)

        if __name__ == "__main__":
            app =  QtWidgets.QApplication(sys.argv)
            window = VentanaPrincipal()
            window.show()
            app.exec_()

                
                
    except:
        pass
    return command

                            


def run_Assistant():
    command =  take_command()
    print('command')

    if 'what time is it' in command:
        print("Current date and time : ")
        print(now.strftime("The time is %H:%M"))
        speak(now.strftime("The time is %H:%M"))
        engine.runAndWait()
    elif 'goodbye' in command:
        print("Hasta la vista... Baby!")
        speak("Hastala vista...Baby!")         
        exit()
    elif 'what is my phone number' in command:
        print('xx xx xx xx xx is your phone number sir') 
        talk('xx xx xx xx xx is your phone number sir')
    elif 'tell me a joke' in command:
        talk(pyjokes.get_joke('en'))
    elif 'what time is it' in command:
        print("Current date and time : ")
        print(now.strftime("The time is %H:%M"))
        speak(now.strftime("The time is %H:%M"))
        engine.runAndWait()
    elif 'goodbye' in command:
        print("Hasta la vista... Baby!")
        speak("Hastala vista...Baby!")         
        exit()
    else:
        talk('just now im not ready for this')




while True:
    run_Assistant()

Ultrasonic-detector-and-voice-warning

Credits

Adán Edmundo Perez
1 project • 1 follower

Comments