Skip to content

Commit

Permalink
Adding notes to a new proyect with two servo motors and a joystick to…
Browse files Browse the repository at this point in the history
… handle them
  • Loading branch information
Dobliuw committed May 9, 2024
1 parent 1ddd4aa commit 7eb150c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 10 deletions.
20 changes: 10 additions & 10 deletions .obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"state": {
"type": "markdown",
"state": {
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/0. Initial programs and Basic.md",
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/5. Micro robot laser.md",
"mode": "source",
"source": false
}
Expand Down Expand Up @@ -98,7 +98,7 @@
"state": {
"type": "backlink",
"state": {
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/0. Initial programs and Basic.md",
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/5. Micro robot laser.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -115,7 +115,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/0. Initial programs and Basic.md",
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/5. Micro robot laser.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
Expand Down Expand Up @@ -150,7 +150,7 @@
"state": {
"type": "outline",
"state": {
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/0. Initial programs and Basic.md"
"file": "Notes/6. Hardware/Arduino/Arduino Proyects/5. Micro robot laser.md"
}
}
}
Expand All @@ -175,6 +175,11 @@
},
"active": "e88a780709720b6e",
"lastOpenFiles": [
"0. Images/servos_with_joystick.jpg",
"Notes/6. Hardware/Arduino/Arduino Proyects/3. Potenciometro con señal análogica a LED.md",
"Notes/6. Hardware/Arduino/Arduino Proyects/5. Micro robot laser.md",
"Notes/6. Hardware/Arduino/Arduino Proyects/4. Photoresistor con Servomotor.md",
"Notes/6. Hardware/Arduino/Arduino Proyects/0. Initial programs and Basic.md",
"0. Images/button_without_resistors_electronic.png",
"Notes/5. Tecnologías/Lenguajes y Tools/C/C.md",
"Notes/4. Cybersecurity/RedTeam/Pentesting/Redes/Pivoting/Pivoting.md",
Expand Down Expand Up @@ -207,10 +212,6 @@
"Notes/4. Cybersecurity/RedTeam/Pentesting/Sistemas/2. Fases Auditoria/3. Escalada de Privilegios/Linux/Python Library Hijacking.md",
"Notes/4. Cybersecurity/RedTeam/Pentesting/Sistemas/2. Fases Auditoria/3. Escalada de Privilegios/Linux/PATH Hijacking.md",
"Notes/4. Cybersecurity/RedTeam/Pentesting/Sistemas/2. Fases Auditoria/3. Escalada de Privilegios/Linux/Keepass master key crack .dmp.md",
"Notes/4. Cybersecurity/RedTeam/Pentesting/Sistemas/2. Fases Auditoria/3. Escalada de Privilegios/Linux/Explotación del Kernel.md",
"Notes/4. Cybersecurity/RedTeam/Pentesting/Sistemas/2. Fases Auditoria/3. Escalada de Privilegios/Linux/Docker Breakout.md",
"Notes/4. Cybersecurity/RedTeam/Pentesting/Sistemas/2. Fases Auditoria/3. Escalada de Privilegios/Linux/Abuso de privilegios de escritura en DB's.md",
"Notes/4. Cybersecurity/RedTeam/Pentesting/Sistemas/2. Fases Auditoria/3. Escalada de Privilegios/Linux/Abuso de privilegios a nivel de Sudoers.md",
"0. Images/pull_down_resistor_electronic.png",
"0. Images/pull_up_resistor_electronic.png",
"0. Images/acii_table.png",
Expand All @@ -219,7 +220,6 @@
"0. Images/semaforo_arduino_1.png",
"0. Images/led_connection_electronic.png",
"0. Images/intefaces_hardware_image.png",
"0. Images/usb_conector_image.png",
"0. Images/usb_interface_image.png"
"0. Images/usb_conector_image.png"
]
}
Binary file added 0. Images/servos_with_joystick.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions Notes/6. Hardware/Arduino/Arduino Proyects/5. Micro robot laser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Componentes necesarios

- Arduino (Cualquier modelo compatible).
- x2 Servomotor.
- Análogico de joystick.
- Cables jumpers, macho macho y macho hembra (en este caso puede variar la cantidad de cables a utilizar dependiendo del cuidado al llevar a cabo en el circuito).

----
# Código desarrollado

El proyecto consiste en realizar la configuración de un joystick para posteriormente hacer uso de dos servomotres enlazados entre si para poder controlar un servomotor cunado el joystick se mueva en el eje X y otro servomotor para cuando el joystick se mueva en el eje Y, de esta manera lograriamos un completo rango de movimiento con un "brazo robot" (Dos servomotores enlazados) que en la puntan podrían tener un lazer a gusto.

```C
#include <Servo.h>

# Used pines
int joystickXPin = A0;
int joystickYPin = A1;
int joystickSwPin = 2;
int servoXPin = 12;
int servoYPin = 13;

# Vars to analog values from joystick (X and Y) and vars to save the angles for servos
float joystickXVal, joystickYVal, servoXAngle, servoYAngle;
int joystickSwVal;

# Declare the two servos
Servo ServoX;
Servo ServoY;

# Print the joystick movements
void printJoystickValues(){
Serial.print("X: ");
Serial.print(joystickXVal);
Serial.print(" Y: ");
Serial.print(joystickYVal);
Serial.print(" SW: ");
Serial.println(joystickSwVal);
delay(200);
}

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(joystickXPin, INPUT);
pinMode(joystickYPin, INPUT);
pinMode(joystickSwPin, INPUT);
# Set de joystick swtich to 1 to get 0 wen is pressed.
digitalWrite(joystickSwPin, HIGH);
# Attach the servo pines to servos
ServoX.attach(servoXPin);
ServoY.attach(servoYPin);
}

void loop() {
// put your main code here, to run repeatedly:
joystickXVal = analogRead(joystickXPin);
joystickYVal = analogRead(joystickYPin);
joystickSwVal = analogRead(joystickSwPin);

printJoystickValues();

# Make a logic to get de 180° possible from 1023 analog values from joystick (X and Y)
servoXAngle = (180./1023.) * joystickXVal;
servoYAngle = (180./1023.) * joystickYVal;

# Move the servos to calculated angle
ServoX.write(servoXAngle);
ServoY.write(servoYAngle);
}

```
----
# Configuración electrónica desarrollada
![[servos_with_joystick.jpg|1200]]

0 comments on commit 7eb150c

Please sign in to comment.