issue107:arduino
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue107:arduino [2016/03/30 08:56] – créée auntiee | issue107:arduino [2016/04/08 14:49] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | **WARNING: This month we’re heading into the big league with controlling household voltage devices. It should go without saying, but I’ll say it anyway, you must make sure your 110/240V devices are unplugged before chopping cables, and double-check your wiring before you do put that plug back into the wall outlet.** | ||
+ | ATTENTION : ce mois-ci, nous passons en première division en pilotant des appareils sous tension domestique. Il va sans dire, mais je le dis quand même, que vous devez vous assurer que vos appareils sont débranchés avant de couper des câbles et vérifier deux fois votre câblage avant de remettre la fiche dans la prise murale. | ||
- | WARNING: This month we’re heading into the big league with controlling household voltage devices. It should go without saying, but I’ll say it anyway, you must make sure your 110/240V devices | + | **In previous articles, I used an LCD screen which, while it worked, would need about a dozen wires and a potentiometer to control |
+ | These newer LCD screens are I2C which means they have a little controller board on the back. It also means they require a newer LCD library (https:// | ||
- | In previous articles, I used an LCD screen which, while it worked, would need about a dozen wires and a potentiometer to control | + | Before adding |
- | These newer LCD screens are I2C which means they have a little controller board on the back. It also means they require a newer LCD library | + | Dans les articles précédents, |
+ | |||
+ | Ces nouveaux écrans LCD sont I2C ce qui signifie qu'ils ont une petite carte de pilotage au dos. Cela signifie aussi qu'ils ont besoin d'une nouvelle bibliothèque | ||
- | Before adding LCD code, we need to do a scan of the LCD screen to get its I2C address. Different models have different addresses. So, grab the code from: http:// | + | Avant d' |
- | LCD Code | + | **LCD Code |
I need to include that new library: | I need to include that new library: | ||
Ligne 19: | Ligne 24: | ||
#define I2C_ADDR | #define I2C_ADDR | ||
- | // you shouldn’t need to touch the pin numbers below | + | < |
#define BACKLIGHT_PIN | #define BACKLIGHT_PIN | ||
Ligne 32: | Ligne 37: | ||
LiquidCrystal_I2C | LiquidCrystal_I2C | ||
- | In my setup, I initialise the screen as 16X2, turn on the backlight, print a message, and use a delay to allow it to be read. | + | In my setup, I initialise the screen as 16X2, turn on the backlight, print a message, and use a delay to allow it to be read.** |
- | lcd.begin (16, | + | Code LCD |
+ | |||
+ | J'ai besoin d' | ||
+ | |||
+ | #include < | ||
+ | |||
+ | Définissez plusieurs picots (des éléments I2C que vous n' | ||
+ | |||
+ | #define I2C_ADDR | ||
+ | < | ||
+ | |||
+ | #define BACKLIGHT_PIN | ||
+ | #define En_pin | ||
+ | #define Rw_pin | ||
+ | #define Rs_pin | ||
+ | #define D4_pin | ||
+ | #define D5_pin | ||
+ | #define D6_pin | ||
+ | #define D7_pin | ||
+ | |||
+ | LiquidCrystal_I2C | ||
+ | |||
+ | Dans mon paramétrage, | ||
+ | |||
+ | **lcd.begin (16, | ||
lcd.setBacklightPin(BACKLIGHT_PIN, | lcd.setBacklightPin(BACKLIGHT_PIN, | ||
Ligne 47: | Ligne 76: | ||
Most of those commands are pretty self explanatory. | Most of those commands are pretty self explanatory. | ||
- | I now have my temperature, | + | I now have my temperature, |
- | lcd.setCursor(0, | + | lcd.begin (16, |
+ | lcd.setBacklightPin(BACKLIGHT_PIN, | ||
+ | |||
+ | lcd.setBacklight(HIGH); | ||
+ | |||
+ | lcd.home(); | ||
+ | |||
+ | lcd.print(" | ||
+ | |||
+ | delay(2000); | ||
+ | |||
+ | La plupart de ces commandes sont explicites. | ||
+ | |||
+ | Maintenant, j'ai la température, | ||
+ | |||
+ | **lcd.setCursor(0, | ||
lcd.print(" | lcd.print(" | ||
Ligne 55: | Ligne 99: | ||
lcd.setCursor() is for placing the text at a particular position on the screen. | lcd.setCursor() is for placing the text at a particular position on the screen. | ||
- | NOTE: if you don’t see anything on your screen on first run, try turning the potentiometer on the back of the LCD screen to adjust the brightness of the screen. | + | NOTE: if you don’t see anything on your screen on first run, try turning the potentiometer on the back of the LCD screen to adjust the brightness of the screen.** |
- | Solid State Relay | + | lcd.setCursor(0, |
+ | |||
+ | lcd.print(" | ||
+ | |||
+ | lcd.setCursor() sert à positionner le texte à un endroit précis de l' | ||
+ | |||
+ | NOTE : si, au premier démarrage, vous ne voyez rien sur votre écran, essayez de tourner le potentiomètre au dos de l' | ||
+ | |||
+ | **Solid State Relay | ||
First, you can use a relay switch with this circuit, but you’ll get a physical clicking sound as the relay switches back and forth. No big deal, but a solid state relay is digital and without sound. Be absolutely sure that the relay switch (solid state or not) is rated to do 110/240V. | First, you can use a relay switch with this circuit, but you’ll get a physical clicking sound as the relay switches back and forth. No big deal, but a solid state relay is digital and without sound. Be absolutely sure that the relay switch (solid state or not) is rated to do 110/240V. | ||
Ligne 63: | Ligne 115: | ||
Before I chop into the cable of my beloved heat mat, I want to make sure this circuit will work. So, instead, I’m going to chop into an unused desk lamp. | Before I chop into the cable of my beloved heat mat, I want to make sure this circuit will work. So, instead, I’m going to chop into an unused desk lamp. | ||
- | With it unplugged, I chopped through the cable and paired off the two inner cables (live and neutral). I then twisted the two live cables together and left the two neutral cables detached. I also put some electrical tape over that twist to cover it up and keep things somewhat safe. | + | With it unplugged, I chopped through the cable and paired off the two inner cables (live and neutral). I then twisted the two live cables together and left the two neutral cables detached. I also put some electrical tape over that twist to cover it up and keep things somewhat safe.** |
+ | |||
+ | Relais statique | ||
+ | |||
+ | Disons d' | ||
+ | |||
+ | Avant de couper le câble de ma chère couverture chauffante, je veux être sûr que le circuit fonctionne. Aussi, à la place, je vais sacrifier une lampe de bureau inutilisée. | ||
+ | |||
+ | Après l' | ||
- | The solid state relay (SSR for short) has two DC inputs (in the photo, at the bottom left, is the red +5v and blue ground). It also has (depending on your SSR) one or more channels. My SSR has two channels. This is where your Arduino (yellow wire in the photo) will tell the SSR to go HIGH or LOW. The final two inputs are for the cable you wish to open/close. In this case the live (top wires in the photo) from my lamp. Now, it didn’t help that my inputs are labelled wrongly. The one marked ‘Ch1’ is actually for SSR channel two. So if you try this and it doesn’t work, try switching your wire from Ch1 to Ch2. You should see a light come on on the SSR to show which channel is HIGH/LOW. | + | **The solid state relay (SSR for short) has two DC inputs (in the photo, at the bottom left, is the red +5v and blue ground). It also has (depending on your SSR) one or more channels. My SSR has two channels. This is where your Arduino (yellow wire in the photo) will tell the SSR to go HIGH or LOW. The final two inputs are for the cable you wish to open/close. In this case the live (top wires in the photo) from my lamp. Now, it didn’t help that my inputs are labelled wrongly. The one marked ‘Ch1’ is actually for SSR channel two. So if you try this and it doesn’t work, try switching your wire from Ch1 to Ch2. You should see a light come on on the SSR to show which channel is HIGH/LOW. |
With those things in place it’s time to write some code. | With those things in place it’s time to write some code. | ||
To test the SSR I’ll flash the lamp on/off. The first new lines of code are: | To test the SSR I’ll flash the lamp on/off. The first new lines of code are: | ||
+ | |||
+ | #define ssr1 53 | ||
+ | |||
+ | int state = LOW; | ||
+ | |||
+ | unsigned long previousMillis= 0; | ||
+ | |||
+ | const long interval= 1000;** | ||
+ | |||
+ | Le relais statique (RS pour faire court) a deux entrées en courant continu (sur la photo, en bas à gauche, le +5V est rouge et la masse bleue). Il comporte aussi (suivant votre RS) un ou plusieurs canaux. Le mien en a deux. C'est par ici que votre Arduino (fil jaune sur la photo) alimentera ou non votre RS. Les deux dernières entrées sont pour le câble que vous souhaitez ouvrir/ | ||
+ | |||
+ | Une fois tout ceci en place, le moment est venu d' | ||
+ | |||
+ | Pour tester le RS, je vais faire clignoter la lampe. Les premières nouvelles lignes de code sont : | ||
#define ssr1 53 | #define ssr1 53 | ||
Ligne 79: | Ligne 153: | ||
const long interval= 1000; | const long interval= 1000; | ||
- | This defines pin 53 on the Arduino as the control pin for the SSR. The state is to keep track of whether the lamp is currently on/off. The previousMillis and interval are for the flash. I’m going to try and use millis rather than delays as millis is more preferable to the program halting delay command. | + | **This defines pin 53 on the Arduino as the control pin for the SSR. The state is to keep track of whether the lamp is currently on/off. The previousMillis and interval are for the flash. I’m going to try and use millis rather than delays as millis is more preferable to the program halting delay command. |
I begin with the usual pinMode and then set the SSR to the initial state of LOW. In other words, off. This SSR is ‘low level trigger’ which means LOW is on, and HIGH is off. | I begin with the usual pinMode and then set the SSR to the initial state of LOW. In other words, off. This SSR is ‘low level trigger’ which means LOW is on, and HIGH is off. | ||
Ligne 91: | Ligne 165: | ||
unsigned long currentMillis = millis(); | unsigned long currentMillis = millis(); | ||
- | as this will be used in the if/then to switch on/off the lamp. | + | as this will be used in the if/then to switch on/off the lamp.** |
- | The only other additional code of note is the switching (top right). CurrentMillis and previousMillis will keep track of how many milliseconds the loop is running for. When it reaches the interval (set up at the start) then the loop ends. Note that this means the code never grinds to a halt like it would with a delay. I can still put stuff to do inside that HIGH/LOW if statement. | + | Ceci définit le picot 53 de l' |
+ | |||
+ | Je commence avec l' | ||
+ | |||
+ | pinMode(ssr1, | ||
+ | |||
+ | digitalWrite(ssr1, | ||
+ | |||
+ | Dans le paramétrage, | ||
+ | |||
+ | unsigned long currentMillis = millis(); | ||
+ | |||
+ | car il sera utilisé dans la boucle si/alors pour commuter la lampe. | ||
+ | |||
+ | **The only other additional code of note is the switching (top right). CurrentMillis and previousMillis will keep track of how many milliseconds the loop is running for. When it reaches the interval (set up at the start) then the loop ends. Note that this means the code never grinds to a halt like it would with a delay. I can still put stuff to do inside that HIGH/LOW if statement. | ||
The inner if/else is just checking to execute: | The inner if/else is just checking to execute: | ||
Ligne 101: | Ligne 189: | ||
And, finally, do the on/off. | And, finally, do the on/off. | ||
- | With the interval set at 1000 this means the lamp will turn on/off every second. | + | With the interval set at 1000 this means the lamp will turn on/off every second.** |
+ | |||
+ | La seule addition notable de code est la commutation (en haut à droite). CurrentMillis et PreviousMillis conservent les durées en millisecondes de parcours de la boucle. Quand « interval » est atteint (fixé au début), | ||
+ | |||
+ | Le if/else intérieur contrôle juste l' | ||
+ | • si l' | ||
+ | • si l' | ||
+ | |||
+ | Et, enfin, exécute le Allumé/ | ||
+ | |||
+ | Avec un intervalle réglé à 1000, ça signifie que la lampe va clignoter chaque seconde. | ||
- | The only downside of removing the delays is that I’m now hammering ThingSpeak every minute or less, but I’ll fix that later. It’s working. That’s the main thing! | + | **The only downside of removing the delays is that I’m now hammering ThingSpeak every minute or less, but I’ll fix that later. It’s working. That’s the main thing! |
The code for this is a gist on my Github at: https:// | The code for this is a gist on my Github at: https:// | ||
Ligne 117: | Ligne 215: | ||
} | } | ||
- | If the temperature goes above 24, the lamp comes on. If the temperature falls below 24, the lamp goes off. | + | If the temperature goes above 24, the lamp comes on. If the temperature falls below 24, the lamp goes off.** |
+ | Le seul inconvénient de retirer les délais est que je vais maintenant solliciter ThingSpeak toutes les minutes ou moins, mais je le réglerai plus tard. Ça marche. C'est le principal ! | ||
+ | Le code correspondant est un gist sur mon Github à : https:// | ||
+ | Pour surveiller une température particulière, | ||
+ | if (DHT.temperature > 24 ) { | ||
+ | state=LOW; | ||
+ | } | ||
+ | if (DHT.temperature < 24) { | ||
+ | state=HIGH; | ||
+ | } | ||
+ | Si la température dépasse 24 °C, la lampe s' | ||
+ | **Mike K. - qualified electrical engineer (true!); and who has an uncle who was electrocuted notes: | ||
+ | Ronnie says: listen to this man. He knows FAR more than me! | ||
+ | Timer-overflow: | ||
- | Mike K. - qualified electrical engineer | + | You may need to allow for that event in your code, otherwise, your code will stop working when it occurs. For example. if a “long” is 4 bytes, and if the time unit is actual millisecs, then this code will fail after 49 days operation |
- | Ronnie says: listen to this man. He knows FAR more than me! | + | Notes de Mike K., ingénieur qualifié en électricité (vrai !) et dont un oncle a été électrocuté : |
- | Timer-overflow: In the real world, you’d might need to find out the maximum value of that “currentMillis” variable, because, sooner-or-later, | + | Ronnie écrit |
- | You may need to allow for that event in your code, otherwise, your code will stop working when it occurs. For example. if a “long” is 4 bytes, and if the time unit is actual millisecs, then this code will fail after 49 days operation | + | Dépassement de la temporisation : dans le monde réel, vous ne devriez pas avoir besoin de déterminer la valeur maximale de la variable « currentMillis » parce que, tôt ou tard, elle sera remise à zéro. Elle est définie ici comme un « entier |
- | Temperature triggers: In the real world, your temp sensor might be “noisy”, | + | Vous pourriez avoir besoin de prévoir cet événement dans votre code ; autrement, votre code s' |
+ | |||
+ | **Temperature triggers: In the real world, your temp sensor might be “noisy”, | ||
• In the initialisation code,set the Device to OFF, and set the “Device_State” to OFF (for simplicity). | • In the initialisation code,set the Device to OFF, and set the “Device_State” to OFF (for simplicity). | ||
• If the new temperature is at/below the lower value, and the Device_State is currently OFF, then set it ON, and set Device_State to ON. | • If the new temperature is at/below the lower value, and the Device_State is currently OFF, then set it ON, and set Device_State to ON. | ||
• If the new temperature is at/above the upper value, and the Device_State is currently ON, then set it OFF, and set Device_State to OFF. | • If the new temperature is at/above the upper value, and the Device_State is currently ON, then set it OFF, and set Device_State to OFF. | ||
- | • If we can read the current state of the device, then the above “Device_State” variable is not needed. And, reverse the above references to ON/OFF, if appropriate. | + | • If we can read the current state of the device, then the above “Device_State” variable is not needed. And, reverse the above references to ON/OFF, if appropriate.** |
- | Wiring: When cutting the mains cable, strip back the outer insulation very slowly and carefully, and do not damage or cut into the wires which are not used by the relay circuit. If there is an earth cable, and if there is an earthing connector in the SSR circuit, then, do not cut the earth cable, but strip about 1-2 cm of it, fold it, and insert it into the earth connector. | + | Seuils de température |
+ | • Dans le code d' | ||
+ | • Si la nouvelle température est à la valeur basse (ou en-dessous), | ||
+ | • Si la nouvelle température est à la valeur haute (ou au-dessus), et que l' | ||
+ | • Si vous pouvez lire l' | ||
- | For safety, the SSR circuit | + | **Wiring: When cutting the mains cable, strip back the outer insulation very slowly and carefully, and do not damage or cut into the wires which are not used by the relay circuit. If there is an earth cable, and if there is an earthing connector |
- | A user might install two relays - one on the positive and one on the negative lines. If a single relay is used - as in this project - it must be connected into the LIVE wire, so that, when the device (lamp, etc) is " | + | For safety, the SSR circuit must be enclosed in a suitable protective box. If the relays get hot when being used, then ensure there is adequate ventilation in the box, and ensure the box is not placed on soft surfaces such as carpets, duvets, etc - which would inhibit ventilation.** |
+ | |||
+ | Câblage : Quand vous coupez les câbles d' | ||
+ | |||
+ | Par sécurité, le circuit du RS doit être placé dans une enveloppe protectrice adaptée. Si les relais deviennent chauds à l' | ||
+ | |||
+ | **A user might install two relays - one on the positive and one on the negative lines. If a single relay is used - as in this project - it must be connected into the LIVE wire, so that, when the device (lamp, etc) is " | ||
Rating of Relays: Ensure that the relay can easily handle the mains voltage (110V AC or 240V AC), and the maximum current that will be used by the devices. For example, a light bulb might use 1.0 Amp current, whereas an electric room heater might use 20+ Amps. | Rating of Relays: Ensure that the relay can easily handle the mains voltage (110V AC or 240V AC), and the maximum current that will be used by the devices. For example, a light bulb might use 1.0 Amp current, whereas an electric room heater might use 20+ Amps. | ||
- | Overall, we should expect that Arduino fans might have kits in their bedrooms, and might decide to control the mains heating, lighting, ventilation, | + | Overall, we should expect that Arduino fans might have kits in their bedrooms, and might decide to control the mains heating, lighting, ventilation, |
+ | |||
+ | L' | ||
+ | |||
+ | Caractéristiques du relais : Assurez-vous que le relais peut facilement supporter la tension secteur (110 V AC ou 240 V AC), ainsi que la courant maximal absorbé par les appareils. Par exemple, une lampe à incandescence pourrait absorber 1 A, alors qu'un radiateur électrique pourrait utiliser 20 A ou plus. | ||
- | | + | En général, vous pouvez vous attendre à ce que des fans d' |
issue107/arduino.1459320978.txt.gz · Dernière modification : 2016/03/30 08:56 de auntiee