Hi, we're making a vending machine. Using Arduino, we want it to do this: when motion and light are detected, a servomotor is activated, which moves the lever and sounds a buzzer to indicate that the container has been reset (filled), and at the same time, an LED is turned on.
(We have the code, but we don't know how to connect it efficiently and make it work;-
We're desperate for help or advice. We should do it for you. Thank you for your attention. sob:
``#include <Servo.h>´´
Servo servo1;
int angulo1 = 0 ;
int TRIG = 10;
int ECO=9;
int DURACION;
int DISTANCIA;
//---------------------------------------------------------------------------------
const unsigned int PIN_ZUM = 9;
const int nTonos = 10;
const int tonos[] = {261, 277, 294, 311 ,330, 349,370, 392, 370,415,440, 466,494};
//[nota:buscar , un tono cancion pendiente :D]
//----------------------------------------------------------------------------------
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
//<em><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>|
pinMode(PIN_ZUM, OUTPUT);
//</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></em>|
pinMode(TRIG,OUTPUT);
pinMode(ECO,INPUT);
servo1.attach(9) ;
Serial.begin(9600);
}
//_________________________________________________________________________________
//si el sensor ultrasonico y de luz detectan luz y proximidad , se ensendera el servo
//y cundo de una vuelta comple se detendra el servo y se ensendera un buzer y un led
//(si no se cumplen las condiciones de luz o movimiento al mismo tiempo se detendra el led y buzer)
//---------------------------------------------------------------------------------
void loop() {
digitalWrite (TRIG,HIGH);
delay(1);
digitalWrite (TRIG,LOW);
DURACION = pulseIn(ECO,HIGH);
DISTANCIA = DURACION /58.2;
Serial.print("Detectado");
delay(200);
//***FOTORESISTENCIA)***_____________________________
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
//------------------------------------------------------------
if (LED_BUILTIN >0 && DISTANCIA > 0){
//***************SERVOMOTOR***************_______________
{
for(angulo1 = 0; angulo1 <= 180; angulo1 += 1)
{
servo1.write(angulo1);
delay(25);
}
for(angulo1 = 360; angulo1 >=0; angulo1 -=1 )
{
servo1.write( angulo1 );
You also don’t want to use pulseIn() as it also blocks the code from doing anything else until it’s done. You should look for an alternative here in the forum as many others have had similar issues.