You are on page 1of 7

#include <Servo.

h>

Servo myservo;

int pos = 0;

// Variable donde se almacena el valor del LDR

int sensor=A5; //sensor de luz LDR

int sensor1=A4; //sensor de presion

int sensor2= A3;

float valorLDR; //Variable para el sensor de luz

float valorPress; //Variable para el sensor de presion

float valorAlimento;

int LEDpin= 13;//Señal presencia pollo

int LEDpeso= 12;//Señal termino de alimento

int cont=0;

void setup()

Serial.begin(9600);

pinMode(LEDpin,OUTPUT);

pinMode(LEDpeso,OUTPUT);

myservo.attach(9);

cont=0;

void loop()

valorLDR=analogRead(sensor);

valorPress=analogRead(sensor1);
valorAlimento=analogRead(sensor2);

//para detectar presencia del pollo

if (valorLDR>=500){

digitalWrite(LEDpin,HIGH);

cont=0;

else{

digitalWrite(LEDpin,LOW);

//Sensor de alimento

if (valorAlimento>=500){

digitalWrite(LEDpeso,LOW);

else{

digitalWrite(LEDpeso,HIGH);

//control de dosificacion de alimento

if ((valorPress>0)&&(valorPress<=20)&&(cont=0)){

cont=cont+1;

for (pos = 0; pos <= 90; pos += 1) {

myservo.write(pos);

delay(15); // waits 15ms for the servo to reach the position

delay(2000);

for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'


delay(15); // waits 15ms for the servo to reach the position

if ((valorPress>=21)&&(valorPress<=40)&&(cont=0)){

cont=cont+1;

for (pos = 0; pos <= 90; pos += 1) {

myservo.write(pos);

delay(15); // waits 15ms for the servo to reach the position

delay(4000);

for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(15); // waits 15ms for the servo to reach the position

if ((valorPress>=41)&&(valorPress<=60)&&(cont=0)){

cont=cont+1;

for (pos = 0; pos <= 90; pos += 1) {

myservo.write(pos);

delay(15); // waits 15ms for the servo to reach the position

delay(8000);

for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(15); // waits 15ms for the servo to reach the position

Serial.println(valorPress);

delay(200);
}
#include <Servo.h>

Servo myservo;

int pos = 0;

// Variable donde se almacena el valor del LDR

int sensor=A5; //sensor de luz LDR

int sensor1=A4; //sensor de presion

float valorLDR; //Variable para el sensor de luz

float valorPress; //Variable para el sensor de presion

int LEDpin= 13;//Señal presencia pollo

int LEDpeso= 12;//Señal termino de alimento

int cont=0;

void setup()

Serial.begin(9600);

pinMode(LEDpin,OUTPUT);

pinMode(LEDpeso,OUTPUT);

myservo.attach(9);

cont=0;

void loop()

valorLDR=analogRead(sensor);

valorPress=analogRead(sensor1);

//para detectar presencia del pollo

if (valorLDR>=500){
digitalWrite(LEDpin,HIGH);

cont=0;

else{

digitalWrite(LEDpin,LOW);

//Sensor de peso

if (valorPress>=500){

digitalWrite(LEDpin,HIGH);

cont=0;

else{

digitalWrite(LEDpin,LOW);

//control de dosificacion de alimento

if ((valorPress>=0)&&(valorPress<=300)&&(cont=0)){

cont=cont+1;

for (pos = 0; pos <= 90; pos += 1) {

myservo.write(pos);

delay(15); // waits 15ms for the servo to reach the position

delay(2000);

for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(15); // waits 15ms for the servo to reach the position

if ((valorPress>=301)&&(valorPress<=700)&&(cont=0)){
cont=cont+1;

for (pos = 0; pos <= 90; pos += 1) {

myservo.write(pos);

delay(15); // waits 15ms for the servo to reach the position

delay(4000);

for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(15); // waits 15ms for the servo to reach the position

if ((valorPress>=701)&&(valorPress<=1000)&&(cont=0)){

cont=cont+1;

for (pos = 0; pos <= 90; pos += 1) {

myservo.write(pos);

delay(15); // waits 15ms for the servo to reach the position

delay(8000);

for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(15); // waits 15ms for the servo to reach the position

Serial.println(valorLDR);

delay(200);

You might also like