Hi, I am a beginner in arduino. I am doing a project which serves to dispense alcohol and measure body temperature. To dispense the alcohol I use an ultrasonic sensor which activates a servomotor that makes the alcohol fall. And for the temperature I use an mlx90614 sensor and the result is seen on an LCD display.
The problem is that when you put your hand on the ultrasonic sensor, the servomotor is activated, but at the same time for some reason, the 16x2 display blinks once, when the display is not linked to it.
I tried to see the connections, but I can't solve it, and in the code, the ultrasonic sensor, the servo and the screen are not linked.
What is the problem?
LarryD
October 24, 2021, 2:09am
2
Let's see your wiring and sketch.
1 Like
Power the servos from an external supply.
i wired the servo that way because i use a mg966r servo
unsigned long previousMicrosTriac1 = 0;
unsigned long previousMicrosTriac2 = 0;
const long intervalTriac1 = 5000;
const long intervalTriac2 = 5;
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MLX90614.h>
int BUZZER = 9;
int cm=0;
long distancia,duracion; //long valores decimales
int posicion1=120;
int posicion2=180;
Servo miServo; //al pin 13
#define Pecho 6 //Echo al pin 6
#define Ptrig 7 //Trig pin 7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Instanciar objeto
Adafruit_MLX90614 termometroIR = Adafruit_MLX90614();
void setup() {
pinMode(BUZZER, OUTPUT);
pinMode(Pecho, INPUT); //define el pin 6 como entrada (echo)
pinMode(Ptrig, OUTPUT); //define el pin 7 como salida (triger)
miServo.attach (10); //define el pin 13 como salida para mover el servo enviando la señal de distancia menor a 10
// Iniciar comunicación serie
Serial.begin(9600);
lcd.begin(16, 2);
// Iniciar termómetro infrarrojo con Arduino
termometroIR.begin();
}
void loop() {
unsigned currentMicros = micros();
if(currentMicros - previousMicrosTriac1 >= intervalTriac1){
previousMicrosTriac1 = currentMicros;
digitalWrite (Ptrig,LOW);
delayMicroseconds(2);
digitalWrite(Ptrig,HIGH); //genera el pulso de triger de 10ms
delayMicroseconds(10);
digitalWrite(Ptrig,LOW);
duracion= pulseIn(Pecho, HIGH); //con esto sabemos cuanto tiempo estuvo en alto(HIGH)
distancia =(duracion/2)/29; // calcula la distancia en centimetros
if (distancia <=10 && distancia >=1){
miServo.write(posicion1); //mueve el servo si la distancia es menor a 10cm
Serial.println("Obstaculo"); //envia la palabra "obstaculo" por el puerto serial
}
else
{
miServo.write(posicion2);
}
}
if(currentMicros - previousMicrosTriac2 >= intervalTriac2){
previousMicrosTriac2 = currentMicros;
// Obtener temperaturas grados Celsius
float temperaturaObjeto = termometroIR.readObjectTempC();
lcd.setCursor(3,0);
lcd.print("Tomese la");
lcd.setCursor(2,1);
lcd.print("temperatura");
if (temperaturaObjeto>30){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temperatura: ");
lcd.setCursor(0,1);
lcd.print(temperaturaObjeto);
delay(1000);
lcd.clear();
if(temperaturaObjeto>=37.5){
tone(BUZZER,2000);
}
else{
noTone(BUZZER);
}
}
}
}
system
Closed
April 22, 2022, 2:47pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.