Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

Pomoć oko programiranja Arduina

Pomoć oko programiranja Arduina 16.02.2021. u 01:38 · pre 70 meseci #1
Pozdrav, treba mi pomoc oko kodiranja arduina, da li neko moze da mi pomogne ?
Re: Pomoć oko programiranja Arduina 16.02.2021. u 09:28 · pre 70 meseci #3
Počneš nešto da radiš i kada ti zapne naćiće se neko da ti pomogne.
Potpis
--
Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.
Re: Pomoć oko programiranja Arduina 16.02.2021. u 11:32 · pre 70 meseci #4
E ovako, pravim projekat parking senzora za garazu, plan mi je da stavim po 3 ili 4 ultrasonic senzora sa obe strane, znaci da se automobili parkiraju jedan pored drugog. Trenutno imam 2 senzora i releje s kojima kontrolisem belu led traku. Kasnije cu ubaciti RGB traku i to znam kako da iskodiram. Interesuje me kako da stopiram loop ili releje koji se nalaze na jednoj strani? A da se pokrene opet kad krene auto da se pomera. Evo mog koda:

//----------------------------------------------------------------------------------------------------------------------
#define trigPin1 9 //pin number 9
#define echoPin1 8 // we'll use this pin to read the signal from the first sensor
#define Relay1 6 // I/O digital ( we will use pin 6 to command an Relay (on/off))
//----------------------------------------------------------------------------------------------------------------------

//define the pins that we will use for the second ultrasonic sensor
//----------------------------------------------------------------------------------------------------------------------
#define trigPin2 10
#define echoPin2 11
#define Relay2 7
//----------------------------------------------------------------------------------------------------------------------

//used variables
//----------------------------------------------------------------------------------------------------------------------
long duration, distance, UltraSensor1, UltraSensor2; //we'll use these variable to store and generate data

char data;
String SerialData="";
//----------------------------------------------------------------------------------------------------------------------

//Make the setup of your pins
//----------------------------------------------------------------------------------------------------------------------
void setup()
{// START SETUP FUNCTION
Serial.begin (9600); // we will use the serial data transmission to display the distance value on the serial monitor

// setup pins first sensor
pinMode(trigPin1, OUTPUT); // from where we will transmit the ultrasonic wave
pinMode(echoPin1, INPUT); //from where we will read the reflected wave
pinMode(Relay1, OUTPUT); // from where we will control the LED

//setup pins second sensor
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(Relay2, OUTPUT);


//inisialize LED status

}// END SETUP FUNCTION


//write the code in the loop function
void loop()
{
// START THE LOOP FUNCTION
SonarSensor(trigPin1, echoPin1); // look bellow to find the difinition of the SonarSensor function
UltraSensor1 = distance; // store the distance in the first variable
SonarSensor(trigPin2,echoPin2); // call the SonarSensor function again with the second sensor pins
UltraSensor2 = distance; // store the new distance in the second variable

while(Serial.available())
{
delay(10);
data=Serial.read();
SerialData+=data;
}

if(SerialData=="display distance")
{
// display the distances on the serial monitor for the first sensor
//----------------------------------------------------------------------------------------------------------------------
Serial.print("distance measured by the first sensor: ");
Serial.print(UltraSensor1);
Serial.println(" cm");
//----------------------------------------------------------------------------------------------------------------------

//display the distance on the serial monitor for the second sensor
//----------------------------------------------------------------------------------------------------------------------
Serial.print("distance measured by the second sensor: ");
Serial.print(UltraSensor2);
Serial.println(" cm");
Serial.println("---------------------------------------------------------------------------------------------------------");
//----------------------------------------------------------------------------------------------------------------------
}

SerialData="";
// make condition to control the LEDs
if(UltraSensor1 <=15)// if distance is less than 15 Cm turn the LED ON
{
digitalWrite(Relay1,LOW);
}
else // else turn the LED OFF
{
digitalWrite(Relay1,HIGH);
}

// do the same thing for second sensor
if(UltraSensor2 <=15)
{
digitalWrite(Relay2,LOW);
}
else
{
digitalWrite(Relay2,HIGH);
}
if(UltraSensor1 <=5)// Blink led
{
delay(200);
digitalWrite(Relay1,HIGH);
delay(200);

}

if(UltraSensor2 <=5) //Blink led
{
delay(200);
digitalWrite(Relay2,HIGH);
delay(200);
}

}//END LOOP FUNTION

// SonarSensor function used to generate and read the ultrasonic wave
void SonarSensor(int trigPinSensor,int echoPinSensor)//it takes the trigPIN and the echoPIN
{
//START SonarSensor FUNCTION
//generate the ultrasonic wave
//----------------------------------------------------------------------------------------------------------------------
digitalWrite(trigPinSensor, LOW);// put trigpin LOW
delayMicroseconds(2);// wait 2 microseconds
digitalWrite(trigPinSensor, HIGH);// switch trigpin HIGH
delayMicroseconds(10); // wait 10 microseconds
digitalWrite(trigPinSensor, LOW);// turn it LOW again
//----------------------------------------------------------------------------------------------------------------------

//read the distance
//----------------------------------------------------------------------------------------------------------------------
duration = pulseIn(echoPinSensor, HIGH);//pulseIn funtion will return the time on how much the configured pin remain the level HIGH or LOW; in this case it will return how much time echoPinSensor stay HIGH
distance= (duration/2) / 29.1; // first we have to divide the duration by two
}// END SonarSensor FUNCTION
Re: Pomoć oko programiranja Arduina 16.02.2021. u 21:12 · pre 70 meseci #5
I jesi li probao da prepraviš išta u ovom pronađenom programu?
Potpis
--
Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.
Re: Pomoć oko programiranja Arduina 16.02.2021. u 21:26 · pre 70 meseci #6
Već sam prepravio i dodao ovo za blinkanje kad je distanca manja od 5, ali nemam ideju kako da stopiram releje kad se distanca ne menja.
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme