0% ont trouvé ce document utile (0 vote)
2 vues19 pages

Code Final

Ce document contient un code Arduino pour contrôler un ascenseur, incluant la gestion des boutons, capteurs, moteur, serrures et affichages. Il gère les modes normal et maintenance, ainsi que l'arrêt d'urgence, tout en affichant des informations sur un écran LCD et un affichage à 7 segments. Le code inclut des fonctions pour déplacer l'ascenseur, déverrouiller les portes et gérer les états des capteurs.

Transféré par

bougherbal melissa
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
2 vues19 pages

Code Final

Ce document contient un code Arduino pour contrôler un ascenseur, incluant la gestion des boutons, capteurs, moteur, serrures et affichages. Il gère les modes normal et maintenance, ainsi que l'arrêt d'urgence, tout en affichant des informations sur un écran LCD et un affichage à 7 segments. Le code inclut des fonctions pour déplacer l'ascenseur, déverrouiller les portes et gérer les états des capteurs.

Transféré par

bougherbal melissa
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd

#include <Wire.

h>

#include <LiquidCrystal_I2C.h>

// Définition des broches pour les boutons

const int button1Pin = 2;

const int button2Pin = 3;

const int button3Pin = 4;

const int maintenanceButtonPin = 24;

const int upButtonPin = 25;

const int downButtonPin = 26;

const int emergencyStopButtonPin = 27;

// Définition des broches pour les capteurs

const int sensor1Pin = 5;

const int sensor2Pin = 6;

const int sensor2_2Pin = 17;

const int sensor3Pin = 7;

// Définition des broches pour le contrôleur moteur

const int motorPin1 = 8;

const int motorPin2 = 9;

const int enablePin = 10;


// Broche pour les serrures électriques à chaque étage

const int lock1Pin = 11;

const int lock2Pin = 12;

const int lock3Pin = 13;

// Définition des broches pour l'afficheur 7 segments

const int segAPin = 14;

const int segBPin = 15;

const int segCPin = 16;

const int segDPin = 18;

const int segEPin = 19;

const int segFPin = 22;

const int segGPin = 23;

// Définition des broches pour les LEDs et le buzzer

const int redLedPin = 28;

const int greenLedPin = 29;

const int orangeLedPin = 30;

const int alarmPin = 31;

// Initialisation de l'afficheur LCD I2C


LiquidCrystal_I2C lcd(0x27, 16, 2); // Adresse I2C par défaut pour certains modules

// Vitesse du moteur

const int motorSpeed = 255; // Ajustez selon votre configuration

// Étage cible et étage actuel

int targetFloor = 0;

int currentFloor = 0;

bool isMoving = false;

bool isLockOpen = false;

bool isMaintenanceMode = false;

bool isEmergencyStopActive = false;

// Temps pour le déverrouillage des serrures (en millisecondes)

const unsigned long lockUnlockDelay = 10000;

unsigned long lockUnlockTime = 0;

// Temps pour laisser la porte ouverte (en millisecondes)

const unsigned long doorOpenDelay = 10000; // 5 secondes

unsigned long doorOpenTime = 0;

// Temps pour le verrouillage des serrures (en millisecondes)

unsigned long lockLockTime = 0; // Déclaré ici


// Prototypes de fonctions

void moveToFloor(int floor);

void moveUp();

void moveDown();

void stopMotor();

void updateCurrentFloor();

void unlockLock(int floor);

void lockLock(int floor);

void displayNumber(int number);

void updateLCD();

void clearLine(int line);

void activateEmergencyStop();

void deactivateEmergencyStop();

void updateModeIndicator();

void setup() {

// Initialisation des boutons en entrée avec résistances de pull-up

pinMode(button1Pin, INPUT_PULLUP);

pinMode(button2Pin, INPUT_PULLUP);

pinMode(button3Pin, INPUT_PULLUP);

pinMode(maintenanceButtonPin, INPUT_PULLUP);

pinMode(upButtonPin, INPUT_PULLUP);
pinMode(downButtonPin, INPUT_PULLUP);

pinMode(emergencyStopButtonPin, INPUT_PULLUP);

// Initialisation des capteurs en entrée

pinMode(sensor1Pin, INPUT);

pinMode(sensor2Pin, INPUT);

pinMode(sensor2_2Pin, INPUT);

pinMode(sensor3Pin, INPUT);

// Initialisation des broches du moteur en sortie

pinMode(motorPin1, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(enablePin, OUTPUT);

// Initialisation des broches des serrures en sortie

pinMode(lock1Pin, OUTPUT);

pinMode(lock2Pin, OUTPUT);

pinMode(lock3Pin, OUTPUT);

// Initialisation des broches de l'afficheur 7 segments en sortie

pinMode(segAPin, OUTPUT);

pinMode(segBPin, OUTPUT);

pinMode(segCPin, OUTPUT);
pinMode(segDPin, OUTPUT);

pinMode(segEPin, OUTPUT);

pinMode(segFPin, OUTPUT);

pinMode(segGPin, OUTPUT);

// Initialisation des broches pour les LEDs et le buzzer

pinMode(redLedPin, OUTPUT);

pinMode(greenLedPin, OUTPUT);

pinMode(orangeLedPin, OUTPUT);

pinMode(alarmPin, OUTPUT);

// Initialisation du moniteur série

[Link](9600);

// Initialisation de l'afficheur LCD I2C

[Link]();

[Link]();

[Link](0, 0);

[Link]("Ascenseur Ready");

// Initialisation des LEDs et de l'alarme

digitalWrite(redLedPin, LOW);

digitalWrite(greenLedPin, HIGH); // Mode normal par défaut


digitalWrite(orangeLedPin, LOW);

digitalWrite(alarmPin, LOW);

void loop() {

// Check if emergency stop button is pressed

if (digitalRead(emergencyStopButtonPin) == 1) {

if (!isEmergencyStopActive) {

activateEmergencyStop();

} else {

deactivateEmergencyStop();

delay(500); // Anti-rebond pour éviter les multiples activations

// Check if maintenance button is pressed to toggle maintenance mode

if (digitalRead(maintenanceButtonPin) == 1 && !isEmergencyStopActive) {

isMaintenanceMode = !isMaintenanceMode;

updateModeIndicator();

delay(500); // Anti-rebond pour éviter les multiples activations

// Normal mode operation


if (!isMaintenanceMode && !isEmergencyStopActive) {

// Check if any button is pressed and set the target floor

if (digitalRead(button1Pin) == 1) {

targetFloor = 1;

isMoving = true;

[Link]("Button 1 pressed, moving to floor 1");

[Link](0, 0);

[Link]("Moving to floor 1 ");

} else if (digitalRead(button2Pin) == 1) {

targetFloor = 2;

isMoving = true;

[Link]("Button 2 pressed, moving to floor 2");

[Link](0, 0);

[Link]("Moving to floor 2 ");

} else if (digitalRead(button3Pin) == 1) {

targetFloor = 3;

isMoving = true;

[Link]("Button 3 pressed, moving to floor 3");

[Link](0, 0);

[Link]("Moving to floor 3 ");

// Move the elevator to the target floor


if (isMoving && !isLockOpen) {

moveToFloor(targetFloor);

// Update the current floor based on the sensor readings

updateCurrentFloor();

// Check if the lock needs to be unlocked or locked

if (isLockOpen && millis() - lockUnlockTime >= lockUnlockDelay) {

lockLock(currentFloor);

} else if (!isLockOpen && isMoving == false && millis() - doorOpenTime >=


doorOpenDelay) {

lockLock(currentFloor);

// Update the 7-segment display with the current floor

displayNumber(currentFloor);

// Update the LCD display with the current floor and status

updateLCD();

} else if (isMaintenanceMode && !isEmergencyStopActive) { // Maintenance mode


operation

if (digitalRead(upButtonPin) == 1) {

moveUp();
[Link]("Maintenance: Moving Up");

delay(500); // Anti-rebond

} else if (digitalRead(downButtonPin) == 1) {

moveDown();

[Link]("Maintenance: Moving Down");

delay(500); // Anti-rebond

} else {

stopMotor();

void moveToFloor(int floor) {

[Link]("Current Floor: ");

[Link](currentFloor);

[Link](", Target Floor: ");

[Link](floor);

if (currentFloor < floor) {

moveUp();

} else if (currentFloor > floor) {

moveDown();

} else {
stopMotor();

[Link]("Arrivé à l'étage ");

[Link](floor);

[Link](0, 0);

[Link]("Arrived at floor ");

[Link](floor);

isMoving = false;

lockUnlockTime = millis(); // Enregistrer le temps d'arrivée à l'étage

doorOpenTime = millis(); // Enregistrer le temps d'ouverture de la porte

unlockLock(floor); // Déverrouiller la porte

currentFloor = floor; // Mettre à jour l'étage actuel

void moveUp() {

digitalWrite(motorPin1, HIGH);

digitalWrite(motorPin2, LOW);

analogWrite(enablePin, motorSpeed);

void moveDown() {

digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, HIGH);
analogWrite(enablePin, motorSpeed);

void stopMotor() {

digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

analogWrite(enablePin, 0);

void updateCurrentFloor() {

// Lire l'état des capteurs

int sensor1State = digitalRead(sensor1Pin);

int sensor2State = digitalRead(sensor2Pin);

int sensor2_2State = digitalRead(sensor2_2Pin);

int sensor3State = digitalRead(sensor3Pin);

// Afficher l'état des capteurs pour le débogage

[Link]("Sensor 1: ");

[Link](sensor1State);

[Link](", Sensor 2: ");

[Link](sensor2State);

[Link](", Sensor 2_2: ");

[Link](sensor2_2State);
[Link](", Sensor 3: ");

[Link](sensor3State);

// Mettre à jour l'étage actuel en fonction des lectures des capteurs

if (sensor1State == LOW) {

currentFloor = 1;

} else if (sensor2State == LOW && sensor2_2State == LOW) {

currentFloor = 2;

} else if (sensor3State == LOW) {

currentFloor = 3;

void unlockLock(int floor) {

[Link]("Unlocking lock for floor ");

[Link](floor);

if (floor == 1) {

digitalWrite(lock1Pin, HIGH); // Unlock the lock for floor 1

} else if (floor == 2) {

digitalWrite(lock2Pin, HIGH); // Unlock the lock for floor 2

} else if (floor == 3) {

digitalWrite(lock3Pin, HIGH); // Unlock the lock for floor 3

}
isLockOpen = true;

lockUnlockTime = millis(); // Enregistrer le temps de déverrouillage

void lockLock(int floor) {

[Link]("Locking lock for floor ");

[Link](floor);

if (floor == 1) {

digitalWrite(lock1Pin, LOW); // Lock the lock for floor 1

} else if (floor == 2) {

digitalWrite(lock2Pin, LOW); // Lock the lock for floor 2

} else if (floor == 3) {

digitalWrite(lock3Pin, LOW); // Lock the lock for floor 3

isLockOpen = false;

lockLockTime = millis(); // Enregistrer le temps de verrouillage

void displayNumber(int number) {

// Éteindre tous les segments

digitalWrite(segAPin, LOW);

digitalWrite(segBPin, LOW);

digitalWrite(segCPin, LOW);
digitalWrite(segDPin, LOW);

digitalWrite(segEPin, LOW);

digitalWrite(segFPin, LOW);

digitalWrite(segGPin, LOW);

// Activer les segments pour afficher le numéro

switch (number) {

case 1:

digitalWrite(segBPin, HIGH);

digitalWrite(segCPin, HIGH);

break;

case 2:

digitalWrite(segAPin, HIGH);

digitalWrite(segBPin, HIGH);

digitalWrite(segDPin, HIGH);

digitalWrite(segEPin, HIGH);

digitalWrite(segGPin, HIGH);

break;

case 3:

digitalWrite(segAPin, HIGH);

digitalWrite(segBPin, HIGH);

digitalWrite(segCPin, HIGH);

digitalWrite(segDPin, HIGH);
digitalWrite(segGPin, HIGH);

break;

default:

// Par défaut, afficher tous les segments pour indiquer un chiffre invalide

digitalWrite(segAPin, HIGH);

digitalWrite(segBPin, HIGH);

digitalWrite(segCPin, HIGH);

digitalWrite(segDPin, HIGH);

digitalWrite(segEPin, HIGH);

digitalWrite(segFPin, HIGH);

digitalWrite(segGPin, HIGH);

break;

void updateLCD() {

// Effacer la première ligne

clearLine(0);

[Link](0, 0);

[Link]("Floor: ");

[Link](currentFloor);

[Link](" ");

if (isMoving) {
[Link]("Moving");

} else {

[Link]("Stop ");

// Effacer la deuxième ligne

clearLine(1);

[Link](0, 1);

[Link]("Door: ");

if (isLockOpen) {

[Link]("Open ");

} else {

[Link]("Closed");

void clearLine(int line) {

[Link](0, line);

for (int i = 0; i < 16; i++) {

[Link](" ");

[Link](0, line);

}
void activateEmergencyStop() {

[Link]("Emergency Stop Activated");

stopMotor();

digitalWrite(alarmPin, HIGH); // Activer l'alarme

digitalWrite(redLedPin, HIGH); // Activer la LED rouge

digitalWrite(greenLedPin, LOW); // Désactiver la LED verte

digitalWrite(orangeLedPin, LOW); // Désactiver la LED orange

isEmergencyStopActive = true;

[Link](0, 0);

[Link]("EMERGENCY MODE ");

[Link](0, 1);

[Link](" ");

void deactivateEmergencyStop() {

[Link]("Emergency Stop Deactivated");

digitalWrite(alarmPin, LOW); // Désactiver l'alarme

digitalWrite(redLedPin, LOW); // Désactiver la LED rouge

isEmergencyStopActive = false;

updateModeIndicator();

[Link](0, 0);

[Link]("STOP DEACTIVATED ");


[Link](0, 1);

[Link](" ");

void updateModeIndicator() {

if (isMaintenanceMode) {

digitalWrite(greenLedPin, LOW); // Désactiver la LED verte

digitalWrite(orangeLedPin, HIGH); // Activer la LED orange

[Link](0, 0);

[Link]("MAINTENANCE MODE ");

} else {

digitalWrite(greenLedPin, HIGH); // Activer la LED verte

digitalWrite(orangeLedPin, LOW); // Désactiver la LED orange

[Link](0, 0);

[Link]("NORMAL MODE ");

Vous aimerez peut-être aussi