top of page
Radar.png
speed-camera-g15d4893ba_640.png

RADAR
com ESP32 OU ARDUINO

>mATERIAL

>Arduíno/ESP32;
>Caixa de cartão ou de outro material;
>Cabo USB;
>Jumpers;
>LCD 16x2;
>Botão pushbutton (2);
>Modulo I2C para LCD;
>Breadboard;
>Telemóvel (Para caso usar ESP32);

>Montagem

Captura de ecrã 2022-02-08 112148.png

>Código(Arduino)

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
float tempo = 0;
int botaoA = 0;
int botaoB = 0;
float velocidade = 0;
void setup() {
  lcd.init();
  lcd.noBacklight();
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);

}

void loop() {
  if ((digitalRead(2) == 0) && (digitalRead(3) == 1)) {
  botaoA = 1;
  lcd.backlight();
  }
  if ((digitalRead(2) == 1) && (digitalRead(3) == 0)) {
  botaoB = 1;
  lcd.backlight();
  }
  if ((botaoA == 1) && (botaoB == 1)) {
  delay(6000);
  lcd.noBacklight();
  tempo = 0;
  botaoA = 0;
  botaoB = 0;
  }
  if (((botaoA == 1) && (botaoB == 0)) || ((botaoA == 0) && (botaoB == 1))) {
  tempo = tempo + 0.1;
  velocidade = 0.16 / (tempo);   //0.16 = distancia de um lado ao outro
  lcd.setCursor(0, 0);
  lcd.print("Tempo:");
  lcd.setCursor(6, 0);
  lcd.print(tempo);
  lcd.setCursor(0, 1);
  lcd.print("velocidade:");
  lcd.setCursor(13, 1);
  lcd.print(velocidade);
  delay(60);
  }
}

>cÓDIGO (esp32)

#include "BluetoothSerial.h"
#include <LiquidCrystal_I2C.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
LiquidCrystal_I2C lcd(0x27, 16, 2);
float tempo = 0;
int botaoA = 0;
int botaoB = 0;
float velocidade = 0;
void setup() {
  SerialBT.begin("Radar");
  lcd.init();
  lcd.noBacklight();
  pinMode(4, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);

}

void loop() {
  if ((digitalRead(4) == 0) && (digitalRead(15) == 1)) {
   botaoA = 1;
   lcd.backlight();
  }
  if ((digitalRead(4) == 1) && (digitalRead(15) == 0)) {
   botaoB = 1;
   lcd.backlight();
  }
  if ((botaoA == 1) && (botaoB == 1)) {
   if (velocidade > 0.3) {
   SerialBT.print('A');
   }
   delay(6000);
   lcd.noBacklight();
   tempo = 0;
   botaoA = 0;
   botaoB = 0;
  }
  if (((botaoA == 1) && (botaoB == 0)) || ((botaoA == 0) && (botaoB == 1))) {
   tempo = tempo + 0.1;
   velocidade = 0.16 / (tempo);
   lcd.setCursor(0, 0);
   lcd.print("Tempo:");
   lcd.setCursor(6, 0);
   lcd.print(tempo);
   lcd.setCursor(0, 1);
   lcd.print("velocidade:");
   lcd.setCursor(13, 1);
   lcd.print(velocidade);
   delay(60);
  }
}

Produto Final

© 2023 por Arduino Power Max

bottom of page