Bonjour mes ami(e)s Arduinoiste !
J'essaye de faire une "lampe" avec une DEL qui s'allume seulement quand la température descend au dessous d'un certain seuil, et que dont on peut régler l'intensité avec un petit potentiomètre de 10Kohms.
Le problème c'est que mon programme ne fonctionne pas, en effet, je l'examine depuis tout a l'heure et j'ai l'impression que ca va ... Mais forcement que non !
Alors je fait appel a vous ? HELP ME PLEASE !!!!
const int onOffSwitchPin = 7;
const int LED = 6; //sortit PWM
const int tempPin = A4;
const int potPin = A0;
int potVal;
float limitTemp = 30.00;
int onOffSwitchState = 0;
int LEDOn = 0;
int temperature;
void setup() {
pinMode(onOffSwitchPin,INPUT);
pinMode(LED,OUTPUT);
// put your setup code here, to run once:
pardon je me suis tromper de nom j'ai mis "nivRes" au lieu de "onOffSwitchState",
voilà le code bon mais qui ne fonctionne toujours pas !
const int onOffSwitchPin = 7;
const int LED = 6; //sortit PWM
const int tempPin = A4;
const int potPin = A0;
int potVal;
float limitTemp = 30.00;
int onOffSwitchState = 0;
int LEDOn = 0;
int temperature;
void setup() {
pinMode(onOffSwitchPin,INPUT);
pinMode(LED,OUTPUT);
// put your setup code here, to run once:
Merci beaucoup de cette réponse si rapide !
Mais il faut que les deux conditions soit réunis donc je suis obligé d'apposer ces différentes conditions en cascade, ya t'il un autre moyen ?
Ca ne fonctionne toujours sa m'affiche même plein d'erreur, je doit me tromper quelque part...
C'est bon ca marche merci beaucoup vraiment ! C'est vraiment que vous m'ayez aider !
Mais j'ai juste une question : Le moniteur série est-il obligatoire ?
Merci encore!
tu ne lisais pas l'inter on/off avec digitalRead
tu mélangeais les "=" et les "==".
les "Serial.print" sont le moyen pour toi de suivre ce qui se passe lorsque ton prg se déroule.
cela te permet d'afficher la valeur d'une variable, ou de voir si le prg entre dans un "if", etc...
une fois débugé, tu mets des " // "devant ces "Serial.print", pour faire qu'ils soient considérés comme des commentaires. donc plus compilés, donc prg moins lourd en mémoire
Rebonjours mes sauveurs !
J'aimerais améliorer mon programme en ajoutant une photorésistance dans mon circuits.
J'aimerais que quand la luminosité augmentent le PWM qui contrôle la luminosité de ma DEL augmentent avec, j'ai essayer comme ca mais ca marche pas...
Pouvez vous m'aidé encore une fois ?
Merci par avance !
const int onOffSwitchPin = 7;
int onOffSwitchState = 0;
const int LED = 6; //sortit PWM
const int tempPin = A4;
const int potPin = A0;
const int luminositeSensorPin = A1;
int potVal;
float limitTemp = 30.00;
//int onOffSwitchState = 0;
int LEDOn = 0;
int temperature;
int luminositeVal = 0;
int potVal2;
void setup() {Serial.begin(115200);
pinMode(tempPin,INPUT);
pinMode(potPin,INPUT);
pinMode(onOffSwitchPin,INPUT);
pinMode(LED,OUTPUT);
// put your setup code here, to run once:
les "sauveurs" apprécieraient que vous utilisassiez les tags de code
corrigez votre post ci dessus et rajoutez les code tags autour du code: [code]`` [color=blue]// votre code ici[/color] ``[/code].
ça doit ressembler à cela:// votre code ici
(faites aussi ctrl-T (PC) or cmd-T (Mac) dans l'IDE avant de copier le code pour qu'il soit indenté correctement)
luminositeVal = analogRead(luminositeSensorPin)/16; c'est 1023 / 4 qui donne un nombre entre 0 et 255 (à la louche) pas en divisant par 16
Rebonjours mes sauveurs !
J'aimerais améliorer mon programme en ajoutant une photorésistance dans mon circuits.
J'aimerais que quand la luminosité augmentent le PWM qui contrôle la luminosité de ma DEL augmentent avec, j'ai essayer comme ca mais ca marche pas...
Pouvez vous m'aidé encore une fois ?
Merci par avance !
const int onOffSwitchPin = 7;
int onOffSwitchState = 0;
const int LED = 6; //sortit PWM
const int tempPin = A4;
const int potPin = A0;
const int luminositeSensorPin = A1;
int potVal;
float limitTemp = 30.00;
//int onOffSwitchState = 0;
int LEDOn = 0;
int temperature;
int luminositeVal = 0;
int potVal2;
void setup() {
Serial.begin(115200);
pinMode(tempPin, INPUT);
pinMode(potPin, INPUT);
pinMode(onOffSwitchPin, INPUT);
pinMode(LED, OUTPUT);
// put your setup code here, to run once:
}
void loop() {
potVal = analogRead(potPin) / 4;
int sensorVal = analogRead(tempPin);
float voltage = (sensorVal / 1024.0) * 5.0;
float temperature = (voltage - 0.5) * 100;
potVal2 = analogRead(potPin) / 16;
luminositeVal = analogRead(luminositeSensorPin) / 16; Serial.print(F("Valeur sensor : ")); Serial.println(luminositeVal);
if (digitalRead(onOffSwitchPin)) {
onOffSwitchState = 1;
Serial.print(F(" onOffSwitchState =")); Serial.println( onOffSwitchState );
}
else {
onOffSwitchState = 0;
Serial.print(F(" onOffSwitchState =")); Serial.println( onOffSwitchState );
}
delay(1500);
if (onOffSwitchState == 1) {
Serial.print(F(" if..........onOffSwitchState =")); Serial.println( onOffSwitchState );
if (temperature <= limitTemp) {
Serial.print(F(" if.......temperature <= limitTemp =")); Serial.println( temperature );
LEDOn = 1; Serial.print(F(" LEDOn =")); Serial.println( LEDOn );
}
}
else {
LEDOn = 0; Serial.print(F(" LEDOn =")); Serial.println( LEDOn );
}
if (LEDOn == 1) {
Serial.print(F(" if..........LEDOn = 1 ")); Serial.println( LEDOn );
analogWrite(LED, potVal); Serial.print(F(" LED = ")); Serial.println(potVal );
}
else {
analogWrite(LED, LOW); Serial.print(F(" LED = ")); Serial.println(LOW );
}
if (luminositeVal < potVal) {
potVal2 + 1; Serial.print(F("Valeur PotVal2 ")); Serial.println(potVal2 );
}
else if (luminositeVal > potVal) {
potVal2 - 1; Serial.print(F("Valeur PotVal2 ")); Serial.println(potVal2 );
}
else if (luminositeVal == potVal) {
potVal2 + 0; Serial.print(F("Valeur PotVal2 ")); Serial.println(potVal2 );
}
}
c'est 1023 / 4 qui donne un nombre entre 0 et 255 (à la louche) pas en divisant par 16
Oui c'est vrai mais c'est pour que ca soit plus cohérent avec la valeur de mon potentiométre, et même en ne divisant que par 4 ca ne fonctionne pas le PWM n'augmente pas pour atteindre le seuil que j'ai fixer avec le potentiomètre ...
J'ai fait une erreur dans le code, voilà le programme correct mais qui ne fonctionne pas.
Ce qui ne fonctionne pas c'est le fait que je choisi une certaine luminosité avec le potentiométre, et je souhaiterais qu'elle soit respecter (que la luminosité de la LED et de l'extérieur respecte le seuil fixer par le potentiométre).
Je récupère la luminosité réelle par la photorésistance, la valeur de mon potentiométre, et de mon bouton marche arrêt.
L'idée c'est que si la luminosité naturelle augmentent je baisse automatiquement l'intensité de la DEL et inversement.
C'est ca qui ne fonctionne pas ...
const int onOffSwitchPin = 7;
int onOffSwitchState = 0;
const int LED = 6; //sortit PWM
const int tempPin = A4;
const int potPin = A0;
const int luminositeSensorPin = A1;
int potVal;
float limitTemp = 30.00;
//int onOffSwitchState = 0;
int LEDOn = 0;
int temperature;
int luminositeVal = 0;
int potVal2;
void setup() {
Serial.begin(115200);
pinMode(tempPin, INPUT);
pinMode(potPin, INPUT);
pinMode(onOffSwitchPin, INPUT);
pinMode(LED, OUTPUT);
// put your setup code here, to run once:
}
void loop() {
potVal = analogRead(potPin) / 16;
int sensorVal = analogRead(tempPin);
float voltage = (sensorVal / 1024.0) * 5.0;
float temperature = (voltage - 0.5) * 100;
potVal2 = analogRead(potPin) / 16;
luminositeVal = analogRead(luminositeSensorPin) / 16; Serial.print(F("Valeur sensor : ")); Serial.println(luminositeVal);
if (digitalRead(onOffSwitchPin)) {
onOffSwitchState = 1;
Serial.print(F(" onOffSwitchState =")); Serial.println( onOffSwitchState );
}
else {
onOffSwitchState = 0;
Serial.print(F(" onOffSwitchState =")); Serial.println( onOffSwitchState );
}
delay(1500);
if (onOffSwitchState == 1) {
Serial.print(F(" if..........onOffSwitchState =")); Serial.println( onOffSwitchState );
if (temperature <= limitTemp) {
Serial.print(F(" if.......temperature <= limitTemp =")); Serial.println( temperature );
LEDOn = 1; Serial.print(F(" LEDOn =")); Serial.println( LEDOn );
}
}
else {
LEDOn = 0; Serial.print(F(" LEDOn =")); Serial.println( LEDOn );
}
if (LEDOn == 1) {
Serial.print(F(" if..........LEDOn = 1 ")); Serial.println( LEDOn );
analogWrite(LED, potVal); Serial.print(F(" LED = ")); Serial.println(potVal );
}
else {
analogWrite(LED, LOW); Serial.print(F(" LED = ")); Serial.println(LOW );
}
if (luminositeVal < potVal) {
potVal2 + 1; Serial.print(F("Valeur PotVal2 ")); Serial.println(potVal2 );
}
else if (luminositeVal > potVal) {
potVal2 - 1; Serial.print(F("Valeur PotVal2 ")); Serial.println(potVal2 );
}
else if (luminositeVal == potVal) {
potVal2 + 0; Serial.print(F("Valeur PotVal2 ")); Serial.println(potVal2 );
}
}
les bouts de code en rouge sont supposés faire quoi? un petit calcul comme cela, pour faire beau? vous ne stockez le résultat de l'addition nulle part...