//This is a project that I am doing, I received help with the code but even so I keep getting errors that I cannot understand.
int SENSOR 1;
int SENSOR 2;
#define LED A // nivel de agua cargando (descarga corta)
#define LED B // nivel de agua listo para tirar
#define LED C // nivel de agua cargando (descarga larga)
#define LED D // nivel de agua listo para tirar
#include<Servo.h>
Servo servoMotor;
const int trigger = 9;
const int echo = 10;
int tiempo;
int distancia;
void setup() {
pinMode (LED A, OUTPUT)
pinMode (LED B, OUTPUT)
pinMode (LED C, OUTPUT)
pinMode (LED D, OUTPUT)
servoMotor.attach(8);
servoMotor.write(180);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
digitalWrite(trigger, LOW);
digitalWrite (LED A, LOW);
digitalWrite (LED B, LOW);
digitalWrite (LED C, LOW);
digitalWrite (LED D, LOW);
}
void loop() {
SENSOR 1 = analogRead (A0); // VERIFICA LECTURA DEL SENSOR 1
SENSOR 2 = analogRead (A1); // VERIFICA LECTUTA DEL SENSOR 2
digitalWrite (trigger, HIGH);
delay(10);
digitalWrite (trigger, LOW);
tiempo= pulseIn (echo, HIGH);
distancia = tiempo/59;
if (distancia < = 3 && distancia > = 11 && SENSOR 1 > = 200)
{
servoMotor.write(0);
delay(8000);
servoMotor.write(15);
delay(8000);
servoMotor.Write (0);
}
if (distancia < = 17 && distancia > = 25 && SENSOR 2 > = 200)
{
servoMotor.write(0);
delay(8000);
servoMotor.write(15);
delay(8000);
servoMotor.Write (0);
}
if (SENSOR 1 > 200 ) {
digitalWrite (LED B, HIGH); // Listo para descarga corta
digitalWrite (LED A, LOW); // cargando
}
else {
digitalWrite (LED B, LOW); //
digitalWrite (LED A, HIGH); //
}
delay (1000);
if (SENSOR 2 > 200 ) {
digitalWrite (LED D, HIGH); // Listo para descarga larga
digitalWrite (LED C, LOW); // cargando
}
else {
digitalWrite (LED D, LOW); //
digitalWrite (LED C, HIGH); //
}
delay (1000);
Do you have a question?
Complete code?
The compiler didn't like that, did it?
Why didn't you say that?
Thanks for using code tags, we appreciate it. Please edit your post, and move your question out of the code section, into the main message where people can read it.
It looks like you could add a little more detail, too.
Really, really LOL!
I rarely read comments in posted code now, because it just wastes time - they're so rarely updated or relevant.
This is a project that I am doing, I received help with the code but even so I keep getting errors that I cannot understand.
if (distancia < = 3 && distancia > = 11 && SENSOR 1 > = 200)
Please rethink this. You have your < and > mixed up, to start with. You did it twice.
Makes me wonder if you really want to do something when "Sensor 2" is actually greater than, instead.
I'm assuming you just left the final } off in your hasty cut-and-paste. Instead of doing that, in the IDE,
press ctrl-T to format your code properly, then press shift-ctrl-C to copy the ENTIRE code for insertion in a message box here. You'll find it automatically adds the code format if you do it that way.
Object names cannot contain spaces.
What are you doing there? You are not assigning pin numbers.
Here is your sketch with the obvious errors fixed. Mostly it was replacing spaces in names with underscores.
//This is a project that I am doing, I received help with the code but even so I keep getting errors that I cannot understand.
int SENSOR_1;
int SENSOR_2;
#define LED_A 2 // nivel de agua cargando (descarga corta)
#define LED_B 3 // nivel de agua listo para tirar
#define LED_C 4 // nivel de agua cargando (descarga larga)
#define LED_D 5 // nivel de agua listo para tirar
#include <Servo.h>
Servo servoMotor;
const int trigger = 9;
const int echo = 10;
int tiempo;
int distancia;
void setup()
{
pinMode(LED_A, OUTPUT);
pinMode(LED_B, OUTPUT);
pinMode(LED_C, OUTPUT);
pinMode(LED_D, OUTPUT);
servoMotor.attach(8);
servoMotor.write(180);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
digitalWrite(trigger, LOW);
digitalWrite(LED_A, LOW);
digitalWrite(LED_B, LOW);
digitalWrite(LED_C, LOW);
digitalWrite(LED_D, LOW);
}
void loop()
{
SENSOR_1 = analogRead(A0); // VERIFICA LECTURA DEL SENSOR 1
SENSOR_2 = analogRead(A1); // VERIFICA LECTUTA DEL SENSOR 2
digitalWrite(trigger, HIGH);
delay(10);
digitalWrite(trigger, LOW);
tiempo = pulseIn(echo, HIGH,30000);
distancia = tiempo / 59;
if (distancia >= 3 && distancia <= 11 && SENSOR_1 >= 200)
{
servoMotor.write(0);
delay(8000);
servoMotor.write(15);
delay(8000);
servoMotor.write(0);
}
if (distancia >= 17 && distancia <= 25 && SENSOR_2 >= 200)
{
servoMotor.write(0);
delay(8000);
servoMotor.write(15);
delay(8000);
servoMotor.write(0);
}
if (SENSOR_1 > 200)
{
digitalWrite(LED_B, HIGH); // Listo para descarga corta
digitalWrite(LED_A, LOW); // cargando
}
else
{
digitalWrite(LED_B, LOW); //
digitalWrite(LED_A, HIGH); //
}
delay(1000);
if (SENSOR_2 > 200)
{
digitalWrite(LED_D, HIGH); // Listo para descarga larga
digitalWrite(LED_C, LOW); // cargando
}
else
{
digitalWrite(LED_D, LOW); //
digitalWrite(LED_C, HIGH); //
}
delay(1000);
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.