[ Dzoni28 @ 16.02.2021. 00:38 ] @
Pozdrav, treba mi pomoc oko kodiranja arduina, da li neko moze da mi pomogne ? |
[ Dzoni28 @ 16.02.2021. 00:38 ] @
[ SASA M. @ 16.02.2021. 08:02 ] @
Verovatno ce ti neko pomoći ako budeš napisao šta te muči.
![]() [ ZAS011 @ 16.02.2021. 08:28 ] @
Počneš nešto da radiš i kada ti zapne naćiće se neko da ti pomogne.
[ Dzoni28 @ 16.02.2021. 10:32 ] @
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 [ ZAS011 @ 16.02.2021. 20:12 ] @
I jesi li probao da prepraviš išta u ovom pronađenom programu?
[ Dzoni28 @ 16.02.2021. 20:26 ] @
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.
Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|