Go Down

Topic: Perguntas de iniciante (Read 5836 times) previous topic - next topic

bubulindo

Será que o protocolo que estás a usar não consegue controlar mais de 120 LED's devido às temporizações?
This... is a hobby.

Danilo_Americo

como fazer para uma porta do arduino responder sempre que uma determinada porta estiver alta?

Fabio_Costa

Hi, I am a beginner in the arduino area, I wanted a help in my code and do an aquarium monitoring, I want to put 7 temperature sensors, 7 relays, separately, 5 ph, 5 water sensor, 5 oxygen sensor . the relays and to activate when the temperature drops, low by 28 degrees, and I want to put an LCD (16.2), to monitor the temperature, ph, water oxygen, and also either via bluetooth to see the dandos and can shoot the bombs manually by a cell phone, I started to do some things, but with difficulty in this project, I thank you already any possible help......... :(




#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 6 on the Arduino
#define ONE_WIRE_BUS 10
#define TEMPERATURE_PRECISION 9

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress insideThermometer;                                    //outsideThermometer;

int relay =7;

void setup(void)

{
 pinMode(relay,OUTPUT);

lcd.begin(16, 2);

 // start serial port
 Serial.begin(9600);
 Serial.println("Dallas Temperature IC Control Library Demo");

 // Start up the library
 sensors.begin();

 // locate devices on the bus
 Serial.print("Locating devices...");
 Serial.print("Found ");
 Serial.print(sensors.getDeviceCount(), DEC);
 Serial.println(" devices.");

 // report parasite power requirements
 Serial.print("Parasite power is: ");
 if (sensors.isParasitePowerMode()) Serial.println("ON");
 else Serial.println("OFF");

 // assign address manually.  the addresses below will beed to be changed
 // to valid device addresses on your bus.  device address can be retrieved
 // by using either oneWire.search(deviceAddress) or individually via
 // sensors.getAddress(deviceAddress, index)
 //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
 //outsideThermometer   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };

 // search for devices on the bus and assign based on an index.  ideally,
 // you would do this to initially discover addresses on the bus and then
 // use those addresses and manually assign them (see above) once you know
 // the devices on your bus (and assuming they don't change).
 //
 // method 1: by index
 if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
                          //if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");

 // method 2: search()
 // search() looks for the next device. Returns 1 if a new address has been
 // returned. A zero might mean that the bus is shorted, there are no devices,
 // or you have already retrieved all of them.  It might be a good idea to
 // check the CRC to make sure you didn't get garbage.  The order is
 // deterministic. You will always get the same devices in the same order
 //
 // Must be called before search()
 //oneWire.reset_search();
 // assigns the first address found to insideThermometer
 //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
 // assigns the seconds address found to outsideThermometer
 //if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");

 // show the addresses we found on the bus
 Serial.print("Device 0 Address: ");
 printAddress(insideThermometer);
 Serial.println();

                     // Serial.print("Device 1 Address: ");
                    // printAddress(outsideThermometer);
                   // Serial.println();

 // set the resolution to 9 bit
 sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
                                // sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);

 Serial.print("Device 0 Resolution: ");
 Serial.print(sensors.getResolution(insideThermometer), DEC);
 Serial.println();

                                // Serial.print("Device 1 Resolution: ");
                              // Serial.print(sensors.getResolution(outsideThermometer), DEC);
                                // Serial.println();
 
 // set up the LCD's number of columns and rows:
 
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
 for (uint8_t i = 0; i < 7; i++)
 {
   // zero pad the address if necessary
   if (deviceAddress < 16) Serial.print("0");
   Serial.print(deviceAddress, HEX);
 }
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
 float tempC = sensors.getTempC(deviceAddress);
 Serial.print("Temp C: ");
 Serial.print(tempC);
 
 Serial.print(" Temp F: ");
 Serial.print(DallasTemperature::toFahrenheit(tempC));
 delay(2000);
 
 
}



// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
 Serial.print("Resolution: ");
 Serial.print(sensors.getResolution(deviceAddress));
 Serial.println();   
}

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
 Serial.print("Device Address: ");
 printAddress(deviceAddress);
 Serial.print(" ");
 printTemperature(deviceAddress);
 Serial.println();
}

void loop(void)
{
 // call sensors.requestTemperatures() to issue a global temperature
 // request to all devices on the bus
 //Serial.print("Requesting temperatures...");
 sensors.requestTemperatures();
 //Serial.println("DONE");

 // print the device information
 //printData(insideThermometer);
 //printData(outsideThermometer);
 
   Serial.println(sensors.getTempC(insideThermometer));
 //Serial.println(sensors.getTempC(outsideThermometer));
 Serial.println("   ");
 
 lcd.setCursor(0, 0);
 lcd.print("Temperatura:");
 lcd.setCursor(0, 2);
 lcd.print("celsius: ");
 lcd.print(sensors.getTempC(insideThermometer));
 lcd.print(" C");
 
 int setpoint = 29;
 int swing = 1;
 if ( sensors.getTempC(insideThermometer) >=setpoint + swing) //&&  sensors.getTempC(insideThermometer) >sensors.getTempC(outsideThermometer) )
 {
 digitalWrite(7,HIGH);
   Serial.println("ON ");

}
else if ( sensors.getTempC(insideThermometer) <setpoint - swing)
{
 digitalWrite(7,LOW);
 Serial.println("OFF ");
}
delay(500);


}


FelipeQ

Sou iniciante ..
Por favor alguém ajude =D
Queria apenas que quando executasse o "case" novamente ele fizesse o reverso, (desligasse o led).

const int Led1 = 7;


void setup() {
 Serial.begin(9600);
 pinMode(Led1, OUTPUT);
}
void loop() {
 if (Serial.available()) {
   char geral = Serial.read();
   switch (geral) {
     case '1':
      digitalWrite(sala, HIGH);
      break;
     default:
      Serial.print("Valor ");
      Serial.print(casa);
      Serial.println(" incorreto.");
      digitalWrite(sala, LOW);
     
     }
   }
 }

pksato

Sou iniciante ..
Por favor alguém ajude =D
Queria apenas que quando executasse o "case" novamente ele fizesse o reverso, (desligasse o led).
Pode armazenar o estado do led em uma variavel
Code: [Select]

const int sala = 7;
int EstadoSala=LOW; // ou HIGH

void setup() {
 Serial.begin(9600);
 pinMode(sala, OUTPUT);
}

void loop() {
   if (Serial.available()) {
   char geral = Serial.read();
   switch (geral) {
     case '1':
      if (EstadoSala = HIGH ) {
         EstadoSala=LOW;
      } else {
         EstadoSala=HIGH;
      };
      digitalWrite(sala, EstadoSala);
      break;
     default:
      Serial.print("Valor ");
      //Serial.print(casa);
      //Serial.println(" incorreto.");
      digitalWrite(sala, LOW);
    
     };
   };
}


Ou assim:
Code: [Select]

const int sala = 7;
int EstadoSala=LOW; // ou HIGH

void setup() {
 Serial.begin(9600);
 pinMode(sala, OUTPUT);
 digitalWrite(sala, EstadoSala); // estado inicial
}

void loop() {
   if (Serial.available()) {
   char geral = Serial.read();
   switch (geral) {
     case '1':    
      digitalWrite(sala, !EstadoSala); // Operação de Negação.
      break;
     default:
      Serial.print("Valor ");
      //Serial.print(casa);
      //Serial.println(" incorreto.");
      digitalWrite(sala, LOW);
    
     };
   };
}


Ou ainda, sem usar nenhuma variável.
Code: [Select]

const int sala = 7;

void setup() {
 Serial.begin(9600);
 pinMode(sala, OUTPUT);
 digitalWrite(sala, LOW); // estado inicial
}

void loop() {
   if (Serial.available()) {
   char geral = Serial.read();
   switch (geral) {
     case '1':    
      digitalWrite(sala, !digitalRead(sala)); // Operação de Negação.
      break;
     default:
      Serial.print("Valor ");
      //Serial.print(casa);
      //Serial.println(" incorreto.");
      digitalWrite(sala, LOW);
    
     };
   };
}


O código original contem vários erros, corrigi-os de modo a validar os meus exemplos.

REGRA: Ao postar o código neste forum, use o marcado de código (code).

Dica: Sempre declare as variáveis, constantes,  strucs no inicio da função, nunca no meio do código.


Go Up