GithubHelp home page GithubHelp logo

approach-sensor-in-arduino-with-c's Introduction

approach-sensor-in-arduino-with-C

this programming was developed to rotate on an UNO arduino plate, which is connected to electronic devices that form an ultrasonic prosuming sensor.

how the programming was made

#include <Ultrasonic.h>

include ultrasonic library

#define pino_trigger 4
#define pino_echo 5

sets the value of the pins

const int ledVerde = 13;
const int ledAmarelo = 12;
const int ledVermelho = 11;
const int buzzer = 9;

sets the values of the LEDs and buzzer

float seno;
int frequencia;

defines the scope of the variables

void setup()
{
  Serial.begin(9600);
  Serial.println("Lendo dados do sensor...");
   
  //Definindo pinos digitais
  pinMode(ledVerde,OUTPUT); //13 como de saída.
  pinMode(ledAmarelo,OUTPUT); //12 como de saída.
  pinMode(ledVermelho,OUTPUT); //11 como de saída.
  pinMode(buzzer, OUTPUT); 
}

defines the exits of the pins

void loop()
{
  //Le as informacoes do sensor, em cm e pol
  float cmMsec, inMsec;
  long microsec = ultrasonic.timing();
  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
  inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
  
  //Exibe informacoes no serial monitor
  Serial.print("Distancia em cm: ");
  Serial.print(cmMsec);
  Serial.print(" - Distancia em polegadas: ");
  Serial.println(inMsec);
  delay(100);

  //Apagando todos os leds
  digitalWrite(ledVerde,LOW);  
  digitalWrite(ledAmarelo,LOW);
  digitalWrite(ledVermelho,LOW);

  pinMode(buzzer, OUTPUT); 
  
  if(cmMsec > 20){
    digitalWrite(ledVerde,HIGH);
    noTone(buzzer);
  }
  if(cmMsec > 10 and cmMsec < 20){
    digitalWrite(ledAmarelo,HIGH);
    noTone(buzzer);
  }
  if(cmMsec < 10){
    digitalWrite(ledVermelho,HIGH);
    tocaBuzzer();
  }
}

defines the logic of the operation of the alarm, such as approximation and connection of the buzzer. It also sets the buzzer speed and sensor delay.

void tocaBuzzer(){
 for(int x=0;x<180;x++){
  seno=(sin(x*3.1416/180));
  frequencia = 2000+(int(seno*1000));
  tone(buzzer,frequencia);
  delay(2);
}
}

defines the operation of the buzzer.

sensor image:

sensor tinkercat:

approach-sensor-in-arduino-with-c's People

Contributors

leonardo8787 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.