Notifications
Clear all

Arduino KY-0008 Laser joystick controling robot drone flap

2 Posts
2 Users
1 Likes
571 Views
(@daviddbrown70)
Member
Joined: 2 years ago
Posts: 1
Topic starter  

April 10,2022

Hi,

I am just starting to learn Arduino coding and I visited many websites on the subject.

I want to control a robot drone , not with radio, but laser KY-008 using a joystick connected to Arduino R3 UNO with rx and tx pins.

Here is my code.I ran my code on the Arduino simulator and the error was 'val' was not declared in this scope. val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)

I tried to cope the error and did a search on the internet

I know I made mistakes,but if some one could give any suggestion,on my error, I would greatly appreciated

it.

Below is my code;

#include <Servo.h>
#define DETECT 2 //pin 2 input receiver
#define ACTION 8 //pin 8 action output
#define POTPIN 0 // analog pin used to connect the potentiometer
void setup()
{
Serial.begin(9600);//Begin Serial communication at a baudrate of 9600:
pinMode(DETECT,INPUT); //define detect input pin 2
pinMode(ACTION,OUTPUT); //define action output pin 8
}

void loop(){
int detected = digitalRead(DETECT);//read pin 2
if(detected==HIGH)//when laser bean detected value is high
{
Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
}

{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
delay(15); // waits for the servo to get there
}

delay(200);

}

Thank You,

DavidBrown70


   
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote