Ir ao conteúdo
  • Cadastre-se

Programação para arduino - celula de carga + hx711


Posts recomendados

Bom dia!

Estou com uma programação e preciso alterar para que os leds do meu projeto funcionem de acordo com o que preciso mas sou totalmente leiga em c++, preciso que o led vermelho acenda si o peso der <ou> ou o led verde acenda si o peso estiver =.

Segue a programação.

#include "HX711.h"

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0

HX711 scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library

void setup() {
Serial.begin(38400);
Serial.println("HX711 Demo");

Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC

Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC

Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)

Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided 
// by the SCALE parameter (not set yet)

scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(); // reset the scale to 0

Serial.println("After setting up the scale:");

Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC

Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC

Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()

Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided 
// by the SCALE parameter set with set_scale

Serial.println("Readings:");
}

void loop() {
Serial.print("one reading:\t");
Serial.print(scale.get_units(), 1);
Serial.print("\t| average:\t");
Serial.println(scale.get_units(10), 1);

scale.power_down(); // put the ADC in sleep mode
delay(5000);
scale.power_up();
}

Muito obrigada a quem conseguir me ajudar, falta isso para finalizar. O led verde esta ligado na 12 e o vermelho na 13 e o amplificador na a0.

Link para o comentário
Compartilhar em outros sites

  • Membro VIP

A linguagem acima não é necessariamente c++ nativa, mas funções dentro dela

 

2 horas atrás, laura91 disse:

led vermelho acenda si o peso der <ou> ou o led verde acenda si o peso estiver =.

em c (ou c++) puro:

if (peso!=peso_que_eu_quero) {led_vermelho=1;led_verde=0;}

else {led_vermelho=0;led_verde=1;}

Uma bela oportunidade pra se profundar mais no c e não ficar só na introdução (ops! linguagem c!!! .. ops! parece que piorou... fazer programa em c! ... aff cada vez pior.... ahhh acho que deu pra entender... ou não kk)

 

  • Curtir 1
Link para o comentário
Compartilhar em outros sites

Bom dia! Isadora, então minha programação ficaria assim? Peguei a programação desse link (http://www.fut-electronics.com/wp-content/plugins/fe_downloads/Uploads/Tutorial_for_Load_Cell_weight_sensor 50KG.pdf), estou usando a mesma celula de carga e amplificador porém preciso que os leds acendam :(
Vou procurar aprender sobre programação pois gostei dos projetos que vi com arduino :)

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library
void setup() {
Serial.begin(38400);
Serial.println("HX711 Demo");
Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided 
// by the SCALE parameter (not set yet)
scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(); // reset the scale to 0
Serial.println("After setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided 
// by the SCALE parameter set with set_scale
Serial.println("Readings:");
}
void loop() {
Serial.print("one reading:\t");
Serial.print(scale.get_units(), 1);
Serial.print("\t| average:\t");
Serial.println(scale.get_units(10), 1);
scale.power_down(); // put the ADC in sleep mode
delay(5000);
scale.power_up();
}
if (peso!=peso_que_eu_quero) {led_vermelho=1;led_verde=0;}
else {led_vermelho=0;led_verde=1;}

Link para o comentário
Compartilhar em outros sites

:(

@Isadora Ferraz

Isadora, então minha programação ficaria assim? Peguei a programação desse link (http://www.fut-electronics.com/wp-content/plugins/fe_downloads/Uploads/Tutorial_for_Load_Cell_weight_sensor 50KG.pdf), estou usando a mesma celula de carga e amplificador porém preciso que os leds acendam. Quando jogo essa programação no Arduino aparece vários erros. 
Vou procurar aprender sobre programação pois gostei dos projetos que vi com arduino 

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library
void setup() {
Serial.begin(38400);
Serial.println("HX711 Demo");
Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided 
// by the SCALE parameter (not set yet)
scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(); // reset the scale to 0
Serial.println("After setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided 
// by the SCALE parameter set with set_scale
Serial.println("Readings:");
}
void loop() {
Serial.print("one reading:\t");
Serial.print(scale.get_units(), 1);
Serial.print("\t| average:\t");
Serial.println(scale.get_units(10), 1);
scale.power_down(); // put the ADC in sleep mode
delay(5000);
scale.power_up();
}
if (peso!=peso_que_eu_quero) {led_vermelho=1;led_verde=0;}
else {led_vermelho=0;led_verde=1;}

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...